#!/bin/bash
##http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=46.8,-119.7&z=2
##http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=46.8,-119.7&z=111


domains=( "FRASER" "FT_EBEY" "PNW" "PNW" "TIGER" )
regions=( "FRASER-WINDOW" "FRASER-WINDOW" "FRASER-WINDOW" "FRASER-WINDOW" "FRASER-WINDOW" "FRASER-WINDOW" "FRASER-WINDOW" "FT_EBEY-WINDOW" "FT_EBEY-WINDOW" "FT_EBEY-WINDOW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "PNW-WINDOW" "TIGER-WINDOW" )
sites=( "Bridal" "Elk" "MtStBenedict" "Ranch" "RUCcompare" "SumasCa" "Woodside" "Ebey" "Ft_Flagler" "Smith_Is" "Arlington" "Baldy" "Chelan" "DeRoche" "Dog" "Farmer" "Grouse" "GrouseLZ" "HarveyField" "Little_Nick" "Mansfield" "Mazama" "Penthouse" "Rampart" "SaddleO" "SaddleT" "Sauk" "Anderson" "AndersonLZ" "BJ" "BJHG" "BJLZN" "BJLZS" "Black" "BlackLZ" "BlackNo" "Blanchard" "BlanchardLZ" "Iron" "KBLI" "KBVS" "Lippy1" "N_Nooksack_Valley" "Padilla" "Red" "RUC_bli_compare" "Stewart" "StewartLZ" "StickyL" "Sumas" "SumasLZ" "Tiger" )
wlons=( -121.748 -121.76 -122.2054 -121.928 -121.99 -122.126 -121.89 -122.76 -122.69 -122.843 -122.15 -120.35 -120.03 -122.112 -122.173 -119.82 -123.0769 -123.103 -122.101 -122.145 -119.65 -120.4 -121.713 -121.41 -119.559 -119.7 -121.6 -122.2631 -122.2648 -122.11 -122.097 -122.145 -122.144 -121.933 -122.07 -122.042 -122.4 -122.4 -121.94 -122.5392 -122.4208 -122.05 -122.149 -122.4681 -122.118 -122.38 -122.27 -122.39 -122.02 -122.229 -122.29 -121.94 )
wlats=( 49.171 49.12 49.29802 49.2344 49.14 49.121 49.247 48.22 48.1 48.318 48.165 46.86 47.81 49.204 46.489 47.61 49.38602 49.3592 47.906 49.188 47.82 48.59 48.333 47.42 46.806 46.8 48.52 48.6471 48.67215 48.86 48.8595 48.86 48.8535 48.982 48.9657 48.99 48.615 48.57 48.48 48.79944 48.47083 48.9569 48.8895 48.46389 48.932 48.74 48.77 48.77 48.97 48.9211 48.92 47.48 )
grids=( "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" "w2" )
dgrids=( "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" "d2" )

rm sounding.log

length=${#sites[@]}

now=$(date)

i=0;

while [[ "$i" -lt "$length"  ]]
 do
 

site=${sites[$i]}
domain=${regions[$i]}
lat=${wlats[$i]}
lon=${wlons[$i]}
grid=${grids[$i]}
outfile=$site"_soundings.html"
let sid=$i+1 
#  echo  "$i -- ${grids[$i]} -- ${sites[$i]} in region ${regions[$i]}"
if [[ $grid == "w2" ]] 
then
  res="1.3"
else
  res="4.0"
fi
echo "$index  sounding$sid  $site $lat $lon $grid  $res in file $outfile" >>sounding.log
rm $outfile
echo "<HTML><HEAD> <link rel=stylesheet type=\"text/css\" href=\"weather.css\" ><link rel=\"shortcut icon\" href=\"http://wxtofly.net/skewt.ico\"><TITLE>" >$outfile
echo "Rasp Soundings</TITLE></HEAD><BODY class='mainbody'>Soundings for " >>$outfile
echo " " >>$outfile
echo " <!-- $outfile created $now -->" >>$outfile 
echo "<h2>$site at $lon&deg;W $lat&deg;N from the $domain region at $res km resolution<br></h2> " >>$outfile
echo "<a href=http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=$lat,$lon&t=p&mid=1291585234&z=111> Google Map of $site </a>" >>$outfile
echo "<TABLE class=\"meso\" ><TR class=\"\"  ALIGN=\"\" VALIGN=\"\" >" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1100lst.$grid.png\" alt=\" $site  at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1200lst.$grid.png\" alt=\" $site at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "</tr><tr class=\"\">" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1300lst.$grid.png\" alt=\" $site at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1400lst.$grid.png\" alt=\" $site at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "</tr><tr class=\"\">" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1500lst.$grid.png\" alt=\" $site at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1600lst.$grid.png\" alt=\" $site at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "</TR><tr class=\"\">" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1700lst.$grid.png\" alt=\" $site at$lon $lat\" width=100%  ></TD>" >>$outfile
echo "<TD class=\"\" ><IMG SRC=\"http://wxtofly.net/RASP/$domain/FCST/sounding$sid.curr.1800lst.$grid.png\" alt=\" $site at $lon $lat\" width=100%  ></TD>" >>$outfile

echo "</TR></TABLE>" >>$outfile
echo "<a href=http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=$lat,$lon&t=p&mid=1291585234&z=111> Google Map of Site </a>" >>$outfile
echo "</BODY></HTML>" >>$outfile

 (( i += 1 )) ;
 
done

#replace "\-WINDOW\/" "/" -- *soundings.html
replace "\-WINDOW" "" -- *soundings.html
bfiles="{"
efiles="}"
files=$bfiles$(ls  ./*soundings.html   | sed  -e 's#^.*\/##' |tr -s "'\n" "," )$efiles
/home/tj/bin/upload "$files"


exit
