/* getDayBounds
 * Called by getDaysIrr. Calculates the times of sunrise and sunset
 * on a given day, month, and year.
 */

#include "gddcalc.h"
#include "solpos.h"

int isLeapYear(int);                                     // prototype

void getDayBounds(int day, int month, int year, float *startMinute, 
		float *stopMinute) {

   long retval;

/* The posdata structure is defined in solpos.h and pd is defined there
 * as a posdata structure. pdat is a pointer to pd. pdat is initialized
 * below with the active variables. The active variables are initialized
 * by routines farther up the chain - such as t2_populate, t3_populate,
 * and . . .
 */
   
   pdat = &pd;
   S_init(pdat);                           // initialization of pdat
   pdat->latitude = active_latitude;
   pdat->longitude = active_longitude;
   pdat->aspect = active_aspect;
   pdat->tilt = active_tilt;
   pdat->year = year;
   pdat->month = month;
   pdat->day = day;
   pdat->hour = active_hour;
   pdat->minute = active_minute;
   pdat->second = active_second;
   pdat->temp = active_temp;
   pdat->press = active_press;
   pdat->timezone = active_timezone;
	
   if (isLeapYear(year))
      pdat->daynum = day + month_days[1][pdat->month];
   else
      pdat->daynum = day + month_days[0][pdat->month];

   retval = S_solpos(pdat);
      
   *startMinute = pdat->sretr;
   *stopMinute = pdat->ssetr;
}
