DateTime datetime_addDays(DateTime date1, DateTime date2) // Input: date1 = an encoded date/time value // date2 = decimal days to be added to date1 // Output: returns date1 + date2 // Purpose: adds a given number of decimal days to a date/time. { double d1 = floor(date1); double d2 = floor(date2); int h1, m1, s1; int h2, m2, s2; datetime_decodeTime(date1, &h1, &m1, &s1); datetime_decodeTime(date2, &h2, &m2, &s2); return d1 + d2 + datetime_encodeTime(h1+h2, m1+m2, s1+s2); }
void iface_saveOutletResults(DateTime reportDate, FILE* file) // // Input: reportDate = reporting date/time // file = ptr. to interface file // Output: none // Purpose: saves system outflows to routing interface file. // { int i, p, yr, mon, day, hr, min, sec; //char theDate[25]; //(5.0.010 - RD) datetime_decodeDate(reportDate, &yr, &mon, &day); datetime_decodeTime(reportDate, &hr, &min, &sec); //sprintf(theDate, " %04d %02d %02d %02d %02d %02d ", //(5.0.010 - RD) // yr, mon, day, hr, min, sec); //(5.0.010 - RD) for (i=0; i<Nobjects[NODE]; i++) { // --- check that node is an outlet node if ( !isOutletNode(i) ) continue; // --- write node ID, date, flow, and quality to file fprintf(file, "\n%-16s", Node[i].ID); //fprintf(file, "%s", theDate); //(5.0.010 - RD) fprintf(file, " %04d %02d %02d %02d %02d %02d ", //(5.0.010 - RD) yr, mon, day, hr, min, sec); //(5.0.010 - RD) fprintf(file, " %-10f", Node[i].inflow * UCF(FLOW)); for ( p = 0; p < Nobjects[POLLUT]; p++ ) { fprintf(file, " %-10f", Node[i].newQual[p]); } } }
int datetime_hourOfDay(DateTime date) // Input: date = an encoded date/time value // Output: returns hour of day (0..23) // Purpose: finds hour of day (0 = 12 AM, ..., 23 = 11 PM) for a given date. { int hour, min, sec; datetime_decodeTime(date, &hour, &min, &sec); return hour; }
long datetime_timeDiff(DateTime date1, DateTime date2) // Input: date1 = an encoded date/time value // date2 = an encoded date/time value // Output: returns date1 - date2 in seconds // Purpose: finds number of seconds between two dates. { double d1 = floor(date1); double d2 = floor(date2); int h, m, s; long s1, s2, secs; datetime_decodeTime(date1, &h, &m, &s); s1 = 3600*h + 60*m + s; datetime_decodeTime(date2, &h, &m, &s); s2 = 3600*h + 60*m + s; secs = (int)(floor((d1 - d2)*SecsPerDay + 0.5)); secs += (s1 - s2); return secs; }
DateTime datetime_addSeconds(DateTime date1, double seconds) // Input: date1 = an encoded date/time value // seconds = number of seconds to add to date1 // Output: returns updated value of date1 // Purpose: adds a given number of seconds to a date/time. { double d = floor(date1); int h, m, s; datetime_decodeTime(date1, &h, &m, &s); return d + (3600.0*h + 60.0*m + s + seconds)/SecsPerDay; }
void datetime_timeToStr(DateTime time, char* s) // Input: time = decimal fraction of a day // Output: s = time in hr:min:sec format // Purpose: represents DateTime time value as a formatted string. { int hr, min, sec; char timeStr[TIME_STR_SIZE]; datetime_decodeTime(time, &hr, &min, &sec); sprintf(timeStr, "%02d:%02d:%02d", hr, min, sec); strcpy(s, timeStr); }
void saveRdiiFlows(DateTime currentDate) // // Input: currentDate = current calendar date/time // Output: none // Purpose: saves current set of RDII inflows in current flow units to file. // { int i, j, yr, mon, day, hr, min, sec; char theDate[25]; // --- write year, month, day, hour, minute of current date to string datetime_decodeDate(currentDate, &yr, &mon, &day); datetime_decodeTime(currentDate, &hr, &min, &sec); sprintf(theDate, " %04d %02d %02d %02d %02d %02d ", yr, mon, day, hr, min, sec); // --- write RDII inflow at each RDII node to file for (i=0; i<NumRdiiNodes; i++) { j = RdiiNodeIndex[i]; fprintf(Frdii.file, "\n%-16s %s %-10f", Node[j].ID, theDate, RdiiNodeFlow[i]*Qcf[FlowUnits]); } }
int project_readOption(char* s1, char* s2) // // Input: s1 = option keyword // s2 = string representation of option's value // Output: returns error code // Purpose: reads a project option from a pair of string tokens. // // NOTE: all project options have default values assigned in setDefaults(). // { int k, m, h, s; double tStep; char strDate[25]; DateTime aTime; DateTime aDate; // --- determine which option is being read k = findmatch(s1, OptionWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, s1); switch ( k ) { // --- choice of flow units case FLOW_UNITS: m = findmatch(s2, FlowUnitWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); FlowUnits = m; if ( FlowUnits <= MGD ) UnitSystem = US; else UnitSystem = SI; break; // --- choice of infiltration modeling method case INFIL_MODEL: m = findmatch(s2, InfilModelWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); InfilModel = m; break; // --- choice of flow routing method case ROUTE_MODEL: m = findmatch(s2, RouteModelWords); if ( m < 0 ) m = findmatch(s2, OldRouteModelWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); if ( m == NO_ROUTING ) IgnoreRouting = TRUE; else RouteModel = m; if ( RouteModel == EKW ) RouteModel = KW; break; // --- simulation start date case START_DATE: if ( !datetime_strToDate(s2, &StartDate) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- simulation start time of day case START_TIME: if ( !datetime_strToTime(s2, &StartTime) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- simulation ending date case END_DATE: if ( !datetime_strToDate(s2, &EndDate) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- simulation ending time of day case END_TIME: if ( !datetime_strToTime(s2, &EndTime) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- reporting start date case REPORT_START_DATE: if ( !datetime_strToDate(s2, &ReportStartDate) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- reporting start time of day case REPORT_START_TIME: if ( !datetime_strToTime(s2, &ReportStartTime) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- day of year when street sweeping begins or when it ends // (year is arbitrarily set to 1947 so that the dayOfYear // function can be applied) case SWEEP_START: case SWEEP_END: strcpy(strDate, s2); strcat(strDate, "/1947"); if ( !datetime_strToDate(strDate, &aDate) ) { return error_setInpError(ERR_DATETIME, s2); } m = datetime_dayOfYear(aDate); if ( k == SWEEP_START ) SweepStart = m; else SweepEnd = m; break; // --- number of antecedent dry days case START_DRY_DAYS: StartDryDays = atof(s2); if ( StartDryDays < 0.0 ) { return error_setInpError(ERR_NUMBER, s2); } break; // --- runoff or reporting time steps // (input is in hrs:min:sec format, time step saved as seconds) case WET_STEP: case DRY_STEP: case REPORT_STEP: if ( !datetime_strToTime(s2, &aTime) ) { return error_setInpError(ERR_DATETIME, s2); } datetime_decodeTime(aTime, &h, &m, &s); h += 24*(int)aTime; s = s + 60*m + 3600*h; if ( s <= 0 ) return error_setInpError(ERR_NUMBER, s2); switch ( k ) { case WET_STEP: WetStep = s; break; case DRY_STEP: DryStep = s; break; case REPORT_STEP: ReportStep = s; break; } break; // --- type of damping applied to inertial terms of dynamic wave routing case INERT_DAMPING: m = findmatch(s2, InertDampingWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); else InertDamping = m; break; // --- Yes/No options (NO = 0, YES = 1) case ALLOW_PONDING: case SLOPE_WEIGHTING: case SKIP_STEADY_STATE: case IGNORE_RAINFALL: case IGNORE_SNOWMELT: case IGNORE_GWATER: case IGNORE_ROUTING: case IGNORE_QUALITY: case IGNORE_RDII: //(5.1.004) m = findmatch(s2, NoYesWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); switch ( k ) { case ALLOW_PONDING: AllowPonding = m; break; case SLOPE_WEIGHTING: SlopeWeighting = m; break; case SKIP_STEADY_STATE: SkipSteadyState = m; break; case IGNORE_RAINFALL: IgnoreRainfall = m; break; case IGNORE_SNOWMELT: IgnoreSnowmelt = m; break; case IGNORE_GWATER: IgnoreGwater = m; break; case IGNORE_ROUTING: IgnoreRouting = m; break; case IGNORE_QUALITY: IgnoreQuality = m; break; case IGNORE_RDII: IgnoreRDII = m; break; //(5.1.004) } break; case NORMAL_FLOW_LTD: m = findmatch(s2, NormalFlowWords); if ( m < 0 ) m = findmatch(s2, NoYesWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); NormalFlowLtd = m; break; case FORCE_MAIN_EQN: m = findmatch(s2, ForceMainEqnWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); ForceMainEqn = m; break; case LINK_OFFSETS: m = findmatch(s2, LinkOffsetWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); LinkOffsets = m; break; // --- compatibility option for selecting solution method for // dynamic wave flow routing (NOT CURRENTLY USED) case COMPATIBILITY: if ( strcomp(s2, "3") ) Compatibility = SWMM3; else if ( strcomp(s2, "4") ) Compatibility = SWMM4; else if ( strcomp(s2, "5") ) Compatibility = SWMM5; else return error_setInpError(ERR_KEYWORD, s2); break; // --- routing or lengthening time step (in decimal seconds) // (lengthening time step is used in Courant stability formula // to artificially lengthen conduits for dynamic wave flow routing // (a value of 0 means that no lengthening is used)) case ROUTE_STEP: case LENGTHENING_STEP: if ( !getDouble(s2, &tStep) ) { if ( !datetime_strToTime(s2, &aTime) ) { return error_setInpError(ERR_NUMBER, s2); } else { datetime_decodeTime(aTime, &h, &m, &s); h += 24*(int)aTime; s = s + 60*m + 3600*h; tStep = s; } } if ( k == ROUTE_STEP ) { if ( tStep <= 0.0 ) return error_setInpError(ERR_NUMBER, s2); RouteStep = tStep; } else LengtheningStep = MAX(0.0, tStep); break; // --- safety factor applied to variable time step estimates under // dynamic wave flow routing (value of 0 indicates that variable // time step option not used) case VARIABLE_STEP: if ( !getDouble(s2, &CourantFactor) ) return error_setInpError(ERR_NUMBER, s2); if ( CourantFactor < 0.0 || CourantFactor > 2.0 ) return error_setInpError(ERR_NUMBER, s2); break; // --- minimum surface area (ft2 or sq. meters) associated with nodes // under dynamic wave flow routing case MIN_SURFAREA: MinSurfArea = atof(s2); break; // --- minimum conduit slope (%) case MIN_SLOPE: if ( !getDouble(s2, &MinSlope) ) return error_setInpError(ERR_NUMBER, s2); if ( MinSlope < 0.0 || MinSlope >= 100 ) return error_setInpError(ERR_NUMBER, s2); MinSlope /= 100.0; break; // --- maximum trials / time step for dynamic wave routing case MAX_TRIALS: m = atoi(s2); if ( m < 0 ) return error_setInpError(ERR_NUMBER, s2); MaxTrials = m; break; // --- head convergence tolerance for dynamic wave routing case HEAD_TOL: if ( !getDouble(s2, &HeadTol) ) { return error_setInpError(ERR_NUMBER, s2); } break; // --- steady state tolerance on system inflow - outflow case SYS_FLOW_TOL: if ( !getDouble(s2, &SysFlowTol) ) { return error_setInpError(ERR_NUMBER, s2); } SysFlowTol /= 100.0; break; // --- steady state tolerance on nodal lateral inflow case LAT_FLOW_TOL: if ( !getDouble(s2, &LatFlowTol) ) { return error_setInpError(ERR_NUMBER, s2); } LatFlowTol /= 100.0; break; case TEMPDIR: // Temporary Directory sstrncpy(TempDir, s2, MAXFNAME); break; } return 0; }