int getFirstRainfall(int j) // // Input: j = rain gage index // Output: returns TRUE if successful // Purpose: positions rainfall record to date with first rainfall. // { int k; // time series index float vFirst; // first rain volume (ft or m) double rFirst; // first rain intensity (in/hr or mm/hr) // --- assign default values to date & rainfall Gage[j].startDate = NO_DATE; Gage[j].rainfall = 0.0; // --- initialize internal cumulative rainfall value Gage[j].rainAccum = 0; // --- use rain interface file if applicable if ( Gage[j].dataSource == RAIN_FILE ) { if ( Frain.file && Gage[j].endFilePos > Gage[j].startFilePos ) { // --- retrieve 1st date & rainfall volume from file fseek(Frain.file, Gage[j].startFilePos, SEEK_SET); fread(&Gage[j].startDate, sizeof(DateTime), 1, Frain.file); fread(&vFirst, sizeof(float), 1, Frain.file); Gage[j].currentFilePos = ftell(Frain.file); // --- convert rainfall to intensity Gage[j].rainfall = convertRainfall(j, (double)vFirst); return 1; } return 0; } // --- otherwise access user-supplied rainfall time series else { k = Gage[j].tSeries; if ( k >= 0 ) { // --- retrieve first rainfall value from time series if ( table_getFirstEntry(&Tseries[k], &Gage[j].startDate, &rFirst) ) { // --- convert rainfall to intensity Gage[j].rainfall = convertRainfall(j, rFirst); return 1; } } return 0; } }
int getNextRainfall(int j) // // Input: j = rain gage index // Output: returns 1 if successful; 0 if not // Purpose: positions rainfall record to date with next non-zero rainfall // while updating the gage's next rain intensity value. // // Note: zero rainfall values explicitly entered into a rain file or // time series are skipped over so that a proper accounting of // wet and dry periods can be maintained. // { int k; // time series index float vNext; // next rain volume (ft or m) double rNext; // next rain intensity (in/hr or mm/hr) Gage[j].nextRainfall = 0.0; do { if ( Gage[j].dataSource == RAIN_FILE ) { if ( Frain.file && Gage[j].currentFilePos < Gage[j].endFilePos ) { fseek(Frain.file, Gage[j].currentFilePos, SEEK_SET); fread(&Gage[j].nextDate, sizeof(DateTime), 1, Frain.file); fread(&vNext, sizeof(float), 1, Frain.file); Gage[j].currentFilePos = ftell(Frain.file); rNext = convertRainfall(j, (double)vNext); } else return 0; } else { k = Gage[j].tSeries; if ( k >= 0 ) { if ( !table_getNextEntry(&Tseries[k], &Gage[j].nextDate, &rNext) ) return 0; rNext = convertRainfall(j, rNext); } else return 0; } } while (rNext == 0.0); Gage[j].nextRainfall = rNext; return 1; }
int getNextRainfall(int j) // // Input: j = rain gage index // Output: returns TRUE if successful // Purpose: positions rainfall record to date with next rainfall. // { int k; // time series index int result; // result of table query (TRUE/FALSE) float vNext; // next rain volume (ft or m) double rNext; // next rain intensity (in/hr or mm/hr) Gage[j].nextRainfall = 0.0; if ( Gage[j].dataSource == RAIN_FILE ) { if ( Frain.file && Gage[j].currentFilePos < Gage[j].endFilePos ) { fseek(Frain.file, Gage[j].currentFilePos, SEEK_SET); fread(&Gage[j].nextDate, sizeof(DateTime), 1, Frain.file); fread(&vNext, sizeof(float), 1, Frain.file); Gage[j].currentFilePos = ftell(Frain.file); Gage[j].nextRainfall = convertRainfall(j, (double)vNext); return 1; } return 0; } else { k = Gage[j].tSeries; if ( k >= 0 ) { result = table_getNextEntry(&Tseries[k], &Gage[j].nextDate, &rNext); if ( result ) Gage[j].nextRainfall = convertRainfall(j, rNext); return result; } return 0; } }