~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to sites/s.out.ascii/main.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 *
4
 
 * MODULE:       s.out.ascii
5
 
 * AUTHOR(S):    Michael Shapiro CERL (original contributor)
6
 
 *               Radim Blazek <radim.blazek gmail.com> (GRASS 6)
7
 
 *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
8
 
 * PURPOSE:      
9
 
 * COPYRIGHT:    (C) 1999-2007 by the GRASS Development Team
10
 
 *
11
 
 *               This program is free software under the GNU General Public
12
 
 *               License (>=v2). Read the file COPYING that comes with GRASS
13
 
 *               for details.
14
 
 *
15
 
 *****************************************************************************/
16
 
#include <stdlib.h>
17
 
#include <string.h>
18
 
#include <grass/gis.h>
19
 
#include <grass/site.h>
20
 
#include <grass/glocale.h>
21
 
 
22
 
int main(int argc, char *argv[])
23
 
{
24
 
    char *mapset, *name;
25
 
    char ebuf[128], nbuf[128];
26
 
    Site *site;
27
 
    char *fs;
28
 
    int full, all, strip, n = 0, s = 0, d = 0;
29
 
    RASTER_MAP_TYPE c = -1;
30
 
    char msg[200];
31
 
    FILE *fd;
32
 
    struct Cell_head window;
33
 
    struct GModule *module;
34
 
    struct
35
 
    {
36
 
        struct Flag *full, *all, *strip;
37
 
    } flag;
38
 
    struct
39
 
    {
40
 
        struct Option *input, *fs;
41
 
    } parm;
42
 
    int G_trim_decimal();
43
 
 
44
 
    G_gisinit(argv[0]);
45
 
 
46
 
    module = G_define_module();
47
 
    module->keywords = _("sites");
48
 
    module->description =
49
 
        "Converts a GRASS site list file into an ASCII listing of "
50
 
        "site locations and their descriptions.";
51
 
 
52
 
    parm.input = G_define_option();
53
 
    parm.input->key = "input";
54
 
    parm.input->type = TYPE_STRING;
55
 
    parm.input->required = YES;
56
 
    parm.input->description = "name of a vector map to be output";
57
 
    parm.input->gisprompt = "old,vector,vector";
58
 
 
59
 
    parm.fs = G_define_option();
60
 
    parm.fs->key = "fs";
61
 
    parm.fs->key_desc = "character|space|tab";
62
 
    parm.fs->type = TYPE_STRING;
63
 
    parm.fs->required = NO;
64
 
    parm.fs->description = "Output field separator";
65
 
    parm.fs->answer = "space";
66
 
 
67
 
    flag.all = G_define_flag();
68
 
    flag.all->key = 'a';
69
 
    flag.all->description =
70
 
        "Output all sites (do not limit to current region)";
71
 
 
72
 
    flag.full = G_define_flag();
73
 
    flag.full->key = 'd';
74
 
    flag.full->description = "Include site attributes in the output";
75
 
 
76
 
    flag.strip = G_define_flag();
77
 
    flag.strip->key = 'i';
78
 
    flag.strip->description =
79
 
        "Include site attribute identifiers in the output";
80
 
 
81
 
    if (G_parser(argc, argv))
82
 
        exit(1);
83
 
    full = flag.full->answer;
84
 
    all = flag.all->answer;
85
 
    strip = flag.strip->answer;
86
 
 
87
 
    name = parm.input->answer;
88
 
    mapset = G_find_sites(name, "");
89
 
    if (mapset == NULL) {
90
 
        sprintf(msg, "sites file [%s] not found", name);
91
 
        G_fatal_error(msg);
92
 
    }
93
 
 
94
 
    if ((fs = parm.fs->answer)) {
95
 
        if (strcmp(fs, "space") == 0)
96
 
            fs = " ";
97
 
        else if (strcmp(fs, "tab") == 0)
98
 
            fs = "\t";
99
 
    }
100
 
    else
101
 
        fs = " ";
102
 
 
103
 
    if (!all)
104
 
        G_get_window(&window);
105
 
    fd = G_fopen_sites_old(name, mapset);
106
 
    if (fd == NULL) {
107
 
        sprintf(msg, "can't open sites file [%s]", name);
108
 
        G_fatal_error(msg);
109
 
    }
110
 
 
111
 
    if (G_site_describe(fd, &n, &c, &s, &d) != 0)
112
 
        G_fatal_error("failed to guess format");
113
 
    site = G_site_new_struct(c, n, s, d);
114
 
 
115
 
    while (G_site_get(fd, site) == 0) {
116
 
        if (all || G_site_in_region(site, &window)) {
117
 
            if (!full) {
118
 
                G_format_easting(site->east, ebuf, -1);
119
 
                G_format_northing(site->north, nbuf, -1);
120
 
                fprintf(stdout, "%s%s%s", ebuf, fs, nbuf);
121
 
                for (n = 0; n < site->dim_alloc; ++n) {
122
 
                    sprintf(nbuf, "%.8f", site->dim[n]);
123
 
                    G_trim_decimal(nbuf);
124
 
                    fprintf(stdout, "%s%s", fs, nbuf);
125
 
                }
126
 
                fprintf(stdout, "\n");
127
 
            }
128
 
            else {
129
 
                char *str = G_site_format(site, fs, strip);
130
 
 
131
 
                fprintf(stdout, "%s\n", str);
132
 
                G_free(str);
133
 
            }
134
 
        }
135
 
    }
136
 
    G_sites_close(fd);
137
 
    exit(0);
138
 
}