~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/raster3d/writeascii.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <sys/types.h>
 
4
#include <unistd.h>
 
5
#include <grass/gis.h>
 
6
#include <grass/raster3d.h>
 
7
 
 
8
/*!
 
9
 * \brief 
 
10
 *
 
11
 *  Writes the cell-values of <em>map</em> in ascii format to file 
 
12
 *  <em>fname</em>. The values are organized by horizontal slices.
 
13
 *
 
14
 *  \param map
 
15
 *  \param fname
 
16
 *  \return void
 
17
 */
 
18
 
 
19
void Rast3d_write_ascii(void *map, const char *fname)
 
20
{
 
21
    FILE *fp;
 
22
    DCELL d1 = 0;
 
23
    DCELL *d1p;
 
24
    FCELL *f1p;
 
25
    int x, y, z;
 
26
    int rows, cols, depths, typeIntern;
 
27
 
 
28
    Rast3d_get_coords_map(map, &rows, &cols, &depths);
 
29
    typeIntern = Rast3d_tile_type_map(map);
 
30
 
 
31
    d1p = &d1;
 
32
    f1p = (FCELL *) &d1;
 
33
 
 
34
    if (fname == NULL)
 
35
        fp = stdout;
 
36
    else if ((fp = fopen(fname, "w")) == NULL)
 
37
        Rast3d_fatal_error("Rast3d_write_ascii: can't open file to write\n");
 
38
 
 
39
    for (z = 0; z < depths; z++) {
 
40
        for (y = 0; y < rows; y++) {
 
41
            fprintf(fp, "z y x %d %d (%d - %d)\n", z, y, 0, cols - 1);
 
42
            for (x = 0; x < cols; x++) {
 
43
                Rast3d_get_value_region(map, x, y, z, d1p, typeIntern);
 
44
 
 
45
                if (typeIntern == FCELL_TYPE)
 
46
                    fprintf(fp, "%.18f ", *f1p);
 
47
                else
 
48
                    fprintf(fp, "%.50f ", d1);
 
49
            }
 
50
            fprintf(fp, "\n");
 
51
        }
 
52
    }
 
53
 
 
54
    if (fp != stdout)
 
55
        fclose(fp);
 
56
}