Example #1
0
void  divider_validate(int j)
//
//  Input:   j = node index
//  Output:  none
//  Purpose: validates a flow divider's properties.
//
{
    int i, k;

    // --- check that diverted link is attached to divider
    k = Node[j].subIndex;
    i = Divider[k].link;
    if ( i < 0 || ( Link[i].node1 != j && Link[i].node2 != j) )
    {
        report_writeErrorMsg(ERR_DIVIDER_LINK, Node[j].ID);
    }

    // --- validate parameters supplied for weir-type divider
    if ( Divider[k].type == WEIR_DIVIDER )
    {
        if ( Divider[k].dhMax <= 0.0 || Divider[k].cWeir <= 0.0 )
            report_writeErrorMsg(ERR_WEIR_DIVIDER, Node[j].ID);
        else
        {
            // --- find flow when weir is full
            Divider[k].qMax = Divider[k].cWeir * pow(Divider[k].dhMax, 1.5)
                              / UCF(FLOW);
            if ( Divider[k].qMin > Divider[k].qMax )
                report_writeErrorMsg(ERR_WEIR_DIVIDER, Node[j].ID);
        }
    }
}
Example #2
0
void  gwater_validateAquifer(Project* project, int j)
//
//  Input:   j = aquifer index
//  Output:  none
//  Purpose: validates groundwater aquifer properties .
//
{
	int p;

    if ( project->Aquifer[j].porosity          <= 0.0 
    ||   project->Aquifer[j].fieldCapacity     >= project->Aquifer[j].porosity
    ||   project->Aquifer[j].wiltingPoint      >= project->Aquifer[j].fieldCapacity
    ||   project->Aquifer[j].conductivity      <= 0.0
    ||   project->Aquifer[j].conductSlope      <  0.0
    ||   project->Aquifer[j].tensionSlope      <  0.0
    ||   project->Aquifer[j].upperEvapFrac     <  0.0
    ||   project->Aquifer[j].lowerEvapDepth    <  0.0
    ||   project->Aquifer[j].waterTableElev    <  project->Aquifer[j].bottomElev
    ||   project->Aquifer[j].upperMoisture     >  project->Aquifer[j].porosity 
    ||   project->Aquifer[j].upperMoisture     <  project->Aquifer[j].wiltingPoint )
        report_writeErrorMsg(project,ERR_AQUIFER_PARAMS, project->Aquifer[j].ID);

    p = project->Aquifer[j].upperEvapPat;
    if ( p >= 0 && project->Pattern[p].type != MONTHLY_PATTERN )
    {
        report_writeErrorMsg(project,ERR_AQUIFER_PARAMS, project->Aquifer[j].ID);
    }
}
Example #3
0
void readTD3200FileLine(int* y, int* m)
//
//  Input:   none
//  Output:  y = year
//           m = month
//  Purpose: reads year & month from line of TD-3200 climate file.
//
{
    char recdType[4] = "";
    char year[5] = "";
    char month[3] = "";
    int  len;

    // --- check for minimum number of characters
    len = (int)strlen(FileLine);
    if ( len < 30 )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_READ, Fclimate.name);
        return;
    }

    // --- check for proper type of record
    sstrncpy(recdType, FileLine, 3);
    if ( strcmp(recdType, "DLY") != 0 )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_READ, Fclimate.name);
        return;
    }

    // --- get record's date 
    sstrncpy(year,  &FileLine[17], 4);
    sstrncpy(month, &FileLine[21], 2);
    *y = atoi(year);
    *m = atoi(month);
}
Example #4
0
void validateGeneralLayout(Project* project)
//
//  Input:   none
//  Output:  nonw
//  Purpose: validates general conveyance system layout.
//
{
    int i, j;
    int outletCount = 0;

    // --- use node inflow attribute to count inflow connections
    for ( i=0; i<project->Nobjects[NODE]; i++ ) project->Node[i].inflow = 0.0;

    // --- examine each link
    for ( j = 0; j < project->Nobjects[LINK]; j++ )
    {
        // --- update inflow link count of downstream node
        i = project->Link[j].node1;
        if ( project->Node[i].type != OUTFALL ) i = project->Link[j].node2;
        project->Node[i].inflow += 1.0;

        // --- if link is dummy link or ideal pump then it must
        //     be the only link exiting the upstream node 
        if ( (project->Link[j].type == CONDUIT && project->Link[j].xsect.type == DUMMY) ||
             (project->Link[j].type == PUMP &&
              project->Pump[project->Link[j].subIndex].type == IDEAL_PUMP) )
        {
            i = project->Link[j].node1;
            if ( project->Link[j].direction < 0 ) i = project->Link[j].node2;
            if ( project->Node[i].degree > 1 )
            {
                report_writeErrorMsg(project,ERR_DUMMY_LINK, project->Node[i].ID);
            }
        }
    }

    // --- check each node to see if it qualifies as an outlet node
    //     (meaning that degree = 0)
    for ( i = 0; i < project->Nobjects[NODE]; i++ )
    {
        // --- if node is of type Outfall, check that it has only 1
        //     connecting link (which can either be an outflow or inflow link)
        if ( project->Node[i].type == OUTFALL )
        {
            if ( project->Node[i].degree + (int)project->Node[i].inflow > 1 )
            {
                report_writeErrorMsg(project,ERR_OUTFALL, project->Node[i].ID);
            }
            else outletCount++;
        }
    }
    if ( outletCount == 0 ) report_writeErrorMsg(project,ERR_NO_OUTLETS, "");

    // --- reset node inflows back to zero
    for ( i = 0; i < project->Nobjects[NODE]; i++ )
    {
        if ( project->Node[i].inflow == 0.0 ) project->Node[i].degree = -project->Node[i].degree;
        project->Node[i].inflow = 0.0;
    }
}
void project_readInput()
//
//  Input:   none
//  Output:  none
//  Purpose: retrieves project data from input file.
//
{
    // --- create hash tables for fast retrieval of objects by ID names
    createHashTables();

    // --- count number of objects in input file and create them
    input_countObjects();
    createObjects();

    // --- read project data from input file
    input_readData();
    if ( ErrorCode ) return;

    // --- establish starting & ending date/time
    StartDateTime = StartDate + StartTime;
    EndDateTime   = EndDate + EndTime;
    ReportStart   = ReportStartDate + ReportStartTime;
    ReportStart   = MAX(ReportStart, StartDateTime);

    // --- check for valid starting & ending date/times
    if ( EndDateTime <= StartDateTime )
    {
        report_writeErrorMsg(ERR_START_DATE, "");
    }
    else if ( EndDateTime <= ReportStart )
    {
        report_writeErrorMsg(ERR_REPORT_DATE, "");
    }
    else
    {
////  Following code segment was modified for release 5.1.009.  ////           //(5.1.009)
////
        // --- compute total duration of simulation in seconds
        TotalDuration = floor((EndDateTime - StartDateTime) * SECperDAY);

        // --- reporting step must be <= total duration
        if ( (double)ReportStep > TotalDuration )
        {
            ReportStep = (int)(TotalDuration);
        }

        // --- reporting step can't be < routing step
        if ( (double)ReportStep < RouteStep )
        {
            report_writeErrorMsg(ERR_REPORT_STEP, "");
        }

        // --- convert total duration to milliseconds
        TotalDuration *= 1000.0;
    }
////
}
Example #6
0
void validateRdii()
//
//  Input:   none
//  Output:  none
//  Purpose: validates UH and RDII inflow object data.
//
{
    int   i,                           // node index
          j,                           // UH group index
          k,                           // individual UH index
          m;                           // month index
    float rsum;                        // sum of UH r-values

    // --- check each unit hydrograph for consistency
    for (j=0; j<Nobjects[UNITHYD]; j++)
    {
        for (m=0; m<12; m++)
        {
            rsum = 0.0;
            for (k=0; k<3; k++)
            {
                // --- if no base time then UH doesn't exist
                if ( UnitHyd[j].tBase[m][k] == 0 ) continue;

                // --- can't have negative UH parameters
                if ( UnitHyd[j].tPeak[m][k] < 0.0 ) 
                {
                    report_writeErrorMsg(ERR_UNITHYD_TIMES, UnitHyd[j].ID);
                }

                // --- can't have negative UH response ratio
                if ( UnitHyd[j].r[m][k] < 0.0 )
                {
                    report_writeErrorMsg(ERR_UNITHYD_RATIOS, UnitHyd[j].ID);
                }
                else rsum += UnitHyd[j].r[m][k];
            }
            if ( rsum > 1.01 )
            {
                report_writeErrorMsg(ERR_UNITHYD_RATIOS, UnitHyd[j].ID);
            }
        }
    }

    // --- check each node's RDII inflow object
    for (i=0; i<Nobjects[NODE]; i++)
    {
        if ( Node[i].rdiiInflow )
        {
            // --- check that sewer area is non-negative
            if ( Node[i].rdiiInflow->area < 0.0 )
            {
                report_writeErrorMsg(ERR_RDII_AREA, Node[i].ID);
            }
        }
    }
}
Example #7
0
void  gage_validate(int j)
//
//  Input:   j = rain gage index
//  Output:  none
//  Purpose: checks for valid rain gage parameters
//
//  NOTE: assumes that any time series used by a rain gage has been
//        previously validated.
//
{
    int i, k;
    int gageInterval;

    // --- for gage with time series data:
    if ( Gage[j].dataSource == RAIN_TSERIES )
    {
        // --- check gage's recording interval against that of time series
        k = Gage[j].tSeries;
        if ( Tseries[k].refersTo >= 0 )
        {
            report_writeErrorMsg(ERR_RAIN_GAGE_TSERIES, Gage[j].ID);
        }
        gageInterval = (int)(floor(Tseries[k].dxMin*SECperDAY + 0.5));
        if ( gageInterval > 0 && Gage[j].rainInterval > gageInterval )
        {
            report_writeErrorMsg(ERR_RAIN_GAGE_INTERVAL, Gage[j].ID);
        } 
        if ( Gage[j].rainInterval < gageInterval )
        {
            report_writeWarningMsg(WARN09, Gage[j].ID);
        }
        if ( Gage[j].rainInterval < WetStep )
        {
            report_writeWarningMsg(WARN01, Gage[j].ID);
            WetStep = Gage[j].rainInterval;
        }

        // --- see if gage uses same time series as another gage
        for (i=0; i<j; i++)
        {
            if ( Gage[i].dataSource == RAIN_TSERIES && Gage[i].tSeries == k )
            {
                Gage[j].coGage = i;

                // --- check that both gages record same type of data
                if ( Gage[j].rainType != Gage[i].rainType )
                {
                    report_writeErrorMsg(ERR_RAIN_GAGE_FORMAT, Gage[j].ID);
                }
                return;
            }
        }
    }
}
Example #8
0
void runoff_initFile(void)
//
//  Input:   none
//  Output:  none
//  Purpose: initializes a Runoff Interface file for saving results.
//
{
    int   nSubcatch;
    int   nPollut;
    int   flowUnits;
    char  fileStamp[] = "SWMM5-RUNOFF";
    char  fStamp[] = "SWMM5-RUNOFF";

    MaxSteps = 0;
    if ( Frunoff.mode == SAVE_FILE )
    {
        // --- write file stamp, # subcatchments & # pollutants to file
        nSubcatch = Nobjects[SUBCATCH];
        nPollut = Nobjects[POLLUT];
        flowUnits = FlowUnits;
        fwrite(fileStamp, sizeof(char), strlen(fileStamp), Frunoff.file);
        fwrite(&nSubcatch, sizeof(int), 1, Frunoff.file);
        fwrite(&nPollut, sizeof(int), 1, Frunoff.file);
        fwrite(&flowUnits, sizeof(int), 1, Frunoff.file);
        MaxStepsPos = ftell(Frunoff.file); 
        fwrite(&MaxSteps, sizeof(int), 1, Frunoff.file);
    }

    if ( Frunoff.mode == USE_FILE )
    {
        // --- check that interface file contains proper header records
        fread(fStamp, sizeof(char), strlen(fileStamp), Frunoff.file);
        if ( strcmp(fStamp, fileStamp) != 0 )
        {
            report_writeErrorMsg(ERR_RUNOFF_FILE_FORMAT, "");
            return;
        }
        nSubcatch = -1;
        nPollut = -1;
        flowUnits = -1;
        fread(&nSubcatch, sizeof(int), 1, Frunoff.file);
        fread(&nPollut, sizeof(int), 1, Frunoff.file);
        fread(&flowUnits, sizeof(int), 1, Frunoff.file);
        fread(&MaxSteps, sizeof(int), 1, Frunoff.file);
        if ( nSubcatch != Nobjects[SUBCATCH]
        ||   nPollut   != Nobjects[POLLUT]
        ||   flowUnits != FlowUnits
        ||   MaxSteps  <= 0 )
        {
             report_writeErrorMsg(ERR_RUNOFF_FILE_FORMAT, "");
        }
    }
}
Example #9
0
int openHotstartFile1()
//
//  Input:   none
//  Output:  none
//  Purpose: opens a previously saved hotstart file.
//
{
    int   nNodes;
    int   nLinks;
    int   nPollut;
    int   flowUnits;
    char  fileStamp[] = "SWMM5-HOTSTART";
    char  fStamp[] = "SWMM5-HOTSTART";

    // --- try to open the file
    if ( Fhotstart1.mode != USE_FILE ) return TRUE;
    if ( (Fhotstart1.file = fopen(Fhotstart1.name, "r+b")) == NULL)
    {
        report_writeErrorMsg(ERR_HOTSTART_FILE_OPEN, Fhotstart1.name);
        return FALSE;
    }

    // --- check that file contains proper header records
    fread(fStamp, sizeof(char), strlen(fileStamp), Fhotstart1.file);
    if ( strcmp(fStamp, fileStamp) != 0 )
    {
        report_writeErrorMsg(ERR_HOTSTART_FILE_FORMAT, "");
        return FALSE;
    }
    nNodes = -1;
    nLinks = -1;
    nPollut = -1;
    flowUnits = -1;
    fread(&nNodes, sizeof(int), 1, Fhotstart1.file);
    fread(&nLinks, sizeof(int), 1, Fhotstart1.file);
    fread(&nPollut, sizeof(int), 1, Fhotstart1.file);
    fread(&flowUnits, sizeof(int), 1, Fhotstart1.file);
    if ( nNodes != Nobjects[NODE]
    ||   nLinks != Nobjects[LINK]
    ||   nPollut   != Nobjects[POLLUT]
    ||   flowUnits != FlowUnits )
    {
         report_writeErrorMsg(ERR_HOTSTART_FILE_FORMAT, "");
         return FALSE;
    }

    // --- read contents of the file and close it
    readHotstartFile();
    fclose(Fhotstart1.file);
    if ( ErrorCode ) return FALSE;
    else return TRUE;
}
Example #10
0
void project_readInput()
//
//  Input:   none
//  Output:  none
//  Purpose: retrieves project data from input file.
//
{
    // --- create hash tables for fast retrieval of objects by ID names
    createHashTables();

    // --- count number of objects in input file and create them
    input_countObjects();
    createObjects();

    // --- read project data from input file
    input_readData();
    if ( ErrorCode ) return;

    // --- establish starting & ending date/time
    StartDateTime = StartDate + StartTime;
    EndDateTime   = EndDate + EndTime;
    ReportStart   = ReportStartDate + ReportStartTime;
    ReportStart   = MAX(ReportStart, StartDateTime);

    // --- check for valid starting & ending date/times
    if ( EndDateTime <= StartDateTime )
    {
        report_writeErrorMsg(ERR_START_DATE, "");
    }
    else if ( EndDateTime <= ReportStart )
    {
        report_writeErrorMsg(ERR_REPORT_DATE, "");
    }
    else
    {
        // --- compute total duration of simulation in milliseconds
        //     (add on 1 msec to account for any roundoff)
        TotalDuration = (EndDateTime - StartDateTime) * MSECperDAY;
        TotalDuration += 1.0;

        // --- reporting step must be <= total duration
        if ( (double)ReportStep > TotalDuration/1000.0 )
        {
            ReportStep = (int)(TotalDuration/1000.0);
        }
        if ( (float)ReportStep < RouteStep )
        {
            report_writeErrorMsg(ERR_REPORT_STEP, "");
        }
    }
}
int runoff_open()
//
//  Input:   none
//  Output:  returns the global error code
//  Purpose: opens the runoff analyzer.
//
{
    IsRaining = FALSE;
    HasRunoff = FALSE;
    HasSnow = FALSE;
    Nsteps = 0;

    // --- open the Ordinary Differential Equation solver
    //     to solve up to 3 ode's.
    if ( !odesolve_open(3) ) report_writeErrorMsg(ERR_ODE_SOLVER, "");

    // --- allocate memory for pollutant washoff loads
    WashoffQual = NULL;
    WashoffLoad = NULL;
    if ( Nobjects[POLLUT] > 0 )
    {
        WashoffQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        if ( !WashoffQual ) report_writeErrorMsg(ERR_MEMORY, "");
        WashoffLoad = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        if ( !WashoffLoad ) report_writeErrorMsg(ERR_MEMORY, "");
    }

    // --- see if a runoff interface file should be opened
    switch ( Frunoff.mode )
    {
      case USE_FILE:
        if ( (Frunoff.file = fopen(Frunoff.name, "r+b")) == NULL)
            report_writeErrorMsg(ERR_RUNOFF_FILE_OPEN, Frunoff.name);
        else runoff_initFile();
        break;
      case SAVE_FILE:
        if ( (Frunoff.file = fopen(Frunoff.name, "w+b")) == NULL)
            report_writeErrorMsg(ERR_RUNOFF_FILE_OPEN, Frunoff.name);
        else runoff_initFile();
        break;
    }

    // --- see if a climate file should be opened
    if ( Frunoff.mode != USE_FILE && Fclimate.mode == USE_FILE )
    {
        climate_openFile();
    }
    return ErrorCode;
}
Example #12
0
void climate_validate()
//
//  Input:   none
//  Output:  none
//  Purpose: validates climatological variables
//
{
    int       i;                                                               //(5.1.007)
    double    a, z, pa;

    // --- check if climate data comes from external data file                 //(5.1.007)
    if ( Wind.type == FILE_WIND || Evap.type == FILE_EVAP ||
         Evap.type == TEMPERATURE_EVAP )
    {
        if ( Fclimate.mode == NO_FILE )
        {
            report_writeErrorMsg(ERR_NO_CLIMATE_FILE, "");
        }
    }

    // --- open the climate data file                                          //(5.1.007)
    if ( Fclimate.mode == USE_FILE ) climate_openFile();                       //(5.1.007)

    // --- snow melt parameters tipm & rnm must be fractions
    if ( Snow.tipm < 0.0 ||
         Snow.tipm > 1.0 ||
         Snow.rnm  < 0.0 ||
         Snow.rnm  > 1.0 ) report_writeErrorMsg(ERR_SNOWMELT_PARAMS, "");

    // --- latitude should be between -90 & 90 degrees
    a = Temp.anglat;
    if ( a <= -89.99 ||
         a >= 89.99  ) report_writeErrorMsg(ERR_SNOWMELT_PARAMS, "");
    else Temp.tanAnglat = tan(a * PI / 180.0);

    // --- compute psychrometric constant
    z = Temp.elev / 1000.0;
    if ( z <= 0.0 ) pa = 29.9;
    else  pa = 29.9 - 1.02*z + 0.0032*pow(z, 2.4); // atmos. pressure
    Temp.gamma = 0.000359 * pa;

    // --- convert units of monthly temperature & evap adjustments             //(5.1.007)
    for (i = 0; i < 12; i++)
    {
        if (UnitSystem == SI) Adjust.temp[i] *= 9.0/5.0;
        Adjust.evap[i] /= UCF(EVAPRATE);
    }
}
Example #13
0
void  node_validate(int j)
//
//  Input:   j = node index
//  Output:  none
//  Purpose: validates a node's properties.
//
{
    TDwfInflow* inflow;

    // --- see if full depth was increased to accommodate conduit crown
    if ( Node[j].fullDepth > Node[j].oldDepth && Node[j].oldDepth > 0.0 )
    {
        report_writeWarningMsg(WARN02, Node[j].ID);
    }

    // --- check that initial depth does not exceed max. depth
    if ( Node[j].initDepth > Node[j].fullDepth + Node[j].surDepth )
        report_writeErrorMsg(ERR_NODE_DEPTH, Node[j].ID);

    if ( Node[j].type == DIVIDER ) divider_validate(j);

    // --- initialize dry weather inflows
    inflow = Node[j].dwfInflow;
    while (inflow)
    {
        inflow_initDwfInflow(inflow);
        inflow = inflow->next;
    }
}
Example #14
0
int routing_open()
//
//  Input:   none
//  Output:  returns an error code
//  Purpose: initializes the routing analyzer.
//
{
    // --- open treatment system
    if ( !treatmnt_open() ) return ErrorCode;

    // --- topologically sort the links
    SortedLinks = NULL;
    if ( Nobjects[LINK] > 0 )
    {
        SortedLinks = (int *) calloc(Nobjects[LINK], sizeof(int));
        if ( !SortedLinks )
        {
            report_writeErrorMsg(ERR_MEMORY, "");
            return ErrorCode;
        }
        toposort_sortLinks(SortedLinks);
        if ( ErrorCode ) return ErrorCode;
    }

    // --- open any routing interface files
    iface_openRoutingFiles();
    return ErrorCode;
}
void iface_openRoutingFiles()
//
//  Input:   none
//  Output:  none
//  Purpose: opens routing interface files.
//
{
    // --- initialize shared variables
    NumIfacePolluts = 0;
    IfacePolluts = NULL;
    NumIfaceNodes = 0;
    IfaceNodes = NULL;
    OldIfaceValues = NULL;
    NewIfaceValues = NULL;

    // --- check that inflows & outflows files are not the same
    if ( Foutflows.mode != NO_FILE && Finflows.mode != NO_FILE )
    {
        if ( strcomp(Foutflows.name, Finflows.name) )
        {
            report_writeErrorMsg(ERR_ROUTING_FILE_NAMES, "");
            return;
        }
    }

    // --- open the file for reading or writing
    if ( Foutflows.mode == SAVE_FILE ) openFileForOutput();
    if ( Finflows.mode == USE_FILE ) openFileForInput();
}
Example #16
0
int openHotstartFile2()
//
//  Input:   none
//  Output:  none
//  Purpose: opens a new hotstart file to save results to.
//
{
    int   nNodes;
    int   nLinks;
    int   nPollut;
    int   flowUnits;
    char  fileStamp[] = "SWMM5-HOTSTART";

    // --- try to open file
    if ( Fhotstart2.mode != SAVE_FILE ) return TRUE;
    if ( (Fhotstart2.file = fopen(Fhotstart2.name, "w+b")) == NULL)
    {
        report_writeErrorMsg(ERR_HOTSTART_FILE_OPEN, Fhotstart2.name);
        return FALSE;
    }

    // --- write file stamp, # nodes, # links, & # pollutants to file
    nNodes = Nobjects[NODE];
    nLinks = Nobjects[LINK];
    nPollut = Nobjects[POLLUT];
    flowUnits = FlowUnits;
    fwrite(fileStamp, sizeof(char), strlen(fileStamp), Fhotstart2.file);
    fwrite(&nNodes, sizeof(int), 1, Fhotstart2.file);
    fwrite(&nLinks, sizeof(int), 1, Fhotstart2.file);
    fwrite(&nPollut, sizeof(int), 1, Fhotstart2.file);
    fwrite(&flowUnits, sizeof(int), 1, Fhotstart2.file);
    return TRUE;
}
Example #17
0
void snow_validateSnowmelt(Project* project, int j)
//
//  Input:   j = snowmelt parameter set index
//  Output:  none
//  Purpose: checks for valid values in a snow melt parameter set.
//
{
    int    k;
    char   err = FALSE;
    double sum = 0.0;

    for ( k = SNOW_PLOWABLE; k <= SNOW_PERV; k++ )
    {
        // --- check melt coeffs.
        if ( project->Snowmelt[j].dhmin[k] > project->Snowmelt[j].dhmax[k] ) err = TRUE; 

        // --- check free water fraction
        if ( project->Snowmelt[j].fwfrac[k] < 0.0 ||
             project->Snowmelt[j].fwfrac[k] > 1.0) err = TRUE;
    }

    // --- check fraction of imperv. area plowable
    if ( project->Snowmelt[j].snn < 0.0 || project->Snowmelt[j].snn > 1.0 ) err = TRUE;

    // --- check that removal fractions sum <= 1.0
    for ( k=0; k<5; k++ ) sum += project->Snowmelt[j].sfrac[k];
    if ( sum > 1.01 ) err = TRUE;
	if (err) report_writeErrorMsg(project, ERR_SNOWPACK_PARAMS, project->Snowmelt[j].ID);
}
int routing_open()
//
//  Input:   none
//  Output:  returns an error code
//  Purpose: initializes the routing analyzer.
//
{
    // --- open treatment system
    if ( !treatmnt_open() ) return ErrorCode;

    // --- topologically sort the links
    SortedLinks = NULL;
    if ( Nobjects[LINK] > 0 )
    {
        SortedLinks = (int *) calloc(Nobjects[LINK], sizeof(int));
        if ( !SortedLinks )
        {
            report_writeErrorMsg(ERR_MEMORY, "");
            return ErrorCode;
        }
        toposort_sortLinks(SortedLinks);
        if ( ErrorCode ) return ErrorCode;
    }

    // --- open any routing interface files
    iface_openRoutingFiles();

    // --- initialize flow and quality routing systems                         //(5.1.008)
    flowrout_init(RouteModel);                                                 //(5.1.008)
    if ( Fhotstart1.mode == NO_FILE ) qualrout_init();                         //(5.1.008)

    return ErrorCode;
}
Example #19
0
int  treatmnt_open(void)
//
//  Input:   none
//  Output:  returns TRUE if successful, FALSE if not
//  Purpose: allocates memory for computing pollutant removals by treatment.
//
{
/////////////////////////////////////////////////////
//  Updated to allocate memory for Cin. (LR - 9/5/05)
/////////////////////////////////////////////////////

    R = NULL;
    Cin = NULL;
    if ( Nobjects[POLLUT] > 0 )
    {
        R = (float *) calloc(Nobjects[POLLUT], sizeof(float));
        Cin = (float *) calloc(Nobjects[POLLUT], sizeof(float));
        if ( R == NULL || Cin == NULL)
        {
            report_writeErrorMsg(ERR_MEMORY, "");
            return FALSE;
        }
    }
    return TRUE;
}
Example #20
0
void readDLY0204FileLine(int* y, int* m)
//
//  Input:   none
//  Output:  y = year
//           m = month
//  Purpose: reads year & month from line of DLY02 or DLY04 climate file.
//
{
    char year[5] = "";
    char month[3] = "";
    int  len;

    // --- check for minimum number of characters
    len = (int)strlen(FileLine);
    if ( len < 16 )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_READ, Fclimate.name);
        return;
    }

    // --- get record's date 
    sstrncpy(year,  &FileLine[7], 4);
    sstrncpy(month, &FileLine[11], 2);
    *y = atoi(year);
    *m = atoi(month);
}
Example #21
0
void readHotstartFile(void)
//
//  Input:   none
//  Output:  none
//  Purpose: reads initial state of all nodes and links from hotstart file.
//
{
    int   i, j;
    long  pos, size;
    float x;

    // --- check that file has correct size
    pos = ftell(Fhotstart1.file);
    fseek(Fhotstart1.file, 0L, SEEK_END);
    size = ( ftell(Fhotstart1.file) - pos ) / sizeof(float);
    if ( size < Nobjects[NODE] * (2 + 2*Nobjects[POLLUT]) +
                Nobjects[LINK] * (3 + Nobjects[POLLUT]) )
    {
         report_writeErrorMsg(ERR_HOTSTART_FILE_READ, "");
         return;
    }
    fseek(Fhotstart1.file, pos, SEEK_SET);

    // --- read node states
    for (i = 0; i < Nobjects[NODE]; i++)
    {
        if ( !readFloat(&x) ) return;
        Node[i].newDepth = x;
        if ( !readFloat(&x) ) return;
        Node[i].newLatFlow = x;
        for (j = 0; j < Nobjects[POLLUT]; j++)
        {
            if ( !readFloat(&x) ) return;
            Node[i].newQual[j] = x;
        }

        // --- read in zero here for back compatibility
        for (j = 0; j < Nobjects[POLLUT]; j++)
        {
            if ( !readFloat(&x) ) return;
        }
    }

    // --- read link states
    for (i = 0; i < Nobjects[LINK]; i++)
    {
        if ( !readFloat(&x) ) return;
        Link[i].newFlow = x;
        if ( !readFloat(&x) ) return;
        Link[i].newDepth = x;
        if ( !readFloat(&x) ) return;
        Link[i].setting = x;
        for (j = 0; j < Nobjects[POLLUT]; j++)
        {
            if ( !readFloat(&x) ) return;
            Link[i].newQual[j] = x;
        }
    }
}
Example #22
0
void createHashTables()
//
//  Input:   none
//  Output:  returns error code
//  Purpose: allocates memory for object ID hash tables
//
{   int j;
    MemPoolAllocated = FALSE;
    for (j = 0; j < MAX_OBJ_TYPES ; j++)
    {
         Htable[j] = HTcreate();
         if ( Htable[j] == NULL ) report_writeErrorMsg(ERR_MEMORY, "");
    }

    // --- initialize memory pool used to store object ID's
    if ( AllocInit() == NULL ) report_writeErrorMsg(ERR_MEMORY, "");
    else MemPoolAllocated = TRUE;
}
Example #23
0
void openRdiiProcessor()
//
//  Input:   none
//  Output:  none
//  Purpose: opens RDII processing system.
//
{
    int j;                             // object index
    int n;                             // RDII node count

    // --- set RDII processing arrays to NULL
    GageData = NULL;
    UHData   = NULL;
    RdiiNodeIndex = NULL;
    RdiiNodeFlow = NULL;
    TotalRainVol = 0.0;
    TotalRdiiVol = 0.0;

    // --- allocate memory used for RDII processing
    if ( !allocRdiiMemory() )
    {
        report_writeErrorMsg(ERR_MEMORY, "");
        return;
    }

    // --- open & initialize RDII file
    if ( !openNewRdiiFile() )
    {
        report_writeErrorMsg(ERR_RDII_FILE_SCRATCH, "");
        return;
    }

    // --- identify index of each node with RDII inflow
    n = 0;    
    for (j=0; j<Nobjects[NODE]; j++)
    {
        if ( Node[j].rdiiInflow )
        {
            RdiiNodeIndex[n] = j;
            n++;
        }
    }
}
Example #24
0
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;
}
Example #25
0
void initRainFile(Project* project)
//
//  Input:   none
//  Output:  none
//  Purpose: initializes rain interface file for reading.
//
{
    char  fileStamp[] = "SWMM5-RAIN";
    char  fStamp[] = "SWMM5-RAIN";
    int   i;
    int   kount;
    long  filePos;

    // --- make sure interface file is open and no error condition
    if ( project->ErrorCode || !project->Frain.file ) return;

    // --- check that interface file contains proper file stamp
    rewind(project->Frain.file);
    fread(fStamp, sizeof(char), strlen(fileStamp), project->Frain.file);
    if ( strcmp(fStamp, fileStamp) != 0 )
    {
        report_writeErrorMsg(project,ERR_RAIN_IFACE_FORMAT, "");
        return;
    }
    fread(&kount, sizeof(int), 1, project->Frain.file);
    filePos = ftell(project->Frain.file);

    // --- locate information for each raingage in interface file
    for ( i = 0; i < project->Nobjects[GAGE]; i++ )
    {
        if ( project->ErrorCode || project->Gage[i].dataSource != RAIN_FILE ) continue;

        // --- match station ID for gage with one in file
        fseek(project->Frain.file, filePos, SEEK_SET);
		if (!findGageInFile(project, i, (int)kount) ||
             project->Gage[i].startFilePos == project->Gage[i].endFilePos )
        {
            report_writeErrorMsg(project,ERR_RAIN_FILE_GAGE, project->Gage[i].ID);
        }
    }
}
Example #26
0
void rdii_openRdii()
//
//  Input:   none
//  Output:  none
//  Purpose: opens an exisiting RDII interface file or creates a new one.
//
{
    // --- initialize shared RDII variables
    RdiiNodeIndex = NULL;
    RdiiNodeFlow = NULL;
    NumRdiiNodes = 0;
    RdiiStartDate = NO_DATE;

    // --- create the RDII file if existing file not being used
    if ( Frdii.mode != USE_FILE ) createRdiiFile();
    if ( Frdii.mode == NO_FILE || ErrorCode ) return;

    // --- open the RDII file
    Frdii.file = fopen(Frdii.name, "rt");
    if ( Frdii.file == NULL)
    {
        if ( Frdii.mode == SCRATCH_FILE )
        {
            report_writeErrorMsg(ERR_RDII_FILE_SCRATCH, "");
        }
        else
        {
            report_writeErrorMsg(ERR_RDII_FILE_OPEN, Frdii.name);
        }
        return;
    }

    // --- read header records from file
    ErrorCode = readRdiiFileHeader();
    if ( ErrorCode )
    {
        report_writeErrorMsg(ErrorCode, Frdii.name);
    }
    else readRdiiFlows();
}
Example #27
0
int addGageToRainFile(int i)
//
//  Input:   i = rain gage index
//  Output:  returns 1 if successful, 0 if not
//  Purpose: adds a gage's rainfall record to rain interface file
//
{
    FILE* f;                           // pointer to rain file
    int   fileFormat;                  // file format code
    int   hdrLines;                    // number of header lines skipped

////////////////////////////////////
////  New line added. (LR - 7/5/06 )
////////////////////////////////////
    // --- let StationID point to NULL
    StationID = NULL;

    // --- check that rain file exists
    if ( (f = fopen(Gage[i].fname, "rt")) == NULL )
        report_writeErrorMsg(ERR_RAIN_FILE_DATA, Gage[i].fname);
    else
    {
        fileFormat = findFileFormat(f, i, &hdrLines);
        if ( fileFormat == UNKNOWN_FORMAT )
        {
            report_writeErrorMsg(ERR_RAIN_FILE_FORMAT, Gage[i].fname);
        }
        else
        {
            readFile(f, fileFormat, hdrLines, Gage[i].startFileDate,
                     Gage[i].endFileDate);
        }
        fclose(f);
    }
    if ( ErrorCode ) return 0;
    else
    return 1;
}
Example #28
0
void climate_validate()
//
//  Input:   none
//  Output:  none
//  Purpose: validates climatological variables
//
{
    double    a, z, pa;

    // --- check if climate file was specified when used 
    //     to supply wind speed or evap rates
    if ( Wind.type == FILE_WIND || Evap.type == FILE_EVAP ||                   //(5.0.016 - LR)
         Evap.type == TEMPERATURE_EVAP )                                       //(5.0.016 - LR)
    {
        if ( Fclimate.mode == NO_FILE )
        {
            report_writeErrorMsg(ERR_NO_CLIMATE_FILE, "");
        }
    }

    // --- snow melt parameters tipm & rnm must be fractions
    if ( Snow.tipm < 0.0 ||                                                    //(5.0.012 - LR)
         Snow.tipm > 1.0 ||                                                    //(5.0.012 - LR)
         Snow.rnm  < 0.0 ||                                                    //(5.0.012 - LR)
         Snow.rnm  > 1.0 ) report_writeErrorMsg(ERR_SNOWMELT_PARAMS, "");      //(5.0.012 - LR)

    // --- latitude should be between -90 & 90 degrees                         //(5.0.013 - LR)
    a = Temp.anglat;
    if ( a <= -89.99 ||                                                        //(5.0.013 - LR)
         a >= 89.99  ) report_writeErrorMsg(ERR_SNOWMELT_PARAMS, "");          //(5.0.013 - LR)
    else Temp.tanAnglat = tan(a * PI / 180.0);                                 //(5.0.012 - LR)

    // --- compute psychrometric constant
    z = Temp.elev / 1000.0;
    if ( z <= 0.0 ) pa = 29.9;
    else  pa = 29.9 - 1.02*z + 0.0032*pow(z, 2.4); // atmos. pressure
    Temp.gamma = 0.000359 * pa;
}
Example #29
0
void readUserFileLine(int* y, int* m)
//
//  Input:   none
//  Output:  y = year
//           m = month
//  Purpose: reads year & month from line of User-Prepared climate file.
//
{
    int n;
    char staID[80];
    n = sscanf(FileLine, "%s %d %d", staID, y, m);
    if ( n < 3 )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_READ, Fclimate.name);
    }
}
Example #30
0
void  output_checkFileSize(Project* project)
//
//  Input:   none
//  Output:  none
//  Purpose: checks if the size of the binary output file will be too big
//           to access using an integer file pointer variable.
//
{
    if ( project->RptFlags.subcatchments != NONE ||
         project->RptFlags.nodes != NONE ||
         project->RptFlags.links != NONE )
    {
        if ( (double)project->OutputStartPos + (double)project->BytesPerPeriod * project->TotalDuration
             / 1000.0 / (double)project->ReportStep >= (double)MAXFILESIZE )
        {
            report_writeErrorMsg(project,ERR_FILE_SIZE, "");
        }
    }
}