2
/****************************************************************************
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>
9
* COPYRIGHT: (C) 1999-2007 by the GRASS Development Team
11
* This program is free software under the GNU General Public
12
* License (>=v2). Read the file COPYING that comes with GRASS
15
*****************************************************************************/
18
#include <grass/gis.h>
19
#include <grass/site.h>
20
#include <grass/glocale.h>
22
int main(int argc, char *argv[])
25
char ebuf[128], nbuf[128];
28
int full, all, strip, n = 0, s = 0, d = 0;
29
RASTER_MAP_TYPE c = -1;
32
struct Cell_head window;
33
struct GModule *module;
36
struct Flag *full, *all, *strip;
40
struct Option *input, *fs;
46
module = G_define_module();
47
module->keywords = _("sites");
49
"Converts a GRASS site list file into an ASCII listing of "
50
"site locations and their descriptions.";
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";
59
parm.fs = G_define_option();
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";
67
flag.all = G_define_flag();
69
flag.all->description =
70
"Output all sites (do not limit to current region)";
72
flag.full = G_define_flag();
74
flag.full->description = "Include site attributes in the output";
76
flag.strip = G_define_flag();
77
flag.strip->key = 'i';
78
flag.strip->description =
79
"Include site attribute identifiers in the output";
81
if (G_parser(argc, argv))
83
full = flag.full->answer;
84
all = flag.all->answer;
85
strip = flag.strip->answer;
87
name = parm.input->answer;
88
mapset = G_find_sites(name, "");
90
sprintf(msg, "sites file [%s] not found", name);
94
if ((fs = parm.fs->answer)) {
95
if (strcmp(fs, "space") == 0)
97
else if (strcmp(fs, "tab") == 0)
104
G_get_window(&window);
105
fd = G_fopen_sites_old(name, mapset);
107
sprintf(msg, "can't open sites file [%s]", name);
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);
115
while (G_site_get(fd, site) == 0) {
116
if (all || G_site_in_region(site, &window)) {
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);
126
fprintf(stdout, "\n");
129
char *str = G_site_format(site, fs, strip);
131
fprintf(stdout, "%s\n", str);