#!/bin/csh

cd /kc11/ralazear/tsdat

#June

foreach site ( 'KALB' 'KBWI' 'KGSO' 'KCHS' 'KMIA' 'KTPA' 'KDTW' 'KMGM' 'KBNA' 'KSPI' 'KMSP' 'KIAH' 'KOMA' \
'KOKC' 'KBIS' 'KMAF' 'KDEN' 'KTUS' 'KGTF' 'KSLC' )

echo 'Now working on ' ${site} 'for June . . . '

foreach yr ( 00 01 02 03 04 05 06 07 08 09 10 11 )
foreach mo ( 06 )
foreach da ( 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 )


#set tempfile = ${site}_${yr}${mo}${da}
#echo "tempfile is " $tempfile


foreach hr ( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 )

set nmo = ${mo}


if (${hr} < 23 ) then
  set nda = $da
else
  set lessnda = `expr ${da} - 1`
  if (${lessnda} < 1) then
      set nda = 31
      set nmo = 05
  endif
  if (${lessnda} > 9) then
      set nda = ${lessnda}
  endif
  if (${lessnda} > 0 && ${lessnda} < 10) then
      set nda = 0$lessnda
  endif
endif

if (${hr} < 10) then
   set rhr = 0$hr
else 
   set rhr = $hr
endif


set tempstr = `echo $site $nda$rhr`
#echo "tempstr is " $tempstr
grep "${tempstr}" metar_iastate/fulldat_${site}_${yr}${mo}${da}.dat >> temp.dat


set fsize = `du -b temp.dat | awk '{print $1}'`

if (${fsize} < 6) then
#     echo "file size is " ${fsize}
     echo ${site} ' for ' ${yr}${nmo}${nda} "at hour " $hr >> missing_data_${site}.txt
endif

rm -rf temp.dat
set nmo = ${mo}

end #end hour loop
end #end day loop
end #end month loop
end #end year loop
end #end site loop


#July

foreach site ( 'KALB' 'KBWI' 'KGSO' 'KCHS' 'KMIA' 'KTPA' 'KDTW' 'KMGM' 'KBNA' 'KSPI' 'KMSP' 'KIAH' 'KOMA' \
'KOKC' 'KBIS' 'KMAF' 'KDEN' 'KTUS' 'KGTF' 'KSLC' )

echo 'Now working on ' ${site} 'for July . . . '

foreach yr ( 00 01 02 03 04 05 06 07 08 09 10 11 )
foreach mo ( 07 )
foreach da ( 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 )


#set tempfile = ${site}_${yr}${mo}${da}
#echo "tempfile is " $tempfile


foreach hr ( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 )

set nmo = ${mo}


if (${hr} < 23 ) then
  set nda = $da
else
  set lessnda = `expr ${da} - 1`
  if (${lessnda} < 1) then
      set nda = 30
      set nmo = 06
  endif
  if (${lessnda} > 9) then
      set nda = ${lessnda}
  endif
  if (${lessnda} > 0 && ${lessnda} < 10) then
      set nda = 0$lessnda
  endif
endif

if (${hr} < 10) then
   set rhr = 0$hr
else 
   set rhr = $hr
endif


set tempstr = `echo $site $nda$rhr`
#echo "tempstr is " $tempstr
grep "${tempstr}" metar_iastate/fulldat_${site}_${yr}${mo}${da}.dat >> temp.dat


set fsize = `du -b temp.dat | awk '{print $1}'`

if (${fsize} < 6) then
#     echo "file size is " ${fsize}
     echo ${site} ' for ' ${yr}${nmo}${nda} "at hour " $hr >> missing_data_${site}.txt
endif

rm -rf temp.dat
set nmo = ${mo}

end #end hour loop
end #end day loop
end #end month loop
end #end year loop
end #end site loop




#August

foreach site ( 'KALB' 'KBWI' 'KGSO' 'KCHS' 'KMIA' 'KTPA' 'KDTW' 'KMGM' 'KBNA' 'KSPI' 'KMSP' 'KIAH' 'KOMA' \
'KOKC' 'KBIS' 'KMAF' 'KDEN' 'KTUS' 'KGTF' 'KSLC' )

echo 'Now working on ' ${site} 'for August . . . '

foreach yr ( 00 01 02 03 04 05 06 07 08 09 10 11 )
foreach mo ( 08 )
foreach da ( 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 )


#set tempfile = ${site}_${yr}${mo}${da}
#echo "tempfile is " $tempfile


foreach hr ( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 )

set nmo = ${mo}


if (${hr} < 23 ) then
  set nda = $da
else
  set lessnda = `expr ${da} - 1`
  if (${lessnda} < 1) then
      set nda = 31
      set nmo = 07
  endif
  if (${lessnda} > 9) then
      set nda = ${lessnda}
  endif
  if (${lessnda} > 0 && ${lessnda} < 10) then
      set nda = 0$lessnda
  endif
endif

if (${hr} < 10) then
   set rhr = 0$hr
else 
   set rhr = $hr
endif


set tempstr = `echo $site $nda$rhr`
#echo "tempstr is " $tempstr
grep "${tempstr}" metar_iastate/fulldat_${site}_${yr}${mo}${da}.dat >> temp.dat


set fsize = `du -b temp.dat | awk '{print $1}'`

if (${fsize} < 6) then
#     echo "file size is " ${fsize}
     echo ${site} ' for ' ${yr}${nmo}${nda} "at hour " $hr >> missing_data_${site}.txt
endif

rm -rf temp.dat
set nmo = ${mo}

end #end hour loop
end #end day loop
end #end month loop
end #end year loop
end #end site loop



echo "Finished! ..."

exit 0



