GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <sys/types.h> 00004 #include <unistd.h> 00005 #include <grass/G3d.h> 00006 00018 void G3d_writeAscii(void *map, const char *fname) 00019 { 00020 FILE *fp; 00021 double d1 = 0; 00022 double *d1p; 00023 float *f1p; 00024 int x, y, z; 00025 int rows, cols, depths, typeIntern; 00026 00027 G3d_getCoordsMap(map, &rows, &cols, &depths); 00028 typeIntern = G3d_tileTypeMap(map); 00029 00030 d1p = &d1; 00031 f1p = (float *)&d1; 00032 00033 if (fname == NULL) 00034 fp = stdout; 00035 else if ((fp = fopen(fname, "w")) == NULL) 00036 G3d_fatalError("G3d_writeAscii: can't open file to write\n"); 00037 00038 for (z = 0; z < depths; z++) 00039 for (y = 0; y < rows; y++) { 00040 fprintf(fp, "z y x %d %d (%d - %d)\n", z, y, 0, cols - 1); 00041 for (x = 0; x < cols; x++) { 00042 G3d_getValueRegion(map, x, y, z, d1p, typeIntern); 00043 00044 if (typeIntern == FCELL_TYPE) 00045 fprintf(fp, "%.18f ", *f1p); 00046 else 00047 fprintf(fp, "%.50f ", d1); 00048 } 00049 fprintf(fp, "\n"); 00050 } 00051 00052 if (fp != stdout) 00053 fclose(fp); 00054 }