-
-
Notifications
You must be signed in to change notification settings - Fork 293
/
user1.c
800 lines (681 loc) · 20.4 KB
/
user1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/*
****************************************************************************
*
* MODULE: v.vol.rst: program for 3D (volume) interpolation and geometry
* analysis from scattered point data using regularized spline
* with tension
*
* AUTHOR(S): Original program (1989) and various modifications:
* Lubos Mitas
*
* GRASS 4.2, GRASS 5.0 version and modifications:
* H. Mitasova, I. Kosinovsky, D. Gerdes, J. Hofierka
*
* PURPOSE: v.vol.rst interpolates the values to 3-dimensional grid from
* point data (climatic stations, drill holes etc.) given in a
* 3D vector point input. Output grid3 file is elev.
* Regularized spline with tension is used for the
* interpolation.
*
* COPYRIGHT: (C) 1989, 1993, 2000 L. Mitas, H. Mitasova,
* I. Kosinovsky, D. Gerdes, J. Hofierka
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/raster3d.h>
#include <grass/dbmi.h>
#include <grass/vector.h>
#include <grass/bitmap.h>
#include <grass/glocale.h>
#include "oct.h"
#include "surf.h"
#include "dataoct.h"
#include "userextern.h"
#include "userglobs.h"
#include "user.h"
/*
x,y,z - input data
npoint - number of input data
az- interpolated values z for output grid
adx,ady, ... - estimation of derivatives for output grid
xmin ... - coordinates of corners of output grid
subroutines
INPUT - input of data x,y,z (test function or measured data)
OUTGR - output of gridded data and derivatives/sec.parameters
*/
/*
INPUT now reads site files using the new, multi-attribute format
(mca 2/12/96)
*/
int INPUT(struct Map_info *In, char *column, char *scol, char *wheresql)
{
struct quadruple *point;
double x, y, z, w, nz = 0., sm;
double c1, c2, c3, c4, c5, c6, nsg;
int i, j, k = 0, a, irev, cfmask;
int ddisk = 0;
double deltx, delty, deltz;
int first_time = 1;
CELL *cellmask;
const char *mapsetm;
char buf[500];
int cat, intval;
struct field_info *Fi;
dbDriver *Driver;
dbCatValArray cvarr, sarray;
int nrec, nrec1, ctype, sctype;
struct line_pnts *Points;
struct line_cats *Cats;
OUTRANGE = 0;
NPOINT = 0;
dmin = dmin * dmin;
/* Read attributes */
db_CatValArray_init(&cvarr);
if (scol != NULL)
db_CatValArray_init(&sarray);
Fi = Vect_get_field(In, 1);
if (Fi == NULL)
G_fatal_error(_("Unable to get layer info for vector map"));
Driver = db_start_driver_open_database(Fi->driver, Fi->database);
if (Driver == NULL)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
Fi->database, Fi->driver);
nrec =
db_select_CatValArray(Driver, Fi->table, Fi->key, column, wheresql,
&cvarr);
ctype = cvarr.ctype;
G_debug(3, "nrec = %d", nrec);
if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE)
G_fatal_error(_("Column type of wcolumn is not supported (must be integer or double)"));
if (nrec < 0)
G_fatal_error(_("Unable to select data from table"));
G_message("%d records selected from table", nrec);
if (scol != NULL) {
nrec1 =
db_select_CatValArray(Driver, Fi->table, Fi->key, scol, wheresql,
&sarray);
sctype = cvarr.ctype;
if (sctype == -1)
G_fatal_error(_("Cannot read column type of smooth column"));
if (sctype == DB_C_TYPE_DATETIME)
G_fatal_error
(_("Column type of smooth column (datetime) is not supported"));
if (sctype != DB_C_TYPE_INT && sctype != DB_C_TYPE_DOUBLE)
G_fatal_error(_("Column type of smooth column is not supported (must be integer or double)"));
}
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
Vect_rewind(In);
while (1) {
int ival, type, ret;
if (-1 == (type = Vect_read_next_line(In, Points, Cats)))
G_fatal_error(_("Unable to read vector map"));
if (type == -2)
break; /* EOF */
if (!(type & GV_POINTS))
continue;
Vect_cat_get(Cats, 1, &cat);
if (cat < 0) {
G_warning(_("Point without category"));
continue;
}
x = Points->x[0];
y = Points->y[0];
z = Points->z[0];
if (ctype == DB_C_TYPE_INT) {
ret = db_CatValArray_get_value_int(&cvarr, cat, &ival);
w = ival;
}
else { /* DB_C_TYPE_DOUBLE */
ret = db_CatValArray_get_value_double(&cvarr, cat, &w);
}
if (ret != DB_OK) {
if (wheresql != NULL)
/* G_message(_("Database record for cat %d not used due to SQL statement")); */
/* do nothing in this case to not confuse user. Or implement second cat list */
;
else
G_warning(_("No record for category %d in table <%s>"), cat,
Fi->table);
continue;
}
if (rsm == -1 && scol != NULL) {
if (sctype == DB_C_TYPE_INT) {
ret = db_CatValArray_get_value_int(&sarray, cat, &intval);
sm = intval;
}
else { /* DB_C_TYPE_DOUBLE */
ret = db_CatValArray_get_value_double(&sarray, cat, &sm);
}
}
G_debug(3, "%f %f %f %f", x, y, z, w);
k++;
w = w * wmult;
z = z * zmult;
c1 = x - ((struct octdata *)(root->data))->x_orig;
c2 = ((struct octdata *)(root->data))->x_orig +
((struct octdata *)(root->data))->n_cols * ew_res - x;
c3 = y - ((struct octdata *)(root->data))->y_orig;
c4 = ((struct octdata *)(root->data))->y_orig +
((struct octdata *)(root->data))->n_rows * ns_res - y;
c5 = z - ((struct octdata *)(root->data))->z_orig;
c6 = ((struct octdata *)(root->data))->z_orig +
((struct octdata *)(root->data))->n_levs * tb_res - z;
if (!
((c1 >= 0) && (c2 >= 0) && (c3 >= 0) && (c4 >= 0) && (c5 >= 0) &&
(c6 >= 0))) {
if (!OUTRANGE) {
G_warning(_("Some points outside of region -- will ignore..."));
}
OUTRANGE++;
}
else {
if (!(point = point_new(x, y, z, w, sm))) {
clean();
G_fatal_error(_("Cannot allocate memory for point"));
}
a = OT_insert_oct(point, root);
if (a == 0) {
NPOINT++;
}
if (a < 0) {
G_warning(_("Can't insert %lf,%lf,%lf,%lf,%lf a=%d"), x, y, z,
w, sm, a);
return -1;
}
if (first_time) {
first_time = 0;
xmin = x;
ymin = y;
zmin = z;
wmin = w;
xmax = x;
ymax = y;
zmax = z;
wmax = w;
}
xmin = amin1(xmin, x);
ymin = amin1(ymin, y);
zmin = amin1(zmin, z);
wmin = amin1(wmin, w);
xmax = amax1(xmax, x);
ymax = amax1(ymax, y);
zmax = amax1(zmax, z);
wmax = amax1(wmax, w);
}
} /* while */
db_CatValArray_free(&cvarr);
c1 = xmin - ((struct octdata *)(root->data))->x_orig;
c2 = ((struct octdata *)(root->data))->x_orig +
((struct octdata *)(root->data))->n_cols * ew_res - xmax;
c3 = ymin - ((struct octdata *)(root->data))->y_orig;
c4 = ((struct octdata *)(root->data))->y_orig +
((struct octdata *)(root->data))->n_rows * ns_res - ymax;
c5 = zmin - ((struct octdata *)(root->data))->z_orig;
c6 = ((struct octdata *)(root->data))->z_orig +
((struct octdata *)(root->data))->n_levs * tb_res - zmax;
if ((c1 > 5 * ew_res) || (c2 > 5 * ew_res) ||
(c3 > 5 * ns_res) || (c4 > 5 * ns_res) ||
(c5 > 5 * tb_res) || (c6 > 5 * tb_res)) {
static int once = 0;
if (!once) {
once = 1;
G_warning(_("Strip exists with insufficient data"));
}
}
nz = wmin;
totsegm = translate_oct(root, ((struct octdata *)(root->data))->x_orig,
((struct octdata *)(root->data))->y_orig,
((struct octdata *)(root->data))->z_orig, nz);
if (!totsegm) {
clean();
G_fatal_error(_("Zero segments!"));
}
((struct octdata *)(root->data))->x_orig = 0;
((struct octdata *)(root->data))->y_orig = 0;
((struct octdata *)(root->data))->z_orig = 0; /* was commented out */
if (outz != NULL)
ddisk += disk;
if (gradient != NULL)
ddisk += disk;
if (aspect1 != NULL)
ddisk += disk;
if (ncurv != NULL)
ddisk += disk;
if (gcurv != NULL)
ddisk += disk;
if (mcurv != NULL)
ddisk += disk;
G_message
("Processing all selected output files will require %d bytes of disk space for temp files",
ddisk);
/*
fprintf(stderr,"xmin=%lf,xmax=%lf,ymin=%lf,ymax=%lf,zmin=%lf,zmax=%lf,wmin=%lf,wmax=%lf\n",xmin,xmax,ymin,ymax,zmin,zmax,wmin,wmax);
*/
fprintf(stderr, "\n");
if (OUTRANGE > 0)
G_warning
(_("There are points outside specified 2D/3D region--ignored %d points (total points: %d)"),
OUTRANGE, k);
if (NPOINT > 0)
G_warning
(_("Points are more dense than specified 'DMIN'--ignored %d points (remain %d)"),
NPOINT, k - NPOINT);
NPOINT = k - NPOINT - NPT - OUTRANGE;
if (NPOINT < KMIN) {
if (NPOINT != 0) {
G_warning
(_("%d points given for interpolation (after thinning) is less than given NPMIN=%d"),
NPOINT, KMIN);
KMIN = NPOINT;
}
else {
fprintf(stderr, "ERROR: zero points in the given region!\n");
return -1;
}
}
if (NPOINT > KMAXPOINTS && KMIN <= KMAX) {
fprintf(stderr,
"ERROR: segmentation parameters set to invalid values: npmin = %d, segmax = %d \n",
KMIN, KMAX);
fprintf(stderr,
"for smooth connection of segments, npmin > segmax (see manual) \n");
return -1;
}
if (NPOINT < KMAXPOINTS && KMAX != KMAXPOINTS)
G_warning
(_("There is less than %d points for interpolation, no segmentation is necessary, to run the program faster, set segmax=%d (see manual)"),
KMAXPOINTS, KMAXPOINTS);
deltx = xmax - xmin;
delty = ymax - ymin;
deltz = zmax - zmin;
nsg = (double)NPOINT / (double)KMIN;
dnorm = deltx * delty * deltz / nsg;
nsg = 3.0;
nsg = 1. / nsg;
dnorm = pow(dnorm, nsg);
/* DEBUG
if (fd4 != NULL)
fprintf (fd4, "deltx,delty %f %f \n", deltx, delty);
*/
nsizc = current_region.cols; /* ((int)(deltx/ew_res))+1; */
nsizr = current_region.rows; /* ((int)(delty/ns_res))+1; */
NPT = k;
x0utm = 0.;
y0utm = 0.;
z0utm = 0.;
/** create a bitmap mask from given raster map **/
if (maskmap != NULL) {
mapsetm = G_find_raster2(maskmap, "");
if (!mapsetm) {
clean();
G_fatal_error(_("Mask raster map [%s] not found"), maskmap);
}
bitmask = BM_create(nsizc, nsizr);
cellmask = Rast_allocate_c_buf();
cfmask = Rast_open_old(maskmap, mapsetm);
for (i = 0; i < nsizr; i++) {
irev = nsizr - i - 1;
Rast_get_c_row(cfmask, cellmask, i);
for (j = 0; j < nsizc; j++) {
if ((cellmask[j] == 0) || Rast_is_c_null_value(&cellmask[j]))
BM_set(bitmask, j, irev, 0);
else
BM_set(bitmask, j, irev, 1);
}
}
G_message(_("Bitmap mask created"));
}
return 1;
}
/*
* OUTGR now writes 3d raster maps (mca 2/15/96)
*/
int OUTGR()
{
void *cf1, *cf2, *cf3, *cf4, *cf5, *cf6, *cf7;
int read_val;
FCELL *cell;
float *data;
int i, iarc, cnt;
int bmask = 1;
int x, y;
float value;
if ((cellinp != NULL) && (cellout != NULL)) {
cell = Rast_allocate_f_buf();
for (i = 0; i < nsizr; i++) {
/* seek to the right row */
G_fseek
(Tmp_fd_cell, ((off_t)(nsizr - 1 - i) * nsizc * sizeof(FCELL)),
0);
fread(cell, sizeof(FCELL), nsizc, Tmp_fd_cell);
Rast_put_f_row(fdcout, cell);
}
}
/*** Initialize output g3d region ***/
current_region.bottom = z_orig_in;
current_region.top = nsizl * tb_res_in + z_orig_in;
if (!(data = (float *)G_malloc(sizeof(float) * nsizr * nsizc * nsizl))) {
clean();
G_fatal_error(_("Out of memory"));
}
/*** Write elevation results ***/
if (outz != NULL) {
cf1 = Rast3d_open_new_opt_tile_size(outz, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf1 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), outz);
}
/* seek to the beginning */
G_fseek(Tmp_fd_z, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_z);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt];
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf1, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf1) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), outz);
} else
G_message(_("3D raster map <%s> created"), outz);
}
/*** Write out the gradient results ***/
if (gradient != NULL) {
cf2 = Rast3d_open_new_opt_tile_size(gradient, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf2 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), gradient);
}
/* seek to the beginning */
G_fseek(Tmp_fd_dx, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dx);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt];
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf2, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf2) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), gradient);
} else
G_message(_("3D raster map <%s> created"), gradient);
}
/*** Write out aspect1 results ***/
if (aspect1 != NULL) {
cf3 = Rast3d_open_new_opt_tile_size(aspect1, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf3 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), aspect1);
}
/* seek to the beginning */
G_fseek(Tmp_fd_dy, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dy);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt] * 180 / M_PI;
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf3, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf3) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), aspect1);
} else
G_message(_("3D raster map <%s> created"), aspect1);
}
/*** Write out aspect2 results ***/
if (aspect2 != NULL) {
cf4 = Rast3d_open_new_opt_tile_size(aspect2, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf4 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), aspect2);
}
/* seek to the beginning */
G_fseek(Tmp_fd_dz, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dz);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt] * 180 / M_PI;
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf4, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf4) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), aspect2);
} else
G_message(_("3D raster map <%s> created"), aspect2);
}
/*** Write out ncurv results ***/
if (ncurv != NULL) {
cf5 = Rast3d_open_new_opt_tile_size(ncurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf5 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), ncurv);
}
/* seek to the beginning */
G_fseek(Tmp_fd_xx, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_xx);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt];
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf5, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf5) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), ncurv);
} else
G_message(_("3D raster map <%s> created"), ncurv);
}
/*** Write out gcurv results ***/
if (gcurv != NULL) {
cf6 = Rast3d_open_new_opt_tile_size(gcurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf6 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), gcurv);
}
/* seek to the beginning */
G_fseek(Tmp_fd_yy, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_yy);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt];
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf6, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf6) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), gcurv);
} else
G_message(_("3D raster map <%s> created"), gcurv);
}
/*** Write mcurv results ***/
if (mcurv != NULL) {
cf7 = Rast3d_open_new_opt_tile_size(mcurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
if (cf7 == NULL) {
clean();
G_fatal_error(_("Unable to open %s for writing"), mcurv);
}
/* seek to the beginning */
G_fseek(Tmp_fd_xy, 0L, 0);
/* Read data in from temp file */
read_val =
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_xy);
if (read_val < 0) {
clean();
G_fatal_error(_("Unable to read data from temp file"));
}
cnt = 0;
for (iarc = 0; iarc < nsizl; iarc++) {
for (y = nsizr - 1; y >= 0; y--) { /* changed by AV */
for (x = 0; x < nsizc; x++) {
if (maskmap != NULL)
bmask = BM_get(bitmask, x, nsizr - y - 1);
else
bmask = 1;
value = data[cnt];
if (!bmask)
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
if (Rast3d_put_float(cf7, x, y, iarc, value) == 0) {
clean();
G_fatal_error(
_("Error writing cell (%d,%d,%d) with value %f"),
x, y, iarc, value);
}
cnt++;
}
}
}
/* Close the file */
if (Rast3d_close(cf7) == 0) {
clean();
G_fatal_error(_("Error closing output file %s"), mcurv);
} else
G_message(_("3D raster map <%s> created"), mcurv);
}
G_free(data);
return 1;
}