GRASS GIS 7 Programmer's Manual  7.0.4(2016)-r00000
wind_format.c
Go to the documentation of this file.
1 
14 #include <stdio.h>
15 #include <grass/gis.h>
16 
17 static void format_double(double, char *, int);
18 
29 void G_format_northing(double north, char *buf, int projection)
30 {
31  if (projection == PROJECTION_LL)
32  G_lat_format(north, buf);
33  else if (projection == -1)
34  format_double(north, buf, TRUE);
35  else
36  format_double(north, buf, FALSE);
37 }
38 
49 void G_format_easting(double east, char *buf, int projection)
50 {
51  if (projection == PROJECTION_LL)
52  G_lon_format(east, buf);
53  else if (projection == -1)
54  format_double(east, buf, TRUE);
55  else
56  format_double(east, buf, FALSE);
57 }
58 
69 void G_format_resolution(double res, char *buf, int projection)
70 {
71  if (projection == PROJECTION_LL)
72  G_llres_format(res, buf);
73  else if (projection == -1)
74  format_double(res, buf, TRUE);
75  else
76  format_double(res, buf, FALSE);
77 }
78 
79 /*
80  * 'full_prec' is boolean, FALSE uses %.8f, TRUE uses %.15g
81  * The reason to have this is that for lat/lon "%.8f" is not
82  * enough to preserve fidelity once converted back into D:M:S,
83  * which leads to rounding errors, especially for resolution.
84  */
85 static void format_double(double value, char *buf, int full_prec)
86 {
87  if (full_prec)
88  sprintf(buf, "%.15g", value);
89  else
90  sprintf(buf, "%.8f", value);
91 
92  G_trim_decimal(buf);
93 }
#define FALSE
Definition: dbfopen.c:117
void G_trim_decimal(char *buf)
Removes trailing zeros from decimal number.
Definition: trim_dec.c:24
void G_format_easting(double east, char *buf, int projection)
Easting to ASCII.
Definition: wind_format.c:49
void G_format_resolution(double res, char *buf, int projection)
Resolution to ASCII.
Definition: wind_format.c:69
void G_format_northing(double north, char *buf, int projection)
Northing to ASCII.
Definition: wind_format.c:29
void G_lon_format(double lon, char *buf)
Definition: ll_format.c:56
#define TRUE
Definition: dbfopen.c:118
void G_llres_format(double res, char *buf)
Definition: ll_format.c:71
void G_lat_format(double lat, char *buf)
Definition: ll_format.c:41