GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
wind_scan.c
Go to the documentation of this file.
1/*!
2 \file lib/gis/wind_scan.c
3
4 \brief GIS Library - Coordinate scanning functions.
5
6 SPDX-FileCopyrightText: 2001-2009, 2011 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Original author CERL
10 */
11
12#include <stdio.h>
13#include <grass/gis.h>
14
15static int scan_double(const char *, double *);
16
17/*!
18 \brief ASCII northing to double.
19
20 Converts the ASCII "northing" coordinate string in <i>buf</i> to its
21 double representation (into <i>northing</i>).
22
23 Supported projection codes (see gis.h):
24 - PROJECTION_XY
25 - PROJECTION_UTM
26 - PROJECTION_LL
27 - PROJECTION_OTHER
28
29 \param buf buffer hold string northing
30 \param[out] northing northing
31 \param projection projection code
32
33 \return 0 on error
34 \return 1 on success
35 */
36int G_scan_northing(const char *buf, double *northing, int projection)
37{
38 if (projection == PROJECTION_LL) {
39 if (!scan_double(buf, northing))
40 return G_lat_scan(buf, northing);
41
42 return 1;
43 }
44
45 return scan_double(buf, northing);
46}
47
48/*!
49 \brief ASCII easting to double.
50
51 Converts the ASCII "easting" coordinate string in <i>buf</i> to its
52 double representation (into <i>easting</i>).
53
54 Supported projection codes (see gis.h):
55 - PROJECTION_XY
56 - PROJECTION_UTM
57 - PROJECTION_LL
58 - PROJECTION_OTHER
59
60 \param buf buffer containing string easting
61 \param[out] easting easting
62 \param projection projection code
63
64 \return 0 on error
65 \return 1 on success
66 */
67int G_scan_easting(const char *buf, double *easting, int projection)
68{
69 if (projection == PROJECTION_LL) {
70 if (!scan_double(buf, easting))
71 return G_lon_scan(buf, easting);
72
73 return 1;
74 }
75
76 return scan_double(buf, easting);
77}
78
79/*!
80 \brief ASCII resolution to double.
81
82 Converts the ASCII "resolution" string in <i>buf</i> to its double
83 representation (into resolution).
84
85 Supported projection codes (see gis.h):
86 - PROJECTION_XY
87 - PROJECTION_UTM
88 - PROJECTION_LL
89 - PROJECTION_OTHER
90
91 \param buf buffer containing string resolution
92 \param[out] res resolution value
93 \param projection projection code
94
95 \return 0 on error
96 \return 1 on success
97 */
98int G_scan_resolution(const char *buf, double *res, int projection)
99{
100 if (projection == PROJECTION_LL) {
101 if (G_llres_scan(buf, res))
102 return (*res > 0.0);
103 }
104
105 return (scan_double(buf, res) && *res > 0.0);
106}
107
108static int scan_double(const char *buf, double *value)
109{
110 char junk[2];
111
112 /* use sscanf to convert buf to double
113 * make sure value doesn't have other characters after it */
114
115 *junk = 0;
116 *value = 0.0;
117
118 if (sscanf(buf, "%lf%1s", value, junk) == 1 && *junk == 0) {
119 while (*buf)
120 buf++;
121 buf--;
122
123 if (*buf >= 'A' && *buf <= 'Z')
124 return 0;
125 if (*buf >= 'a' && *buf <= 'z')
126 return 0;
127
128 return 1; /* success */
129 }
130
131 return 0; /* failure */
132}
int G_lon_scan(const char *, double *)
Definition ll_scan.c:50
int G_lat_scan(const char *, double *)
Definition ll_scan.c:45
int G_llres_scan(const char *, double *)
Definition ll_scan.c:55
#define PROJECTION_LL
Projection code - Latitude-Longitude.
Definition gis.h:126
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
Definition wind_scan.c:98
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
Definition wind_scan.c:36
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.
Definition wind_scan.c:67