# Re: temperature at a certain depth

```Hi,
The data you supply as example pose a couple of difficulties
for interpolating temperature at the depths you wish, but it is possible.

1) the depths are non-monotonic increasing or decreasing
(31.90,32.00,31.80, ...) but the "sorti" function can handle this

2) one of the output depths you request (0) is outside the range of input
depths in the data set - this may require a special definition, perhaps
defining the surface temperature as the shallowest value, provided it
is shallower than some tolerance

So here is one way to get what you want

file/form=free/var=tin,din c4s1.txt ! reads in the data "as-is"

let idep=sorti(din) ! the indices for a monotonic non-decreasing axis
let dep=samplei(din,idep) ; let temp=samplei(tin,idep) ! reordered data

let zo=zsequence({0,5,10,15,20,25,30})  ! the output depths you require
let tk=temp*dk      ! dk to be defined in the repeat loop below
let to=tk[x=@sum]   ! "integrate" the kernel

repeat/k=1:7 (let dk=dep[i=@weq:`zo`] ; list/nohead/form=(2f8.4) zo,to)

If you cut and paste this into Ferret you will find all is well EXCEPT
that a missing value is printed out for zo=0 . This is because depth=0
is outside the range of depth data in this file.  A similar missing
value would be printed if sampling did not go as deep as one or more of
the requested output depths.  To pick a reasonable surface value you
might try something like
let tol=0.5 ! if depth < 0.5m is acceptably close to the surface
let t0m=if(dep[i=1] le tol)then temp[i=1] ; list t0m

Mick

|____spillane@pmel.noaa.gov____|
|__Room 2070 Bldg#3 NOAA/PMEL__|
|____Phone_:_(206)526-6780_____|
The data example provided was
> temp(d)  depth(m)
> 29.68	31.9
> 29.68	32.0
> 29.68	31.8
> 29.68	31.0
> 29.69	30.2
> 29.73	28.7
> 29.75	27.6
> 29.76	26.4
> 29.76	25.4
> 29.76	24.0
> 29.75	22.8
> 29.75	21.9
> 29.75	20.6
> 29.75	19.4
> 29.76	18.1
> 29.81	16.8
> 29.82	15.5
> 29.82	14.0
> 29.83	12.7
> 29.81	11.3
> 29.78	9.8
> 29.78	8.7
> 29.82	7.0
> 29.90	5.7
> 29.97	4.1
> 29.99	2.9
> 29.95	1.3
> 29.9	0.1
>
> Takaya Namba

```