#! /bin/csh -f

set start_time = `date +%s`
source ~/.cshrc

set mi = `date -u +%M`
set hh = `date -u +%H`
set mm = `date -u +%m`
set dd = `date -u +%d`
set yy = `date -u +%Y`
echo The Current Date Is $yy$mm$dd
set date0 = $yy$mm$dd$hh$mi

set mi = `date -u -d -1hours +%M`; set mm = `date -u -d -1hours +%m`; set dd = `date -u -d -1hours +%d`
set hh = `date -u -d -1hours +%H`; set yy = `date -u -d -1hours +%Y`; set date1 = $yy$mm$dd$hh$mi

set mi = `date -u -d -2hours +%M`; set mm = `date -u -d -2hours +%m`; set dd = `date -u -d -2hours +%d`
set hh = `date -u -d -2hours +%H`; set yy = `date -u -d -2hours +%Y`; set date2 = $yy$mm$dd$hh$mi

set mi = `date -u -d -3hours +%M`; set mm = `date -u -d -3hours +%m`; set dd = `date -u -d -3hours +%d`
set hh = `date -u -d -3hours +%H`; set yy = `date -u -d -3hours +%Y`; set date3 = $yy$mm$dd$hh$mi

set mi = `date -u -d -6hours +%M`; set mm = `date -u -d -6hours +%m`; set dd = `date -u -d -6hours +%d`
set hh = `date -u -d -6hours +%H`; set yy = `date -u -d -6hours +%Y`; set date6 = $yy$mm$dd$hh$mi

set mi = `date -u -d -12hours +%M`; set mm = `date -u -d -12hours +%m`; set dd = `date -u -d -12hours +%d`
set hh = `date -u -d -12hours +%H`; set yy = `date -u -d -12hours +%Y`; set date12 = $yy$mm$dd$hh$mi

set mi = `date -u -d -24hours +%M`; set mm = `date -u -d -24hours +%m`; set dd = `date -u -d -24hours +%d`
set hh = `date -u -d -24hours +%H`; set yy = `date -u -d -24hours +%Y`; set date24 = $yy$mm$dd$hh$mi

set mm = `date -u -d -48hours +%m`; set dd = `date -u -d -48hours +%d`
set yy = `date -u -d -48hours +%Y`; set datedelete = $yy$mm$dd

cd /aca1/nb965428/wrf2gem/mesonet/lidar
foreach station (PROF_ALBA PROF_BELL PROF_BRON PROF_BUFF PROF_CHAZ PROF_JORD PROF_REDH PROF_TUPP PROF_CLYM PROF_OWEG PROF_STAT PROF_WANT PROF_EHAM PROF_QUEE PROF_SUFF PROF_STON PROF_WEBS)
echo "starting $station"
echo " "
cd $station
rm script.csh 
echo "#\!/bin/csh -f"                                                     >! script.csh
echo "source /aca1/nb965428/.cshrc-acad"                                  >> script.csh
echo "cp ../*.ncl ."                                                      >> script.csh
echo "rm radiometer.csv lidar.csv station.txt"                            >> script.csh
echo "cp ../${station}.txt station.txt"                                   >> script.csh
echo "ln -s ${station}radiometer.csv radiometer.csv"                      >> script.csh
echo "ln -s ${station}lidar.csv lidar.csv"                                >> script.csh
echo "/aca1/bin/ncl combined.ncl >> output.txt"                           >> script.csh
echo "cp skewt.png ${date0}${station}skewt.png"                           >> script.csh
echo "cp ${date1}${station}skewt.png  ../${station}skewt1h.png"           >> script.csh
echo "cp ${date2}${station}skewt.png  ../${station}skewt2h.png"           >> script.csh
echo "cp ${date3}${station}skewt.png  ../${station}skewt3h.png"           >> script.csh
echo "cp ${date6}${station}skewt.png  ../${station}skewt6h.png"           >> script.csh
echo "cp ${date12}${station}skewt.png  ../${station}skewt12h.png"         >> script.csh
echo "cp ${date24}${station}skewt.png  ../${station}skewt24h.png"         >> script.csh
echo "mv skewt.png ../${station}skewt.png"                                >> script.csh
echo "mv zonal.png ../${station}timeheight.png"                           >> script.csh
echo "mv xy.png ../${station}xy.png"                                      >> script.csh
echo "rm ${datedelete}*${station}skewt.png"                               >> script.csh
echo ""                                                                   >> script.csh

chmod 777 script.csh
script.csh &
sleep 20
cd /aca1/nb965428/wrf2gem/mesonet/lidar
end

set end_time   = `date  +%s`
@ length_time  = $end_time - $start_time
echo "It took this long to plot data: $length_time seconds"
