#!/bin/csh

# Attention, si on change set z 1 8, il faut aussis
# changer set xaxis 1000 545 100 qui force les labels des axes.
set lmax=7
set pmin=663

# mpage 0.5 8.3 1 3.5 4 1 90 90
#mpage 1.3 7.5 0.5 9 1 4 100 95
# mpage 1.3 7.5 2 7.5 1 4 100 95
mpage 1.3 5.5 2 5.5 1 4 100 92


foreach q ( tr01 tr03 tr18 )

if ( $q == tr01 ) then
set time=( 40 44 48 52 )
set titre=( T0 T0+12h T0+24h T0+48h )
set ylab="\  \ \ \ Direct from \ Monterfile "
set dq=tr01
set file=/home/hourdin/SIMA/OFFLINE/histrac.nc
else
set time=( 13 9 5 1 )
set titre= ( " " " " " " " " )
set dq=$q
set file=/home/hourdin/SIMA/sim52/histracn.nc
if ( $q == tr03 ) then
set ylab="\ \ \ \ Backward \ from D08 "
else
set ylab="\ \ \ \ Backward \ from PL08 "
endif
endif


cat <<eod> ! deux.exec
set gxout shaded
exec un.exec &0 &1 &2
set gxout contour
set ccolor 1
set clab off
exec un.exec &0 &1 &2
eod

if ( $q == tr01 ) then
cat <<eod>> deux.exec
* draw title \ \ \ \ \ &3
eod
endif

cat <<eod> ! un.exec
run page.gs &0
draw map
set clevs 0.1 0.2 0.5 1 2 5 10
set t &2
set yaxis 1000 $pmin 100
d ave(maskout(&1,0.015-abs(-0.00424577994 *lon+ 0.0206564255*lat-1.)),lat=30,lat=70)/0.340
run stats.gs s -2 97600 0.1
* run statd.gs s 08.42 53.5  0.1
run statd.gs s 15.32 97600   0.1
eod

cat <<eod> ! main.exec
sdfopen $file
set rgb 21 255 255 255
set rgb 22 240 240 240
set rgb 23 220 220 220
set rgb 24 210 210 210
set rgb 25 200 200 200
set rgb 26 190 190 190
set rgb 27 180 180 180
set rgb 28 170 170 170
set rgb 29 160 160 160
set rgb 30 150 150 150
set rgb 31 140 140 140
set rgb 32 130 130 130
set rgb 33 120 120 120
set rgb 34 110 110 110
set rgb 35 100 100 100
set rgb 36  90  90  90
set rgb 37  80  80  80
set rgb 38  70  70  70
set rgb 39  60  60  60
set rgb 40  50  50  50
set rgb 41  40  40  40
set rgb 42  30  30  30
set rgb 43  20  20  20
set rgb 44  10  10  10
set rgb 45   0   0   0
set rbcols 21 22 24 28 32 36 39 42
set lon -5 18
set lat 1
set z 1 $lmax
set grads off
eod

cat <<eod>> main.exec
set xlab off
set grid off
exec deux.exec 1 $dq $time[1] $titre[1]
*  draw ylab $ylab
exec deux.exec 2 $dq $time[2] $titre[2]
exec deux.exec 3 $dq $time[3] $titre[3]
set xlab on
exec deux.exec 4 $dq $time[4] $titre[4]
eod


if ( $q == tr18 ) then
cat <<eod>> main.exec
* run hcbar.gs
eod
endif

if ( $q == tr03 ) then
cat <<eod>> main.exec
run hcbar.gs
set gxout contour
set clab off
set rgb 21 150 150 150
set ccolor 30
set mpdraw off
set xlab off
exec un.exec 1 tr18 $time[1]
set mpdraw off
set ccolor 30
exec un.exec 2 tr18 $time[2]
set ccolor 30
exec un.exec 3 tr18 $time[3]
set ccolor 30
set xlab on
exec un.exec 4 tr18 $time[4]
eod
endif




cat <<eod>> main.exec
enable print ${q}z
print
quit
eod

grads -pbc "exec main.exec"

gxeps ${q}z -c  -o

end
