This is for those who want to modify the SWMM5 code for MATLAB work 

How to Add Extra Output Files to #SWMM 5.1.011 – the goal here is to automatically make calibration files for InfoSWMM, H2OMap SWMM, SWMM 5 and other programs based on the name of the Outflows file in SWMM 5.

Step 1.   Add names to globals.h

EXTERN TFile

                  Finp,                     // Input file

                  Fout,                     // Output file

                  Frpt,                     // Report file

                  Fclimate,                 // Climate file

                  Frain,                    // Rainfall file

                  Frunoff,                  // Runoff file

                  Frdii,                    // RDII inflow file

                  Fhotstart1,               // Hot start input file

                  Fhotstart2,               // Hot start output file

                  Finflows,                 // Inflows routing file

                  Foutflows,                // Outflows routing file

                  FcalibrationS,            // Calibration file Innovyze RED 2016  // Storage Volume in a Storage Node

                  FcalibrationR,            // Calibration file Innovyze RED 2016   Runoff

                  FcalibrationE,            // Calibration file Innovyze RED 2016   Groundwater Elevation

                  FcalibrationG,            // Calibration file Innovyze RED 2016   Groundwater Q

                  FcalibrationH,            // Calibration file Innovyze RED 2016   Node Depth

                  FcalibrationL,            // Calibration file Innovyze RED 2016   Node Lateral Q

                  FcalibrationQ,            // Calibration file Innovyze RED 2016  Link Q

                  FcalibrationV,            // Calibration file Innovyze RED 2016  Link V

                  FcalibrationD;            // Calibration file Innovyze RED 2016  Link D

Step 2. Name them in iface.c

      case OUTFLOWS_FILE:

        if ( k != SAVE_FILE ) return error_setInpError(ERR_ITEMS"");

        Foutflows.mode = k;

        sstrncpy(Foutflows.name, tok[2], MAXFNAME);

        // SWMM 5 Calibration File // Innovyze RED - 2016

        sstrncpy(FcalibrationS.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationR.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationG.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationE.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationH.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationL.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationQ.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationV.name, tok[2], MAXFNAME);

        sstrncpy(FcalibrationD.name, tok[2], MAXFNAME);

            FcalibrationS.mode = k;

             FcalibrationR.mode = k;

             FcalibrationG.mode = k;

             FcalibrationE.mode = k;

             FcalibrationH.mode = k;

             FcalibrationL.mode = k;

             FcalibrationQ.mode = k;

             FcalibrationV.mode = k;

             FcalibrationD.mode = k;

             strcat(FcalibrationS.name,".SWMM5_S_CALIBRATION.DAT");

             strcat(FcalibrationR.name,".SWMM5_R_CALIBRATION.DAT");

             strcat(FcalibrationG.name,".SWMM5_G_CALIBRATION.DAT");

             strcat(FcalibrationE.name,".SWMM5_E_CALIBRATION.DAT");

             strcat(FcalibrationH.name,".SWMM5_H_CALIBRATION.DAT");

             strcat(FcalibrationL.name,".SWMM5_L_CALIBRATION.DAT");

             strcat(FcalibrationQ.name,".SWMM5_Q_CALIBRATION.DAT");

             strcat(FcalibrationV.name,".SWMM5_V_CALIBRATION.DAT");

             strcat(FcalibrationD.name,".SWMM5_D_CALIBRATION.DAT");

           break;

Step 3. Open them in iface.c

void openFileForOutput()

//

//  Input:   none

//  Output:  none

//  Purpose: opens a routing interface file for writing.

//

{

    int i, n;

    // --- open the routing file for writing text

    Foutflows.file = fopen(Foutflows.name, "wt");

       FcalibrationS.file  = fopen(FcalibrationS.name, "wt");                        // Innovyze RED 2016

       FcalibrationR.file = fopen(FcalibrationR.name, "wt");                        // Innovyze RED 2016

       FcalibrationG.file = fopen(FcalibrationG.name, "wt");                        // Innovyze RED 2016

       FcalibrationE.file = fopen(FcalibrationE.name, "wt");                        // Innovyze RED 2016

       FcalibrationH.file = fopen(FcalibrationH.name, "wt");                        // Innovyze RED 2016

       FcalibrationL.file = fopen(FcalibrationL.name, "wt");                        // Innovyze RED 2016

       FcalibrationQ.file = fopen(FcalibrationQ.name, "wt");                        // Innovyze RED 2016

       FcalibrationV.file = fopen(FcalibrationV.name, "wt");                        // Innovyze RED 2016

       FcalibrationD.file = fopen(FcalibrationD.name, "wt");                        // Innovyze RED 2016

    if ( Foutflows.file == NULL )

    {

        report_writeErrorMsg(ERR_ROUTING_FILE_OPEN, Foutflows.name);

        return;

    }

Step 5.   Alter Report.c to save data to the Extra Output files

I will leave out these details as they are too tedious. 

    if ( Nobjects[SUBCATCH] == 0 ) return;

    WRITE(";Subcatchment Results");

     k = 0;

    for (j = 0; j < Nobjects[SUBCATCH]; j++)

    {

        if ( Subcatch[j].rptFlag == TRUE )

        {

            fprintf(FcalibrationR.file,"\n%s", Subcatch[j].ID);   

               //fprintf(FcalibrationG.file,"\n%s", Subcatch[j].ID);   

               //Fprintf(FcalibrationE.file,"\n%s", Subcatch[j].ID);          

                    report_SubcatchHeader(Subcatch[j].ID);

            for ( period = 1; period <= Nperiods; period++ )

            {

                output_readDateTime(period, &days);

                datetime_dateToStr(days, theDate);

                datetime_timeToStr(days, theTime);

                output_readSubcatchResults(period, k);

                        datetime_decodeDate(days, &year, &month, &day);               

                 fprintf(FcalibrationR.file, "\n%02d/%02d/%4d %4s %9.3f R",   

                   month,day,year, theTime, SubcatchResults[SUBCATCH_RUNOFF]) ;

            }

            k++;

        }

    }

Step 5.  Close them in iface.c

void iface_closeRoutingFiles()

//

//  Input:   none

//  Output:  none

//  Purpose: closes routing interface files.

//

{

    FREE(IfacePolluts);

    FREE(IfaceNodes);

    if ( OldIfaceValues != NULL ) project_freeMatrix(OldIfaceValues);

    if ( NewIfaceValues != NULL ) project_freeMatrix(NewIfaceValues);

    if ( Finflows.file )  fclose(Finflows.file);

    if ( Foutflows.file ) fclose(Foutflows.file);

    if ( FcalibrationS.file )  fclose(FcalibrationS.file);  //  Innovyze RED - 2016

    if ( FcalibrationR.file ) fclose(FcalibrationR.file);   //  Innovyze RED - 2016

    if ( FcalibrationG.file ) fclose(FcalibrationG.file);   //  Innovyze RED - 2016

    if ( FcalibrationE.file ) fclose(FcalibrationE.file);   //  Innovyze RED - 2016

    if ( FcalibrationH.file ) fclose(FcalibrationH.file);   //  Innovyze RED - 2016

    if ( FcalibrationL.file ) fclose(FcalibrationL.file);   //  Innovyze RED - 2016

    if ( FcalibrationQ.file ) fclose(FcalibrationQ.file);   //  Innovyze RED - 2016

    if ( FcalibrationV.file ) fclose(FcalibrationV.file);   //  Innovyze RED - 2016

    if ( FcalibrationD.file ) fclose(FcalibrationD.file);   //  Innovyze RED - 2016

}

You need to be a member of SWMM 5 or SWMM or EPASWMM and SWMM5 in ICM_SWMM to add comments!

Join SWMM 5 or SWMM or EPASWMM and SWMM5 in ICM_SWMM

Email me when people reply –