Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Create a new Macro icon and rename it 'step2'. We start editing the macro with reading our FLEXTRA output file.

Code Block
#Metview Macro

...

 

flx=read("res_multi.txt") 

Now variable flx holds all the data in our FLEXTRA output. First, we will find out the number of trajectory groups we have by using the count() function.
num=count(flx)
Now we will create a for loop to go though all the trajectory groups and extract and print some data out of them:
for i=1 to num do
vals=flextra_group_get(flx[i],["name","type"])
print("tr: ",i," name: ",vals[1]," type: ",vals[2])
end for
Here we used the flextra_group_get() function to read the value for a list of metadata keys from the i-th trajectory group. Please note that just as in the previous step we specified the trajectory group by the [] operator.
In the next step we will read some data from the first trajectory of the second trajectory group (volcano Stromboli). It goes like this:
vals=flextra_tr_get(flx[2],1,["date","lat","lon"]
In the last step we print the data:
print(" ")
print("date: ",vals[1])
print("lat: ",vals[2])
print("lon: ",vals[3])
Now, if you run this macro you will see the data values appearing in the standard output.

...

Now we will run FLEXTRA with the data we generated in the previous step. You will find a FLEXTRA Run icon called 'run_normal' in your folder. Open its editor and start editing.

First, we will specify the input data for the computations. We could follow the same way as we did in the rest of the tutorial where we specified the input data path and the AVAILABLE file via parameters Flextra Input Path and Flextra Available File Path. But instead we will use our Flextra Prepare icon to specify the data. Now set

Set Flextra Input Mode to 'Icon' and drop your FLEXTRA Prepare icon into the Flextra Input Data field.

You do not need to edit the rest of the parameters. They are prepared for you to compute a 3 hour-long trajectory starting from volcano Katla at 3 UTC yesterday (we used the same relative date as in the FLEXTRA Prepare icon).

Save your FLEXTRA Run icon (Apply) then right-click and execute to start the trajectory computations. Within a minute (it might take longer on your machine) the icon should turn green indicating that the run was successful and the results have been cached. Right-click and examine the icon to look at its content.

We can visualise the results in exactly the same way as we did it throughout the tutorial. By using a FLEXTRA Visualiser icon.

...

Just like the other FLEXTRA icons the FLEXTRA Prepare icon can also be used in Macro. Its macro command equivalent is flextra_prepare().

However, please note that it should be used with extra care. The reason for it is that flextra_prepare() is executed asynchronously and if we do not reference the variable it returns we can run into problems. The following macro code illustrates this situation:
 

Code Block
res=flextra_prepare(

...


	flextra_output_path:

...


 	"/scratch/graphics/cgr/flextra_data",

...


 	...

...


)

...

 

flextra_run(

...


flextra_input_mode : "path",

...


flextra_input_path : "/scratch/graphics/cgr/flextra_data",

...


 	...

...


)

  With this code we want to generate the input data for FLEXTRA with flextra_prepare() but we do not use the variable it returns in flextra_run(). Instead we simply use the path where the generated input data should be located. Now, because flextra_prepare() is executed asynchronously the macro starts to execute it and does not wait until it finishes but jumps immediately to flextra_run(). Then flextra_run() fails because the input data is not yet in place so the macro fails as well.

We can overcome this difficulty by simply referencing the return value of flextra_prepare() right after it is called e.g. by printing it.
 

Code Block
res=flextra_prepare( ...

...


 )
 
print(res)

...

 
 
flextra_run( ...

...


 )

  Alternatively we can set the Macro execution mode to synchronous by using the waitmode() function. We need to place it before calling flextra prepare() like this:

 

Code Block
languagebash
waitmode(1)

...

 
 
res=flextra_prepare( ...

...


 ) 
 
flextra_run( ...

...


 )