#!/bin/csh -x
#
unset noclobber

set DATE=$1

set dat=`caldate.3.0.1 $DATE + 0h 'yyyymmddhh - sd' `
echo $dat
set data=`echo $dat | cut -c1-8`
set dat2=`echo $dat | cut -c9-10`


cat <<EOF> /home/etamodel//posfig/scripts/loopfig.gs

'open /home/etamodel/Eta10km/grbctl/$DATE/etabru10.$DATE.pgrbf.ctl'
'c'
*'run /home/etamodel/posfig/scripts/rgb.gs'
'set map 1 1 6 '
'set mpdset brmap_hires'
*'set gxout grfill'
'set gxout vector'
i=21
j=100
while(i<=24)

'set x 1 112 '
'set y 1 78'
'set lev 950' 
*'set vpage 0 5.5 0 8'
*'set parea 0.5 5.3 0 8' 
'set vpage 0 8 5 10.9'
*'set parea 0.5 5.3 0 8' 
'set clevs 1 2 3 4 5 6 7 8 9 10'
'set ccols 15 9 14 4 11 5 3 10 7 12 2 '
dir='tabela_sp'i''

'set t ' i
'set grads off'
'd skip(uvel,3,3);vvel);mag(uvel,vvel)'
ilab=i-1
'draw title  $data'ilab' '
while (1)
a=read(dir)

if(sublin(a,1)=1);break;endif
if(sublin(a,1)!=0);break;endif 
lin=sublin(a,2)
lon=subwrd(lin,3)
lat=subwrd(lin,2)
sg=subwrd(lin,4)
'q w2xy 'lon' 'lat''
xx=subwrd(result,3)
yy=subwrd(result,6)
'set string 1'
'set strsiz .1 .1'
'draw string 1 0.1 By Correia '
'draw string 'xx' 'yy' 'sg ' '
*say ' arquivo ' lon ' 'lat ' ' xx' 'yy
endwhile (1)
*'d mag(uvel,vvel)'

'set vpage 0 8 0 5'
*'set parea 5.7 10.5 0 8'
'set lon -50.47 -47.56'
'set lat -23.7 -21'
'set clevs 1 2 3 4 5 6 7 8 9 10'
'set ccols 15 9 14 4 11 5 3 10 7 12 2 '
*9 14 4 11 5 13 3 10 7 12 8 2 6
'set t ' i
'set grads off'
'd skip(uvel,2,2);vvel);mag(uvel,vvel)'
'run cbar.gs'

*if (ilab<10)
'enable print /home/etamodel//posfig/scripts/figs/$data'ilab'.gmf'
*else
*'enable print /home/etamodel//posfig/scripts/figs/$data'ilab'.gmf'
*endif


*************************************************
arq='tabela_sp'j''
while (1)
b=read(arq)

if(sublin(b,1)=1);break;endif
if(sublin(b,1)!=0);break;endif 
lin=sublin(b,2)
lon2=subwrd(lin,3)
lat2=subwrd(lin,2)
sg2=subwrd(lin,4)
'q w2xy 'lon2' 'lat2''
xx2=subwrd(result,3)
yy2=subwrd(result,6)
'set string 1'
'set strsiz .1 .1'
*'draw string 'xx' 'yy' o '
'draw string 'xx2' 'yy2' 'sg2 ' '
*say ' arquivo ' lon ' 'lat ' ' xx' 'yy
endwhile (1)
c=i+1
d=j+1
'!cp tabela_sp tabela_sp'c''
'!cp tabela_sp tabela_sp'd''
'!rm tabela_sp'i''
'!rm tabela_sp'j''
*'draw string 'xx' 'yy' 'sg ' '
'run cbar.gs'
'print'
'disable print'

*'!/home/etamodel/bin/gxpng -r -x 470 -y 360 -i /home/etamodel/posfig/scripts/figs/'$data'0'ilab'.gmf -o /home/etamodel//posfig/scripts/figs/'$dat'.png'
*if (d<10)

'!/home/etamodel/bin/gxpng -r -x  470 -y 360 -i /home/etamodel/posfig/scripts/figs/$data'ilab'.gmf -o /home/etamodel/posfig/scripts/figs/$data'ilab'.png'
*else
*'!/home/etamodel/bin/gxpng -r -x  470 -y 360 -i /home/etamodel/posfig/scripts/figs/$data'ilab'.gmf -o /home/etamodel/posfig/scripts/figs/$data'ilab'.png'
*endif

i=i+1
j=j+1
*'q pos'
'clear'
endwhile
'quit'


EOF

grads -pc "run /home/etamodel//posfig/scripts/loopfig.gs"

end
exit
