Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Scroll pdf ignore
Panel
titleDownload
Expand
titleClick here for files to download...
Excerpt Include
A Quick Tour of Metview
A Quick Tour of Metview
nopaneltrue

Attachments
uploadfalse
oldfalse
patterns*.tar.gz,*.grib,*.grb
sortByname

Functions

The most basic way to group lines of Macro code is into a function. Let's write a function to compute wind speed given its U and V vector components.

...

Note that it does not matter where the function is defined in the macro - it will be found.

Notice that the function does not restrict the type of variables coming into it - they could be fieldsets, numbers, geopoints or any other data type which is compatible with the operations being performed by the function (square root, multiplication and addition). Try calling the function with plain numbers:

Code Block
languagepy
print(wind_speed(3, 4))

We could restrict the function so that it only accepts fieldset parameters:

...

Including Other Macros

Now split the macro into file two  separate files: the wind_speed macro should have the function definition, and the call_wind_speed macro should read the GRIB data, call the function and plot the data (it should not work now, because it cannot find the function).

...

Warning
An include statement is interpreted before the rest of the macro is executed, including lines that precede the include statement. run.  This means that you cannot, for instance, use a dynamically generated path to find the file to be included.

...

This allows you to build your own personal function library. For a function to be available to other users, you can place the macros with the functions into shared folder on the file system; all users will need to set the environment variable METVIEW_MACRO_PATH to this location before starting Metview.

Extending the Macro Language

It is possible to write your own C/C++/Fortran code and interface it with Metview Macro. In this way we can write functions in another language and call them directly from a macro, passing variables such as vectors, numbers and fieldsets between them. This is beyond the scope of this training course, but be aware that it is possible! It is currently documented in the 2014 Metview training course, and examples are given in the solutions folder if you'd like to have a look.