void readRdiiFlows() // // Input: none // Output: none // Purpose: reads date and flow values of next RDII inflows from RDII file. // { int i, n; int yr = 0, mon = 0, day = 0, hr = 0, min = 0, sec = 0; // year, month, day, hour, minute, second float x; // RDII flow in original units char line[MAXLINE+1]; // line from RDII data file char s[MAXLINE+1]; // node ID label (not used) RdiiStartDate = NO_DATE; for (i=0; i<NumRdiiNodes; i++) { if ( feof(Frdii.file) ) return; fgets(line, MAXLINE, Frdii.file); n = sscanf(line, "%s %d %d %d %d %d %d %f", s, &yr, &mon, &day, &hr, &min, &sec, &x); if ( n < 8 ) return; RdiiNodeFlow[i] = x / Qcf[RdiiFlowUnits]; } RdiiStartDate = datetime_encodeDate(yr, mon, day) + datetime_encodeTime(hr, min, sec); RdiiEndDate = datetime_addSeconds(RdiiStartDate, RdiiStep); }
void readNewIfaceValues() // // Input: none // Output: none // Purpose: reads data from inflows interface file for next date. // { int i, j; char* s; int yr = 0, mon = 0, day = 0, hr = 0, min = 0, sec = 0; // year, month, day, hour, minute, second char line[MAXLINE+1]; // line from interface file // --- read a line for each interface node NewIfaceDate = NO_DATE; for (i=0; i<NumIfaceNodes; i++) { if ( feof(Finflows.file) ) return; fgets(line, MAXLINE, Finflows.file); // --- parse date & time from line if ( strtok(line, SEPSTR) == NULL ) return; s = strtok(NULL, SEPSTR); if ( s == NULL ) return; yr = atoi(s); s = strtok(NULL, SEPSTR); if ( s == NULL ) return; mon = atoi(s); s = strtok(NULL, SEPSTR); if ( s == NULL ) return; day = atoi(s); s = strtok(NULL, SEPSTR); if ( s == NULL ) return; hr = atoi(s); s = strtok(NULL, SEPSTR); if ( s == NULL ) return; min = atoi(s); s = strtok(NULL, SEPSTR); if ( s == NULL ) return; sec = atoi(s); // --- parse flow value s = strtok(NULL, SEPSTR); if ( s == NULL ) return; NewIfaceValues[i][0] = atof(s) / Qcf[IfaceFlowUnits]; // --- parse pollutant values for (j=1; j<=NumIfacePolluts; j++) { s = strtok(NULL, SEPSTR); if ( s == NULL ) return; NewIfaceValues[i][j] = atof(s); } } // --- encode date & time values NewIfaceDate = datetime_encodeDate(yr, mon, day) + datetime_encodeTime(hr, min, sec); }
void setNextEvapDate(DateTime theDate) // // Input: theDate = current simulation date // Output: sets a new value for NextEvapDate // Purpose: finds date for next change in evaporation after the current date. // { int yr, mon, day, k; double d, e; // --- do nothing if current date hasn't reached the current next date if ( NextEvapDate > theDate ) return; switch ( Evap.type ) { // --- for constant evaporation, use a next date far in the future case CONSTANT_EVAP: NextEvapDate = theDate + 365.; break; // --- for monthly evaporation, use the start of the next month case MONTHLY_EVAP: datetime_decodeDate(theDate, &yr, &mon, &day); if ( mon == 12 ) { mon = 1; yr++; } else mon++; NextEvapDate = datetime_encodeDate(yr, mon, 1); break; // --- for time series evaporation, find the next entry in the // series on or after the current date case TIMESERIES_EVAP: k = Evap.tSeries; if ( k >= 0 ) { NextEvapDate = theDate + 365.; while ( table_getNextEntry(&Tseries[k], &d, &e) && d <= EndDateTime ) { if ( d >= theDate ) { NextEvapDate = d; NextEvapRate = e; break; } } } break; // --- for climate file daily evaporation, use the next day case FILE_EVAP: NextEvapDate = floor(theDate) + 1.0; break; default: NextEvapDate = theDate + 365.; } }
int readStdLine(Project* project, char *line, DateTime day1, DateTime day2) // // Input: line = line of data from a standard rainfall data file // day1 = starting day of record of interest // day2 = ending day of record of interest // Output: returns -1 if past end of desired record, 0 if data line could // not be read successfully or 1 if line read successfully // Purpose: reads a line of data from a standard rainfall data file and // writes its data to the rain interface file. // { DateTime date1; DateTime date2; int year, month, day, hour, minute; float x; // --- parse data from input line if (!parseStdLine(project,line, &year, &month, &day, &hour, &minute, &x)) return 0; // --- see if date is within period of record requested date1 = datetime_encodeDate(year, month, day); if ( day1 != NO_DATE && date1 < day1 ) return 0; if ( day2 != NO_DATE && date1 > day2 ) return -1; // --- see if record is out of sequence date2 = date1 + datetime_encodeTime(hour, minute, 0); if ( date2 <= project->PreviousDate ) { report_writeErrorMsg(project,ERR_RAIN_FILE_SEQUENCE, project->Gage[project->GageIndex].fname); //(5.1.010) report_writeLine(project,line); return -1; } project->PreviousDate = date2; switch (project->RainType) { case RAINFALL_INTENSITY: x = x * project->Interval / 3600.0f; break; case CUMULATIVE_RAINFALL: if ( x >= project->RainAccum ) { x = x - project->RainAccum; project->RainAccum += x; } else project->RainAccum = x; break; } x *= (float)project->UnitsFactor; // --- save rainfall to binary interface file saveRainfall(project, date1, hour, minute, x, FALSE); return 1; }
DateTime climate_getNextEvap(DateTime days) // // Input: days = current simulation date //(5.0.019 - LR) // Output: returns date (in whole days) when evaporation rate next changes // Purpose: finds date for next change in evaporation. // { int yr, mon, day, k; double d, e; days = floor(days); //(5.0.019 - LR) switch ( Evap.type ) { case CONSTANT_EVAP: return days + 365.; case MONTHLY_EVAP: datetime_decodeDate(days, &yr, &mon, &day); if ( mon == 12 ) { mon = 1; yr++; } else mon++; return datetime_encodeDate(yr, mon, 1); case TIMESERIES_EVAP: //// Following section modified for release 5.0.019 //// //(5.0.019 - LR) if ( NextEvapDate > days ) return NextEvapDate; k = Evap.tSeries; if ( k >= 0 ) { while ( table_getNextEntry(&Tseries[k], &d, &e) && d <= EndDateTime ) { if ( d > days ) { NextEvapDate = d; NextEvapRate = e; return d; } } } ////////////////////////////////////////////////////////// return days + 365.; case FILE_EVAP: return days + 1.0; default: return days + 365.; } }
int datetime_dayOfYear(DateTime date) // Input: date = an encoded date/time value // Output: returns day of year (1..365) // Purpose: finds day of year (Jan 1 = 1) for a given date. { int year, month, day; DateTime startOfYear; datetime_decodeDate(date, &year, &month, &day); startOfYear = datetime_encodeDate(year, 1, 1); return (int)(floor(date - startOfYear)) + 1; }
int datetime_strToDate(char* s, DateTime* d) // Input: s = date as string // Output: d = encoded date; // returns 1 if conversion successful, 0 if not // Purpose: converts string date s to DateTime value. // { int yr = 0, mon = 0, day = 0, n; char month[4]; char sep1, sep2; *d = -DateDelta; if (strchr(s, '-') || strchr(s, '/')) { switch (DateFormat) { case Y_M_D: n = sscanf(s, "%d%c%d%c%d", &yr, &sep1, &mon, &sep2, &day); if ( n < 3 ) { mon = 0; n = sscanf(s, "%d%c%3s%c%d", &yr, &sep1, month, &sep2, &day); if ( n < 3 ) return 0; } break; case D_M_Y: n = sscanf(s, "%d%c%d%c%d", &day, &sep1, &mon, &sep2, &yr); if ( n < 3 ) { mon = 0; n = sscanf(s, "%d%c%3s%c%d", &day, &sep1, month, &sep2, &yr); if ( n < 3 ) return 0; } break; default: // M_D_Y n = sscanf(s, "%d%c%d%c%d", &mon, &sep1, &day, &sep2, &yr); if ( n < 3 ) { mon = 0; n = sscanf(s, "%3s%c%d%c%d", month, &sep1, &day, &sep2, &yr); if ( n < 3 ) return 0; } } if (mon == 0) mon = datetime_findMonth(month); *d = datetime_encodeDate(yr, mon, day); } if (*d == -DateDelta) return 0; else return 1; }
int readStdLine(char *line, DateTime day1, DateTime day2) // // Input: line = line of data from a standard rainfall data file // day1 = starting day of record of interest // day2 = ending day of record of interest // Output: returns -1 if past end of desired record, 0 if data line could // not be read successfully or 1 if line read successfully // Purpose: reads a line of data from a standard rainfall data file and // writes its data to the rain interface file. // { DateTime date1; int year, month, day, hour, minute; float x; // --- parse data from input line if (!parseStdLine(line, &year, &month, &day, &hour, &minute, &x)) return 0; // --- see if date is within period of record requested date1 = datetime_encodeDate(year, month, day); if ( day1 != NO_DATE && date1 < day1 ) return 0; if ( day2 != NO_DATE && date1 > day2 ) return -1; switch (RainType) { case RAINFALL_INTENSITY: x = x * Interval / 3600.0; break; case CUMULATIVE_RAINFALL: if ( x >= RainAccum ) { x = x - RainAccum; RainAccum += x; } else RainAccum = x; break; } x *= UnitsFactor; // --- save rainfall to binary interface file saveRainfall(date1, hour, minute, x, FALSE); return 1; }
DateTime climate_getNextEvap(DateTime days) // // Input: days = current simulation date (in whole days) // Output: returns date (in whole days) when evaporation rate next changes // Purpose: finds date for next change in evaporation. // { int yr, mon, day, k; double d, e; switch ( Evap.type ) { case CONSTANT_EVAP: return days + 365.; case MONTHLY_EVAP: datetime_decodeDate(days, &yr, &mon, &day); if ( mon == 12 ) { mon = 1; yr++; } else mon++; return datetime_encodeDate(yr, mon, 1); case TIMESERIES_EVAP: k = Evap.tSeries; while ( table_getNextEntry(&Tseries[k], &d, &e) ) { if ( d > days ) return d; } return days + 365.; case FILE_EVAP: return days + 1.0; default: return days + 365.; } }
void setDefaults() // // Input: none // Output: none // Purpose: assigns default values to project variables. // { int i, j; // Project title & temp. file path for (i = 0; i < MAXTITLE; i++) strcpy(Title[i], ""); strcpy(TempDir, ""); // Interface files Frain.mode = SCRATCH_FILE; // Use scratch rainfall file Fclimate.mode = NO_FILE; Frunoff.mode = NO_FILE; Frdii.mode = NO_FILE; Fhotstart1.mode = NO_FILE; Fhotstart2.mode = NO_FILE; Finflows.mode = NO_FILE; Foutflows.mode = NO_FILE; Frain.file = NULL; Fclimate.file = NULL; Frunoff.file = NULL; Frdii.file = NULL; Fhotstart1.file = NULL; Fhotstart2.file = NULL; Finflows.file = NULL; Foutflows.file = NULL; Fout.file = NULL; Fout.mode = NO_FILE; // Analysis options UnitSystem = US; // US unit system FlowUnits = CFS; // CFS flow units InfilModel = HORTON; // Horton infiltration method RouteModel = KW; // Kin. wave flow routing method AllowPonding = FALSE; // No ponding at nodes InertDamping = SOME; // Partial inertial damping NormalFlowLtd = BOTH; // Default normal flow limitation ForceMainEqn = H_W; // Hazen-Williams eqn. for force mains LinkOffsets = DEPTH_OFFSET; // Use depth for link offsets LengtheningStep = 0; // No lengthening of conduits CourantFactor = 0.0; // No variable time step MinSurfArea = 0.0; // Force use of default min. surface area SkipSteadyState = FALSE; // Do flow routing in steady state periods IgnoreRainfall = FALSE; // Analyze rainfall/runoff IgnoreRDII = FALSE; // Analyze RDII //(5.1.004) IgnoreSnowmelt = FALSE; // Analyze snowmelt IgnoreGwater = FALSE; // Analyze groundwater IgnoreRouting = FALSE; // Analyze flow routing IgnoreQuality = FALSE; // Analyze water quality WetStep = 300; // Runoff wet time step (secs) DryStep = 3600; // Runoff dry time step (secs) RouteStep = 300.0; // Routing time step (secs) ReportStep = 900; // Reporting time step (secs) StartDryDays = 0.0; // Antecedent dry days MaxTrials = 0; // Force use of default max. trials HeadTol = 0.0; // Force use of default head tolerance SysFlowTol = 0.05; // System flow tolerance for steady state LatFlowTol = 0.05; // Lateral flow tolerance for steady state // Deprecated options SlopeWeighting = TRUE; // Use slope weighting Compatibility = SWMM4; // Use SWMM 4 up/dn weighting method // Starting & ending date/time StartDate = datetime_encodeDate(2004, 1, 1); StartTime = datetime_encodeTime(0,0,0); StartDateTime = StartDate + StartTime; EndDate = StartDate; EndTime = 0.0; ReportStartDate = NO_DATE; ReportStartTime = NO_DATE; SweepStart = 1; SweepEnd = 365; // Reporting options RptFlags.input = FALSE; RptFlags.continuity = TRUE; RptFlags.flowStats = TRUE; RptFlags.controls = FALSE; RptFlags.subcatchments = FALSE; RptFlags.nodes = FALSE; RptFlags.links = FALSE; RptFlags.nodeStats = FALSE; // Temperature data Temp.dataSource = NO_TEMP; Temp.tSeries = -1; Temp.ta = 70.0; Temp.elev = 0.0; Temp.anglat = 40.0; Temp.dtlong = 0.0; Temp.tmax = MISSING; // Wind speed data Wind.type = MONTHLY_WIND; for ( i=0; i<12; i++ ) Wind.aws[i] = 0.0; // Snowmelt parameters Snow.snotmp = 34.0; Snow.tipm = 0.5; Snow.rnm = 0.6; // Snow areal depletion curves for pervious and impervious surfaces for ( i=0; i<2; i++ ) { for ( j=0; j<10; j++) Snow.adc[i][j] = 1.0; } // Evaporation rates Evap.type = CONSTANT_EVAP; for (i=0; i<12; i++) { Evap.monthlyEvap[i] = 0.0; Evap.panCoeff[i] = 1.0; } Evap.recoveryPattern = -1; Evap.recoveryFactor = 1.0; Evap.tSeries = -1; Evap.dryOnly = FALSE; //// Following code segment added to release 5.1.007. //// //(5.1.007) // Climate adjustments for (i = 0; i < 12; i++) { Adjust.temp[i] = 0.0; // additive adjustments Adjust.evap[i] = 0.0; // additive adjustments Adjust.rain[i] = 1.0; // multiplicative adjustments } Adjust.rainFactor = 1.0; }
int readCMCLine(Project* project, char *line, int fileFormat, DateTime day1, DateTime day2) // // Input: line = line of data from rainfall data file // fileFormat = code of data file's format // day1 = starting day of record of interest // day2 = ending day of record of interest // Output: returns -1 if past end of desired record, 0 if data line could // not be read successfully or 1 if line read successfully // Purpose: reads a line of data from an AES or CMC rainfall data file and // writes its data to the rain interface file. // { char flag, isMissing; DateTime date1; long sn, v; int col, j, jMax, elem, y, m, d, hour, minute; float x; // --- get year, month, day & element code from line if ( fileFormat == AES_HLY ) { if ( sscanf(line, "%7ld%3d%2d%2d%3d", &sn, &y, &m, &d, &elem) < 5 ) return 0; if ( y < 100 ) y = y + 2000; else y = y + 1000; col = 17; } else { if ( sscanf(line, "%7ld%4d%2d%2d%3d", &sn, &y, &m, &d, &elem) < 5 ) return 0; col = 18; } // --- see if date is within period of record requested date1 = datetime_encodeDate(y, m, d); if ( day1 != NO_DATE && date1 < day1 ) return 0; if ( day2 != NO_DATE && date1 > day2 ) return -1; // --- make sure element code is for rainfall if ( fileFormat == AES_HLY && elem != 123 ) return 0; else if ( fileFormat == CMC_FIF && elem != 159 ) return 0; else if ( fileFormat == CMC_HLY && elem != 123 ) return 0; // --- read rainfall from each recording interval hour = 0; // starting hour minute = 0; // starting minute jMax = 24; // # recording intervals if ( fileFormat == CMC_FIF ) jMax = 96; for (j=1; j<=jMax; j++) { if ( sscanf(&line[col], "%6ld%c", &v, &flag) < 2 ) return 0; col += 7; if ( v == -99999 ) isMissing = TRUE; else isMissing = FALSE; // --- convert rain measurement from 0.1 mm to inches and save it x = (float)( (double)v / 10.0 / MMperINCH); if ( x > 0 || isMissing) { saveRainfall(project,date1, hour, minute, x, isMissing); } // --- update hour & minute for next interval if ( fileFormat == CMC_FIF ) { minute += 15; if ( minute == 60 ) { minute = 0; hour++; } } else hour++; } return 1; }
int readNWSLine(Project* project, char *line, int fileFormat, DateTime day1, DateTime day2) // // Input: line = line of data from rainfall data file // fileFormat = code of data file's format // day1 = starting day of record of interest // day2 = ending day of record of interest // Output: returns -1 if past end of desired record, 0 if data line could // not be read successfully or 1 if line read successfully // Purpose: reads a line of data from a rainfall data file and writes its // data to the rain interface file. // { char flag1, flag2, isMissing; DateTime date1; long result = 1; int k, y, m, d, n; int hour, minute; long v; float x; int lineLength = strlen(line)-1; int nameLength = 0; // --- get year, month, & day from line switch ( fileFormat ) { case NWS_TAPE: if ( lineLength <= 30 ) return 0; if (sscanf(&line[17], "%4d%2d%4d%3d", &y, &m, &d, &n) < 4) return 0; k = 30; break; case NWS_SPACE_DELIMITED: if ( project->hasStationName ) nameLength = 31; if ( lineLength <= 28 + nameLength ) return 0; k = 18 + nameLength; if (sscanf(&line[k], "%4d %2d %2d", &y, &m, &d) < 3) return 0; k = k + 10; break; case NWS_COMMA_DELIMITED: if ( lineLength <= 28 ) return 0; if ( sscanf(&line[18], "%4d,%2d,%2d", &y, &m, &d) < 3 ) return 0; k = 28; break; case NWS_ONLINE_60: case NWS_ONLINE_15: if ( lineLength <= project->DataOffset + 23 ) return 0; if ( sscanf(&line[project->DataOffset], "%4d%2d%2d", &y, &m, &d) < 3 ) return 0; k = project->DataOffset + 8; break; default: return 0; } // --- see if date is within period of record requested date1 = datetime_encodeDate(y, m, d); if ( day1 != NO_DATE && date1 < day1 ) return 0; if ( day2 != NO_DATE && date1 > day2 ) return -1; // --- read each recorded rainfall time, value, & codes from line while ( k < lineLength ) { flag1 = 0; flag2 = 0; v = 99999; hour = 25; minute = 0; switch ( fileFormat ) { case NWS_TAPE: n = sscanf(&line[k], "%2d%2d%6ld%c%c", &hour, &minute, &v, &flag1, &flag2); k += 12; break; case NWS_SPACE_DELIMITED: n = sscanf(&line[k], " %2d%2d %6ld %c %c", &hour, &minute, &v, &flag1, &flag2); k += 16; break; case NWS_COMMA_DELIMITED: n = sscanf(&line[k], ",%2d%2d,%6ld,%c,%c", &hour, &minute, &v, &flag1, &flag2); k += 16; break; case NWS_ONLINE_60: case NWS_ONLINE_15: n = sscanf(&line[k], " %2d:%2d", &hour, &minute); n += sscanf(&line[project->ValueOffset], "%8ld %c", &v, &flag1); // --- ending hour 0 is really hour 24 of previous day if ( hour == 0 ) { hour = 24; date1 -= 1.0; } k += lineLength; break; default: n = 0; } // --- check that we at least have an hour, minute & value // (codes might be left off of the line) if ( n < 3 || hour >= 25 ) break; // --- set special condition code & update daily & hourly counts setCondition(project,flag1); if ( project->Condition == DELETED_PERIOD || project->Condition == MISSING_PERIOD || flag1 == 'M' ) isMissing = TRUE; else if ( v >= 9999 ) isMissing = TRUE; else isMissing = FALSE; // --- handle accumulation codes if ( flag1 == 'a' ) { project->AccumStartDate = date1 + datetime_encodeTime(hour, minute, 0); } else if ( flag1 == 'A' ) { saveAccumRainfall(project,date1, hour, minute, v); } // --- handle all other conditions else { // --- convert rain measurement to inches & save it x = (float)v / 100.0f; if ( x > 0 || isMissing ) saveRainfall(project,date1, hour, minute, x, isMissing); } // --- reset condition code if special condition period ended if ( flag1 == 'A' || flag1 == '}' || flag1 == ']') project->Condition = 0; } return result; }
int readNWSLine(char *line, int fileFormat, DateTime day1, DateTime day2) // // Input: line = line of data from rainfall data file // fileFormat = code of data file's format // day1 = starting day of record of interest // day2 = ending day of record of interest // Output: returns -1 if past end of desired record, 0 if data line could // not be read successfully or 1 if line read successfully // Purpose: reads a line of data from a rainfall data file and writes its // data to the rain interface file. // { char flag1, flag2, isMissing; DateTime date1; long result = 1; int k, y, m, d, n; int hour, minute; long v; float x; int lineLength = strlen(line)-1; // --- get year, month, & day from line switch ( fileFormat ) { case NWS_TAPE: if ( lineLength <= 30 ) return 0; if (sscanf(&line[17], "%4d%2d%4d%3d", &y, &m, &d, &n) < 4) return 0; k = 30; break; case NWS_SPACE_DELIMITED: if ( lineLength <= 28 ) return 0; if (sscanf(&line[18], "%4d %2d %2d", &y, &m, &d) < 3) return 0; k = 28; break; case NWS_COMMA_DELIMITED: if ( lineLength <= 28 ) return 0; if ( sscanf(&line[18], "%4d,%2d,%2d", &y, &m, &d) < 3 ) return 0; k = 28; break; default: return 0; } // --- see if date is within period of record requested date1 = datetime_encodeDate(y, m, d); if ( day1 != NO_DATE && date1 < day1 ) return 0; if ( day2 != NO_DATE && date1 > day2 ) return -1; // --- read each recorded rainfall time, value, & codes from line while ( k < lineLength ) { switch ( fileFormat ) { case NWS_TAPE: n = sscanf(&line[k], "%2d%2d%6d%c%c", &hour, &minute, &v, &flag1, &flag2); k += 12; break; case NWS_SPACE_DELIMITED: n = sscanf(&line[k], " %2d%2d %6d %c %c", &hour, &minute, &v, &flag1, &flag2); k += 16; break; case NWS_COMMA_DELIMITED: n = sscanf(&line[k], ",%2d%2d,%6d,%c,%c", &hour, &minute, &v, &flag1, &flag2); k += 16; break; } if ( n < 5 || hour >= 25 ) break; // --- set special condition code & update daily & hourly counts setCondition(flag1); if ( Condition != NO_CONDITION ) isMissing = TRUE; else if ( v == 99999 ) isMissing = TRUE; else isMissing = FALSE; // --- convert rain measurement from hundreth's of an inch & save it x = (float)v / 100.0; if ( x > 0 ) saveRainfall(date1, hour, minute, x, isMissing); // --- reset condition code if special condition period ended if ( flag1 == 'A' || flag1 == '}' || flag1 == ']') Condition = 0; } return result; }