GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
writeascii.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <grass/G3d.h>
6 
18 void G3d_writeAscii(void *map, const char *fname)
19 {
20  FILE *fp;
21  double d1 = 0;
22  double *d1p;
23  float *f1p;
24  int x, y, z;
25  int rows, cols, depths, typeIntern;
26 
27  G3d_getCoordsMap(map, &rows, &cols, &depths);
28  typeIntern = G3d_tileTypeMap(map);
29 
30  d1p = &d1;
31  f1p = (float *)&d1;
32 
33  if (fname == NULL)
34  fp = stdout;
35  else if ((fp = fopen(fname, "w")) == NULL)
36  G3d_fatalError("G3d_writeAscii: can't open file to write\n");
37 
38  for (z = 0; z < depths; z++)
39  for (y = 0; y < rows; y++) {
40  fprintf(fp, "z y x %d %d (%d - %d)\n", z, y, 0, cols - 1);
41  for (x = 0; x < cols; x++) {
42  G3d_getValueRegion(map, x, y, z, d1p, typeIntern);
43 
44  if (typeIntern == FCELL_TYPE)
45  fprintf(fp, "%.18f ", *f1p);
46  else
47  fprintf(fp, "%.50f ", d1);
48  }
49  fprintf(fp, "\n");
50  }
51 
52  if (fp != stdout)
53  fclose(fp);
54 }
void G3d_getValueRegion(G3D_Map *map, int x, int y, int z, void *value, int type)
Returns in *value the cell-value of the cell with region-coordinate (x, y, z). The value returned is ...
Definition: tileio.c:244
int y
Definition: plot.c:34
return NULL
Definition: dbfopen.c:1394
tuple cols
fclose(fd)
int G3d_tileTypeMap(G3D_Map *map)
Returns the type in which tiles of map are stored in memory.
Definition: headerinfo.c:161
void G3d_fatalError(const char *,...)
This function prints the error message msg, and terminates the program with an error status...
Definition: g3derror.c:58
void G3d_getCoordsMap(G3D_Map *map, int *rows, int *cols, int *depths)
Returns the size of the region of map in cells.
Definition: headerinfo.c:19
void G3d_writeAscii(void *map, const char *fname)
Writes the cell-values of map in ascii format to file fname. The values are organized by horizontal s...
Definition: writeascii.c:18