int gwater_readAquiferParams(Project* project, int j, char* tok[], int ntoks) // // Input: j = aquifer index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns error message // Purpose: reads aquifer parameter values from line of input data // // Data line contains following parameters: // ID, porosity, wiltingPoint, fieldCapacity, conductivity, // conductSlope, tensionSlope, upperEvapFraction, lowerEvapDepth, // gwRecession, bottomElev, waterTableElev, upperMoisture // (evapPattern) // { int i, p; double x[12]; char *id; // --- check that aquifer exists if ( ntoks < 13 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(project, AQUIFER, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); // --- read remaining tokens as numbers for (i = 0; i < 11; i++) x[i] = 0.0; for (i = 1; i < 13; i++) { if ( ! getDouble(tok[i], &x[i-1]) ) return error_setInpError(ERR_NUMBER, tok[i]); } // --- read upper evap pattern if present p = -1; if ( ntoks > 13 ) { p = project_findObject(project, TIMEPATTERN, tok[13]); if ( p < 0 ) return error_setInpError(ERR_NAME, tok[13]); } // --- assign parameters to aquifer object project->Aquifer[j].ID = id; project->Aquifer[j].porosity = x[0]; project->Aquifer[j].wiltingPoint = x[1]; project->Aquifer[j].fieldCapacity = x[2]; project->Aquifer[j].conductivity = x[3] / UCF(project, RAINFALL); project->Aquifer[j].conductSlope = x[4]; project->Aquifer[j].tensionSlope = x[5] / UCF(project, LENGTH); project->Aquifer[j].upperEvapFrac = x[6]; project->Aquifer[j].lowerEvapDepth = x[7] / UCF(project, LENGTH); project->Aquifer[j].lowerLossCoeff = x[8] / UCF(project, RAINFALL); project->Aquifer[j].bottomElev = x[9] / UCF(project, LENGTH); project->Aquifer[j].waterTableElev = x[10] / UCF(project, LENGTH); project->Aquifer[j].upperMoisture = x[11]; project->Aquifer[j].upperEvapPat = p; return 0; }
int snow_readMeltParams(Project* project, char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns error code // Purpose: reads snow melt parameters from a tokenized line of input data. // // Format of data are: // Name SubArea Cmin Cmax Tbase FWF SD0 FW0 SNN0/SD100 // Name REMOVAL SDplow Fout Fimperv Fperv Fimelt Fsubcatch (Subcatch) // { int i, j, k, m, n; double x[7]; if ( ntoks < 8 ) return error_setInpError(ERR_ITEMS, ""); // --- save snow melt parameter set name if not already done so j = project_findObject(project, SNOWMELT, tok[0]); if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]); if ( project->Snowmelt[j].ID == NULL ) project->Snowmelt[j].ID = project_findID(project, SNOWMELT, tok[0]); // --- identify data keyword k = findmatch(tok[1], SnowmeltWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, tok[1]); // --- number of parameters to read n = 7; // 7 for subareas if ( k == SNOW_REMOVAL ) n = 6; // 6 for Removal if ( ntoks < n + 2 ) return error_setInpError(ERR_ITEMS, ""); for (i=0; i<7; i++) x[i] = 0.0; // --- parse each parameter for (i=0; i<n; i++) { if ( ! getDouble(tok[i+2], &x[i]) ) return error_setInpError(ERR_NUMBER, tok[i+2]); } // --- parse name of subcatch receiving snow plowed from current subcatch if ( k == SNOW_REMOVAL ) { x[6] = -1.0; if ( ntoks >= 9 ) { m = project_findObject(project, SUBCATCH, tok[8]); if ( m < 0 ) return error_setInpError(ERR_NAME, tok[8]); x[6] = m; } } // --- save snow melt parameters setMeltParams(project, j, k, x); return 0; }
int controls_addRuleClause(int r, int keyword, char* tok[], int nToks) // // Input: r = rule index // keyword = the clause's keyword code (IF, THEN, etc.) // tok = an array of string tokens that comprises the clause // nToks = number of tokens // Output: returns an error code // Purpose: addd a new clause to a control rule. // { switch (keyword) { case r_RULE: if ( Rules[r].ID == NULL ) Rules[r].ID = project_findID(CONTROL, tok[1]); InputState = r_RULE; if ( nToks > 2 ) return ERR_RULE; //(5.0.010 - LR) return 0; case r_IF: if ( InputState != r_RULE ) return ERR_RULE; InputState = r_IF; return addPremise(r, r_AND, tok, nToks); case r_AND: if ( InputState == r_IF ) return addPremise(r, r_AND, tok, nToks); else if ( InputState == r_THEN || InputState == r_ELSE ) return addAction(r, tok, nToks); else return ERR_RULE; case r_OR: if ( InputState != r_IF ) return ERR_RULE; return addPremise(r, r_OR, tok, nToks); case r_THEN: if ( InputState != r_IF ) return ERR_RULE; InputState = r_THEN; return addAction(r, tok, nToks); case r_ELSE: if ( InputState != r_THEN ) return ERR_RULE; InputState = r_ELSE; return addAction(r, tok, nToks); case r_PRIORITY: if ( InputState != r_THEN && InputState != r_ELSE ) return ERR_RULE; InputState = r_PRIORITY; if ( !getDouble(tok[1], &Rules[r].priority) ) return ERR_NUMBER; if ( nToks > 2 ) return ERR_RULE; //(5.0.010 - LR) return 0; } return 0; }
int rdii_readUnitHydParams(char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads parameters of an RDII unit hydrograph from a line of input. // { int i, j, m, g; float x[9]; // --- check that RDII UH object exists in database j = project_findObject(UNITHYD, tok[0]); if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]); // --- assign UH ID to name in hash table if ( UnitHyd[j].ID == NULL ) UnitHyd[j].ID = project_findID(UNITHYD, tok[0]); // --- line has 2 tokens; assign rain gage to UH object if ( ntoks == 2 ) { g = project_findObject(GAGE, tok[1]); if ( g < 0 ) return error_setInpError(ERR_NAME, tok[1]); UnitHyd[j].rainGage = g; return 0; } // --- line has 11 tokens; retrieve & save UH params. if ( ntoks == 11 ) { // --- find which month UH params apply to m = datetime_findMonth(tok[1]); if ( m == 0 ) { if ( !match(tok[1], w_ALL) ) return error_setInpError(ERR_KEYWORD, tok[1]); } // --- read 3 sets of r-t-k values for ( i = 0; i < 9; i++ ) { if ( ! getFloat(tok[i+2], &x[i]) ) return error_setInpError(ERR_NUMBER, tok[i+2]); } // --- save UH params setUnitHydParams(j, m, x); return 0; } else return error_setInpError(ERR_ITEMS, ""); }
int junc_readParams(int j, int k, char* tok[], int ntoks) // // Input: j = node index // k = junction index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error message // Purpose: reads a junction's properties from a tokenized line of input. // // Format of input line is: // nodeID elev maxDepth initDepth surDepth aPond { int i; double x[6]; char* id; if ( ntoks < 2 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(NODE, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); // --- parse invert elev., max. depth, init. depth, surcharged depth, // & ponded area values for ( i = 1; i <= 5; i++ ) { x[i-1] = 0.0; if ( i < ntoks ) { if ( ! getDouble(tok[i], &x[i-1]) ) return error_setInpError(ERR_NUMBER, tok[i]); } } // --- check for non-negative values (except for invert elev.) for ( i = 1; i <= 4; i++ ) { if ( x[i] < 0.0 ) return error_setInpError(ERR_NUMBER, tok[i+1]); } // --- add parameters to junction object Node[j].ID = id; node_setParams(j, JUNCTION, k, x); return 0; }
int table_readCurve(char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads a tokenized line of data for a curve table. // { int j, m, k, k1 = 1; double x, y; // --- check for minimum number of tokens if ( ntoks < 3 ) return error_setInpError(ERR_ITEMS, ""); // --- check that curve exists in database j = project_findObject(CURVE, tok[0]); if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]); // --- check if this is first line of curve's data // (curve's ID will not have been assigned yet) if ( Curve[j].ID == NULL ) { // --- assign ID pointer & curve type Curve[j].ID = project_findID(CURVE, tok[0]); m = findmatch(tok[1], CurveTypeWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, tok[1]); Curve[j].curveType = m; k1 = 2; } // --- start reading pairs of X-Y value tokens for ( k = k1; k < ntoks; k = k+2) { if ( k+1 >= ntoks ) return error_setInpError(ERR_ITEMS, ""); if ( ! getDouble(tok[k], &x) ) return error_setInpError(ERR_NUMBER, tok[k]); if ( ! getDouble(tok[k+1], &y) ) return error_setInpError(ERR_NUMBER, tok[k+1]); table_addEntry(&Curve[j], x, y); } return 0; }
int landuse_readParams(Project* project, int j, char* tok[], int ntoks) // // Input: j = land use index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads landuse parameters from a tokenized line of input. // // Data format is: // landuseID (sweepInterval sweepRemoval sweepDays0) // { char *id; if ( ntoks < 1 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(project,LANDUSE, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); project->Landuse[j].ID = id; if ( ntoks > 1 ) { if ( ntoks < 4 ) return error_setInpError(ERR_ITEMS, ""); if ( ! getDouble(tok[1], &project->Landuse[j].sweepInterval) ) return error_setInpError(ERR_NUMBER, tok[1]); if ( ! getDouble(tok[2], &project->Landuse[j].sweepRemoval) ) return error_setInpError(ERR_NUMBER, tok[2]); if ( ! getDouble(tok[3], &project->Landuse[j].sweepDays0) ) return error_setInpError(ERR_NUMBER, tok[3]); } else { project->Landuse[j].sweepInterval = 0.0; project->Landuse[j].sweepRemoval = 0.0; project->Landuse[j].sweepDays0 = 0.0; } if ( project->Landuse[j].sweepRemoval < 0.0 || project->Landuse[j].sweepRemoval > 1.0 ) return error_setInpError(ERR_NUMBER, tok[2]); return 0; }
int outfall_readParams(int j, int k, char* tok[], int ntoks) // // Input: j = node index // k = outfall index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error message // Purpose: reads an outfall's properties from a tokenized line of input. // // Format of input line is: // nodeID elev FIXED fixedStage (flapGate) (routeTo) // nodeID elev TIDAL curveID (flapGate) (routeTo) // nodeID elev TIMESERIES tseriesID (flapGate) (routTo) // nodeID elev FREE (flapGate) (routeTo) // nodeID elev NORMAL (flapGate) (routeTo) // { int i, m, n; double x[7]; //(5.1.008) char* id; if ( ntoks < 3 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(NODE, tok[0]); // node ID if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); if ( ! getDouble(tok[1], &x[0]) ) // invert elev. return error_setInpError(ERR_NUMBER, tok[1]); i = findmatch(tok[2], OutfallTypeWords); // outfall type if ( i < 0 ) return error_setInpError(ERR_KEYWORD, tok[2]); x[1] = i; // outfall type x[2] = 0.0; // fixed stage x[3] = -1.; // tidal curve x[4] = -1.; // tide series x[5] = 0.; // flap gate x[6] = -1.; // route to subcatch//(5.1.008) n = 4; if ( i >= FIXED_OUTFALL ) { if ( ntoks < 4 ) return error_setInpError(ERR_ITEMS, ""); n = 5; switch ( i ) { case FIXED_OUTFALL: // fixed stage if ( ! getDouble(tok[3], &x[2]) ) return error_setInpError(ERR_NUMBER, tok[3]); break; case TIDAL_OUTFALL: // tidal curve m = project_findObject(CURVE, tok[3]); if ( m < 0 ) return error_setInpError(ERR_NAME, tok[3]); x[3] = m; break; case TIMESERIES_OUTFALL: // stage time series m = project_findObject(TSERIES, tok[3]); if ( m < 0 ) return error_setInpError(ERR_NAME, tok[3]); x[4] = m; Tseries[m].refersTo = TIMESERIES_OUTFALL; } } if ( ntoks == n ) { m = findmatch(tok[n-1], NoYesWords); // flap gate if ( m < 0 ) return error_setInpError(ERR_KEYWORD, tok[n-1]); x[5] = m; } //// Added for release 5.1.008. //// //(5.1.008) if ( ntoks == n+1) { m = project_findObject(SUBCATCH, tok[n]); if ( m < 0 ) return error_setInpError(ERR_NAME, tok[n]); x[6] = m; } //// Node[j].ID = id; node_setParams(j, OUTFALL, k, x); return 0; }
int subcatch_readParams(int j, char* tok[], int ntoks) // // Input: j = subcatchment index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads subcatchment parameters from a tokenized line of input data. // // Data has format: // Name RainGage Outlet Area %Imperv Width Slope CurbLength Snowpack // { int i, k, m; char* id; double x[9]; // --- check for enough tokens if ( ntoks < 8 ) return error_setInpError(ERR_ITEMS, ""); // --- check that named subcatch exists id = project_findID(SUBCATCH, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); // --- check that rain gage exists k = project_findObject(GAGE, tok[1]); if ( k < 0 ) return error_setInpError(ERR_NAME, tok[1]); x[0] = k; // --- check that outlet node or subcatch exists m = project_findObject(NODE, tok[2]); x[1] = m; m = project_findObject(SUBCATCH, tok[2]); x[2] = m; if ( x[1] < 0.0 && x[2] < 0.0 ) return error_setInpError(ERR_NAME, tok[2]); // --- read area, %imperv, width, slope, & curb length for ( i = 3; i < 8; i++) { if ( ! getDouble(tok[i], &x[i]) || x[i] < 0.0 ) return error_setInpError(ERR_NUMBER, tok[i]); } // --- if snowmelt object named, check that it exists x[8] = -1; if ( ntoks > 8 ) { k = project_findObject(SNOWMELT, tok[8]); if ( k < 0 ) return error_setInpError(ERR_NAME, tok[8]); x[8] = k; } // --- assign input values to subcatch's properties Subcatch[j].ID = id; Subcatch[j].gage = (int)x[0]; Subcatch[j].outNode = (int)x[1]; Subcatch[j].outSubcatch = (int)x[2]; Subcatch[j].area = x[3] / UCF(LANDAREA); Subcatch[j].fracImperv = x[4] / 100.0; Subcatch[j].width = x[5] / UCF(LENGTH); Subcatch[j].slope = x[6] / 100.0; Subcatch[j].curbLength = x[7]; // --- create the snow pack object if it hasn't already been created if ( x[8] >= 0 ) { if ( !snow_createSnowpack(j, (int)x[8]) ) return error_setInpError(ERR_MEMORY, ""); } return 0; }
int table_readTimeseries(char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads a tokenized line of data for a time series table. // { int j; // time series index int k; // token index int state; // 1: next token should be a date // 2: next token should be a time // 3: next token should be a value double x, y; // time & value table entries DateTime d; // day portion of date/time value DateTime t; // time portion of date/time value // --- check for minimum number of tokens if ( ntoks < 3 ) return error_setInpError(ERR_ITEMS, ""); // --- check that time series exists in database j = project_findObject(TSERIES, tok[0]); if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]); // --- if first line of data, assign ID pointer if ( Tseries[j].ID == NULL ) Tseries[j].ID = project_findID(TSERIES, tok[0]); // --- check if time series data is in an external file if ( strcomp(tok[1], w_FILE ) ) { sstrncpy(Tseries[j].file.name, tok[2], MAXFNAME); Tseries[j].file.mode = USE_FILE; return 0; } // --- parse each token of input line x = 0.0; k = 1; state = 1; // start off looking for a date while ( k < ntoks ) { switch(state) { case 1: // look for a date entry if ( datetime_strToDate(tok[k], &d) ) { Tseries[j].lastDate = d; k++; } // --- next token must be a time state = 2; break; case 2: // look for a time entry if ( k >= ntoks ) return error_setInpError(ERR_ITEMS, ""); // --- first check for decimal hours format if ( getDouble(tok[k], &t) ) t /= 24.0; // --- then for an hrs:min format else if ( !datetime_strToTime(tok[k], &t) ) return error_setInpError(ERR_NUMBER, tok[k]); // --- save date + time in x x = Tseries[j].lastDate + t; // --- next token must be a numeric value k++; state = 3; break; case 3: // --- extract a numeric value from token if ( k >= ntoks ) return error_setInpError(ERR_ITEMS, ""); if ( ! getDouble(tok[k], &y) ) return error_setInpError(ERR_NUMBER, tok[k]); // --- add date/time & value to time series table_addEntry(&Tseries[j], x, y); // --- start over looking first for a date k++; state = 1; break; } } return 0; }
int gage_readParams(int j, char* tok[], int ntoks) // // Input: j = rain gage index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads rain gage parameters from a line of input data // // Data formats are: // Name RainType RecdFreq SCF TIMESERIES SeriesName // Name RainType RecdFreq SCF FILE FileName Station Units StartDate // { int k, err; char *id; char fname[MAXFNAME+1]; char staID[MAXMSG+1]; double x[7]; // --- check that gage exists if ( ntoks < 2 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(GAGE, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); // --- assign default parameter values x[0] = -1.0; // No time series index x[1] = 1.0; // Rain type is volume x[2] = 3600.0; // Recording freq. is 3600 sec x[3] = 1.0; // Snow catch deficiency factor x[4] = NO_DATE; // Default is no start/end date x[5] = NO_DATE; x[6] = 0.0; // US units strcpy(fname, ""); strcpy(staID, ""); if ( ntoks < 5 ) return error_setInpError(ERR_ITEMS, ""); k = findmatch(tok[4], GageDataWords); if ( k == RAIN_TSERIES ) { err = readGageSeriesFormat(tok, ntoks, x); } else if ( k == RAIN_FILE ) { if ( ntoks < 8 ) return error_setInpError(ERR_ITEMS, ""); sstrncpy(fname, tok[5], MAXFNAME); sstrncpy(staID, tok[6], MAXMSG); err = readGageFileFormat(tok, ntoks, x); } else return error_setInpError(ERR_KEYWORD, tok[4]); // --- save parameters to rain gage object if ( err > 0 ) return err; Gage[j].ID = id; Gage[j].tSeries = (int)x[0]; Gage[j].rainType = (int)x[1]; Gage[j].rainInterval = (int)x[2]; Gage[j].snowFactor = x[3]; Gage[j].rainUnits = (int)x[6]; if ( Gage[j].tSeries >= 0 ) Gage[j].dataSource = RAIN_TSERIES; else Gage[j].dataSource = RAIN_FILE; if ( Gage[j].dataSource == RAIN_FILE ) { sstrncpy(Gage[j].fname, fname, MAXFNAME); sstrncpy(Gage[j].staID, staID, MAXMSG); Gage[j].startFileDate = x[4]; Gage[j].endFileDate = x[5]; } Gage[j].unitsFactor = 1.0; Gage[j].coGage = -1; Gage[j].isUsed = FALSE; return 0; }
int landuse_readPollutParams(int j, char* tok[], int ntoks) // // Input: j = pollutant index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads pollutant parameters from a tokenized line of input. // // Data format is: // pollutID cUnits cRain cGW cRDII kDecay IsSediment snowOnly coPollut coFrac // { int i, k, coPollut, snowFlag, sedFlag; float x[4], coFrac; char *id; // --- extract pollutant name & units if ( ntoks < 6 ) return error_setInpError(ERR_ITEMS, ""); //added sedFlag = 0; if ( ntoks >= 7 ) { sedFlag = findmatch(tok[6], SedimentWords); if ( sedFlag < 0 ) return error_setInpError(ERR_KEYWORD, tok[6]); } if (sedFlag == 4) { sedFlag = 1; tok[0] = "SAND"; } id = project_findID(POLLUT, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); k = findmatch(tok[1], QualUnitsWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, tok[1]); // --- extract concen. in rain, gwater, & I&I and decay coeff for ( i = 2; i <= 5; i++ ) { if ( ! getFloat(tok[i], &x[i-2]) ) return error_setInpError(ERR_NUMBER, tok[i]); } // --- set defaults for snow only flag & co-pollut. parameters snowFlag = 0; coPollut = -1; coFrac = 0.0; // --- check for snow only flag if ( ntoks >= 8 ) { snowFlag = findmatch(tok[7], NoYesWords); if ( snowFlag < 0 ) return error_setInpError(ERR_KEYWORD, tok[7]); } // --- check for co-pollutant if ( ntoks >= 10 ) { if ( !strcomp(tok[8], "*") ) { coPollut = project_findObject(POLLUT, tok[8]); if ( coPollut < 0 ) return error_setInpError(ERR_NAME, tok[8]); if ( ! getFloat(tok[9], &coFrac) ) return error_setInpError(ERR_NUMBER, tok[9]); } } // --- save values for pollutant object Pollut[j].ID = id; Pollut[j].units = k; if ( Pollut[j].units == MG ) Pollut[j].mcf = UCF(MASS); else if ( Pollut[j].units == UG ) Pollut[j].mcf = UCF(MASS) / 1000.0; else Pollut[j].mcf = 1.0; Pollut[j].pptConcen = x[0]; Pollut[j].gwConcen = x[1]; Pollut[j].rdiiConcen = x[2]; Pollut[j].kDecay = x[3]/SECperDAY; Pollut[j].sedflag = sedFlag; Pollut[j].snowOnly = snowFlag; Pollut[j].coPollut = coPollut; Pollut[j].coFraction = coFrac; return 0; }
int divider_readParams(int j, int k, char* tok[], int ntoks) // // Input: j = node index // k = divider index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error message // Purpose: reads a flow divider's properties from a tokenized line of input. // // Format of input line is: // nodeID elev divLink TABULAR curveID (optional params) // nodeID elev divLink OVERFLOW (optional params) // nodeID elev divLink CUTOFF qCutoff (optional params) // nodeID elev divLink WEIR qMin dhMax cWeir (optional params) // where optional params are: // maxDepth initDepth surDepth aPond // { int i, m, m1, m2, n; double x[11]; char* id; // --- get ID name if ( ntoks < 4 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(NODE, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); // --- get invert elev. if ( ! getDouble(tok[1], &x[0]) ) return error_setInpError(ERR_NUMBER, tok[1]); // --- initialize parameter values for ( i=1; i<11; i++) x[i] = 0.0; // --- check if no diverted link supplied if ( strlen(tok[2]) == 0 || strcmp(tok[2], "*") == 0 ) x[1] = -1.0; // --- otherwise get index of diverted link else { m1 = project_findObject(LINK, tok[2]); if ( m1 < 0 ) return error_setInpError(ERR_NAME, tok[2]); x[1] = m1; } // --- get divider type n = 4; m1 = findmatch(tok[3], DividerTypeWords); if ( m1 < 0 ) return error_setInpError(ERR_KEYWORD, tok[3]); x[2] = m1; // --- get index of flow diversion curve for Tabular divider x[3] = -1; if ( m1 == TABULAR_DIVIDER ) { if ( ntoks < 5 ) return error_setInpError(ERR_ITEMS, ""); m2 = project_findObject(CURVE, tok[4]); if ( m2 < 0 ) return error_setInpError(ERR_NAME, tok[4]); x[3] = m2; n = 5; } // --- get cutoff flow for Cutoff divider if ( m1 == CUTOFF_DIVIDER ) { if ( ntoks < 5 ) return error_setInpError(ERR_ITEMS, ""); if ( ! getDouble(tok[4], &x[4]) ) return error_setInpError(ERR_NUMBER, tok[4]); n = 5; } // --- get qmin, dhMax, & cWeir for Weir divider if ( m1 == WEIR_DIVIDER ) { if ( ntoks < 7 ) return error_setInpError(ERR_ITEMS, ""); for (i=4; i<7; i++) if ( ! getDouble(tok[i], &x[i]) ) return error_setInpError(ERR_NUMBER, tok[i]); n = 7; } // --- no parameters needed for Overflow divider if ( m1 == OVERFLOW_DIVIDER ) n = 4; // --- retrieve optional full depth, init. depth, surcharged depth // & ponded area m = 7; for (i=n; i<ntoks && m<11; i++) { if ( ! getDouble(tok[i], &x[m]) ) { return error_setInpError(ERR_NUMBER, tok[i]); } m++; } // --- add parameters to data base Node[j].ID = id; node_setParams(j, DIVIDER, k, x); return 0; }
int storage_readParams(int j, int k, char* tok[], int ntoks) // // Input: j = node index // k = storage unit index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error message // Purpose: reads a storage unit's properties from a tokenized line of input. // // Format of input line is: // nodeID elev maxDepth initDepth FUNCTIONAL a1 a2 a0 aPond fEvap (infil) // nodeID elev maxDepth initDepth TABULAR curveID aPond fEvap (infil) // { int i, m, n; double x[9]; char* id; // --- get ID name if ( ntoks < 6 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(NODE, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); // --- get invert elev, max. depth, & init. depth for ( i = 1; i <= 3; i++ ) { if ( ! getDouble(tok[i], &x[i-1]) ) return error_setInpError(ERR_NUMBER, tok[i]); } // --- get surf. area relation type m = findmatch(tok[4], RelationWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, tok[4]); x[3] = 0.0; // a1 x[4] = 0.0; // a2 x[5] = 0.0; // a0 x[6] = -1.0; // curveID x[7] = 0.0; // aPond x[8] = 0.0; // fEvap // --- get surf. area function coeffs. if ( m == FUNCTIONAL ) { for (i=5; i<=7; i++) { if ( i < ntoks ) { if ( ! getDouble(tok[i], &x[i-2]) ) return error_setInpError(ERR_NUMBER, tok[i]); } } n = 8; } // --- get surf. area curve name else { m = project_findObject(CURVE, tok[5]); if ( m < 0 ) return error_setInpError(ERR_NAME, tok[5]); x[6] = m; n = 6; } // --- ignore next token if present (deprecated ponded area property) //(5.1.007) if ( ntoks > n) { if ( ! getDouble(tok[n], &x[7]) ) return error_setInpError(ERR_NUMBER, tok[n]); n++; } // --- get evaporation fraction if present if ( ntoks > n ) { if ( ! getDouble(tok[n], &x[8]) ) return error_setInpError(ERR_NUMBER, tok[n]); n++; } // --- add parameters to storage unit object Node[j].ID = id; node_setParams(j, STORAGE, k, x); // --- read exfiltration parameters if present if ( ntoks > n ) return exfil_readStorageParams(k, tok, ntoks, n); //(5.1.007) return 0; }
int landuse_readParams(int j, char* tok[], int ntoks) // // Input: j = land use index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads landuse parameters from a tokenized line of input. // // Data format is: // landuseID (sweepInterval sweepRemoval sweepDays0 //HSPF --> pctimp smpf krer jrer affix cover kser jser kger jger frc_sand frc_silt frc_clay) // { char *id; if ( ntoks < 1 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(LANDUSE, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); Landuse[j].ID = id; if ( ntoks > 1 ) { //if ( ntoks < 4 ) return error_setInpError(ERR_ITEMS, ""); if ( ntoks < 17 ) return error_setInpError(ERR_ITEMS, ""); if ( ! getFloat(tok[1], &Landuse[j].sweepInterval) ) return error_setInpError(ERR_NUMBER, tok[1]); if ( ! getFloat(tok[2], &Landuse[j].sweepRemoval) ) return error_setInpError(ERR_NUMBER, tok[2]); if ( ! getFloat(tok[3], &Landuse[j].sweepDays0) ) return error_setInpError(ERR_NUMBER, tok[3]); // HSPF parameters if ( ! getFloat(tok[4], &Landuse[j].pctimp) ) return error_setInpError(ERR_NUMBER, tok[4]); if ( ! getFloat(tok[5], &Landuse[j].smpf) ) return error_setInpError(ERR_NUMBER, tok[5]); if ( ! getFloat(tok[6], &Landuse[j].krer) ) return error_setInpError(ERR_NUMBER, tok[6]); if ( ! getFloat(tok[7], &Landuse[j].jrer) ) return error_setInpError(ERR_NUMBER, tok[7]); if ( ! getFloat(tok[8], &Landuse[j].affix) ) return error_setInpError(ERR_NUMBER, tok[8]); if ( ! getFloat(tok[9], &Landuse[j].cover) ) return error_setInpError(ERR_NUMBER, tok[9]); if ( ! getFloat(tok[10], &Landuse[j].kser) ) return error_setInpError(ERR_NUMBER, tok[10]); if ( ! getFloat(tok[11], &Landuse[j].jser) ) return error_setInpError(ERR_NUMBER, tok[11]); if ( ! getFloat(tok[12], &Landuse[j].kger) ) return error_setInpError(ERR_NUMBER, tok[12]); if ( ! getFloat(tok[13], &Landuse[j].jger) ) return error_setInpError(ERR_NUMBER, tok[13]); if ( ! getFloat(tok[14], &Landuse[j].frc_sand) ) return error_setInpError(ERR_NUMBER, tok[14]); if ( ! getFloat(tok[15], &Landuse[j].frc_silt) ) return error_setInpError(ERR_NUMBER, tok[15]); if ( ! getFloat(tok[16], &Landuse[j].frc_clay) ) return error_setInpError(ERR_NUMBER, tok[16]); } else { Landuse[j].sweepInterval = 0.0; Landuse[j].sweepRemoval = 0.0; Landuse[j].sweepDays0 = 0.0; Landuse[j].pctimp = 0.0; Landuse[j].smpf = 0.0; Landuse[j].krer = 0.0; Landuse[j].jrer = 0.0; Landuse[j].affix = 0.0; Landuse[j].cover = 0.0; Landuse[j].kser = 0.0; Landuse[j].jser = 0.0; Landuse[j].kger = 0.0; Landuse[j].jger = 0.0; Landuse[j].frc_sand = 0.0; Landuse[j].frc_silt = 0.0; Landuse[j].frc_clay = 0.0; } if ( Landuse[j].sweepRemoval < 0.0 || Landuse[j].sweepRemoval > 1.0 ) return error_setInpError(ERR_NUMBER, tok[2]); return 0; }
int landuse_readPollutParams(Project* project, int j, char* tok[], int ntoks) // // Input: j = pollutant index // tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads pollutant parameters from a tokenized line of input. // // Data format is: // ID Units cRain cGW cRDII kDecay (snowOnly coPollut coFrac cDWF cInit) // { int i, k, coPollut, snowFlag; double x[4], coFrac, cDWF, cInit; char *id; // --- extract pollutant name & units if ( ntoks < 6 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(project, POLLUT, tok[0]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[0]); k = findmatch(tok[1], QualUnitsWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, tok[1]); // --- extract concen. in rain, gwater, & I&I for ( i = 2; i <= 4; i++ ) { if ( ! getDouble(tok[i], &x[i-2]) || x[i-2] < 0.0 ) { return error_setInpError(ERR_NUMBER, tok[i]); } } // --- extract decay coeff. (which can be negative for growth) if ( ! getDouble(tok[5], &x[3]) ) { return error_setInpError(ERR_NUMBER, tok[5]); } // --- set defaults for snow only flag & co-pollut. parameters snowFlag = 0; coPollut = -1; coFrac = 0.0; cDWF = 0.0; cInit = 0.0; // --- check for snow only flag if ( ntoks >= 7 ) { snowFlag = findmatch(tok[6], NoYesWords); if ( snowFlag < 0 ) return error_setInpError(ERR_KEYWORD, tok[6]); } // --- check for co-pollutant if ( ntoks >= 9 ) { if ( !strcomp(tok[7], "*") ) { coPollut = project_findObject(project, POLLUT, tok[7]); if ( coPollut < 0 ) return error_setInpError(ERR_NAME, tok[7]); if ( ! getDouble(tok[8], &coFrac) || coFrac < 0.0 ) return error_setInpError(ERR_NUMBER, tok[8]); } } // --- check for DWF concen. if ( ntoks >= 10 ) { if ( ! getDouble(tok[9], &cDWF) || cDWF < 0.0) return error_setInpError(ERR_NUMBER, tok[9]); } // --- check for initial concen. if ( ntoks >= 11 ) { if ( ! getDouble(tok[10], &cInit) || cInit < 0.0 ) return error_setInpError(ERR_NUMBER, tok[9]); } // --- save values for pollutant object project->Pollut[j].ID = id; project->Pollut[j].units = k; if ( project->Pollut[j].units == MG ) project->Pollut[j].mcf = UCF(project, MASS); else if (project->Pollut[j].units == UG) project->Pollut[j].mcf = UCF(project, MASS) / 1000.0; else project->Pollut[j].mcf = 1.0; project->Pollut[j].pptConcen = x[0]; project->Pollut[j].gwConcen = x[1]; project->Pollut[j].rdiiConcen = x[2]; project->Pollut[j].kDecay = x[3]/SECperDAY; project->Pollut[j].snowOnly = snowFlag; project->Pollut[j].coPollut = coPollut; project->Pollut[j].coFraction = coFrac; project->Pollut[j].dwfConcen = cDWF; project->Pollut[j].initConcen = cInit; return 0; }
int transect_readParams(int* count, char* tok[], int ntoks) // // Input: count = transect index // tok[] = array of string tokens // ntoks = number of tokens // Output: updated value of count, // returns an error code // Purpose: read parameters of a transect from a tokenized line of input data. // // Format of transect data follows that used for HEC-2 program: // NC nLeft nRight nChannel // X1 name nSta xLeftBank xRightBank 0 0 0 xFactor yFactor // GR Elevation Station ... // { int i, k; int index = *count; // transect index int errcode; // error code double x[10]; // parameter values char* id; // transect ID name // --- match first token to a transect keyword k = findmatch(tok[0], TransectKeyWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, tok[0]); // --- read parameters associated with keyword switch ( k ) { // --- NC line: Manning n values case 0: // --- finish processing the previous transect transect_validate(index - 1); // --- read Manning's n values if ( ntoks < 4 ) return error_setInpError(ERR_ITEMS, ""); for (i = 1; i <= 3; i++) { if ( ! getDouble(tok[i], &x[i]) ) return error_setInpError(ERR_NUMBER, tok[i]); } return setManning(x); // --- X1 line: identifies start of next transect case 1: // --- check that transect was already added to project // (by input_countObjects) if ( ntoks < 10 ) return error_setInpError(ERR_ITEMS, ""); id = project_findID(TRANSECT, tok[1]); if ( id == NULL ) return error_setInpError(ERR_NAME, tok[1]); // --- read in rest of numerical values on data line for ( i = 2; i < 10; i++ ) { if ( ! getDouble(tok[i], &x[i]) ) return error_setInpError(ERR_NUMBER, tok[i]); } // --- update total transect count *count = index + 1; // --- transfer parameter values to transect's properties return setParams(index, id, x); // --- GR line: station elevation & location data case 2: // --- check that line contains pairs of data values if ( (ntoks - 1) % 2 > 0 ) return error_setInpError(ERR_ITEMS, ""); // --- parse each pair of Elevation-Station values i = 1; while ( i < ntoks ) { if ( ! getDouble(tok[i], &x[1]) ) return error_setInpError(ERR_NUMBER, tok[i]); if ( ! getDouble(tok[i+1], &x[2]) ) return error_setInpError(ERR_NUMBER, tok[i+1]); errcode = addStation(x[1], x[2]); if ( errcode ) return errcode; i += 2; } return 0; } return 0; }