#!/bin/csh
#
setenv Q /home/atmos/q/research
#
cd $Q/ppt/obs/katz
#
if ( $1 == "" ) then
 echo '     Forgot input commands'
 exit
endif
set yr = $1
set mn = $2
set limit = $3
#
echo '     Removing files'
if (-e $yr${mn}katz.gem) rm $yr${mn}katz.gem
if (-e test.01) rm test.*
#
echo '     Reading data'
compile read_dlyprcp
set dy = 01
while ( $dy <= $limit )
 if (-e $Q/nicppt/katz/tmp/usa-dlyprcp-19$yr$mn$dy) then

  read_dlyprcp $Q/nicppt/katz/tmp/usa-dlyprcp-19$yr$mn$dy test.$dy

 endif

 @ dy = $dy + 1
 if ( $dy < 10 ) set dy = "0"$dy

end
#
echo '     Creating GEMPAK file'
sfcfil<<EOF
sfoutf=$yr${mn}katz.gem
sfprmf=p24i
stnfil=katz.tblfl
shipfl=no
timstn=62/0
sffsrc=
run
 
EOF
#
set dy = 01
while ( $dy <= $limit )
 if (-e test.$dy) then
  sfedit<<EOF
  sfefil=test.$dy
  sffile=$yr${mn}katz.gem
  run

EOF
 endif
 @ dy = $dy + 1
 if ( $dy < 10 ) set dy = "0"$dy
end 
