`fieldset ( fieldset `

** op ** fieldset )

Operation between two fieldsets. `op`

is one of the operators below :

+ Addition | - Subtraction |

* Multiplication | / Division |

^ Power |

The fieldsets returned by these boolean operators are boolean fieldsets (containing only 1 where result is true, 0 where it is false) :

> Larger Than | < Smaller Than |

>= Larger or Equal | <= Smaller or Equal |

= Equal | <> Not Equal |

In all of the above operations, a missing value in one of the input fieldsets results in a corresponding missing value in the output fieldset.

`fieldset ( fieldset `

** op ** number )

fieldset ( number

**fieldset )**

`op`

Operations between fieldsets and numbers. `op`

is any of the operations defined above. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
geopoints ( fieldset
```

** op ** geopoints )

geopoints ( geopoints

**fieldset )**

`op`

Operations between fieldsets and geopoints. `op`

is any of the operations defined above. Missing values, both in the fieldset and in the original geopoints variable result in a value of geo_missing_value.

```
fieldset ( fieldset
```

** and ** fieldset )

fieldset ( fieldset

**fieldset )**

`or`

fieldset (

**fieldset )**

`not`

Conjunction, Disjunction and Negation. Boolean operators consider all null values to be false and all non null values to be true. The fieldsets created by boolean operators are binary fieldsets (containing only 1 where result is true, 0 where it is false). For example :

` a = retrieve(...)`

` b = retrieve(...)`

` c = a and b `

creates a fieldset c with values of 1 where the corresponding values of fieldset a and fieldset b are both non zero, and 0 otherwise. For an example of the use of boolean operators, see the `mask`

function. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
fieldset ( fieldset
```

** and ** number )

fieldset ( number

**fieldset )**

`or`

Boolean operations between fieldsets and numbers. See above. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
geopoints ( fieldset
```

** and ** geopoints )

geopoints ( geopoints

**fieldset )**

`or`

Boolean operations between fieldsets and geopoints. See above.

```
fieldset ( fieldset
```

** & ** fieldset

**... )**

`&`

fieldset ( nil

**fieldset**

`&`

**... )**

`&`

fieldset ( fieldset

**nil )**

`&`

fieldset

**( fieldset,fieldset,... )**

`merge`

Merge several fieldsets. The output is a fieldset with as many fields as the total number of fields in all merged fieldsets. Merging with the value `nil`

does nothing, and is used to initialise when building a fieldset from nothing.

```
fieldset fieldset
```

** [ **number

`]`

fieldset fieldset

**number,number**

`[`

`]`

fieldset fieldset

**number,number,number**

`[`

`]`

Extract a selection of fields from a fieldset. If one parameter is given, only one field is selected. If two parameters are given, the fields ranging from the first to the last index are returned. The optional third parameter represents an increment n - every nth field from the first to the last index are returned.

```
```

* # copies fields 1, 5, 9, 13, 17 of x into y *

Y = X[1,20,4]

`fieldset fieldset`

** [ **vector

`]`

Extract a selection of fields from a fieldset. The vector supplied as the argument provides the set of indices to be used. For example:```
```

```
```

* # copies fields 2, 1, 3 of x into y *

x = |2, 1, 3|

y = x[i]** **

` fieldset `

** abs ** ( fieldset )

Returns the fieldset of the absolute value of the input fieldset at each grid point or spectral coefficient. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** acos ** ( fieldset )

fieldset

**( fieldset )**

`asin`

fieldset

**( fieldset )**

`atan`

Return the fieldset of the arc trigonometric function of the input fieldset at each grid point. Result is in radians. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** cos ** ( fieldset )

Returns the fieldset of the cosine of the input fieldset at each grid point. Input values must be in radians. Missing values are retained, unaltered by the calculation.

```
number
```

** count ** ( fieldset )

Returns the number of fields in a fieldset.

```
fieldset
```

** exp ** ( fieldset )

Returns the fieldset of the exponential of the input fieldset at each grid point. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** float ** ( fieldset, number)

Returns a fieldset with integer data converted into floating point data for more accurate computations. The second parameter is optional; if given it defines the number of bits used for packing the float values. If not given, the default value of 24 is used (unless function gribsetbits(number) has been called to set it).

```
fieldset
```

** int ** ( fieldset )

Returns the fieldset of the integer part of the input fieldset at each grid point or spectral coefficient. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** integer ** ( fieldset )

Returns the fieldset of the integer part of the input fieldset at each grid point or spectral coefficient. This function modifies the resulting GRIB header to be of integer data type. Missing values are replaced with LONG_MAX. This function was used in Metview 3 to enable the plotting of certain types of satellite imagery.

```
fieldset
```

** log ** ( fieldset )

Returns the fieldset of the natural log of the input fieldset at each grid point. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** log10 ** ( fieldset )

Returns the fieldset of the log base 10 of the input fieldset at each grid point. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** neg ** ( fieldset )

Returns the fieldset of the negative of the input fieldset at each grid point or spectral coefficient. The same as (- fieldset). Missing values are retained, unaltered by the calculation.

```
fieldset
```

** sgn ** ( fieldset )

Returns the fieldset of the sign of the values of the input fieldset at each grid point or spectral coefficient : -1 for negative values, 1 for positive and 0 for null values. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** sin ** ( fieldset )

Returns the fieldset of the sine of the input fieldset at each grid point. Input fieldset must have values in radians. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** sqrt ** ( fieldset )

Returns the fieldset of the square root of the input fieldset at each grid point. Missing values are retained, unaltered by the calculation.

```
fieldset
```

** tan ** ( fieldset )

Return the tangent of the input fieldset at each grid point. Input fieldset must have values in radians. Missing values are retained, unaltered by the calculation.

```
number or list
```

** accumulate ** ( fieldset )

For each field in the fieldset, this function calculates the sum of all the values of the field. If there is only one field in the fieldset, a number is returned. Otherwise, a list of numbers is returned. Only non-missing values are considered in the calculation. If there are no valid values, the function returns `nil`

for that field.

```
number or list
```

** average ** ( fieldset )

For each field in the fieldset, this function calculates the average of all the field values. If there is only one field in the fieldset, a number is returned. Otherwise, a list of numbers is returned. Only non-missing values are considered in the calculation. If there are no valid values, the function returns `nil`

for that field.

Note that the `average()`

function does not return the physically correct average of the field but merely the average of all field values using the following formula:

To get the physically correct average value of a field, use the `integrate()`

function (which employs a cosine latitude weighting)

```
vector or list
```

** average_ew ** ( fieldset,list,number )

The function average_ew() takes as parameters a fieldset, a list of four numbers that define an area ( [N,W,S,E] ) and a number that defines the output one-dimensional grid interval in degrees.

The function returns a vector (if the input fieldset contains only one field) or a list of vectors. The elements of the returned vector(s) are means computed over rows of similar latitude using those grid points that fall inside the given area. Means are computed at intervals as specified in the third parameter. The output vector size is thus independent of the grid interval in the input fieldset.

Each grid point value is weighted by the cosine of its latitude. Missing values are ignored. If a latitude belt contains no grid point values then the missing value indicator `vector_missing_value`

is returned.

Example:

` ave = average_ew(fs, [60,-180,-60,180], 2.5) `

This function call will compute means over full latitude circles starting from 60N, stepping 2.5 degrees until 60S. If `fs`

contains only one field the output would be a vector of 49 E-W mean values, from North to South. If `fs`

contains n fields then the output would be a list of n vectors, where each of these n vectors would contain 49 means.

For the above example, each value returned (representing the mean at latitude Lat ) is the mean of non-missing values in those grid points whose latitude coordinate is between Lat-1.25 and Lat+1.25 (1.25 is 2.5/2), i.e. within a latitude belt with width of 2.5 degrees, centered around Lat.

```
vector or list
```

** average_ns ** ( fieldset,list,number )

The function average_ns() takes as parameters a fieldset, a list of four numbers that define an area ( [N,W,S,E] ) and a number that defines the output one-dimensional grid interval in degrees.

The function returns a vector (if the input fieldset contains only one field) or a list of vectors. The elements of the returned list(s) are means computed over lines of similar longitude using those grid points that fall inside the given area. Means are computed at intervals as specified in the third parameter. The output vector size is thus independent of the grid interval in the input fieldset.

Each grid point value is weighted by the cosine of its latitude. Missing values are ignored. If a longitude line contains no grid point values then the missing value indicator `vector_missing_value`

is returned.

Example:

` ave = average_ns(fs, [30,0,-30,360], 5) `

This function call will compute means over longitudes 30N...30S, in 5 degree intervals around the globe. The result for each field in `fs`

would be a vector of 73 values (in this case values for 0 and 360 are duplicated values).

Each value returned (representing the mean at longitude Lon ) is a mean of non-missing values in those grid points whose longitude coordinate is between Lon-2.5 and Lon+2.5 (2.5 is 5/2), in the belt between 30N and 30S.

```
fieldset
```

** bearing ** (f: fieldset, reflat: number, reflon: number )

fieldset

**(f: fieldset, ref: list )**

`bearing`

Computes the bearing for each grid point with reference to the given location. The location (in degrees) may be specified by supplying either two numbers (latitude and longitude respectively) or a 2-element list containing latitude and longitude in that order.

The bearing is the angle between the Northward meridian going through the reference point and the great circle connecting the reference point and the given gridpoint. It is measured in degrees clockwise from North. If a gridpoint is located on the same latitude as the reference point the bearing is regarded constant: it is either 90° (East) or 270° (West). If the gridpoint is co-located with the reference point the bearing is set to a missing value.

` date or list `

**base_date** ( fieldset )

Returns the base dates (including the time components) of the given fields. If the fieldset has only one field, a date is returned; otherwise a list of dates is returned.

` fieldset `

** bitmap ** (fieldset,number)

fieldset

**(fieldset,fieldset)**

`bitmap`

Returns a copy of the input fieldset (first argument) with zero or more of its values replaced with grib missing value indicators. If the second argument is a number, then any value equal to that number in the input fieldset is replaced with the missing value indicator. If the second argument is another fieldset with the same number of fields as the first fieldset, then the result takes the arrangement of missing values from the second fieldset. If the second argument is another fieldset with one field, the arrangement of missing values from that field are copied into all fields of the output fieldset. See also `nobitmap`

.

` number or list `

** corr_a ** ( fieldset,fieldset )

number or list

**( fieldset,fieldset,list )**

`corr_a`

Computes the correlation between two fieldsets over a weighted area. The area, if specified, is a list of numbers representing North, West, South, East. If the area is not specified, the whole field will be used in the calculation. The result is a number for a single field, or a list for a multi-field fieldset.

Note that the following lines are equivalent, although the first is more efficient:

`z = corr_a (x, y)`

z = covar_a (x, y) / (sqrt(var_a(x)) * sqrt(var_a(y)))

```
fieldset
```

** coslat ** ( fieldset )

For each field in the input fieldset, this function creates a field where each grid point has the value of the cosine of its latitude.

```
fieldset
```

** covar ** ( fieldset,fieldset )

Computes the covariance of two fieldsets. With n fields in the input fieldsets, if xik and yik are the ith values of the kth field of each input field respectively and zi is the ith value of the resulting field, the formula can be written :

Note that the following lines are equivalent:

` z = covar(x,y)`

z = mean(x*y)-mean(x)*mean(y)

A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
number or list
```

** covar_a ** ( fieldset,fieldset )

number or list

**( fieldset,fieldset,list )**

`covar_a`

Computes the covariance of two fieldsets over a weighted area. The area, if specified, is a list of numbers representing North, West, South, East. If the area is not specified, the whole field will be used in the calculation. The result is a number for a single field, or a list for a multi-field fieldset.

```
list
```

** datainfo ** ( fieldset )

Returns a list of definitions - one for each field in the fieldset. Each definition provides the following members: the index of the field in the fieldset, the number of missing values, the number of values that are present and the proportion of each. The following example illustrates how to use the function.

`fs = read (strGribFile)`

listdefInfo = datainfo (fs)

loop defInfo in listdefInfo

print ("Field index : ", defInfo.index)

print ("Number of values present : ", defInfo.number_present)

print ("Number of values missing : ", defInfo.number_missing)

print ("Proportion values present : ", defInfo.proportion_present)

print ("Proportion values missing : ", defInfo.proportion_missing)

end loop

```
fieldset
```

** direction ** ( fieldset,fieldset )

Returns a fieldset with the value in each grid point being the direction computed from the given U and V fieldsets; the first input fieldset is assumed to be the East-West (U) component and the second the North-South (V) component. The resulting numbers are directions, in degrees clockwise from North, where a value of 0 represents a wind from the North and a value of 90 represents a wind from the East.

```
fieldset
```

** distance ** ( fieldset,number,number )

fieldset

**( fieldset,list )**

`distance`

Returns a fieldset with the value in each grid point being the distance in meters from the given geographical location. The location may be specified by supplying either two numbers (latitude and longitude respectively) or a 2-element list containing latitude and longitude in that order. The location should be specified in degrees.

```
fieldset
```

** div ** ( fieldset,fieldset )

Returns a fieldset with as many fields as the input fieldsets; the grid points of the output fieldset are the integer part of the division of the first fieldset by the second fieldset (the function operating field by field).

With n fields in the input fieldsets, if xik , yik are the ith value of the kth input fieldsets and zi is the ith value of the resulting field:

A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
fieldset
```

** divergence ** (fx: fieldset, fy: fieldset)

Computes the horizontal divergence of 2-dimensional vector fields. The computations for a vector field `f=(f`

_{x} ,`f`

_{y} ) are based on the following formula:

where

`R`

is the radius of the Earth`φ`

is the latitude- λ is the longitude.

The derivatives are computed with a second order finite-difference approximation. The resulting fields contain missing values on the poles. If the input fields are horizontal wind components the GRIB `paramId`

of the resulting field is set to `155`

(=divergence). Please note that this function is only implemented for regular latitude-longitude grids.

```
fieldset
```

** duplicate ** ( fieldset,number )

Returns a fieldset with the specified number of copies of the field in the input fieldset. The input fieldset must contain only one field.

```
list
```

** find ** ( fieldset,number )

list

**( fieldset,number,list )**

`find`

list

**( fieldset,number,field )**

`find`

A filtering function that returns a list of locations (lat/long pairs), where the values of the input fieldset given as the first argument equal the value specified as the second argument. Missing values in the input field are not returned.

- if there is a third argument, and it is a list of four numbers (lat/long coordinates) defining a geographical area - [North,West,South,East] , the function returns a list of locations
*within that area*where the fieldset values equal the input value - if there is a third argument, and it is a mask field, the function returns a list of locations
*within the area defined by the mask*(ie, where the mask gridpoints are non-zero) where the fieldset values equal the input value.

- if there is a third argument, and it is a list of four numbers (lat/long coordinates) defining a geographical area - [North,West,South,East] , the function returns a list of locations

```
list
```

** find ** ( fieldset,list )

list

**( fieldset,list,list )**

`find`

list

**( fieldset,list,field )**

`find`

A filtering function that returns a list of locations (lat/long pairs), where the values of the input fieldset given as the first argument are within the interval [a, b] specified as the second argument (a two value list). Missing values in the input field are not returned.

- if there is a third argument, and it is a list of four numbers (lat/long coordinates) defining a geographical area - [North,West,South,East] , returns a list of locations
*within that area*where the field values are within the interval [a, b] - if there is a third argument, and it is a mask field, returns a list of locations
*within the area defined by the mask*(ie, where the mask gridpoints are non-zero) where the fieldset values are within the interval [a, b]

- if there is a third argument, and it is a list of four numbers (lat/long coordinates) defining a geographical area - [North,West,South,East] , returns a list of locations

` fieldset `

** first_derivative_x ** (f: fieldset)

Computes the zonal (from West to East) partial derivative of each field in the fieldset. The computations for a field `f`

are based on the following formula:

where

- R is the radius of the Earth
`φ`

is the latitude- λ is the longitude.

The derivatives are computed with a second order finite-difference approximation. The resulting fields contain missing values on the poles. Please note that this function is only implemented for regular latitude-longitude grids.

```
fieldset
```

** first_derivative_y ** (f: fieldset)

Computes the meridional (from South to North) partial derivative of each field in the fieldset. The computations for a field `f`

are based on the following formula:

where

`R`

is the radius of the Earth`φ`

is the latitude`λ`

is the longitude.

The derivatives are computed with a second order finite-difference approximation. The resulting fields contain missing values on the poles. Please note that this function is only implemented for regular latitude-longitude grids.

` list `

** frequencies ** ( fieldset,list )

list

**( fieldset,list,list )**

`frequencies`

Counts the number of grid points whose values fall within a set of specified intervals. These intervals are given as the second argument - a list of values in ascending order, starting with the upper bound of the first interval, eg [0, 10, 20] . A third argument, if given, specifies a geographical area over which to consider values - [North,West,South,East] . Missing values in the input field are not included in the results.

If the input fieldset has just one field, then the result is a list of n+1 elements where n is the number of elements in the interval list. Using the above example, the output list could be described as follows:

- the first element is the number of values below 0
- the second element is the number of values in the range [0, 10)
- the third element is the number of values in the range [10, 20)
- the fourth element is the number of values above 20

If the input fieldset has more than one field, the result is a list of lists, one for each field. Note that this function accumulates its results between fields in a fieldset.

```
fieldset
```

** geostrophic_wind_pl ** (z: fieldset)

Computes the geostrophic wind from geopotential fields defined on pressure levels. For a given `z`

geopotential field the computation of the geostrophic wind components is based on the following formulas:

where

`R`

is the radius of the Earth`φ`

is the latitude`λ`

is the longitude`f=2Ωsinφ`

is the Coriolis parameter, where Ω is the Earth's angular velocity.

The derivatives are computed with a second order finite-difference approximation. The resulting fieldset contains two fields for each input field: the u and v geostrophic wind components. In each output field the points close to the poles and the Equator are bitmapped (they contain missing values). Please note that this function is only implemented for regular latitude-longitude grids.

` geopoints `

** gfind ** ( fieldset,number )

geopoints

**( fieldset,number,number )**

`gfind`

A filtering function that returns a geopoints holding the grid points whose value is equal to the *value* of the first number. Missing values in the input field are not returned. If a second number is given as the third argument it is a tolerance *threshold* and the geopoints will hold the grid points for which :

`abs(data-value) <= threshold `

```
fieldset
```

** gradient ** (f: fieldset)

Computes the horizontal gradient of each field in the fieldset. The computations for a field `f`

are based on the following formula:

where

`R`

is the radius of the Earth`φ`

is the latitude`λ`

is the longitude.

The derivatives are computed with a second order finite-difference approximation. The resulting fieldset contains two fields for each input field: the zonal derivative followed by the meridional derivative. The output fields are bitmapped on the poles (they contain missing values there). Please note that this function is only implemented for regular latitude-longitude grids.

Please be aware that in versions before Metview 5.5.3 the resulting fields of `gradient()`

appear in the **wrong order**. The correct order should look like this:

`[gradx_f1, grady_f1, gradx_f2, grady_f2, ....]`

but instead of it the following order is produced:

`[gradx_f1, gradx_f2,..., grady_f1, grady_f2, ....]`

` list `

**grib_get** (fieldset, list)`list `

**grib_get** (fieldset, list, string)

For the efficient retrieval of multiple GRIB keys from a fieldset. A single call to grib_get can replace multiple calls to the other grib_get_* functions and is hence more efficient. The keys are provided as a list for the second argument; by default they will be retrieved as strings, but their type can be specified by adding a modifier to their names, following the convention used by *grib_ls* where the key name is followed by a colon and then one or two characters which specify the type (s=string, l=long, d=double, la=long array, da=double array). For example, the key 'centre' can be retrieved as a string with `'centre'`

or `'centre:s'`

, or as a number with `'centre:l'`

. The result is always a list of lists; by default, or if the optional third argument is `'field'`

, the result will be grouped by field, containing one list per field, each of these lists containing one element per key; if the optional third parameter is `'key'`

, the result will be grouped by key, containing one list per key, each of these lists containing one element per field. Example - the following lines of Macro code on a particular 6-field fieldset:

`print(grib_get(data, ['editionNumber', 'centre', 'level', 'step'], 'field'))`

`print(grib_get(data, ['editionNumber', 'centre:l', 'level', 'step'], 'key'))`

produces this output:

`[[1,ecmf,1000,0],[1,ecmf,500,0],[1,ecmf,100,0],[1,ecmf,1000,48],[1,ecmf,500,48],[1,ecmf,100,48]]`

`[[1,1,1,1,1,1],[98,98,98,98,98,98],[1000,500,100,1000,500,100],[0,0,0,48,48,48]]`

` number or list `

** grib_get_long ** ( fieldset, string )

number or list

**( fieldset, string )**

`grib_get_double`

number or list

**( fieldset, string )**

`grib_get_string`

vector or list

**( fieldset, string )**

`grib_get_long_array`

vector or list

**( fieldset, string )**

`grib_get_double_array`

These functions return information from the given fieldset's GRIB header. Available keys (to be passed as the second parameter) can be inspected by Examining the GRIB file (right-click, Examine). Alternatively, use the GRIB API command *grib_dump* to see the available key names. See https://software.ecmwf.int/wiki/display/GRIB/Grib+API+keys for more details on key names.

The first three functions return a number if the input fieldset has a single field, otherwise they return a list of numbers. The `array' functions return a vector of numbers if the input fieldset has a single field, otherwise they return a list of vectors.

The following example shows the retrieval of GRIB header information, including the derived key 'max', using the different functions:

`print (grib_get_long (data, "editionNumber"))`

print (grib_get_long (data, "max"))

print (grib_get_double (data, "max"))

print (grib_get_string (data, "max"))

print (grib_get_string (data, "typeOfGrid"))

The output from this on an example single-field GRIB file was:

`1`

317

317.278808594

317.279

regular_ll

The following example shows how to obtain the list of parallels from a reduced Gaussian grid fieldset:

`a = read('/x/y/z/data_in_gg.grb')`

pl = grib_get_long_array (a, 'pl')

print (count(pl))

print (pl)

` fieldset `

** grib_set **( fieldset, list )

This function sets information in the given fieldset's GRIB header, automatically deducing the type from the value passed (not from the key name). The list provided as the second argument should be a set of key/value pairs, for example:

`f = grib_set(f, ["date", 20150601, # integer`

` "time", 0600, # integer`

` "stepType", "avg", # string`

` "startStep", 0 , # integer`

"endStep", 31, # integer` "unitOfTimeRange", "D", # string`

"longitudeOfLastGridPointInDegrees"]) 100.5 # double

```
fieldset
```

** grib_set_long ** ( fieldset, list )

fieldset

**( fieldset, list )**

`grib_set_double`

fieldset

**( fieldset, list )**

`grib_set_string`

These functions set information in the given fieldset's GRIB header, and are type-specific. The list provided as the second argument should be a set of key/value pairs, for example:

`data = grib_set_long (data,`

["centre", 99,

"level", 200])

This function does not modify the input fieldset, but returns a new fieldset with the modifications applied.

Available keys can be inspected by Examining the GRIB file (right-click, Examine). Alternatively, use the GRIB API command *grib_dump* to see the available key names. See https://software.ecmwf.int/wiki/display/GRIB/Grib+API+keys for more details on key names.

If applied to a multi-field fieldset, then all fields are modified.

```
number
```

** gribsetbits ** ( number )

This function sets the number of GRIB packing bits to the value given (eg 8, 10, 16), and returns the previously used internal value. This function is particularly useful when dealing with 10-bit satellite images as these require GRIB packing to be set to 10 bits.

`fieldset `

**grid_cell_area** ( fieldset )

Computes the area of each grid cell in a fieldset with the grid points supposed to be at the centre of the grid cells. The grid cell area is returned in m^{2} units. This function only works for regular latitude-longitude grids and various types of Gaussian grids.

` fieldset `

**indexes** ( fieldset, vector )

Given a fieldset and a vector of target values, this function finds for each gridpoint the indexes of the nearest values in the target. Indexes are zero-based and will always have a minimum value of zero and a maximum value equal to the index of the last element of the target vector. A value lying between two values in the vector will use the index of the nearest value; if equidistant, then the higher value is used. The input vector MUST be sorted in ascending order. Example: if these are our inputs:

`GRIB: 10,20,30,40`

` 15,25,35,45`

` 8, 4,20,11`

`VECTOR: | 5,10,15,20,25,30 |`

then our output would be a new GRIB, with values equal to the input values' positions in the input vector:

`GRIB: 1,3,5,5`

2,4,5,5

1,0,3,1

`number or list `

**integral** (fieldset)

Computes the surface integral of each field in a fieldset. The result is either a number (for one input field) or a list of numbers (for multiple input fields). The computations are based on the cell area (in m^{2} units) returned by the `grid_cell_area()`

function.

` number or list `

** integrate ** ( fieldset )

number or list

**( fieldset,list )**

`integrate`

number or list

**( fieldset,fieldset )**

`integrate`

This function computes the average of each a field in a fieldset over an area. The area of the individual cells can be approximated with the following formula:

\[ A_{i} = 2 R^{2} cos\phi_{i} sin(\frac{\Delta\phi_{i}}{2}) \Delta\lambda_{i} \]where:

`R`

is the radius of the Earth`φ`

_{i}is the latitude of the i-th grid cell

is the size of the grid cells in latitude`Δ`

φ_{i}`Δλ`

_{i}is the size of the i-th grid cell in longitude.

The function then **supposes that Δφ** and the weighted average over the area is computed as:

_{i}is constant

This formula is only used for **regular latitude-longitude** and **Gaussian** grids. For all other grid types `integrate()`

simply returns the mathematical average of the values (just like the `average()`

function does).

Please note that for **Gaussian** grids the formula can only be only regarded as an approximation since `Δφ`

is not constant!_{i}

If the input fieldset contains only one field, a number is returned. If there is more than one field, a list of numbers is returned. Missing values in the input fieldset are bypassed in this calculation. For each field for which there are no valid values, `nil`

is returned.

- If the fieldset is the only argument, the integration is done on all grid points.
- If a list is the second argument, it must contain four numbers which are respectively the north, west, south and east boundaries of an area. The integration is done on the grid points contained inside this area :

` europe = [75,-12.5,35,42.5]`

x = integrate(field,europe)

- If a fieldset is the second argument it is used as a mask. It should contain either one or as many fields as the first fieldset. If it has a single field then this mask is applied to all fields of the input fieldset. If it has the same number of fields as the input fieldset, then a different mask is applied to each input field. The integration is performed only on the grid points where the mask values are non zero. The following code shows a simple example:

```
```

* # Retrieve land-sea mask and interpolate to LL grid*

lsm = retrieve(

type : "an",

date : -1,

param : "lsm",

grid : [1.5,1.5],

levtype : "sfc"

)

* # The following line forces the values to 0 or 1. *

lsm = lsm > 0.5

* # Now compute the average value on land and on sea *

land = integrate(field, lsm)

sea = integrate(field, not lsm)

```
number or list
```

** interpolate ** ( fieldset,list )

number or list

**( fieldset,number,number )**

`interpolate`

Interpolate a fieldset at a given point. The method used is bilinear interpolation. If a list is given, it must contain two numbers - latitude and longitude. If two numbers are given, the first is the latitude, the second the longitude. The field must be a gridded field. If the fieldset has only one field, a number is returned; otherwise a list is returned. Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, `nil`

is returned. Note that a similar function, ```
nearest_gridpoint()
```

, also exists.

```
geopoints
```

** interpolate ** ( fieldset,geopoints )

Generates a set of geopoints from a field. The first field of the input fieldset is used. The field is interpolated for each position of the geopoints given as a second parameter. The method used is bilinear interpolation. The output geopoints take their date, time and level from the fieldset. Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, the internal geopoints missing value is used (this value can be checked for with the built-in variable `geo_missing_value`

or removed with the function `remove_missing_values`

). Note that a similar function, ```
nearest_gridpoint()
```

, also exists.

```
fieldset
```

** laplacian ** (f: fieldset)

Computes the Laplacian of each field in the fieldset. The computations for a field `f`

are based on the following formula:

where

- R is the radius of the Earth
- φ is the latitude
- λ is the longitude.

The derivatives are computed with a second order finite-difference approximation. The resulting fields contain missing values on the poles. Please note that this function is only implemented for regular latitude-longitude grids.

` vector or list `

**latitudes** ( fieldset )

This function returns the grid point latitudes as a vector. If the fieldset contains more than one field it returns a list of vectors. Each of these vectors contains as many elements as grid points in each field.

` vector or list `

**longitudes** ( fieldset )

This function returns the grid point longitudes as a vector. If the fieldset contains more than one field it returns a list of vectors. Each of these vectors contains as many elements as grid points in each field.

` fieldset `

** lookup ** ( fieldset,fieldset )

fieldset

**( fieldset,list )**

`lookup`

These two functions build an output fieldset using the values in the first input fieldset as indices in a look-up action on a second input fieldset or input list :

- Takes the grid values in the first fieldset and uses them as index in the second fieldset. E.g. a grid value of n in the first fieldset, retrieves the corresponding grid point value of the (n-1)th field of the second fieldset (indexing is 0 based). The output fieldset is built from these values and has as many fields as the second fieldset.
- Takes the grid values in the first fieldset and uses them as index in the list - real numbers are truncated, not rounded. E.g. a grid value of n in the first fieldset, retrieves the (n-1)th list element (indexing is 0 based). The output fieldset is built from these values and has as many fields as the first fieldset.

Any missing values in the first fieldset will cause the function to fail with a `value out of range' error message.

```
fieldset
```

** mask ** ( fieldset,list )

For each field of the input fieldset, this function creates a field containing grid point values of 0 or 1 according to whether they are outside or inside a defined geographical area.

The list parameter must contain exactly four numbers representing a geographical area. These numbers should be in the order north, west, south and east (negative values for western and southern coordinates). Non-rectangular masks, and even convex masks can be created by using the operators and , or and not . To create the following mask :

First decompose into basic rectangles :

Then create a mask for each of them and use and and or to compose the desired mask. This is the corresponding macro :

```
```

* # Define basic rectangles *

a = [50,-120,10,-30]

b = [20,20,50,10]

c = [50,50,40,100]

d = [35,-60,-40,100]

* # The field is used to get the grid information *

f = retrieve(...)

* # First compute the union of a,c and d *

m = mask(f,a) or mask(f,d) or mask(f,c)

* # Then remove b *

m = m and not mask(f,b)

The resulting mask field can be used in the integrate() function.

` fieldset `

** max ** ( fieldset )

fieldset

**( fieldset )**

`min`

Returns the fieldset of maximum (minimum) value of the input fieldset at each grid point or spectral coefficient. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
fieldset
```

** max ** ( fieldset,fieldset )

fieldset

**( fieldset,fieldset )**

`min`

Returns the fieldset of maximum (minimum) value of the two input fieldsets at each grid point or spectral coefficient. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

```
fieldset
```

** max ** ( fieldset,number )

fieldset

**( fieldset,number )**

`min`

Returns the fieldset of the maximum (minimum) of the number and the fieldset value at each grid point or spectral coefficient. Missing values in the input fieldset are transferred to the output fieldset.

```
geopoints
```

** max ** ( fieldset,geopoints )

geopoints

**( fieldset,geopoints )**

`min`

Returns geopoints of maximum (minimum) of the fieldset value and the geopoint value at each grid point or spectral coefficient. Missing values, either in the fieldset or in the original geopoints variable, result in a value of geo_missing_value .

```
number
```

** maxvalue ** ( fieldset )

number

**( fieldset,list )**

`maxvalue`

number

**( fieldset )**

`minvalue`

number

**( fieldset,list )**

`minvalue`

Returns the maximum (minimum) value of all the values of all the fields of the fieldset. The versions that take a list as a second parameter require a geographical area (north, west, south, east); only points within this area will be included in the calculation. Only non-missing values are considered in the calculation. If there are no valid values, the function returns `nil`

.

```
matrix or list
```

** matrix ** ( fieldset )

Generates a matrix containing the values of the input field, or a list of matrices if there are more than one field in the fieldset. Only works with regular lat/long grids.

```
fieldset
```

** mean ** ( fieldset )

Computes the mean field of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

```
fieldset
```

** mean_ew ** ( fieldset )

Takes a fieldset as its parameter and computes the mean for each line of constant latitude. The result is a fieldset where the value at each point is the mean of all the points at that latitude. Missing values are excluded; if there are no valid values, then the grib missing value indicator will be returned for those points.

```
fieldset
```

** merge ** ( fieldset,fieldset,... )

Merge several fieldsets. The same as the operator &. The output is a fieldset with as many fields as the total number of fields in all merged fieldsets. Merging with the value `nil`

does nothing, and is used to initialise when building a fieldset from nothing.

`fieldset `

**ml_to_hl**(mfld: fieldset, z: fieldset, zs: fieldset, hlist: list, reflev: string, method: string)

Interpolates a fieldset on model levels (i.e. on hybrid or eta levels used by the IFS) onto height levels (in m) above sea or ground level. At gridpoints where interpolation is not possible missing value is returned. This function has the following positional arguments:

`mfld`

: the fieldset to be interpolated`z`

: the geopotential fieldset on model levels (it must contain the same levels as`mfld`

but the order of the levels can be different)`zs`

: the surface geopotential field (if the`reflev`

argument is set to`"sea"`

it should be set to`nil`

*).*`hlist`

: the list of target height levels (they can came in any given order)`reflev`

: specifies the reference level for the target heights. The possible values are`"sea"`

and`"ground"`

`method`

: specifies the interpolation method. The possible values are`"linear"`

and`"log"`

.

Please note that geopotential is not archived operationally on model levels in MARS at ECMWF. To compute geopotential on model levels use Metview's mvl_geopotential_on_ml() function. The following example shows how to use function `ml_to_hl()`

together with `mvl_geopotential_on_ml()`

:

# retrieve the data on model levels - surface geopotential (zs) is only available in the first forecast step! common_retrieve_params = ( type : "fc", levtype : "ml", step : 12, grid : [1.5,1.5] ) t = retrieve param : "t", levelist : [1, 'to', 137], common_retrieve_params) q = retrieve param : "q", levelist : [1, 'to', 137], common_retrieve_params) lnsp = retrieve( param : "lnsp", levelist : 1, common_retrieve_params) zs = retrieve( param : "z", levelist : 1, type : "fc", levtype : "ml", step : 0, grid : [1.5,1.5]) # compute geopotential on model levels z = mvl_geopotential_on_ml(t, q, lnsp, zs) # interpolate the t field onto a list of height levels above sea level hlevs = [1000, 2000, 3000, 4000, 5000] th = ml_to_hl (t, z, nil, hlevs, "sea", "linear")

```
```

` fieldset `

** mod ** ( fieldset,fieldset )

Returns a fieldset with as many fields as the input fieldsets; the grid point values of the output fieldset are the remainder of the division of the first fieldset by the second fieldset (the function operating field by field). Where the gridpoint values of the second fieldset are larger than those of the first, the output gridpoint value is set to the integer part of the first input gridpoint value. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset. Note that only the integer parts of the inputs are considered in the calculation, meaning that a second parameter of 0.5 would cause a division by zero.

With n fields in the input fieldsets, if xik, yik are the ith value of the kth input fieldsets and zi is the ith value of the resulting field:

` `

`fieldset `

**mvl_geopotential_on_ml**(t:fieldset, q:fieldset, lnsp:fieldset, zs:fieldset)

Computes geopotential on model levels.

Parameter `t`

should be a fieldset of temperature on model levels in ascending numeric order (e.g. 1-137), `q`

a fieldset of specific humidity on model levels in ascending numeric order, `lnsp`

a field of log of surface pressure on model level 1, `zs`

a field of geopotential on model level 1 (available from MARS). All fields must be GRIDDED data - no spherical harmonics, and they must all be on the same grid, with the same number of points. The function assumes that there are no other dimensions contained in the data, e.g. all fields should have the same date and time. The return value is a fieldset of geopotential on model levels.

The code below illustrates how to use this function:

*# retrieves analysis data on model levels*

`r = (date: -1, time: 12, levtype: "ml", grid: [1.5,1.5])`

t = retrieve(r,levelist: [1,"to",137],param: "t")

q = retrieve(r,levelist: [1,"to",137],param: "q")

zs = retrieve(r,levelist: 1,param: "z")

lnsp = retrieve(r,levelist: 1,param: "lnsp")

*# computes the geopotential*

`z_ml = mvl_geopotential_on_ml(t, q, lnsp, zs)`

` `

`fieldset `

**mvl_ml2hPa**(lnsp: fieldset, mfld: fieldset, plist: list)

Interpolates a fieldset currently on model levels onto pressure levels (in hPa). Locations where interpolation is not possible are returned as missing.

Parameter `lnsp`

is a field of logarithm of surface pressure; `mfld`

is the fieldset to be interpolated and should be on model levels; `plist`

is a list of pressure levels in hPa - the result will be the `mfld`

fieldset interpolated onto these levels. Neither `mfld`

nor `plist`

need to be sorted.

The following code shows a simple example:

`# retrieve the data in model levels `

`common_retrieve_params = ( type : "fc", levtype : "ml", step : 12, grid : [1.5,1.5] ) `

`tmod = retrieve`

` param : "t", `

`levelist : [1, 'to', 91], `

`common_retrieve_params) `

`lnsp = retrieve( `

`param : "lnsp", `

`levelist : 1, `

`common_retrieve_params) `

`# interpolate onto a list of pressure levels `

`plevels = [1000, 900, 850, 500, 300, 100, 10, 1, 0.1] `

`tpres = mvl_ml2hPa (lnsp, tmod, plevels)`

```
number or list
```

** nearest_gridpoint ** ( fieldset,list[,string] )

number or list

**( fieldset,number,number[,string] )**

`nearest_gridpoint`

`vector or list `**nearest_gridpoint** ( fieldset,vector,vector[,string] )

Returns the value of the nearest point to a given location (or locations) in each field of a fieldset. The field must be a gridded field. If a list is given, it must contain two numbers - latitude and longitude. If two numbers are given, the first is the latitude, the second the longitude. For batch processing of multiple locations, two vectors can be given, the first is a vector of latitudes, the second the longitudes; this can be much more efficient than multiple calls with a single location each. If the fieldset has only one field, a number (or vector) is returned; otherwise a list of numbers (or a list of vectors) is returned.

By default, when the nearest gridpoint value is a missing value or the location is out of the grid area, `nil`

is returned in the case of a single coordinate, or vector_missing_value in the case of a vector. If an extra parameter `'valid'`

is added to the function call, then of the surrounding points, the nearest valid one is returned; `nil`

will still be returned if all the surrounding points are missing.

Note that a similar function, interpolate(), also exists.

```
geopoints
```

** nearest_gridpoint ** ( fieldset,geopoints )

Generates a set of geopoints from a field. The first field of the input fieldset is used. The result is a set of geopoints whose values are those of the nearest gridpoints in the field to the geopoints given as a second parameter. Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, the internal geopoints missing value is used (this value can be checked for with the built-in variable `geo_missing_value`

or removed with the function `remove_missing_values`

). Note that a similar function, ```
interpolate()
```

, also exists.

```
list
```

** nearest_gridpoint_info ** ( fieldset,list[,string] )

list

**( fieldset,number,number[,string] )**

`nearest_gridpoint_info`

Returns the value and location of the nearest point to a given location in each field of a fieldset. If a list is given, it must contain two numbers - latitude and longitude. If two numbers are given, the first is the latitude, the second the longitude. The field must be a lat-long field. The return value is a list of definitions, one for each field, and each containing the following members: value , latitude , longitude . Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, `nil`

is returned. If an extra parameter `'valid'`

is added to the function call, then of the surrounding points, the nearest valid one is returned; `nil`

will still be returned if all the surrounding points are missing.

The following example illustrates how to use the function.

`fs = read (strGribFile)`

listdef = nearest_gridpoint_info(fs, 51.46, -1.33)

loop ngp in listdef

print ("Value : ", ngp.value)

print ("Latitude : ", ngp.latitude)

print ("Longitude : ", ngp.longitude)

end loop

` fieldset `

** nobitmap ** ( fieldset,number )

Returns a copy of the input fieldset (first argument) with all of its missing values replaced with the number specified by the second argument. See also `bitmap`

.

`fieldset `

**percentile**(...)

Computes the specified percentiles for a given fieldset. This is a Metview icon function, for detailed documentation please see Percentile.

` fieldset `

** pressure ** ( fieldset )

fieldset

**( fieldset,number )**

`pressure`

fieldset

**( fieldset,list )**

`pressure`

fieldset

**( fieldset,fieldset )**

`pressure`

This function creates fields of pressure from the logarithm of the surface pressure (lnsp) and a list of model levels. *Note that this function only works with gridded fields and assumes that the parameter for lnsp is 152. A newer, more flexible version of this function exists - see* `unipressure ()`

.

- The first argument is always a fieldset containing an lnsp field. If no other parameter is given, the list of levels will range from 1 to (number of vertical coordinates/2)-1 as coded in the GRIB header of the lnsp parameter.
- The second argument specifies the levels at which the output fields must be generated. To generate a single level, pass a number. For more than one level, either pass a list of levels or a fieldset. If a fieldset is passed as the second parameter, the level information is extracted from each field of the fieldset.

Missing values in the lnsp field are retained in the output fieldset.

```
fieldset
```

** rmask ** ( fieldset,number,number,number )

fieldset

**( fieldset,list )**

`rmask`

Similar to mask , except that a round mask is computed with a given radius around a geographical centre point. These can be given by either:

- three numbers : latitude, longitude (in degrees), radius (in meters)
- a list containing the above three numbers

The name of this function is derived from the fact that it creates a "round mask" or a "radius mask".

```
fieldset
```

** rms ** ( fieldset )

Computes the root mean square of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if x_{i} ^{k} is the i^{th} value of the k^{th} input field and y_{i} is the i^{th} value of the resulting field, the formula can be written :

Note that the following lines are equivalent :

` y = rms(x)`

y = sqrt(mean(x*x))

```
fieldset
```

** second_derivative_x ** (f: fieldset)

Computes the second zonal (from West to East) partial derivative of each field in the fieldset. The computations for a field `f`

are based on the following formula:

where

`R`

is the radius of the Earth`φ`

is the latitude`λ`

is the longitude.

```
fieldset
```

** second_derivative_y ** (f: fieldset)

Computes the second meridional (from South to North) partial derivative of each field in the fieldset. The computations for a field `f`

are based on the following formula:

where

`R`

is the radius of the Earth`φ`

is the latitude.

` fieldset `

**set_values** ( fieldset,vector )

`fieldset `

**set_values** ( fieldset,list )`fieldset `

**set_values** ( fieldset,vector,string )

`fieldset `

**set_values** ( fieldset,list,string )

Creates a new fieldset with all the fields' values replaced by those supplied. If supplied as a single vector, the values are set in all fields; if a list of vectors is supplied then there must be the same number of vectors as there are fields in the fieldset. The default behaviour is to produce an error if the input fieldset and vector have different numbers of values. If, however, a third parameter (set to the string '`resize`

') is passed to the function, the resulting fieldset will instead be resized to have the same number of values as the input vector - this can be useful when creating a new fieldset from a template. Missing values in the vector(s) are retained as missing values in the fieldset.

` fieldset `

** sinlat ** ( fieldset )

For each field in the input fieldset, this function creates a field where each grid point has the value of the sine of its latitude. For example, the following macro adds the coriolis parameter to each grid point of a field :

```
```

* # Computes absolute vorticity from vorticity *

omega = 2 * pi / 86400

coriolis = 2 * omega * sinlat(vort)

absvort = vort + coriolis

```
fieldset
```

** sort ** ( fieldset )

fieldset

**( fieldset,string )**

`sort`

fieldset

**( fieldset,list )**

`sort`

fieldset

**( fieldset,string,string )**

`sort`

fieldset

**( fieldset,list,string )**

`sort`

fieldset

**( fieldset,list,list )**

`sort`

This function accepts a fieldset as input and returns it sorted according to keys and rules specified in the other input arguments.

Specified with only the fieldset as its single argument, `sort()`

sorts in __ascending order__ the fieldset according to the following MARS keys: **date**, **time**, **step**, **number** (ensemle member), **levelist** and **param** (integer ID).

The second argument allows you to modify the precedence of the sorting keys - e.g. if the second argument is a string "param", then the sorting is done according to the param key. If the second argument is a list you specify a list of sorting keys - e.g. ["param", "date"] sorts on parameter and then date.

The third argument specifies a sorting direction. This can be a string (">" or "<") or a list ([">", "<", ">",...]). If it is a string, the sorting direction it specifies applies to all sorting keys specified in the second argument. If it is a list, then the second argument *must* also be a list with the same number of elements - the sorting directions apply to each sorting key specified.

```
fieldset
```

** stdev ** ( fieldset )

Computes the standard deviation of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

Note that the following lines are equivalent :

`y = stdev(x)`

y = sqrt(mean(x*x)-mean(x)*mean(x))

y = sqrt(var(x))

```
number or list
```

** stdev_a ** ( fieldset )

number or list

**( fieldset,list )**

`stdev_a`

Computes the standard deviation over a weighted area. The area, if specified, is a list of numbers representing North, West, South, East. If the area is not specified, the whole field will be used in the calculation. The result is a number for a single field, or a list for a multi-field fieldset.

```
fieldset
```

** sum ** ( fieldset )

Computes the sum of a fieldset. The result is a single-field fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

` vector or list `

**surrounding_points_indexes** ( fieldset,list[,string] )

vector or list **surrounding_points_indexes** ( fieldset,number,number[,string] )

vector or list **surrounding_points_indexes** ( fieldset,vector,vector[,string] )

Returns the indexes of the four gridpoints surrounding the given location, ordered by increasing distance from the target point. If a list is given, it must contain two numbers - latitude and longitude. If two numbers are given, the first is the latitude, the second the longitude. The field must be a gridded field. If the fieldset has only one field, a single vector of indexes is returned; otherwise a list of vectors is returned. In the case where the field is a reduced Gaussian grid and the input location is at the North or South pole, beyond the most extreme row of points, there will be a 'circle' of surrounding points, and all of these indexes are returned.

For batch processing of multiple locations, two vectors can be given, the first is a vector of latitudes, the second the longitudes; this can be much more efficient than multiple calls with a single location each. If the fieldset has only one field, a single vector is returned; otherwise a list of vectors is returned.

By default, if any of the surrounding points are missing, the function will return `nil`

. To prevent this, and to return all the points regardless, add the option `'all'`

as the last parameter of the function call.

` fieldset `

**tan lat ** ( fieldset )

For each field in the input fieldset, this function creates a field where each grid point has the value of the tangent of its latitude. The resulting fields contain missing values on the poles.

` fieldset `

** thickness ** ( fieldset )

fieldset

**( fieldset,number )**

`thickness`

fieldset

**( fieldset,list )**

`thickness`

fieldset

**( fieldset,fieldset )**

`thickness`

This function creates fields of thickness from the logarithm of the surface pressure (lnsp ) and a list of model levels. *Note that this function only works with lat/long grids and assumes that the parameter for lnsp is 152. A newer, more flexible version of this function exists - see* unithickness () .

- The first argument is always a fieldset containing an lnsp field. If no other parameter is given, the list of levels will range from 1 to (number of vertical coordinates/2)-1 as coded in the GRIB header of the lnsp .
- The second argument specifies the levels at which the output fields must be generated. To generate a single level, pass a number. For more than one level, either pass a list of levels or a fieldset. If a fieldset is passed as the second parameter, the level information is extracted from each field of the fieldset.

Missing values in the lnsp field are retained in the output fieldset.

```
fieldset
```

** unipressure ** ( fieldset )

fieldset

**( fieldset,fieldset )**

`unipressure`

fieldset

**( fieldset,list )**

`unipressure`

fieldset

**( fieldset,number )**

`unipressure`

fieldset

**( fieldset,fieldset,number )**

`unipressure`

fieldset

**( fieldset,list,number )**

`unipressure`

This function creates fields of pressure from the logarithm of the surface pressure (lnsp) and a list of model levels. Unlike pressure() , this function works with all grid types known to Metview (not just lat/long); it also allows the user to override the parameter number for lnsp (default 152).

- The first argument is always a fieldset containing an lnsp field. If no other parameter is given, then pressure is computed for all model levels that are described in the GRIB header of fieldset .
- If number is given (always the last parameter) it is the lnsp parameter code (default is 152).
- list should contain model levels for which pressure is to be computed. Note that also for a single model level one has to use a list (this is a signature difference compared to the old function pressure() ).
- If fieldset is given as the second parameter then pressure is computed for those model levels found in the second fieldset.

Missing values in the lnsp field are retained in the output fieldset.

```
fieldset
```

** unithickness ** ( fieldset )

fieldset

**( fieldset,fieldset )**

`unithickness`

fieldset

**( fieldset,list )**

`unithickness`

fieldset

**( fieldset,number )**

`unithickness`

fieldset

**( fieldset,fieldset,number )**

`unithickness`

fieldset

**( fieldset,list,number )**

`unithickness`

This function creates fields of thickness from the logarithm of the surface pressure (lnsp) and a list of model levels. Unlike thickness() , this function works with all grid types known to Metview (not just lat/long); it also allows the user to override the parameter number for lnsp (default 152).

- The first argument is always a fieldset containing an lnsp field. If no other parameter is given, then thickness is computed for all model levels that are described in the GRIB header of fieldset .
- If number is given (always the last parameter) it is the lnsp parameter code (default is 152).
- list should contain model levels for which thickness is to be computed. Note that also for a single model level one has to use a list (this is a signature difference compared to the old function thickness() ).
- If fieldset is given as the second parameter then thickness is computed for those model levels found in the second fieldset.

Missing values in the lnsp field are retained in the output fieldset.

```
fieldset
```

** univertint ** ( fieldset)

fieldset

**( fieldset, fieldset )**

`univertint`

fieldset

**( fieldset, number )**

`univertint`

fieldset

**( fieldset, fieldset, number )**

`univertint`

fieldset

**( fieldset, fieldset, list)**

`univertint`

Universal vertical integration. This function is similar to `vertint()`

, except that `univertint()`

also works with sparse levels whereas `vertint()`

is restricted to continuous levels.

This function performs a vertical integration of the input fieldset. If just one fieldset is given, it must also contain the logarithm of the surface pressure (lnsp). If the function is called with two fieldsets, the first one is a fieldset containing an lnsp field, the second one is the multi-level fieldset. A number may optionally be given as the last parameter in order to specify the lnsp code used in the fieldset that contains the lnsp data; its default value is 152. If a list with two elements [top, bottom] is given as the third parameter, then the integration is performed between (and including) these layers.

A missing value in any field will result in a missing value in the corresponding place in the output fieldset.

The function computes:

\[ \int_{bottom}^{top} f \frac{dp}{g} \]where

`f`

is the fieldset`p`

is the pressure`g`

is the acceleration of gravity (9.81 m/s^{2}).

` date or list `

**valid_date** ( fieldset )

Returns the valid dates (including the time components) of the given fields. If the fieldset has only one field, a date is returned; otherwise a list of dates is returned.

` vector or list `

**values** ( fieldset )

This function returns the grid point values as a vector. If the fieldset contains more than one field it returns a list of vectors. Each of these vectors contains as many elements as grid points in each field. Missing values are included in the results as `vector_missing_value`

.

```
```

* # x is a fieldset of n fields *

xgrid = values(x)

field1_values = xgrid[1]

gridpoint1 = field1_values[1]

* # or equivalently *

gridpoint1 = xgrid[1][1]

` fieldset `

** var ** ( fieldset )

Computes the variance of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

Note that the following lines are equivalent :

` y = var(x)`

y = mean(x*x)-mean(x)*mean(x)

```
number or list
```

** var_a ** ( fieldset )

number or list

**( fieldset,list )**

`var_a`

Computes the variance over a weighted area. The area, if specified, is a list of numbers representing North, West, South, East. If the area is not specified, the whole field will be used in the calculation. The result is a number for a single field, or a list for a multi-field fieldset.

```
fieldset
```

** vertint ** ( fieldset )

```
fieldset
```

** vertint ** ( fieldset,fieldset )

This function performs a vertical integration of the input fieldset, which must contain a range of model levels for the same parameter. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. If the function is called with the fieldset as its single argument, it must also contain the logarithm of the surface pressure (lnsp ). If the function is called with two parameters, the first one is a fieldset containing an lnsp field, the second one is the multi-level fieldset.

The function computes :

\[ \int_{bottom}^{top} f \frac{dp}{g} \]where

`f`

is the fieldset`p`

is the pressure`g`

is the acceleration of gravity (9.81 m/s^{2}).

The following example computes the total amount of liquid water in the atmosphere by integrating the cloud liquid water content (clwc ) over all levels of the model

```
```

* # Retrieve clwc *

clwc = retrieve(

levtype : "ml",

levelist : [1,"to",31],

param : "clwc",

date : -1,

grid : [2.5,2.5]

)

* # Retrieve lnsp *

lnsp = retrieve(

levtype : "ml",

levelist : 1,

param : "lnsp",

date : -1,

grid : [2.5,2.5]

)

* # Integrate the field *

x = vertint(lnsp,clwc)`plot(x)`

```
fieldset
```

** vorticity ** (fx fieldset, fy: fieldset)

Computes the vertical component of the `curl`

differential operator for 2-dimensional vector fields. For wind fields (i.e. when the input fieldsets are `u`

and `v`

wind components) this computes the relative vorticity (ζ). The computations for a vector field `f=(f`

_{x} `,f`

_{y} ) are based on the following formula :

where

`R`

is the radius of the Earth`φ`

is the latitude`λ`

is the longitude.

The derivatives are computed with a second order finite-difference approximation. The resulting fields contain missing values on the poles. If the input fields are horizontal wind components the GRIB `paramId`

of the resulting field is set to `138`

(relative vorticity). Please note that this function is only implemented for regular latitude-longitude grids.