@@ -52,10 +52,6 @@ CForcingGrid *CModel::ForcingCopyCreate(const CForcingGrid *pGrid,
5252 pTout=GetForcingGrid (typ);
5353 }
5454
55- // int nGridHRUs=pGrid->GetnHydroUnits();
56- // int nCells =pGrid->GetRows()*pGrid->GetCols(); //handles 3D or 2D
57- // cout<<"**ForcingGrid Copy Create : "<<ForcingToString(pGrid->GetForcingType())<<"-->"<<ForcingToString(pTout->GetForcingType())<< " is new?:"<<is_new<<"**"<<endl;
58-
5955 return pTout;
6056}
6157
@@ -126,6 +122,7 @@ void CModel::GenerateGriddedPrecipVars(const optStruct &Options)
126122// / \brief Creates all missing gridded temperature data based on gridded information available,
127123// / e.g when only sub-daily temperature is provided estimate daily average, minimum and maximum temperature.
128124// / data are assumed to have the same resolution and hence can be initialized together.
125+ // / called with each new chunk of data
129126// /
130127// / \param Options [in] major options of the model
131128//
@@ -261,10 +258,10 @@ void CModel::GenerateAveSubdailyTempFromMinMax(const optStruct &Options)
261258 for (int it=0 ; it<nVals; it++) { // loop over all time points (nVals)
262259 for (int ic=0 ; ic<nNonZero; ic++){ // loop over non-zero grid cell indexes
263260 time_idx_chunk = int (floor (t+TIME_CORRECTION));
264- Tmin = pTmin->GetValue_avg (ic, floor (t + time_shift+TIME_CORRECTION)*nValsPerDay, nValsPerDay);
265- Tmax = pTmax->GetValue_avg (ic, floor (t + time_shift+TIME_CORRECTION)*nValsPerDay, nValsPerDay);
266- T1corr = pTave->DailyTempCorrection (t+time_shift );
267- T2corr = pTave->DailyTempCorrection (t+time_shift+ Options.timestep );
261+ Tmin = pTmin->GetValue_avg (ic, floor (t- time_shift+TIME_CORRECTION)*nValsPerDay, nValsPerDay);
262+ Tmax = pTmax->GetValue_avg (ic, floor (t- time_shift+TIME_CORRECTION)*nValsPerDay, nValsPerDay);
263+ T1corr = pTave->DailyTempCorrection (t);
264+ T2corr = pTave->DailyTempCorrection (t+Options.timestep );
268265 val=pTave_daily->GetValue (ic, time_idx_chunk)+0.25 *(Tmax-Tmin)*(T1corr+T2corr);
269266 pTave->SetValue ( ic, it, val);
270267 }
@@ -280,8 +277,8 @@ void CModel::GenerateAveSubdailyTempFromMinMax(const optStruct &Options)
280277 pTave = ForcingCopyCreate (pTave_daily,F_TEMP_AVE,1.0 ,nVals,Options);
281278
282279 int nNonZero =pTave->GetNumberNonZeroGridCells ();
283- for (int it=0 ; it<nVals; it++) { // loop over time points in buffer
284- for (int ic=0 ; ic<nNonZero; ic++) { // loop over non-zero grid cell indexes
280+ for (int it=0 ; it<nVals; it++) { // loop over time points in buffer
281+ for (int ic=0 ; ic<nNonZero; ic++) { // loop over non-zero grid cell indexes
285282 pTave->SetValue (ic,it,pTave_daily->GetValue (ic,it)); // --> just copy daily average values
286283 }
287284 }
@@ -308,18 +305,20 @@ void CModel::GenerateMinMaxAveTempFromSubdaily(const optStruct &Options)
308305 pTmax_daily = ForcingCopyCreate (pTave,F_TEMP_DAILY_MAX,1.0 ,nVals,Options);
309306 pTave_daily = ForcingCopyCreate (pTave,F_TEMP_DAILY_AVE,1.0 ,nVals,Options);
310307
308+ int t_idx;
311309 double time;
312310 double time_shift=Options.julian_start_day -floor (Options.julian_start_day +TIME_CORRECTION);
313- int nsteps_in_day=int ( 1.0 /interval);
311+ int nsteps_in_day=( int )( rvn_round ( 1.0 /interval) );
314312
315313 for (int it=0 ; it<nVals; it++) { // loop over time points in buffer
316- time=(double )it*1.0 /interval ;
314+ time=(double )it*nsteps_in_day ;
317315 time=floor (time-time_shift+TIME_CORRECTION); // model time corresponding to 00:00 on day of it
316+ t_idx=(int )(time);
318317
319318 for (int ic=0 ; ic<pTave->GetNumberNonZeroGridCells (); ic++){ // loop over non-zero grid cell indexes
320- pTmin_daily->SetValue (ic, it, pTave->GetValue_min (ic, time , nsteps_in_day));
321- pTmax_daily->SetValue (ic, it, pTave->GetValue_max (ic, time , nsteps_in_day));
322- pTave_daily->SetValue (ic, it, pTave->GetValue_avg (ic, time , nsteps_in_day));
319+ pTmin_daily->SetValue (ic, it, pTave->GetValue_min (ic, t_idx , nsteps_in_day));
320+ pTmax_daily->SetValue (ic, it, pTave->GetValue_max (ic, t_idx , nsteps_in_day));
321+ pTave_daily->SetValue (ic, it, pTave->GetValue_avg (ic, t_idx , nsteps_in_day));
323322 }
324323 }
325324
0 commit comments