Dear all,I want to use MATLAB and SWMM5 for optimal calibration. In doing so:1) MATLAB has to generate some random values (decision variables) as inputs for SWMM5 (here is width of subcatchments2)Previous subcatchment widths replaced with New ones. So it is necessary that MATLAB reads inp file and replaces older subcatchment widths with generated values.3)SWMM5 has to run in DOS version (swmm54)MATLAB has to read rpt file and picks some result to calculate objective function5) generate other values and repeat steps 1 to 4.My question is:How can MATLAB read INP,RPT and OUT files?Any help would be appreciated.

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 –

Replies

  • Hello everybody!, I have encountered the same issue in the last year, and because of this I have developed an open source solution to replicate the SWMM algorithm in Matlab, Python, and LabVIEW easily. I have called it MatSWMM an it is available at: https://github.com/water-systems/MatSWMM

    MatSWMM can be useful to model Real-time control for urban drainage systems, extract simulation results and edit systematically a system that has been created with the SWMM platform. I hope this can be useful to fullfil the requirements of the unpleasant batch simulation problems. 

    Please check it out, and feel free to contact me (ga.riano949@uniandes.edu.co) if any doubt or suggestion appears. 

  • If you want to modify the code further you can alter the SWMM 5 DOS engine to bring in more parameters

    Sorry, I forgot

    In the DOS version of SWMM 5 you need to modify the code in SWMM5_H for swmm_step so that it passes information from VBA to the engine.

    int  DLLEXPORT   swmm_step(double* elapsedTime, double* Total_Inflow, double* Total_Outflow,double* Total_Flood, double* System_CE, double* System_ST);  //(5.0.023 - RED)

    change the lengths in SWMM5.DEF

    LIBRARY SWMM5.DLL

    EXPORTS
    swmm_close = _swmm_close@0 
    swmm_end = _swmm_end@0
    swmm_getMassBalErr = _swmm_getMassBalErr@12 
    swmm_getVersion = _swmm_getVersion@0 
    swmm_open = _swmm_open@12 
    swmm_report = _swmm_report@0 
    swmm_run = _swmm_run@12 
    swmm_start = _swmm_start@4 
    swmm_step = _swmm_step@24

    and change the code in swmm5.c

    int DLLEXPORT swmm_step(DateTime* elapsedTime, double* Total_Inflow, double* Total_Outflow,double* Total_Flood, double* System_CE, double* System_ST) 

    3293137563?profile=original

  • Here is what it looks like for others in the future

    Parse Strings

    Identify parts of strings, find and replace substrings

    MATLAB Functions

    ischar Determine whether item is character array
    isletter Array elements that are alphabetic letters
    isspace Array elements that are space characters
    isstrprop Determine whether string is of specified category
    sscanf Read formatted data from string
    strfind Find one string within another
    strrep Find and replace substring
    strtok Selected parts of string
    validatestring Check validity of text string
    symvar Determine symbolic variables in expression
    regexp Match regular expression (case sensitive)
    regexpi Match regular expression (case insensitive)
    regexprep Replace string using regular expression
    regexptranslate Translate string into regular expression
    • int DLLEXPORT swmm_step(DateTime* elapsedTime, double* Total_Inflow, double* Total_WWF,
      double* Total_Outflow,double* Initial_Storage,double* Total_Storage,
      double* Total_Flooding, double* Total_Rain,
      double* Total_Snow,double* Total_Snowdepth, double* BasinTemp,
      double* OmegaIn,double* TSIn,
      double* percent_flooded, double* percent_surcharged,
      double* avg_Iter,double* avg_TS,
      double* max_Iter,double* min_TS);

      is a longer example

    • Thank you Robert. I' ll try to use what you 've stated.

  • Hi, I would read each line as a String and for the lines following the [SUBCATCHMENTS] section tag parse the line to extract the width and then add back your new width estimate.  This will just mean you need to parse one type of SWMM 5 data line.

    Here is the format of the line you want to parse

    3293134954?profile=RESIZE_1024x1024

    • Thank you Bob for your valuable help.

      Do you know some commands to read inp file in MATLAB?

      I roughly wrote a code to read inp file as string using 

      commands below in MATLAB:

      1) fileread('file name')

      2)  fopen('file name')

      3) fgetl('file id')

      but this is complex. On the other hand, I can not suitably write new widths values in text file.

      Do you know What MATLAB commands I have to use to parse subcatchment section, change the width and add back to subcatchment section? 

       

This reply was deleted.