12. Output of Arrays |
Top Previous Next |
As previously explained, SIMPLACE also works with array variables (e.g., DOUBLEARRAY, INTARRAY). One can output the entire array, some specific element or selected elements.
In order to do this see the following examples:
<out id="RadiationIntensity|10" datatype="DOUBLEARRAY" rule="diurnal.RadiationIntensity" /> (shows the 10th element of the array)
<out id="SelectedTemperature|1,4-7,12" datatype="DOUBLEARRAY" rule="diurnal.Temperature" /> (shows the 1st, from 4th to 10th and the 12th element of the array)
<out id="SelectedTemperature|LAST" datatype="DOUBLEARRAY" rule="diurnal.Temperature" /> (shows the last element of the array)
As you may have noticed after the | mark of the id you can add the number or numbers of the elements in which you are interested.
Task 12.1 In the output section output of the solution 12_Arrays.sol.xml add the following combinations of elements:
- the 12th element of the diurnal.RadiationIntensity array
- the 2nd, from 11-14th and 24th element of the diurnal.Temperature array
- the last element of the diurnal.Temperature array using a predefined keyword "LAST"
- test what happens if you exceed the size of the array, lets say |99999
Hints
- See the training Adding outputs
Solution
Follow this link.
The following two tasks are more complex and involve few more advanced techniques on how to output different values of the arrays. And they definitely worth to be considered even for a beginner of SIMPLACE.
Task 12.2 Calculate the sum of Global Radiation in 12_Arrays.sol.xml by adding a rule to an output variable with the following content:
var sum=0;for (var radiationpart : ${diurnal.Radiation}){sum = sum + radiationpart}; return sum;
where diurnal.Radiation is a double array of radiation values throughout the day.
Hints
- See the training Adding outputs
Solution
Follow this link.
Task 12.3 We have another double array diurnal.Temperature with Temperature values.
Calculate the min and max temperatures using the same solution 12_Arrays.sol.xml by adding two output variables with the following content in the rule:
var min=${diurnal.Temperature[0]};for (var temperature : ${diurnal.Temperature}){if(temperature < min){min=temperature}}; return min;
and for the max temperature try to do it by yourself ;)
Hints
- Javascript programming language is used for calculation the min and max temperatures.
Solution
Follow this link.
*ModelSolutions are found in simplace_modules\test\training\solution\1_WorkingWithSolutions