#! /bin/csh -f

set start_time = `date +%s`
source ~/.cshrc
cp *ncl *csv save
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`
set mmnow = `date -u +%m`
set ddnow = `date -u +%d`
set yynow = `date -u +%Y`
echo The Current Date Is $yy$mm$dd$dd$mi
set date = $yy$mm$dd

cd /network/rit/lab/mesonet/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 "getting $station radiometer file"
rm -rf ${station}radiometer.csv ${station}lidar.csv 2*csv
rm -rf ${station}/${station}radiometer.csv ${station}/${station}lidar.csv
scp "nbassill@operations.nysmesonet.org:/mnt/remote/meso2-storage1/archive/profiler/radiometer_raw/$station/$yy/$mm/$yy-$mm-$dd*lv2.csv" .
ls 2*lv2.csv
cat 2*lv2.csv >! ${station}/${station}radiometer.csv
echo "getting $station LIDAR file"
scp "nbassill@operations.nysmesonet.org:/mnt/remote/meso2-storage1/archive/profiler/lidar_raw/$station/$yy/$mm/$yy$mm$dd*_reconstruction_wind_data.csv" .
mv $yy$mm$dd*_reconstruction_wind_data.csv ${station}/${station}lidar.csv
echo " "
end
cd /network/rit/lab/mesonet/mesonet/lidar

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

# make plots

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


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 ~/.cshrc"                                                    >> script.csh
echo "rm *ncl"                                                            >> script.csh
echo "cp /network/rit/lab/mesonet/mesonet/lidar/*.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 "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 10
cd /network/rit/lab/mesonet/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"

scp *.png nbassill@operations.nysmesonet.org:/home/nbassill/public_html/plots/profiler
scp PROF*skewt.png PROF*skewt12h.png *xy*png *time*png nbassill@operations.nysmesonet.org:/home/nbassill/public_html/archive/$yynow/$mmnow/$ddnow/profiler
scp *csh *ncl statewide/*csh statewide/plot/*ncl nbassill@operations.nysmesonet.org:/home/nbassill/public_html/archive/$yy/$mm/$dd/profiler/scripts


