#!/bin/tcsh -f
rm -rf synopsis


##setenv HD /Net/water/amishra/RSM_ROMS/FL-DWN/RCP8.5/CLD2/O/mon
setenv HD /Net/water/amishra/RSM_ROMS/FL-DWN/RCP8.5/CLD2/O/mon

@ yr = 40

@ loop = $yr
while ($loop <= 70)
set yr = $loop

setenv Y01 `echo $yr | awk '{printf("%03d", $1)}'`
echo $Y01
@ yr1 = $loop + 2000
echo 'Y01=' $yr
echo 'YEAR1=' $yr1
##mkdir ${HD}/traw
cd ${HD}/traw
rm -rf *ncl synopsis
echo 'going to prepare Ucur file  GrADS readable using' $yr1  >> synopsis
#############################################
###### CREATE NCL file
#############################################
cat > vert_${yr1}.ncl << EOF
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin

     cdf_file_01 = addfile("${HD}/ocean_avg.${yr1}01.nc","r")
     sst_01 = cdf_file_01->w   
     filo_01 = "vert-${yr1}01-s.dat"
     fbinrecwrite (filo_01, -1, sst_01 )

     cdf_file_02 = addfile("${HD}/ocean_avg.${yr1}02.nc","r")
     sst_02 = cdf_file_02->w   
     filo_02 = "vert-${yr1}02-s.dat"
     fbinrecwrite (filo_02, -1, sst_02 )

     cdf_file_03 = addfile("${HD}/ocean_avg.${yr1}03.nc","r")
     sst_03 = cdf_file_03->w   
     filo_03 = "vert-${yr1}03-s.dat"
     fbinrecwrite (filo_03, -1, sst_03 )

     cdf_file_04 = addfile("${HD}/ocean_avg.${yr1}04.nc","r")
     sst_04 = cdf_file_04->w   
     filo_04 = "vert-${yr1}04-s.dat"
     fbinrecwrite (filo_04, -1, sst_04 )

     cdf_file_05 = addfile("${HD}/ocean_avg.${yr1}05.nc","r")
     sst_05 = cdf_file_05->w   
     filo_05 = "vert-${yr1}05-s.dat"
     fbinrecwrite (filo_05, -1, sst_05 )

     cdf_file_06 = addfile("${HD}/ocean_avg.${yr1}06.nc","r")
     sst_06 = cdf_file_06->w   
     filo_06 = "vert-${yr1}06-s.dat"
     fbinrecwrite (filo_06, -1, sst_06 )

     cdf_file_07 = addfile("${HD}/ocean_avg.${yr1}07.nc","r")
     sst_07 = cdf_file_07->w   
     filo_07 = "vert-${yr1}07-s.dat"
     fbinrecwrite (filo_07, -1, sst_07 )

     cdf_file_08 = addfile("${HD}/ocean_avg.${yr1}08.nc","r")
     sst_08 = cdf_file_08->w   
     filo_08 = "vert-${yr1}08-s.dat"
     fbinrecwrite (filo_08, -1, sst_08 )

     cdf_file_09 = addfile("${HD}/ocean_avg.${yr1}09.nc","r")
     sst_09 = cdf_file_09->w   
     filo_09 = "vert-${yr1}09-s.dat"
     fbinrecwrite (filo_09, -1, sst_09 )

     cdf_file_10 = addfile("${HD}/ocean_avg.${yr1}10.nc","r")
     sst_10 = cdf_file_10->w   
     filo_10 = "vert-${yr1}10-s.dat"
     fbinrecwrite (filo_10, -1, sst_10 )

     cdf_file_11 = addfile("${HD}/ocean_avg.${yr1}11.nc","r")
     sst_11 = cdf_file_11->w   
     filo_11 = "vert-${yr1}11-s.dat"
     fbinrecwrite (filo_11, -1, sst_11 )

     cdf_file_12 = addfile("${HD}/ocean_avg.${yr1}12.nc","r")
     sst_12 = cdf_file_12->w   
     filo_12 = "vert-${yr1}12-s.dat"
     fbinrecwrite (filo_12, -1, sst_12 )
end
EOF
#############################################
ncl vert_${yr1}.ncl
wait
#############################################
rm vert_${yr1}.ncl
 @ loop = $loop + 1
end
exit
