#! /bin/csh -f

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

cd /aca1/nb965428/wrf2gem/mesonet/lidar/statewide
mv *dat plot
cd plot

set mi = `date -u +%M`
set nowmi = `date -u +%M`
set mm = `date -u +%m`
set nowmm = `date -u +%m`
set dd = `date -u +%d`
set nowdd = `date -u +%d`
set hh = `date -u +%H`
set nowhh = `date -u +%H`
set yy = `date -u +%y`
set nowyy = `date -u +%y`

echo The Current Date Is $yy$mm$dd
set date = $yy$mm$dd$hh$mi

#get looping times
set date0 = $yy$mm$dd$hh$mi

set mi = `date -u -d -10minutes +%M`; set mm = `date -u -d -10minutes +%m`; set dd = `date -u -d -10minutes +%d`
set hh = `date -u -d -10minutes +%H`; set yy = `date -u -d -10minutes +%y`; set date1 = $yy$mm$dd$hh$mi

set mi = `date -u -d -20minutes +%M`; set mm = `date -u -d -20minutes +%m`; set dd = `date -u -d -20minutes +%d`
set hh = `date -u -d -20minutes +%H`; set yy = `date -u -d -20minutes +%y`; set date2 = $yy$mm$dd$hh$mi

set mi = `date -u -d -30minutes +%M`; set mm = `date -u -d -30minutes +%m`; set dd = `date -u -d -30minutes +%d`
set hh = `date -u -d -30minutes +%H`; set yy = `date -u -d -30minutes +%y`; set date3 = $yy$mm$dd$hh$mi

set mi = `date -u -d -40minutes +%M`; set mm = `date -u -d -40minutes +%m`; set dd = `date -u -d -40minutes +%d`
set hh = `date -u -d -40minutes +%H`; set yy = `date -u -d -40minutes +%y`; set date4 = $yy$mm$dd$hh$mi

set mi = `date -u -d -50minutes +%M`; set mm = `date -u -d -50minutes +%m`; set dd = `date -u -d -50minutes +%d`
set hh = `date -u -d -50minutes +%H`; set yy = `date -u -d -50minutes +%y`; set date5 = $yy$mm$dd$hh$mi

set mi = `date -u -d -60minutes +%M`; set mm = `date -u -d -60minutes +%m`; set dd = `date -u -d -60minutes +%d`
set hh = `date -u -d -60minutes +%H`; set yy = `date -u -d -60minutes +%y`; set date6 = $yy$mm$dd$hh$mi

set mi = `date -u -d -70minutes +%M`; set mm = `date -u -d -70minutes +%m`; set dd = `date -u -d -70minutes +%d`
set hh = `date -u -d -70minutes +%H`; set yy = `date -u -d -70minutes +%y`; set date7 = $yy$mm$dd$hh$mi

set mi = `date -u -d -80minutes +%M`; set mm = `date -u -d -80minutes +%m`; set dd = `date -u -d -80minutes +%d`
set hh = `date -u -d -80minutes +%H`; set yy = `date -u -d -70minutes +%y`; set date8 = $yy$mm$dd$hh$mi

set mi = `date -u -d -90minutes +%M`; set mm = `date -u -d -90minutes +%m`; set dd = `date -u -d -90minutes +%d`
set hh = `date -u -d -90minutes +%H`; set yy = `date -u -d -90minutes +%y`; set date9 = $yy$mm$dd$hh$mi

set mi = `date -u -d -100minutes +%M`; set mm = `date -u -d -100minutes +%m`; set dd = `date -u -d -100minutes +%d`
set hh = `date -u -d -100minutes +%H`; set yy = `date -u -d -100minutes +%y`; set date10 = $yy$mm$dd$hh$mi

set mi = `date -u -d -110minutes +%M`; set mm = `date -u -d -110minutes +%m`; set dd = `date -u -d -110minutes +%d`
set hh = `date -u -d -110minutes +%H`; set yy = `date -u -d -110minutes +%y`; set date11 = $yy$mm$dd$hh$mi

set mi = `date -u -d -120minutes +%M`; set mm = `date -u -d -120minutes +%m`; set dd = `date -u -d -120minutes +%d`
set hh = `date -u -d -120minutes +%H`; set yy = `date -u -d -120minutes +%y`; set date12 = $yy$mm$dd$hh$mi

set mi = `date -u -d -130minutes +%M`; set mm = `date -u -d -130minutes +%m`; set dd = `date -u -d -130minutes +%d`
set hh = `date -u -d -130minutes +%H`; set yy = `date -u -d -130minutes +%y`; set date13 = $yy$mm$dd$hh$mi

set mi = `date -u -d -140minutes +%M`; set mm = `date -u -d -140minutes +%m`; set dd = `date -u -d -140minutes +%d`
set hh = `date -u -d -140minutes +%H`; set yy = `date -u -d -140minutes +%y`; set date14 = $yy$mm$dd$hh$mi

set mi = `date -u -d -150minutes +%M`; set mm = `date -u -d -150minutes +%m`; set dd = `date -u -d -150minutes +%d`
set hh = `date -u -d -150minutes +%H`; set yy = `date -u -d -150minutes +%y`; set date15 = $yy$mm$dd$hh$mi

set mi = `date -u -d -160minutes +%M`; set mm = `date -u -d -160minutes +%m`; set dd = `date -u -d -160minutes +%d`
set hh = `date -u -d -160minutes +%H`; set yy = `date -u -d -160minutes +%y`; set date16 = $yy$mm$dd$hh$mi

set mi = `date -u -d -170minutes +%M`; set mm = `date -u -d -170minutes +%m`; set dd = `date -u -d -170minutes +%d`
set hh = `date -u -d -170minutes +%H`; set yy = `date -u -d -170minutes +%y`; set date17 = $yy$mm$dd$hh$mi

set mi = `date -u -d -180minutes +%M`; set mm = `date -u -d -180minutes +%m`; set dd = `date -u -d -180minutes +%d`
set hh = `date -u -d -180minutes +%H`; set yy = `date -u -d -180minutes +%y`; set date18 = $yy$mm$dd$hh$mi

cd /aca1/nb965428/wrf2gem/mesonet/lidar/statewide/plot
rm columnvapor.png columnliquid.png cloudbase.png temp.png
ncl statewide.ncl
convert cloudbase.png -gravity North -chop 0x50 temp.png
convert -shave 175x300 +repage temp.png cloudbase.png
convert columnliquid.png -gravity North -chop 0x50 temp.png
convert -shave 175x300 +repage temp.png columnliquid.png
convert columnvapor.png -gravity North -chop 0x50 temp.png
convert -shave 175x300 +repage temp.png columnvapor.png

cp columnvapor.png columnliquid.png cloudbase.png /home/nb965428/public_html/profiler
mv columnvapor.png ${date}CV.png
mv columnliquid.png ${date}CL.png
mv cloudbase.png ${date}CB.png
mv  ${date}CB.png ${date}CL.png ${date}CV.png png

foreach variable (CV CL CB)
ln -s png/${date0}${variable}.png ${date0}0${variable}.png
ln -s png/${date0}${variable}.png ${date0}1${variable}.png
ln -s png/${date0}${variable}.png ${date0}2${variable}.png
ln -s png/${date0}${variable}.png ${date0}3${variable}.png
ln -s png/${date0}${variable}.png ${date0}4${variable}.png
ln -s png/${date1}${variable}.png .
ln -s png/${date2}${variable}.png .
ln -s png/${date3}${variable}.png .
ln -s png/${date4}${variable}.png .
ln -s png/${date5}${variable}.png .
ln -s png/${date6}${variable}.png .
ln -s png/${date7}${variable}.png .
ln -s png/${date8}${variable}.png .
ln -s png/${date9}${variable}.png .
ln -s png/${date10}${variable}.png .
ln -s png/${date11}${variable}.png .
ln -s png/${date12}${variable}.png .
ln -s png/${date13}${variable}.png .
ln -s png/${date14}${variable}.png .
ln -s png/${date15}${variable}.png .
ln -s png/${date16}${variable}.png .
ln -s png/${date17}${variable}.png .
ln -s png/${date18}${variable}.png .

convert -delay 20 -loop 0 *${variable}.png temp.gif
convert temp.gif -coalesce -repage 0x0 -shave 175x300 +repage animated${variable}.gif 
cp animated${variable}.gif /home/nb965428/public_html/profiler
rm *.png *gif
end


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