#/bin/bash

rm -f ts.dat


for file in MAR*.nc ; do

ferret <<EOF
use $file
set mem/size=10000
let msk = if ( lat ge 50.6 and lat le 51.4 and lon ge 2.5 and lon le 5.7) then 1 else 0
let ws = msk*(winz^2+WINM^2)^0.5/msk[x=@sum,y=@sum]
let pbl= hght*msk/msk[x=@sum,y=@sum]
list/nohead/append/file=ts.dat/format=(10f8.2) pbl[l=@ave,x=@sum,y=@sum],ws[l=@ave,k=22,x=@sum,y=@sum],ws[l=@ave,k=19,x=@sum,y=@sum],ws[l=@ave,k=17,x=@sum,y=@sum],ws[l=@ave,k=10,x=@sum,y=@sum]
quit
EOF
done
