...
This is fine for a single field, but if you move between the two fields in the plot, there are two different vertical levels - but we only have one title, and it was constructed using the meta-data from the first field. We cannot tell it to "use this title for the first field, but use another title for the second field". So in this case we should use a handy feature of the Text Plotting icon which is described in the next section.
Using
...
meta-data references in titles
In the previous example, Macro constructed a title string and passed it to the plot()
command, which used it directly. However, the plot()
command can be more clever than that. For a start, it knows to translate <magics_title/>
into the automatic title. It also has some other tricks.
...
Create a copy of your macro and change just one line:
Code Block |
---|
field_level = "<grib_info key='level'/>" |
Now, we are no longer extracting the level ourselves, but we are asking the plotting module to extract it at plotting time. With this change, the title will show the correct level for each field. We could extend this to construct complex titles showing various information.
Dealing with multiple overlaid fields
Adapt your macro to read and plot the geopotential data. Use the supplied rh_shade icon to colour the relative humidity field:
Code Block | ||
---|---|---|
| ||
rh = read("relative_humidity.grib")
z = read("geopotential.grib")
...
rh_shade = mcont( ... )
plot(rh, rh_shade, z, title) |
We now have two title lines. When we ask the plotting engine to extract meta-data from its fields, it will produce one title line per field. If we don't want this, then we need to tell it which field we do want a title line for.
Modify the field_level definition so that the <grib_info>
tag contains a where clause:
Code Block | ||
---|---|---|
| ||
field_level = "<grib_info key='level' where='shortName=r'/>" |
Now, the title will only be produced for the relative humidity field (its shortName key is "r"). We would need to do this for all <grib_info>
tags if there were more.
We should also update the parameter names in the title - let's assume that each frame will contain the same parameters (they contain different levels), so we could change field_names
to this:
Code Block | ||
---|---|---|
| ||
field_names = grib_get_string(rh[1], 'name') & ' / ' & grib_get_string(z[1], 'name') |
Extra Work
Meta-data references in Macro
Continue the work of updating the macro first macro to use nothing but meta-data references so that it does not extract anything from the GRIB header itself and everything is taken at plot time.