This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
howtos:toolcoding:tool_shell_scripts [2010/03/16 12:40] shona.weldon |
howtos:toolcoding:tool_shell_scripts [2010/03/16 13:03] shona.weldon |
||
---|---|---|---|
Line 16: | Line 16: | ||
* look() - shows what is in the current directory optionally a string can be provided to filter the results | * look() - shows what is in the current directory optionally a string can be provided to filter the results | ||
+ | **TIP:** In the interactive TOOL window hit <Ctrl> and the up arrow key to get the previous command to save typing | ||
Line 69: | Line 70: | ||
One of the challenges of running shell scripts in standard mode is the need to create and shape objects. To mitigate this, TOOL scripts can be run in //local// mode in which TOOL objects - as files - can be accessed from and output to the the local working directory. This is especially useful if certain TOOL objects (with instance data) exist in a modelbase. These variables can be exported directly from SAMM (right click on variable | Export Variables...) to the working directory. The TOOL file format preserves shape and instance data. | One of the challenges of running shell scripts in standard mode is the need to create and shape objects. To mitigate this, TOOL scripts can be run in //local// mode in which TOOL objects - as files - can be accessed from and output to the the local working directory. This is especially useful if certain TOOL objects (with instance data) exist in a modelbase. These variables can be exported directly from SAMM (right click on variable | Export Variables...) to the working directory. The TOOL file format preserves shape and instance data. | ||
+ | |||
+ | ===== Example session ===== | ||
+ | Suppose you wanted to test some code in a script which required building a shaped object (with an informant from your model called canReg) running a couple of tools and then showing the result with table. Here's one example of how to use interactive TOOL and a tool script to do that. | ||
+ | |||
+ | * Make a sub directory in your model account (can also be done in a user account depending on what you want to do) to hold your test script and any data it may create | ||
+ | * In that directory write your script text file (myScript.t) just as you would any other piece of tool code (most similar to view writing): | ||
+ | <file> | ||
+ | informant canReg[] | ||
+ | |||
+ | local myStock[cr,ts] = create(; dim=canReg, dim=SEQ;time:1992:1994:1;year) | ||
+ | myStock[cr,ts] = import(; rowTitles=on, dataFile=$home/primaryData/inputStock.txt ) | ||
+ | |||
+ | local myStockTot[ts] = sum (myStock[cr,ts]; dim=canReg) | ||
+ | |||
+ | table (myStockTot[ts]) | ||
+ | </file> | ||
+ | * Launch interactive TOOL - find it under Start/All Programs/whatIf/TOOL | ||
+ | * Login as your model account | ||
+ | * Check where you are and move to the directory you created above: | ||
+ | |||
+ | **TIP:** In the interactive TOOL window hit <Ctrl> and the up arrow key to get the previous command to save typing | ||
+ | |||
+ | <code> | ||
+ | TOOL> where() | ||
+ | TOOL> look() | ||
+ | TOOL> moveto("the appropriate path to your testing directory") | ||
+ | </code> | ||
+ | * Make sure your $informDir points to the model informants you wish to use. | ||
+ | <code> | ||
+ | TOOL> showenv() | ||
+ | TOOL> $informPath = "full path to model's informants directory" | ||
+ | </code> | ||
+ | * Look to see that your script exists in the current directory if not check where you are and that the file actually does exist where you think it should! | ||
+ | <code> | ||
+ | TOOL> look() | ||
+ | </code> | ||
+ | * Run your script: | ||
+ | <code> | ||
+ | TOOL> tool -l myScript.t | ||
+ | </code> | ||
+ | |||
+ | You can modify your script with a text editor and save it and then re-run it in the same TOOL session. | ||
+ | |||
+ | |||
+ | |||
+ | |||
===== Other Useful Information ===== | ===== Other Useful Information ===== |