Defining nap functions

The final command in the procedure should be a nap command defining the result.

The following procedure defines a NAP function sind() to be sin(angle in degrees):

% proc sind x {nap "sin(x / 180p-1)"}
% [nap "sind {0 30 90}"]; # Try it
0 0.5 1

The following procedure defines a NAP function giving zonal means from a matrix with latitude/longitude coordinate variables:

% proc zonal_mean matrix {
      nap "latitude  = coordinate_variable(matrix, 0)"
      nap "longitude = coordinate_variable(matrix, 1)"
      nap "a = area_on_globe(latitude, longitude)"
      nap "sum(a * matrix, 1) / sum (a, 1)"
}
% pwd
/sol/home/dav480/tcl_nap/data
% nap "z = [nap_get net zht_r21.nc zht]"
::NAP::35-35
% nap "zm = zonal_mean(z)"
::NAP::201-201
% $zm a
::NAP::201-201  f64  MissingValue: NaN  References: 1  Unit: (NULL)
Dimension 0   Size: 56     Name: latitude  Coordinate-variable: ::NAP::47-47
Value:
2320.95 2270.02 2165.5 1940.87 1534.45 1004.65 ..
% plot_nao zm
.win0

Author: Harvey Davies       © 2005, CSIRO Australia.       Legal Notice and Disclaimer
CVS Version Details: $Id: demo_define_function.html,v 1.2 2005/03/15 01:06:52 dav480 Exp $