Hi,
small C programming question:
r.sunmask -sg el=dtm.10meters timezone=1 output=vuoto east=1694215 north=5104320 year=1998 month=12 day=23 hour=12 minute=15 sec=0
Calculating sun position... (using solpos (V. 11 April 2001) from NREL)
WARNING: Specified point 1694215.000000, 5104320.000000 outside of current
window, is that intended? Anyway, it will be used.
date=1998.12.23
daynum=357
time=12:15:00
decimaltime=12.250000
longitudine=11.510999
latitude=46.063343
timezone=1.000000
sunazimuth=180.501633
sunangleabovehorzizont=20.544914
sunrise=07:60 <------- ! Would like to see 8:00 here
sunset=16:26
The related code looks like this:
fprintf (stdout, "sunrise=%02.0f:%02.0f\n", floor(pdat->sretr/60.), fmod(pdat->sretr, 60.));
fprintf (stdout, "sunset=%02.0f:%02.0f\n", floor(pdat->ssetr/60.), fmod(pdat->ssetr, 60.));
Should I add 'if' (if minutes >=60) conditions or is there a better way
to avoid 07:60 output?
Thanks
Markus
Markus Neteler wrote:
small C programming question:
r.sunmask -sg el=dtm.10meters timezone=1 output=vuoto east=1694215 north=5104320 year=1998 month=12 day=23 hour=12 minute=15 sec=0
sunrise=07:60 <------- ! Would like to see 8:00 here
The related code looks like this:
fprintf (stdout, "sunrise=%02.0f:%02.0f\n", floor(pdat->sretr/60.), fmod(pdat->sretr, 60.));
fprintf (stdout, "sunset=%02.0f:%02.0f\n", floor(pdat->ssetr/60.), fmod(pdat->ssetr, 60.));
This will happen if the modulus is between 59.5 and 60; printf("%.0f") will
round to nearest rather than truncating.
Should I add 'if' (if minutes >=60) conditions or is there a better way
to avoid 07:60 output?
Convert pdat->sretr to pdat->ssetr to integers, e.g.:
int sretr = (int) floor(pdat->sretr + 0.5);
int ssetr = (int) floor(pdat->ssetr + 0.5);
/* Remove +0.5 above if you want round-down instead of round-to-nearest */
fprintf (stdout, "sunrise=%02d:%02d\n", sretr/60, sretr%60));
fprintf (stdout, "sunset=%02d:%02d\n", ssetr/60, ssetr%60));
--
Glynn Clements <glynn@gclements.plus.com>
On Mon, Dec 06, 2004 at 03:02:43PM +0000, Glynn Clements wrote:
Markus Neteler wrote:
> small C programming question:
>
> r.sunmask -sg el=dtm.10meters timezone=1 output=vuoto east=1694215 north=5104320 year=1998 month=12 day=23 hour=12 minute=15 sec=0
> sunrise=07:60 <------- ! Would like to see 8:00 here
> The related code looks like this:
> fprintf (stdout, "sunrise=%02.0f:%02.0f\n", floor(pdat->sretr/60.), fmod(pdat->sretr, 60.));
> fprintf (stdout, "sunset=%02.0f:%02.0f\n", floor(pdat->ssetr/60.), fmod(pdat->ssetr, 60.));
This will happen if the modulus is between 59.5 and 60; printf("%.0f") will
round to nearest rather than truncating.
> Should I add 'if' (if minutes >=60) conditions or is there a better way
> to avoid 07:60 output?
Convert pdat->sretr to pdat->ssetr to integers, e.g.:
int sretr = (int) floor(pdat->sretr + 0.5);
int ssetr = (int) floor(pdat->ssetr + 0.5);
/* Remove +0.5 above if you want round-down instead of round-to-nearest */
I'm not sure what's preferred.
fprintf (stdout, "sunrise=%02d:%02d\n", sretr/60, sretr%60));
fprintf (stdout, "sunset=%02d:%02d\n", ssetr/60, ssetr%60));
Thanks for the quick help, Glynn.
Markus