Creating a Batch File on multiple iteration simulation.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alienxxx
Posts: 5
Joined: 22 Nov 2012 12:45

Creating a Batch File on multiple iteration simulation.

#1 Post by alienxxx » 23 Apr 2013 03:01

Hi all.

I have made a Rainfall Simulation model which would run for varying hours ( like 4 hours or 6 hours as we desire).
The model will make various necessary input files and output files in one complete iteraration ( Say for the 1st hour) and again for subsequent iterations.
i have made a batch file for the 1st iteration where I can get the result for first 1 hour of rainfall. I need a batch file that would enable the simulation to run for 'N' hours through user defined input choice. N ( No of iterations) being the user defined choice. I suppose proper looping will do but I am not able to it.

My code as of now , looks like this for the first iteration ( and its working ).

Code: Select all

@echo off

mode 20,5

rem *** ALERT: Sleep for 5 seconds ***
ping -n 5 127.0.0.1 > nul
rem ***************************************

Set Path="E:\kolsim"

rem *************Start SWMM5.exe**************************
E:\kolsim\swmm_new.exe E:\kolsim\100_fe.inp E:\kolsim\kolsim\report.rpt E:\kolsim\kolsim\report.out
rem ***************************************

rem *** ALERT: Sleep for 5 seconds ***
ping -n 5 127.0.0.1 > nul
rem ***************************************

rem ******Copy Flooded Nodes****
 E:\kolsim\kolsim\swmmtotx1.exe
rem ***************************************

rem *** ALERT: WAIT for 5 seconds ***
ping -n 2 127.0.0.1 > nul
rem ************************************

E:\kolsim\delete_first_line.exe

rem *** ALERT: WAIT for 2 seconds ***
ping -n 2 127.0.0.1 > nul
rem ************************************

rem ***Make Flood_nodes table*****
E:\kolsim\kolsim\floodedn_to_nodes.exe
rem ************************************

rem *****Create .bdy and .bci files*****
E:\kolsim\kolsim\create_new.exe cord.txt flooded_nodes.txt kol.bdy kol.bci
rem ************************************

rem *** ALERT: WAIT for 4 seconds ***
ping -n 4 127.0.0.1 > nul
rem ************************************

rem ****Start FLOOD SImulation***
E:\kolsim\kolsim\lisflood.exe -v koldem.dem.ascii kol.par
rem ************************************

rem *** ALERT: WAIT for 4 seconds ***
ping -n 4 127.0.0.1 > nul
rem ************************************

rem*** Rename Report File by date and time*******
ren report.rpt report-%date:~10,4%-%date:~7,2%-%date:~4,2%_%time:~0,2%hr%time:~3,2%min%time:~3,2%sec.txt
ren report.rpt report-%date:~10,4%-%date:~7,2%-%date:~4,2%_%time:~1,1%hr%time:~3,2%min%time:~3,2%sec.txt
rem******************************************************

rem ***Rename Result Folder by date and time****

pause



Please help regarding setting up a batch for the multiple simulation using user defined choice for no of simulation ( like N=4 or N=6).
Thanks.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Creating a Batch File on multiple iteration simulation.

#2 Post by abc0502 » 23 Apr 2013 15:43

Putting your code as a function, and using if command to check for the user if he input "N" or input "number of iteration" then pass that number to a for command that count and run the function.

something like that:

Code: Select all

IF /I "%~1" == "N" (
      SET "num=1"
      FOR /L %%A IN ( 1 1 %num% ) Do (
            CALL :function_name
      )
) ELSE (
      SET "num=%~1"
      FOR /L %%A IN ( 1 1 %num% ) Do (
            CALL :function_name
      )
)

Exit

Rem Put Your Function below here
:function_name
Rem Code

Goto :EOF

you said your code runs for 1 houre, that mean after it's done, it will eterate depending on the user input.

Also you can replace:

Code: Select all

      SET "num=1"
      FOR /L %%A IN ( 1 1 %num% ) Do (
            CALL :function_name
      )

with:

Code: Select all

CALL :function_name
it will run once then

Hope That what you meant.

Post Reply