#!/bin/sh
# deux fichiers en entree et trace des vectuers vents
# superposes heure par heure
   longmin=0
   longmax=144
   latmin=5.
   latmax=20.
   xtick=24.
   ytick=50.
   
   fic1=$1
   fic2=$2
   fic3=$3
   city=$4

\rm $city.ps boxwind wind1.data wind2.data wind3.data test text_wind

box="-Bfa"${xtick}"/fa"${ytick}"WSne"

# Making locations of text frames

titlon=50.
titlat=19

titloncity1=5
titlatcity1=18
titloncity2=5
titlatcity2=10

bxmin=130
bxmax=144
bymin=5
bymax=7
bxarrow=132
byarrow=5.5
bytext=5.75


echo $bxmax " " $bymin >  "boxwind"
echo $bxmax " " $bymax >> "boxwind"
echo $bxmin " " $bymax >> "boxwind"
echo $bxmin " " $bymin >> "boxwind"
echo $bxmax " " $bymin >> "boxwind"
echo $bxarrow "  " $byarrow "  0. 1." > "wind3.data"
echo $bxarrow "  " $bytext  "  11 0 0 0  5 m/s" > "text_wind"
echo $titlon " " $titlat " 13 0 0 0" > ".txt1"

psca="-D15.2/6./12./0.5"
pars="-JX15/5.1  -R"$longmin"/"$longmax"/"$latmin"/"$latmax

echo " -------------------------------------------------------------"
echo " -- Destruction des fichiers temporaires "
\rm $palette wind.data
\rm .nbline

echo " -- Nettoyage du precedent post-script "$city".ps"
\rm $city.ps

       
pscoast ${pars} ${box} -S255WS  -K -P  > $city.ps

echo "Vecteurs vents donnees"
gawk '{
       xdecal=$1
       ydecal=$2+20
       ff=$3
       dir=$4
       if(dir >= 0.)dir2=dir/3.14159*180.
       if(dir < 0.)dir2=360.+dir/3.14159*180.
       printf("%-f %-f %f %-f \n",xdecal,ydecal,dir2,ff/5.) >> "wind4.data"
       }' $fic1
 
echo "Vecteurs vents 1er fichier"
gawk '{
       xdecal=$1-48
       ydecal=$2+15
       ff=sqrt($4*$4+$3*$3)
       dir=atan2($4,$3)
       if(dir >= 0.)dir2=dir/3.14159*180.
       if(dir < 0.)dir2=360.+dir/3.14159*180.
       printf("%-f %-f %f %-f \n",xdecal,ydecal,dir2,ff/5.) >> "wind1.data"
       }' $fic1
 
echo "Vecteurs vents 2eme fichier"
gawk '{
       xdecal=$1-48
       ydecal=$2+8
       ff=sqrt($4*$4+$3*$3)
       dir=atan2($4,$3)
       if(dir >= 0.)dir2=dir/3.14159*180.
       if(dir < 0.)dir2=360.+dir/3.14159*180.
       printf("%-f %-f %f %-f \n",xdecal,ydecal,dir2,ff/5.) >> "wind2.data"
       }' $fic2
 
# data 
#psxy wind4.data ${pars}  -Sv0.02/0.1/0.05 -G0       -M -K -O -P  >> $city.ps
#echo ${titloncity1} ${titlatcity1} 11 0 0 0 "Data" > .txt
#pstext .txt ${pars} -W0/250/0 -N -O -P -K >>  $city.ps

psxy wind1.data ${pars}  -Sv0.02/0.1/0.05 -G0       -M -K -O -P  >> $city.ps
echo ${titloncity1} ${titlatcity1} 11 0 0 0 "ECMWF" > .txt
pstext .txt ${pars} -W0/250/0 -N -O -P -K >>  $city.ps


psxy wind2.data ${pars}  -Sv0.02/0.1/0.05 -G0 -M -K -O -P  >> $city.ps
echo ${titloncity2} ${titlatcity2} 11 0 0 0 "RAMS" > .txt
pstext .txt ${pars} -W0/250/0 -N -O -P -K >>  $city.ps

# titre de la figure
\rm .txt
echo ${titlon} ${titlat} 13 0 0 0 ${city} > .txt
pstext .txt ${pars} -W230 -N -O -P -K >>  $city.ps

# echelle du vecteur vent
psxy boxwind ${pars}  -M -W5/0/0/0 -O -P  -K -G255 >> $city.ps
psxy wind3.data ${pars}  -Sv0.02/0.1/0.05  -O -P -K  -G0 >> $city.ps
pstext text_wind ${pars} -O -P  >> $city.ps


\rm wind.data
# Bug dans le set-up des post-scripts
gawk '{
       if($0 !~ "/ImagingBBox")print $0 >> "test.ps"
       }' $city.ps
\mv test.ps $city.ps
#\rm .nbline
echo "-----------------------------"
echo " Output file = " $city".eps"
ps2epsi $city.ps $city.eps
ghostview  -font 6x13 $city.eps &



