4. Variable filenames

Top  Previous  Next

At the moment you are using the direct name of the weather data file when referencing to the weather file, but you can also create a variable containing the filename and later use it in your solution.

 

Now create a new variable in the <variables> section by adding a new line in the 01_FirstSolution.sol.xml:

 

 <var id="myVariable" datatype="CHAR" description="describe the variable">This is SIMPLACE training</var>

 

The new variable created above will take the value = 'This is SIMPLACE training'. Also note that the variable must have an unique 'id' name and a 'datatype'. Its also recommend to provide a 'description'.

 

There are different data types in programming languages, lets consider those which are used in SIMPLACE:

Data type

Definition

CHAR

in SIMPLACE same as String, which means any combination of symbols (usually letters): weather, Bonn, MyName, Hello World, blablabla,

DATE

a date: 31.12.1970 or 1.1.1970 (normally formatted as dd.mm.yyyy)

DOUBLE

a number with decimal fraction: 3.14 or 7.52

DOUBLEARRAY

a vector of DOUBLE values (also known as array): [3.14, 5.72, 124.57, 64.62] is a DOUBLEARRAY with 4 values separated by commas

INT

an integer value: 1, 2, 3, 4 ...

INTARRAY

same as DOUBLEARRAY, but with integer values: [1, 2, 3, 4] - an INTARRAY with 4 values separated by commas

BOOLEAN

has two values: TRUE or FALSE, e.g., is it raining? - TRUE or FALSE.

More info can be found on the <variables> page

 

 

Once a variable is defined in the <variables> section, it can be used at some parts of the solution.

For example, in the filename of an interface object when enclosed with the placeholders ${}:

 

 <filename>${_WORKDIR_}/training/data/lintul/${vLocation}.txt</filename>

 

 


 

Task 4. In ModelSolution 01_FirstSolution.sol.xml change the weatherfile interface by creating a variable for the weather file name, then use it instead of the explicit name of the weather file.

 

 Hints:

  - It's a good practice to concatenate variables with the file extensions, e.g.: ${myVariable}.txt, e.g., in the weatherfile interface.

  - Make sure that the variable name is used correctly.

 

 Solution:

  Follow this link.

 

 

*ModelSolutions are found in simplace_modules\test\training\solution\1_WorkingWithSolutions