#!/bin/csh -f

if ( $#argv == 0) then
    echo " "
    echo "mk_atm_tb_aquarius.csh yrdoy1 yrdoy2"
    exit
endif


# Generate TB files
set first06=${1}00
set last06=${2}18
set i = $first06
while ( $i <= $last06)
    echo Retrieving /pub/joel/aquarius-met/N${i}_QMET_NCEP_6h.bz2
    ncftpget samoa.gsfc.nasa.gov . "/pub/joel/aquarius-met/N${i}_QMET_NCEP_6h.bz2"
    echo Unzipping N${i}_QMET_NCEP_6h.bz2
    bunzip2 N${i}_QMET_NCEP_6h.bz2

    set mndy=`doy2mndy.csh $i`
    set hr = `echo $i | cut -c 8-9`

    set fmtdte = `doy2mndy.csh $i`
    set sec = `date -u -d "$fmtdte $hr" +%s`
    @ sec2 = $sec + 21600

    set i=`date -u -d "1970-01-01 $sec2 seconds" +%Y%j%H`
    echo i: $i
end

set mndy=`doy2mndy.csh $1`
set yr=`echo $mndy | cut -d "-" -f1`
set mn=`echo $mndy | cut -d "-" -f2`
set dy1=`echo $mndy | cut -d "-" -f3`

set mndy=`doy2mndy.csh $2`
set dy2=`echo $mndy | cut -d "-" -f3`

echo atm_tb_aquarius ./ $yr $mn $dy1 $dy2
atm_tb_aquarius ./ $yr $mn $dy1 $dy2


# Rename
foreach i (TB_??????????.DAT)

    set j=`echo $i | cut -c 4-11`
    set hr=`echo $i | cut -c 12-13`
    @ sec = $hr * 3600
    set yrdoyhr=`date -u -d "$j $sec secs" +%Y%j%H`

    mv $i N${yrdoyhr}_QATM_NCEP_6h.h5

end

exit




