#!/bin/sh
# Script de lecture des donnees lidar Palaiseau pour ESQUIF
# Pre-requis: GMT

palette="GMTcolor.cpt"

echo " -------------------------------------------------------------"
echo "         ESQUIF PALAISEAU LIDAR"
echo " -------------------------------------------------------------"
echo " --  Remove temporary files "
\rm test1 test

xmin=0.
xmax=24.
zmin=0.
zmax=3000.

psca="-D15.5/6./12./.7"
pars="-JX15/12  -R"$xmin"/"$xmax"/"$zmin"/"$zmax
grid="-R"$xmin"/"$xmax"/"$zmin"/"$zmax

echo " -------------------------------------------------------------"
echo " -- Give name of raw data file:"
echo " "
echo "             poi1_25071998 "
echo "             poi1_26071998 "
echo "             poi2_08081998 "
echo "             poi2_09081998 "
echo "             poi3_16061999 "
echo "             poi3_17061999 "
echo "             poi4_25061999 "
echo "             poi5_02071999 "
echo "             poi6_16071999 "
echo "             poi6_17071999 "
echo "             poi6_18071999 "
echo " -------------------------------------------------------------"
read date
echo " -------------------------- output -----------------------"
echo " - color (rainbow)......................................1"
echo " - black and white .....................................2"
echo " "
read color


fic_time="T_"$date
fic_alt="X_"$date
fic_val="PR2_"$date

echo "-- Treatment of "$fic_time " & " $fic_alt " & " $fic_val

echo "-- Remove old file = "$date".ps"
\rm $date.ps

echo "0 0" > test1
psxy ${pars} -Bfa2g2f40:"Time(h)":/fa100g100f2000mSWne:"Height (km)": -P -K test1 > $date.ps

echo "-- Reading raw data...."
gawk -f Lidar_PR2_gmt.awk -v fic_time=${fic_time} fic_alt=${fic_alt} fic_val=${fic_val} ${fic_alt}  ${fic_time} ${fic_val} 
echo "-- End of reading raw data...."

gawk '{
   if(FNR==1)vmin=10000
   if(FNR==1)vmax=0
   if($3 <= vmin){vmin=$3}
   if($3 >= vmax){vmax=$3}
   nline=FNR
   if(nline % 100 == 0){
   print nline " lines - min = " vmin/1 " - max = " vmax/1 " - pas = " (vmax-vmin)/20
   }
}' test
echo " -- Estimated values -> min = " ${vmin} " et max = " ${vmax}

echo " -- Give your choice for MIN and MAX and STEP"
read vmin vmax pas


echo " -- Creating color table " $palette
if [ $color = "1" ]; then
   makecpt -Crainbow -T${vmin}/${vmax}/${pas} > $palette
fi
if [ $color = "2" ]; then
   makecpt -Cgray -T${vmin}/${vmax}/${pas} -I > $palette
fi

echo "pscontour"
pscontour test  -C$palette ${pars} -I  -P -M -K -O >> $date.ps
psscale -C$palette ${psca} -I  -P -O >> $date.ps

echo " -------------------------------------------------------------"
echo "Ghostview "$date".ps &"
ghostview -font 6x13 -geometry 800x600 $date.ps &

\rm $palette
