#!/bin/ksh

#-- delete existing ASCII output file
rm -rf outfile.txt

#-- name of the input file
infile=euin.nc

#-- arrays of the points lon lat locations
set -A lon -0.963246
set -A lat 38.308579

#-- loop to retrieve the data of the selected points 
for i in $(seq 0 3)
do
   cdo -O remapnn,lon=${lon[$i]}/lat=${lat[$i]} $infile tmp.nc
   cdo -outputtab,lon,lat,date,value tmp.nc >> outfile.txt
done

#-- delete the multiple entries of the header line in output file
header="#" 
awk '!header[$0]++' outfile.txt > tmp2.txt
mv tmp2.txt outfile.txt

#-- remove temporary file
rm tmp.nc

exit
