This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
howtos:toolcoding:subroutinepackage [2012/02/08 21:37] shona.weldon created |
howtos:toolcoding:subroutinepackage [2013/03/26 11:51] marcus.williams |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Subroutine Package ====== | ====== Subroutine Package ====== | ||
- | From here you can download a set of sub-routines that can be put in your Vx/views directory. They can then then be loaded using the informants window and once in your model any view can call the sub routines. | + | Subroutines are reusable code files that can be called from views. The advantage of using them is there is only one copy of common code which makes it more maintainable and also gives consistency to how you interact with your views. |
+ | We have developed a set of subroutines you can use as a starting point. Below is a .zip file which is a package of files to get you started and the rest of this article describes how to use them. | ||
+ | This is the subroutine package that should be unzipped in your model account directory. Something like /models/myModel/Vx/views to create a subdirectory called subroutines. | ||
+ | |||
+ | {{:howtos:toolcoding:subroutines.zip|}} | ||
+ | |||
+ | Please consider these **use at your own risk**. We are not supporting them but are just providing them as a starting point from which you can modify them as you wish! | ||
+ | |||
+ | **whatIf? Team members**: Please look in /models/caness/V5/views/subroutines for the most current subroutines and under there find TemplateExamples for the most up to date templates. | ||
+ | |||
+ | ===== Setup of installed files ===== | ||
+ | Once you have extracted the files there are 3 files you must copy and adjust for your current model/version | ||
+ | |||
+ | getModelVersion_CopyAndCustomize.t | ||
+ | * This file is used to figure out what the current version of your model is | ||
+ | * copy this file and re-name it to: getModelVersion.t | ||
+ | * Edit the file and adjust the version number | ||
+ | |||
+ | getProjectNames_CopyAndCustomize.t | ||
+ | * This file is used to manage the names of various projects which might be running out of this model | ||
+ | * For now the only thing it is used for is makeing export directories for each project and is related to the getProjectExportPath.t subroutine | ||
+ | * copy this file and re-name it to: getProjectNames.t | ||
+ | * edit the file and adjust the project names | ||
+ | |||
+ | informs_CopyAndCustomize.samm | ||
+ | * This file is used to load the sub-routines into a model | ||
+ | * copy this file and rename it to: informs.samm | ||
+ | * edit the file and adjust the path to the subroutines directory in the "setpath" line of the file | ||
+ | |||
+ | ===== Loading subroutines ===== | ||
+ | Sub-routines are only available to views running in SAMM once the are loaded into the model family. Here's how to do that. | ||
+ | * Set your file path to where the subroutines live, something like: | ||
+ | * /models/myModel/Vx/views/subroutines | ||
+ | * From the Windows menu open the informants window | ||
+ | * Right click and say load, note it will default to whatever you set in your file path followed by informs.samm which is the file you edited above. | ||
+ | |||
+ | Now you are ready to write views that use subroutines. See below info about the examples that are a part of the sub routine bundle you have downloaded and extracted. | ||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | In that new folder you will find an examples sub folder with some example views: | ||
+ | |||
+ | levelVarProjection.t | ||
+ | * This type of view projects a variable which holds variables which are not share variables, like rates or efficiency levels etc | ||
+ | * It gives several different ways to project this variable through a menu command | ||
+ | |||
+ | shareVarProjection.t | ||
+ | * This type of view projects a share variable ensuring that it sums to 1 over some dimension even after projection | ||
+ | * It gives several different ways to project this variable through a menu command | ||
+ | |||
+ | usingGetModelVersion.t | ||
+ | * A sub routine that gets the model version so it can be used in display or creating paths etc | ||
+ | * The advantage is you can write views that are version independant | ||
+ | * It works by consulting the following file to get the version so this file must be updated each time a new version is made | ||
+ | * getModelVersion.t |