====== General View Writing ====== Here's a presentation with information about view writing {{:howtos:using_views_with_samm.ppt|}} Here are some examples of import and exports: [[how_tos::#Working with data]] ===== Understanding indexing wrt history and background ===== This is especially useful to understand when working with create and feedback views. For more information see the product documentation under TOOL Language/TOOL Scripts/View. When referencing an object array, you must specify the element in the array that you would like to access. This is accomplished by using array indexes. The form of an object array reference is: objectName[upperDims,auxDims][index] where: * //index// the array index. It may be one of the following values: * integer constant * a positive integer value such as 1,2,3,.... For example, tempObject[][2]. ^$history^$background^Object Type^Object Array Contents Value of^$numScns^ |true|true|U|object[][1] = history instance|2| | | | |object[][2] = background instance| | |true|true|F|object[][1] = history instance|3| | | | |object[][2] = background instance| | | | | |object[][3] = new instance to be filled| | |true|false|U|object[][1] = history instance|1| |true|false|F|object[][1] = history instance|2| | | | |object[][2] = new instance to be filled| | |false|true|U|object[][1] = background instance|1| |false|true|F|object[][1] = background instance|2| | | | |object[][2] = new instance to be filled| | |false|false|U|object[][1] = no instance - Error —| | |false|false|F|object[][1] = new instance to be filled|1| note: ''$history'' has value ''false'' when running views in calibrator. ===== Example Files ===== views.samm - This is a Create view, which loads the initial data for four variables in a simple input-output model. Fields: * creview - identifies the view as a Create view * import - indicates that variables are to be imported from external files * testInOut.s - name of the model base * import.v - file containing the names of the variables to be imported * import.t - Tool commands to import the external data according to the format of each variable setpath $HOME/V4/cal/views ! Data creation views: creview import testInOut.c import.v import.t "importing first scenario" ! Data display views: disview energyUseRpt myCalc energyUseRpt .v energyUseRpt .t "energy use report" import.v - The names of the four variables to be imported are listed. The order of the variables must conform to the order in import.t. It is recommended to select from the Documentor the variable names to be imported and paste them here to avoid spelling errors. F indicates ...? ! accounts variables finalDemand F accounts/Inputs F accounts/Outputs F accounts/primary F ! inOutModel variables import.t - The following Tool script associates the imported data to a specific scenario defined by $index. The //import// command indicates the variable to be filled, the format of the external file, followed by its name. ! accounts variables creview finalDemand[c][] creview Inputs[c,i][] creview Outputs[i,c][] creview primary[i][] ! inOutModel variables string $importDir $importDir = $home + "/models/inOut/PrimaryData" integer $index $index = 1 if $history == true $index = $index + 1 endif if $background == true $index = $index + 1 endif ! accounts variables say ("importing accounts variables") finalDemand[c][$index] = import (; rowTitles=off, dataFile=$importDir/finalDemand.txt) Inputs[c,i][$index] = import (; format=coord, allCoord=on, dataFile=$importDir/Inputs.txt) Outputs[i,c][$index] = import (; rowTitles=on, dataFile=$importDir/Outputs.txt) primary[i][$index] = import (; rowTitles=off, dataFile=$importDir/PrimaryInputs.txt) ! inOutModel variables say ("importing inOutModel variables") say ("Done.") ===== Loading Views into SAMM ===== - Before a a view can be run it must be loaded into SAMM Here are the steps for loading a view: - In the //Windows// menu, click //Views// . - Click //Load// in the //View Actions// window - Set the correct path name to the //views.samm// file. This will be found in the //views// folder under the //sim// folder under the model version in your home directory. - click OK Here are the steps for re-loading a view after editing the .t or .v - Delete the existing view - Repeat above steps ===== Running a View ===== Here are the steps for running a view: - Click //run// in the View Actions menu or double click the view. Note that running a //create// view generates new //instances// of the variables. To see how instances can be combined in a scenario see: [[concepts:Scenario Management - Understanding Scenarios, Variables and Instances]]