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