#!/bin/bash 

#Petit script super simple pour tracer le Groenland

# On part du fichier hz, S, H, B enroule j a l'exterieur
# nx=41 ny= 71


file=$1

RANGE=-R0/1600/0/2800
PROJEC=-JX12/21

# creation des fichiers grd
tail +5 $file | awk '{print $1}' |xyz2grd -Gsurf.grd -I40 $RANGE  \
-ZBL

grdsample surf.grd -Gsurf-fin.grd  $RANGE -I10  

#grd2xyz surf-fin.grd -ZBL > surf-fin.z

tail +5 $file | awk '{print $3}' |xyz2grd -Gbed.grd -I40 $RANGE  \
-ZBL

grdsample surf.grd -Gbed-fin.grd  $RANGE -I10  

tail +5 $file | awk '{print $2}' |xyz2grd -GH.grd -I40 $RANGE  \
-ZBL

grdsample H.grd -GH-fin.grd  $RANGE -I5  

#grd2xyz H-fin.grd -ZBL > Hfin.z

#paste  surf-fin.z Hfin.z > SH.z

#awk '{ if ($2 <=10 ) print $1/10000 ; else print $1 }' SH.z \
# | xyz2grd -Gcombine-fin.grd -I10 $RANGE -ZBL

# tail +5 $file | awk '{ if ($2 <=1 ) print $1/10000 ; else print $1 }' \
# |xyz2grd -Gcombine.grd -I40 $RANGE -ZBL
# grdsample combine.grd -Gcombine-fin.grd  $RANGE -I10 -Q 

rm contour*xyz
# la mer en bleu
psxy  <<EOF -P $RANGE $PROJEC -G140/102/255 -K > POST 
0  0
1600 0
1600 2800
0    2800
0  0
EOF

grdcontour bed.grd -Ccote.iso  $RANGE $PROJEC -D -S20  > BIDON
psclip contour*xyz $RANGE $PROJEC -O -K >> POST

# la Terre en vert
psxy  <<EOF -P $RANGE $PROJEC -G000/255/000 -K -O >> POST 
0  0
1600 0
1600 2800
0    2800
0  0
EOF

# enleve le clip terre
psclip -C -K -O >> POST
rm contour*xyz


#grdimage bed-fin.grd -Ba500f100 -Cmer-grass.cpt  -P $RANGE $PROJEC  -K -X2 -Y1 > POST

grdcontour H-fin.grd -Ccontour.iso -W4/255/0/0 $RANGE $PROJEC -D -S20 > bidon

psclip contour*xyz $RANGE $PROJEC -O -K >> POST

#grdimage surf-fin.grd -Ba500f100 -Cglace-bleue.cpt  -P $RANGE $PROJEC  -K  -O >> POST

# grdview combine.grd -Ba500f100 -Cglace-sur-land.cpt -Qi -P $RANGE $PROJEC  -K -X2 -Y1 > POST

#grdcontour H-fin.grd -Csurf.iso  $RANGE $PROJEC -O -K >> POST


#grdview surf-fin.grd -Cglace-bleue.cpt -Qs -P $RANGE $PROJEC  -K -O >> POST
grdimage surf-fin.grd -Cglace-bleue.cpt  -P $RANGE $PROJEC  -K -O >> POST
grdcontour surf-fin.grd -C500 -A1000 $RANGE $PROJEC -O -K >> POST

psclip -C -K -O >> POST
# grdcontour surf.grd -Ccontour.iso $RANGE $PROJEC -O -K >> POST



#grdcontour H-fin.grd -Ccontour.iso -W4/255/0/0 $RANGE $PROJEC -O -S20  >> POST
psxy contour*xyz $RANGE $PROJEC -O -K  -W4/255/0/0 >> POST

# gates
psxy gate*.txt  $RANGE $PROJEC -O -K  -W15   >> POST

# trace les meridiens et paralleles
# lon lat des coins bas gauche  -55.82902  58.77798       haut droit :  12.45875  80.15318   

#psbasemap  -JS-44/90/12 -R-55.82902/58.77798/12.45875/80.15318r -Ba10g10/a5g5 -O >> POST
pscoast -JS-44/90/12 -R-55.82902/58.77798/12.45875/80.15318r -Ba10g10/a5g5 -O -W2 >> POST