-
-
Notifications
You must be signed in to change notification settings - Fork 288
/
writeascii.c
56 lines (48 loc) · 1.33 KB
/
writeascii.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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/raster3d.h>
/*!
* \brief
*
* Writes the cell-values of <em>map</em> in ascii format to file
* <em>fname</em>. The values are organized by horizontal slices.
*
* \param map
* \param fname
* \return void
*/
void Rast3d_write_ascii(void *map, const char *fname)
{
FILE *fp;
DCELL d1 = 0;
DCELL *d1p;
FCELL *f1p;
int x, y, z;
int rows, cols, depths, typeIntern;
Rast3d_get_coords_map(map, &rows, &cols, &depths);
typeIntern = Rast3d_tile_type_map(map);
d1p = &d1;
f1p = (FCELL *) &d1;
if (fname == NULL)
fp = stdout;
else if ((fp = fopen(fname, "w")) == NULL)
Rast3d_fatal_error("Rast3d_write_ascii: can't open file to write\n");
for (z = 0; z < depths; z++) {
for (y = 0; y < rows; y++) {
fprintf(fp, "z y x %d %d (%d - %d)\n", z, y, 0, cols - 1);
for (x = 0; x < cols; x++) {
Rast3d_get_value_region(map, x, y, z, d1p, typeIntern);
if (typeIntern == FCELL_TYPE)
fprintf(fp, "%.18f ", *f1p);
else
fprintf(fp, "%.50f ", d1);
}
fprintf(fp, "\n");
}
}
if (fp != stdout)
fclose(fp);
}