~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to raster/r.sunmask/g_solposition.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 *----------------------------------------------------------------------------*/
26
26
 
27
27
/* uncomment to get debug output */
28
 
/*#define DEBUG */
29
28
 
30
29
#include <math.h>
31
30
#include <string.h>
32
31
#include <stdio.h>
33
32
#include <grass/gis.h>
 
33
#include <grass/glocale.h>
34
34
#include <grass/gprojects.h>
35
35
#include "solpos00.h"
36
36
 
37
37
struct posdata pd, *pdat;       /* declare solpos data struct and a pointer for it */
38
38
 
39
39
 
40
 
long G_calc_solar_position(double longitude, double latitude, double timezone,
41
 
                           int year, int month, int day, int hour, int minute,
42
 
                           int second)
 
40
long calc_solar_position(double longitude, double latitude, double timezone,
 
41
                         int year, int month, int day, int hour, int minute,
 
42
                         int second)
43
43
{
44
44
 
45
45
    /* Note: this code is valid from year 1950 to 2050 (solpos restriction)
63
63
 
64
64
    /* we don't like to run G_calc_solar_position in xy locations */
65
65
    if (window.proj == 0)
66
 
        G_fatal_error
67
 
            ("Can't calculate sun position in xy locations. Specify sunposition directly.");
 
66
        G_fatal_error(_("Unable to calculate sun position in un-projected locations. "
 
67
                        "Specify sunposition directly."));
68
68
 
69
69
    pdat = &pd;                 /* point to the structure for convenience */
70
70
 
75
75
    S_init(pdat);
76
76
 
77
77
    /* check if given point is in current window */
78
 
#ifdef DEBUG
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,
80
79
            window.south);
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,
82
81
            window.east);
83
 
#endif
 
82
    
84
83
    inside = 0;
85
84
    if (latitude >= window.south && latitude <= window.north &&
86
85
        longitude >= window.west && longitude <= window.east)
87
86
        inside = 1;
88
87
    if (!inside)
89
 
        G_warning
90
 
            ("Specified point %f, %f outside of current region, is that intended? Anyway, it will be used.\n",
91
 
             longitude, latitude);
 
88
        G_warning(_("Specified point %f, %f outside of current region, "
 
89
                    "is that intended? Anyway, it will be used."),
 
90
                  longitude, latitude);
92
91
 
93
92
    /* if coordinates are not in lat/long format, transform them: */
94
93
    if ((G_projection() != PROJECTION_LL) && window.proj != 0) {
95
 
#ifdef DEBUG
96
 
        fprintf(stderr,
97
 
                "Transforming input coordinates to lat/long (req. for solar position)\n");
98
 
#endif
99
 
 
 
94
        G_debug(1, "Transforming input coordinates to lat/long (req. for solar position)");
 
95
        
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"));
103
99
 
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"));
106
102
 
107
103
        if (pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0)
108
 
            G_fatal_error
109
 
                ("Can't get projection key values of current location");
110
 
 
 
104
            G_fatal_error(_("Unable to get projection key values of current location"));
 
105
        
111
106
        G_free_key_value(in_proj_info);
112
107
        G_free_key_value(in_unit_info);
113
108
 
114
 
#ifdef DEBUG
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,
120
 
                iproj.pj->es);
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,
123
 
                iproj.pj->phi0);
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,
126
114
                latitude);
127
115
        /* see src/include/projects.h, struct PJconsts */
128
 
#endif
129
 
 
 
116
        
130
117
        /* set output projection to lat/long for solpos */
131
118
        oproj.zone = 0;
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) {
140
 
            fprintf(stderr,
141
 
                    "Error in pj_do_proj (projection of input coordinate pair)\n");
142
 
            exit(0);
 
127
            G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
143
128
        }
144
129
 
145
 
#ifdef DEBUG
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,
148
132
                latitude);
149
 
#endif
150
 
 
151
133
 
152
134
    }                           /* transform if not LL */
153
135