GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wind_format.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <grass/gis.h>
19 
20 
21 static void format_double(double, char *, int);
22 
23 
36 int G_format_northing(double north, char *buf, int projection)
37 {
38  if (projection == PROJECTION_LL)
39  G_lat_format(north, buf);
40  else if (projection == -1)
41  format_double(north, buf, TRUE);
42  else
43  format_double(north, buf, FALSE);
44 
45  return 0;
46 }
47 
48 
61 int G_format_easting(double east, char *buf, int projection)
62 {
63  if (projection == PROJECTION_LL)
64  G_lon_format(east, buf);
65  else if (projection == -1)
66  format_double(east, buf, TRUE);
67  else
68  format_double(east, buf, FALSE);
69 
70  return 0;
71 }
72 
73 
86 int G_format_resolution(double res, char *buf, int projection)
87 {
88  if (projection == PROJECTION_LL)
89  G_llres_format(res, buf);
90  else if (projection == -1)
91  format_double(res, buf, TRUE);
92  else
93  format_double(res, buf, FALSE);
94 
95  return 0;
96 }
97 
98 /*
99  * 'full_prec' is boolean, FALSE uses %.8f, TRUE uses %.15g
100  * The reason to have this is that for lat/lon "%.8f" is not
101  * enough to preserve fidelity once converted back into D:M:S,
102  * which leads to rounding errors, especially for resolution.
103  */
104 static void format_double(double value, char *buf, int full_prec)
105 {
106  if (full_prec)
107  sprintf(buf, "%.15g", value);
108  else
109  sprintf(buf, "%.8f", value);
110 
111  G_trim_decimal(buf);
112 
113  return;
114 }
int G_lat_format(double lat, char *buf)
Definition: ll_format.c:41
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_format_resolution(double res, char *buf, int projection)
Resolution to ASCII.
Definition: wind_format.c:86
#define FALSE
Definition: dbfopen.c:117
int G_trim_decimal(char *buf)
Removes trailing zeros from decimal number.
Definition: trim_dec.c:30
#define TRUE
Definition: dbfopen.c:118
char * value
Definition: env.c:30
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int G_format_easting(double east, char *buf, int projection)
Easting to ASCII.
Definition: wind_format.c:61
int G_lon_format(double lon, char *buf)
Definition: ll_format.c:58
int G_format_northing(double north, char *buf, int projection)
Northing to ASCII.
Definition: wind_format.c:36
int G_llres_format(double res, char *buf)
Definition: ll_format.c:74