void Ambient::calcSpacedDaysHours(double lat, double lon, double tmz, int nday, double delta_hr, vector<vector<double> > &utime, vector<int> &uday){ //Method taken from PTGen code (Wagner 2008 thesis) double pi = PI; uday.resize(nday); vector<int> ntstep(nday), ntstep_day(nday); vector<double> noons(nday), hours(nday); DateTime DT; int month, dom; for(int i=0; i<nday; i++){ //Calculate the day number - The days are evenly distributed over the cosine wave of the year uday[i] = 355 - (int)floor(acos(-1.+2.*i/(float)(nday-1))/pi*(float)(355-172)); DT.hours_to_date(uday[i]*24 +12., month, dom); DT.SetHour(12); DT.SetDate(2011, month, dom); DT.SetYearDay(uday[i]); double hrs[2]; Ambient::calcDaytimeHours(hrs, lat*D2R, lon*D2R, tmz, DT); noons.at(i) = (hrs[0]+hrs[1])/2.; //shorten the time by 0.9 so we don't get stuff really close to the horizon ntstep[i] = (int)floor( (hrs[1]-noons.at(i))*.9/delta_hr ); //For the calculated day, determine the solar declination angle and the number of daylight hours //delta[i] = asin(23.45*D2R*cos((float)(uday[i]-173)*D2R)); //nhour[i] = (int)(floor((2./15.*acos(-tan(phi)*tan(delta[i]))*r2d)/2.)); ntstep_day[i] = 2*ntstep[i]+1; } //Store the day and time in the utime array utime.clear(); vector<double> utemp; int nflux_sim = 0; for(int i=0; i<nday; i++){ utemp.clear(); for(int j=0; j<ntstep_day[i]; j++){ utemp.push_back( noons[i]+(-ntstep[i]+j)*delta_hr -12.); nflux_sim++; } utime.push_back(utemp); } }
void Ambient::setDateTime(DateTime &DT, double day_hour, double year_day, double year){ DT.setZero(); double min, sec; min = (day_hour - floor(day_hour))*60.; sec = (min - floor(min))*60.; DT.SetHour(int(floor(day_hour))); DT.SetMinute(int(min)); DT.SetSecond(int(sec)); DT.SetYearDay(int(year_day)); DT.SetYear(int(year)); int month, dom; DT.hours_to_date((year_day-1)*24.+day_hour, month, dom); DT.SetMonth(int(month)); DT.SetMonthDay(int(dom)); }