GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Macros
Pages
ll_format.c
Go to the documentation of this file.
1
2
/***************************************************************
3
G_lat_format (lat, buf)
4
double lat;
5
char *buf;
6
7
G_lon_format (lon, buf)
8
double lon;
9
char *buf;
10
11
G_llres_format (res, buf)
12
double res;
13
char *buf;
14
15
formats lat (latitude in degrees), or lon (longitude in degrees)
16
into buf as dd:mm:ssH, where H (hemishpere) is
17
N for nothern hemishpere, S for southern,
18
W for western hemishpere, E for eastern
19
none for resolution
20
(lat > 0 is northern, lat < 0 is southern)
21
(lon > 0 is eastern, lon < 0 is western)
22
23
Note: lat should be in the range -90 to 90s, but
24
the range is NOT checked by G_lat_format().
25
lon can be anything, but
26
values outside [-180,180] are moved into this range
27
by adding (or subtracting) 360.
28
29
NOTE: These routines are used by G_format_northing(), G_format_easting(), and
30
G_format_resolution(). Those routines are intended to provide
31
a general interface to window values and should be used instead of
32
these projection specific routines. In other words, these routines
33
are for the library only, programmers shouldn't use them.
34
***************************************************************/
35
#include <grass/gis.h>
36
#include <string.h>
37
38
static
int
format(
char
*,
int
,
int
,
double
,
char
);
39
static
int
ll_parts(
double
,
int
*,
int
*,
double
*);
40
41
int
G_lat_format
(
double
lat,
char
*buf)
42
{
43
int
d, m;
44
char
h
;
45
double
s
;
46
47
G_lat_parts
(lat, &d, &m, &s, &h);
48
format(buf, d, m, s, h);
49
50
return
0;
51
}
52
53
char
*
G_lat_format_string
(
void
)
54
{
55
return
"dd:mm:ss{N|S}"
;
56
}
57
58
int
G_lon_format
(
double
lon,
char
*buf)
59
{
60
int
d, m;
61
char
h
;
62
double
s
;
63
64
G_lon_parts
(lon, &d, &m, &s, &h);
65
format(buf, d, m, s, h);
66
67
return
0;
68
}
69
char
*
G_lon_format_string
(
void
)
70
{
71
return
"ddd:mm:ss{E|W}"
;
72
}
73
74
int
G_llres_format
(
double
res,
char
*buf)
75
{
76
int
d, m;
77
char
h
;
78
double
s
;
79
80
G_lat_parts
(res, &d, &m, &s, &h);
81
h = 0;
82
format(buf, d, m, s, h);
83
84
return
0;
85
}
86
char
*
G_llres_format_string
(
void
)
87
{
88
return
"dd:mm:ss"
;
89
}
90
91
92
static
int
format(
char
*buf,
int
d,
int
m,
double
s
,
char
h
)
93
{
94
char
temp[50];
95
double
ss;
96
97
sprintf(temp,
"%f"
, s);
98
sscanf(temp,
"%lf"
, &ss);
99
if
(ss >= 60) {
100
ss = 0;
/* force it to zero */
101
if
(++m >= 60) {
102
m = 0;
103
d++;
104
}
105
}
106
107
if
(ss < 10.0)
108
sprintf(temp,
"0%f"
, ss);
109
else
110
sprintf(temp,
"%f"
, ss);
111
G_trim_decimal
(temp);
112
if
(strcmp(temp,
"00"
) != 0 && strcmp(temp,
"0"
) != 0)
113
sprintf(buf,
"%d:%02d:%s%c"
, d, m, temp, h);
114
else
if
(m > 0)
115
sprintf(buf,
"%d:%02d%c"
, d, m, h);
116
else
if
(d > 0)
117
sprintf(buf,
"%d%c"
, d, h);
118
else
119
sprintf(buf,
"0"
);
120
121
return
0;
122
}
123
124
int
G_lat_parts
(
double
lat,
/* lat in degrees to be split into parts */
125
int
*d,
int
*m,
/* degrees, minutes */
126
double
*s,
/* seconds */
127
char
*h
/* hemisphere */
128
)
129
{
130
if
(lat < 0) {
131
*h =
'S'
;
132
lat = -lat;
133
}
134
else
135
*h =
'N'
;
136
137
ll_parts(lat, d, m, s);
138
139
return
0;
140
}
141
142
int
G_lon_parts
(
double
lon,
/* lon in degrees to be split into parts */
143
int
*d,
int
*m,
/* degrees, minutes */
144
double
*s,
/* seconds */
145
char
*h
/* hemisphere */
146
)
147
{
148
while
(lon > 180.0)
149
lon -= 360.0;
150
while
(lon < -180.0)
151
lon += 360.0;
152
153
if
(lon < 0) {
154
*h =
'W'
;
155
lon = -lon;
156
}
157
else
158
*h =
'E'
;
159
160
ll_parts(lon, d, m, s);
161
162
return
0;
163
}
164
165
static
int
ll_parts(
double
ll,
/* ll in degrees to be split into parts */
166
int
*d,
int
*m,
/* degrees, minutes */
167
double
*s)
168
{
/* seconds */
169
if
(ll == 0.0) {
170
*d = 0;
171
*m = 0;
172
*s = 0.0;
173
}
174
else
{
175
*d = ll;
176
*m = (ll - *d) * 60;
177
if
(*m < 0)
178
*m = 0;
179
*s = ((ll - *d) * 60 - *m) * 60;
180
if
(*s < 0)
181
*s = 0;
182
}
183
184
return
0;
185
}
lib
gis
ll_format.c
Generated on Sat Oct 5 2013 12:11:08 for GRASS Programmer's Manual by
1.8.4