-
-
Notifications
You must be signed in to change notification settings - Fork 294
/
wind_scan.c
134 lines (101 loc) · 2.88 KB
/
wind_scan.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*!
\file lib/gis/wind_scan.c
\brief GIS Library - Coordinate scanning functions.
(C) 2001-2009, 2011 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Original author CERL
*/
#include <stdio.h>
#include <grass/gis.h>
static int scan_double(const char *, double *);
/*!
\brief ASCII northing to double.
Converts the ASCII "northing" coordinate string in <i>buf</i> to its
double representation (into <i>northing</i>).
Supported projection codes (see gis.h):
- PROJECTION_XY
- PROJECTION_UTM
- PROJECTION_LL
- PROJECTION_OTHER
\param buf buffer hold string northing
\param[out] northing northing
\param projection projection code
\return 0 on error
\return 1 on success
*/
int G_scan_northing(const char *buf, double *northing, int projection)
{
if (projection == PROJECTION_LL) {
if (!scan_double(buf, northing))
return G_lat_scan(buf, northing);
return 1;
}
return scan_double(buf, northing);
}
/*!
\brief ASCII easting to double.
Converts the ASCII "easting" coordinate string in <i>buf</i> to its
double representation (into <i>easting</i>).
Supported projection codes (see gis.h):
- PROJECTION_XY
- PROJECTION_UTM
- PROJECTION_LL
- PROJECTION_OTHER
\param buf buffer containing string easting
\param[out] easting easting
\param projection projection code
\return 0 on error
\return 1 on success
*/
int G_scan_easting(const char *buf, double *easting, int projection)
{
if (projection == PROJECTION_LL) {
if (!scan_double(buf, easting))
return G_lon_scan(buf, easting);
return 1;
}
return scan_double(buf, easting);
}
/*!
\brief ASCII resolution to double.
Converts the ASCII "resolution" string in <i>buf</i> to its double
representation (into resolution).
Supported projection codes (see gis.h):
- PROJECTION_XY
- PROJECTION_UTM
- PROJECTION_LL
- PROJECTION_OTHER
\param buf buffer containing string resolution
\param[out] resolution resolution value
\param projection projection code
\return 0 on error
\return 1 on success
*/
int G_scan_resolution(const char *buf, double *res, int projection)
{
if (projection == PROJECTION_LL) {
if (G_llres_scan(buf, res))
return (*res > 0.0);
}
return (scan_double(buf, res) && *res > 0.0);
}
static int scan_double(const char *buf, double *value)
{
char junk[2];
/* use sscanf to convert buf to double
* make sure value doesn't have other characters after it */
*junk = 0;
*value = 0.0;
if (sscanf(buf, "%lf%1s", value, junk) == 1 && *junk == 0) {
while (*buf)
buf++;
buf--;
if (*buf >= 'A' && *buf <= 'Z')
return 0;
if (*buf >= 'a' && *buf <= 'z')
return 0;
return 1; /* success */
}
return 0; /* failure */
}