GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
wind_format.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/wind_format.c
3 *
4 * \brief GIS Library - Window formatting functions.
5 *
6 * SPDX-FileCopyrightText: 2001-2009 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 void format_double(double, char *, int);
16
17/*!
18 * \brief Northing to ASCII.
19 *
20 * Converts the double representation of the <i>north</i> coordinate to
21 * its ASCII representation (into <i>buf</i>).
22 *
23 * \param north northing
24 * \param[out] buf buffer to hold formatted string
25 * \param projection projection code, or -1 to force full precision FP
26 */
27void G_format_northing(double north, char *buf, int projection)
28{
29 if (projection == PROJECTION_LL)
30 G_lat_format(north, buf);
31 else if (projection == -1)
32 format_double(north, buf, TRUE);
33 else
34 format_double(north, buf, FALSE);
35}
36
37/*!
38 * \brief Easting to ASCII.
39 *
40 * Converts the double representation of the <i>east</i> coordinate to
41 * its ASCII representation (into <i>buf</i>).
42 *
43 * \param east easting
44 * \param[out] buf buffer to hold formatted string
45 * \param projection projection code, or -1 to force full precision FP
46 */
47void G_format_easting(double east, char *buf, int projection)
48{
49 if (projection == PROJECTION_LL)
50 G_lon_format(east, buf);
51 else if (projection == -1)
52 format_double(east, buf, TRUE);
53 else
54 format_double(east, buf, FALSE);
55}
56
57/*!
58 * \brief Resolution to ASCII.
59 *
60 * Converts the double representation of the <i>resolution</i> to its
61 * ASCII representation (into <i>buf</i>).
62 *
63 * \param res resolution value
64 * \param[out] buf buffer to hold formatted string
65 * \param projection projection code, or -1 to force full precision FP
66 */
67void G_format_resolution(double res, char *buf, int projection)
68{
69 if (projection == PROJECTION_LL)
70 G_llres_format(res, buf);
71 else if (projection == -1)
72 format_double(res, buf, TRUE);
73 else
74 format_double(res, buf, FALSE);
75}
76
77/*
78 * 'full_prec' is boolean, FALSE uses %.8f, TRUE uses %.15g
79 * The reason to have this is that for lat/lon "%.8f" is not
80 * enough to preserve fidelity once converted back into D:M:S,
81 * which leads to rounding errors, especially for resolution.
82 */
83static void format_double(double value, char *buf, int full_prec)
84{
85 if (full_prec)
86 sprintf(buf, "%.15g", value);
87 else
88 sprintf(buf, "%.8f", value);
89
90 G_trim_decimal(buf);
91}
void G_lat_format(double, char *)
Definition ll_format.c:40
void G_lon_format(double, char *)
Definition ll_format.c:55
void G_llres_format(double, char *)
Definition ll_format.c:70
void G_trim_decimal(char *)
Removes trailing zeros from decimal number.
Definition trim_dec.c:22
#define TRUE
Definition gis.h:75
#define FALSE
Definition gis.h:79
#define PROJECTION_LL
Projection code - Latitude-Longitude.
Definition gis.h:126
void G_format_northing(double north, char *buf, int projection)
Northing to ASCII.
Definition wind_format.c:27
void G_format_resolution(double res, char *buf, int projection)
Resolution to ASCII.
Definition wind_format.c:67
void G_format_easting(double east, char *buf, int projection)
Easting to ASCII.
Definition wind_format.c:47