News About Us Support Bugs & Tasks Links
dklfgj dfgjmpsdklg dfgjdsklfg dfjglksdfjg sdfgjokdfjg dfgjoksdfjg sdfgjksdlfgjsdf gdgjopksdfgj

Using Scripts to Run APSIM

RSS

Under C:\Program Files\Apsim73\Model you will find a few executable files,


********************************************************************
I will give you a brief explaination of how APSIM works so you can understand these executables better.


- So the way Apsim works is the GUI just creates an xml file with a .apsim extension.
The GUI can be thought of as just an xml editor.


- When you do a run in the GUI, each simulation in your .apsim file is converted to a separate .sim file.
So if you have 4 simulations in your .apsim file then you will end up with 4 .sim files.


- Each of these .sim files is then used as the input file for an actual APSIM run.
So if you have 4 .sim files then you will have 4 separate runs of APSIM.
*******************************************************************



You can manually open and edit the .apsim file in a text editor and it is the same thing as using the GUI.
So you can obviously write your own scripts to just open this plain text file and edit the xml.
(By the way ApsimUI.exe is the executable for GUI)

You can then just automate the running of this .apsim file by using the ApsimRun.exe.
You can just call it from a command line and pass it the name of the .apsim file as a parameter.
The location of the .met file and the output files should be embedded in the xml of the .apsim file.


------------------------------------------------------------------------------------------------------
Just something you should note: Make sure you run the ApsimRun.exe from the folder where the .apsim file is.
Eg. if my .apsim file is in C:\Shaun\shaun.apsim I should change directories to Shaun first,


Cd C:\Shaun\
C:\Program Files\Apsim73\Model\ApsimRun.exe shaun.apsim


Most of the time the APSIM will just put stuff like .sum file etc in the current directory. So if you do,


Cd C:\Program Files\Apsim73\Model\
ApsimRun.exe C:\Shaun\shaun.apsim


Then all your .sum files etc will end up in C:\Program Files\Apsim73\Model\.
-----------------------------------------------------------------------------------------------------



^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Also note in DOS you have to put " " around paths that have a space in them.
eg. if a directory is called "Program Files" you should write CD "C:\Program Files"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



#####################################################################################################
Please Note: Apsim 7.3 has a minor bug where when you refer to either the .apsim or .sim file in the current directory
you can not just put the name of the .apsim or .sim file.
Instead you have to put a ".\" in front of the name for the .apsim or .sim file.
Eg. Cd C:\Shaun\
C:\Program Files\Apsim73\Model\ApsimRun.exe .\shaun.apsim
#####################################################################################################



Now if you don't want to run all the simulations in a .apsim file,
lets say you only want to run one of the simulations,
then you can manually convert a .apsim file into its .sim files by using, ApsimToSim.exe
Just give it the name of the .apsim file as a parameter.


You can then use Apsim.exe to run each of these .sim files separately.
Just give Apsim.exe the name of the .sim file as its parameter.
(Note that all ApsimRun.exe does is call ApsimToSim.exe and then call Apsim.exe for each Simulation)


Dividing the .apsim file up into .sim files is done so each .sim file can be run (by using Apsim.exe) as a separate process on your CPU.
So if you have a dual or quad core processor they can be run simultaneously.


Optionally you can even use the scripting to do some optimisation.
Because APSIM just outputs plain text files (the .out files), they can be used in whatever statistics software you desire (eg. R, S+, SyStat, GenStat, Matlab, etc.).
So you can just script the calling of the stats software once the .out files are created.
You can then have your scripts automatically generate new .apsim or .sim files based on the analysis of the last set of runs. (just use a template .sim or .apsim file and use regular expressions to find and replace the variables you want to optimize)
Then just use a loop in your script to keep iterating through batches of runs to get an optimum outcome.

Please note: You can specify more then one output file in any given simulation. So a single .sim file can generate more then one .out file. This is handy for grouping certain types of variables together for analysis. So for example you might group all your soil nitrogen variables into one .out file, and all your soil water variables into another.

SiteSearch, Login/Logout, Account Settings, Create a new Page