# Re: position of min or max

Hi Martin,
Here is a way you can do it using an "index variable" to encode
the values of indices. If indices i,j,k,l only ranged from 1-9 then
v = 1000*i + 100*j +10*k + l
could be used to encode the point (8,4,6,2) with v=8462.

Lets look for the maximum salinity in the Levitus Monthly
Climatology.  Here there are 360,180,24,12 values for the i,j,k,l
indices so we can't hope to encode all 4 dimensions.  But
v = 1000*i + j
will at least encode the two biggest. This leads to the following
example, where for reasons of memory I confine the search to part
of the tropical Pacific.
!----------------------------------------------------------------------
! findmax.jnl : search for maximum in 4-d
use levitus98_monthly.cdf
region/x=130:160/y=-20:20
let smax=salt[i=@max,j=@max,k=1:24@max,l=1:12@max]
list smax
! looking for an exact match to smax may fail due to limited precision
! so look for 99.99% of maximum
let spos=if(salt ge `0.9999*smax`)then 1000*i[g=salt]+j[g=salt] else 0
let sij=spos[x=@max,y=@max]
list/form=(12f8.0)/ord=tz sij
!----------------------------------------------------------------------

The result is a table that shows that the maximum salinity in this
subregion is found at two depth/time positions k=5,l=5 and k=2,l=12 but
both at the same lon/lat position coded by the value 141082. i.e at
i=141 and j=82.

Hope this helps,
Mick

|--****--****-*---*---***--***--|____spillane@pmel.noaa.gov____|
|-*__---*-----*--*-*--*--*-*--*-|_SCIENCE APPLICATIONS SUPPORT_|
|--***--*-----*-*---*-***--***--|____EPIC/Ferret/PlotPlus______|
|-----*-*-----*-*****-*----*----|__Room 2070 Bldg#3 NOAA/PMEL__|
|-****---****-*-*---*-*----*----|____Phone_:_(206)526-6780_____|