25
25
*----------------------------------------------------------------------------*/
27
27
/* uncomment to get debug output */
31
30
#include <string.h>
33
32
#include <grass/gis.h>
33
#include <grass/glocale.h>
34
34
#include <grass/gprojects.h>
35
35
#include "solpos00.h"
37
37
struct posdata pd, *pdat; /* declare solpos data struct and a pointer for it */
40
long G_calc_solar_position(double longitude, double latitude, double timezone,
41
int year, int month, int day, int hour, int minute,
40
long calc_solar_position(double longitude, double latitude, double timezone,
41
int year, int month, int day, int hour, int minute,
45
45
/* Note: this code is valid from year 1950 to 2050 (solpos restriction)
77
77
/* check if given point is in current window */
79
fprintf(stderr, "window.north: %f, window.south: %f\n", window.north,
78
G_debug(1, "window.north: %f, window.south: %f\n", window.north,
81
fprintf(stderr, "window.west: %f, window.east : %f\n", window.west,
80
G_debug(1, "window.west: %f, window.east : %f\n", window.west,
85
84
if (latitude >= window.south && latitude <= window.north &&
86
85
longitude >= window.west && longitude <= window.east)
90
("Specified point %f, %f outside of current region, is that intended? Anyway, it will be used.\n",
88
G_warning(_("Specified point %f, %f outside of current region, "
89
"is that intended? Anyway, it will be used."),
93
92
/* if coordinates are not in lat/long format, transform them: */
94
93
if ((G_projection() != PROJECTION_LL) && window.proj != 0) {
97
"Transforming input coordinates to lat/long (req. for solar position)\n");
94
G_debug(1, "Transforming input coordinates to lat/long (req. for solar position)");
100
96
/* read current projection info */
101
97
if ((in_proj_info = G_get_projinfo()) == NULL)
102
G_fatal_error("Can't get projection info of current location");
98
G_fatal_error(_("Unable to get projection info of current location"));
104
100
if ((in_unit_info = G_get_projunits()) == NULL)
105
G_fatal_error("Can't get projection units of current location");
101
G_fatal_error(_("Unable to get projection units of current location"));
107
103
if (pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0)
109
("Can't get projection key values of current location");
104
G_fatal_error(_("Unable to get projection key values of current location"));
111
106
G_free_key_value(in_proj_info);
112
107
G_free_key_value(in_unit_info);
115
109
/* Try using pj_print_proj_params() instead of all this */
116
fprintf(stderr, "Projection found in location:\n");
117
fprintf(stderr, "IN: meter: %f zone: %i proj: %s (iproj struct)\n",
110
G_debug(1, "Projection found in location:");
111
G_debug(1, "IN: meter: %f zone: %i proj: %s (iproj struct)",
118
112
iproj.meters, iproj.zone, iproj.proj);
119
fprintf(stderr, "IN: ellps: a: %f es: %f\n", iproj.pj->a,
121
fprintf(stderr, "IN: x0: %f y0: %f\n", iproj.pj->x0, iproj.pj->y0);
122
fprintf(stderr, "IN: lam0: %f phi0: %f\n", iproj.pj->lam0,
124
fprintf(stderr, "IN: k0: %f\n", iproj.pj->k0);
125
fprintf(stderr, "IN coord: longitude: %f, latitude: %f\n", longitude,
113
G_debug(1, "IN coord: longitude: %f, latitude: %f", longitude,
127
115
/* see src/include/projects.h, struct PJconsts */
130
117
/* set output projection to lat/long for solpos */
132
119
oproj.meters = 1.;
137
124
/* XX do the transform
138
125
* outx outy in_info out_info */
139
126
if (pj_do_proj(&longitude, &latitude, &iproj, &oproj) < 0) {
141
"Error in pj_do_proj (projection of input coordinate pair)\n");
127
G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
146
fprintf(stderr, "Transformation to lat/long:\n");
147
fprintf(stderr, "OUT: longitude: %f, latitude: %f\n", longitude,
130
G_debug(1, "Transformation to lat/long:");
131
G_debug(1, "OUT: longitude: %f, latitude: %f", longitude,
152
134
} /* transform if not LL */