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.
We've already written code to compute wind speed:
speed = sqrt(u*u + v*v)
We can easily create a function around this code, taking u
and v
as input parameters. Create a new Macro icon and call it wind_speed
. Enter the following into it:
function wind_speed(u, v) speed = sqrt(u*u + v*v) end wind_speed
Within the same macro, read in some wind data and call the function, plotting the result:
u = read('wind_u.grib') v = read('wind_v.grib') speed = wind_speed(u,v)
Note that it does not matter where the function is defined in the macro - it will be found.