How to use Ferret External Functions for sorting and sampling
Below is an annotated version of the script ef_sort_demo.jnl
! ef_sort_demo.jnl
! *am* 9/98
! Description: Demonstration of external functions for sort/sample:
! SORTI, SORTJ, SORTK, SORTL to obtain lists of indices of
sorted data
! SAMPLEI, SAMPLEJ, SAMPLEK, SAMPLEL to sample data at a list
of indices
A first simple example of sorting: Sort a list of data. Use COADS
sea surface data at a location where some of the data is missing.
These are grid-changing functions so specify the region of the arguments
in square brackets.
USE coads_climatology
LIST sst[x=19e,y=77n,l=1:6]
yes? LIST sst[x=19e,y=77n,l=1:6]
SEA SURFACE TEMPERATURE (Deg C)
LATITUDE: 77N
DATA SET: /opt/local/ferret/fer_dsets/descr/coads_climatology.des
19E
0
16-JAN / 1: 0.300
15-FEB / 2: ....
17-MAR / 3: ....
16-APR / 4: 5.000
16-MAY / 5: 1.350
16-JUN / 6: 2.799
|
The sequence of calls is: Compute the sorted indices, then sample the data using the new order of indices.
Show the indices and the sorted temperatures
LET tsorted_indices = sortl(sst[x=19e,y=77n,l=1:6])
LET tsorted_sst = samplel(sst[x=19e,y=77n,l=1:6], tsorted_indices)
LIST tsorted_indices, tsorted_sst
yes? LIST tsorted_indices, tsorted_sst DATA SET: /opt/local/ferret/fer_dsets/descr/coads_climatology.des COADS Monthly Climatology (1946-1989) T: 0.5 to 6.5 LONGITUDE: 19E LATITUDE: 77N Column 1: TSORTED_INDICES is SORTL(SST[X=19E,Y=77N,L=1:6]) Column 2: TSORTED_SST is SAMPLEL(SST[X=19E,Y=77N,L=1:6], TSORTED_INDICES) TSORTED_TSORTED_ 1 / 1: 1.000 0.300 2 / 2: 5.000 1.350 3 / 3: 6.000 2.799 4 / 4: 4.000 5.000 5 / 5: .... .... 6 / 6: .... .... |
We can also use the constant-array notation to pick out a couple
of points:
LIST samplel(sst[x=19e,y=77n,l=1:6], {1,5})
yes? LIST samplel(sst[x=19e,y=77n,l=1:6], {1,5})
SAMPLEL(SST[X=19E,Y=77N,L=1:6], {1,5})
LATITUDE: 77N
DATA SET: /opt/local/ferret/fer_dsets/descr/coads_climatology.des
19E
0
1 / 1: 0.300
2 / 2: 1.350
|
| |