#

# NOAA water level xy plot
sed 's/,/ /g' env_data/CO-OPS__8452660__wl.csv | awk '{if (NF == 9) print $1"T"$2, $3}' >! test
psxy test -R2016-10-27T23:54/2016-11-13T23:59/-1/2 -JX6i/2i -Ba1WeSn -W4 -K -P >! plot.ps


# hobo thermistor xy plot
sed 's/,/ /g' hobos/10-27-2016-LP-T09.csv | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if (($8=="AM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9; if (($8=="AM") && ($5 >= 12))print $4+2000"-"$2"-"$3"T"$5-12":"$6":"$7, $9; if (($8=="PM") && ($5 >= 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9;  if (($8=="PM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5+12":"$6":"$7, $9}' >! test
psxy test -R2016-10-27T23:54/2016-11-13T23:59/10/14 -JX6i/2i -Ba1WeSn -W4 -K -P >! plot2.ps

# hobo pressure xy plot
sed 's/,/ /g' hobos/10-27-2016-UP-PTBTM.csv | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if (($8=="AM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9; if (($8=="AM") && ($5 >= 12))print $4+2000"-"$2"-"$3"T"$5-12":"$6":"$7, $9; if (($8=="PM") && ($5 >= 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9;  if (($8=="PM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5+12":"$6":"$7, $9}' >! test
psxy test -R2016-10-27T23:54/2016-11-13T23:59/210/230 -JX6i/2i -Ba1/a20WeSn -W4 -K -P >! plot3.ps


echo ">" >! test2
foreach file (hobos/10-27-2016-LP-T*.csv)
	set N = `echo $file | sed 's/T/ /g'| sed 's/\./ /g' | awk '{print $2}' `
	
	if ($N == "SFC") then
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if ((NR > 2) && (NF > 1)) print NR, "1", $9, $9, $9}' >> test2
	endif
	if ($N != "SFC") then 
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{if ((NR > 2) && (NF > 1)) print NR, "'$N'", $9, $9, $9}' >> test2
	endif
end
foreach file (hobos/10-27-2016-LP-PTBTM.csv)
	set N = `echo $file | sed 's/PT/ /g'| sed 's/\./ /g' | awk '{print $2}' `
	
	if ($N == "BTM") then
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if ((NR > 2) && (NF > 1)) print NR, "15", $10, $10, $10}' >> test2
	endif
end
awk '{ if (NR > 1) print $0}' test2 >! test2a
xyz2grd test2a -I1/1 -F -R0/4210/0/16 -N0 -GLP_T.grd

makecpt -Crainbow -T5/16/1 >! temp.cpt
grdgradient LP_T.grd -Gintense.grd -A270 -Nt1
#grdimage LP_T.grd -R0/4210/0/16 -JX6i/-3i -Ctemp.cpt -Ba50/a5f1WeSn  -K -P >! plot_L.ps 

#grdview LP_T.grd -R0/4210/0/16/0/25 -JZ2i -E150/65 -JX6i/-3i -Qs -Ctemp.cpt -Iintense.grd -Ba50/a5f1WeSn  -O -P -Y4i >> plot_L.ps 

psxyz test2a -R1/4200/0/16/5/25 -JZ2i -E150/65 -JX6i/-3i -Ctemp.cpt -So0.1/0.2 -Bf288/a5f1wESn  -K -P >! plot_L.ps 

psscale -D0i/1i/2i/0.2i -Ctemp.cpt -O -K >> plot_L.ps 


# hobo pressure xy plot
sed 's/,/ /g' hobos/10-27-2016-LP-TSFC.csv | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if (($8=="AM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9; if (($8=="AM") && ($5 >= 12))print $4+2000"-"$2"-"$3"T"$5-12":"$6":"$7, $9; if (($8=="PM") && ($5 >= 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9;  if (($8=="PM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5+12":"$6":"$7, $9}' >! testx
psxy testx -R2016-10-27T23:54/2016-11-11T23:59/5/25 -JX6i/1.5i -Ba1/a5E -W4/blue -K -O -Y6i >> plot_L.ps 

# NOAA water level xy plot
sed 's/,/ /g' env_data/CO-OPS__8452660__wl.csv | awk '{if (NF == 9) print $1"T"$2, $3}' >! test
psxy test -R2016-10-27T23:54/2016-11-11T23:59/-1/2 -J -Ba1WSn -W4 -K -O >> plot_L.ps 



# hobo pressure xy plot
sed 's/,/ /g' hobos/10-27-2016-LP-PTBTM.csv | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if (($8=="AM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9; if (($8=="AM") && ($5 >= 12))print $4+2000"-"$2"-"$3"T"$5-12":"$6":"$7, $9; if (($8=="PM") && ($5 >= 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9;  if (($8=="PM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5+12":"$6":"$7, $9}' >! teste
psxy teste -R2016-10-27T23:54/2016-11-11T23:59/280/290 -J -Ba1/a5E -W4/red -K -O -Y1.5i>> plot_L.ps 

# NOAA water level xy plot
sed 's/,/ /g' env_data/CO-OPS__8452660__wl.csv | awk '{if (NF == 9) print $1"T"$2, $3}' >! test
psxy test -R2016-10-27T23:54/2016-11-11T23:59/-1/2 -J -Ba1WSn -W4 -K -O >> plot_L.ps 




# NOAA wind speed xy plot
sed 's/,/ /g' env_data/CO-OPS_8452660_from_20161027_to_20161111_met.csv | sed 's/\// /g'  | awk '{print $3"-"$1"-"$2"T"$4, $5}'>! testD
psxy testD -R2016-10-27T23:54/2016-11-11T23:59/0/40 -J -Ba10E -W4/green -K -O -Y1.5i >> plot_L.ps 

# NOAA air temp xy plot
sed 's/,/ /g' env_data/CO-OPS_8452660_from_20161027_to_20161111_met.csv | sed 's/\// /g'  | awk '{print $3"-"$1"-"$2"T"$4, $8}' | awk '{ if (NF == 2) print $0}' >! testD
psxy testD -R2016-10-27T23:54/2016-11-11T23:59/0/70 -J -Ba10Wn -W4 -K -O >> plot_L.ps 








echo ">" >! test2
foreach file (hobos/10-27-2016-UP-T*.csv)
	set N = `echo $file | sed 's/T/ /g'| sed 's/\./ /g' | awk '{print $2}' `
	
	if ($N == "SFC") then
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if ((NR > 2) && (NF > 1)) print NR, "1", $9, $9, $9}' >> test2
	endif
	if ($N == "BTM") then
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if ((NR > 2) && (NF > 1)) print NR, "12", $9, $9, $9}' >> test2
	endif
	if ($N != "SFC") then 
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{if ((NR > 2) && (NF > 1)) print NR, "'$N'", $9, $9, $9}' >> test2
	endif
end
foreach file (hobos/10-27-2016-UP-PTBTM.csv)
	set N = `echo $file | sed 's/PT/ /g'| sed 's/\./ /g' | awk '{print $2}' `
	
	if ($N == "BTM") then
		sed 's/,/ /g' $file | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if ((NR > 2) && (NF > 1)) print NR, "12", $10, $10, $10}' >> test2
	endif
end

awk '{ if (NR > 1) print $0}' test2 >! test2a
xyz2grd test2a -I1/1 -R0/4210/0/16 -GLP_T.grd

#makecpt -Crainbow -T5/16/1 >! temp.cpt
#grdgradient LP_T.grd -Gintense.grd -A270 -Nt1
#grdimage LP_T.grd -R0/4210/0/16 -JX6i/-3i -Ctemp.cpt -Ba50/a5f1WeSn  -K -P >! plot_U.ps 

#grdview LP_T.grd -R0/4210/0/16/0/25 -JZ2i -E150/65 -JX6i/-3i -Qs -Ctemp.cpt -Iintense.grd -Ba50/a5f1WeSn  -O -P -Y4i >> plot_U.ps 
psxyz test2a -R100/4200/0/16/5/25 -JZ2i -E150/65 -JX6i/-3i -Ctemp.cpt -So0.1/0.2 -Ba500/a5f1WeSn  -P -K >! plot_U.ps 
psscale -D0i/1i/2i/0.2i -Ctemp.cpt -O -K >> plot_U.ps 


# hobo pressure xy plot
sed 's/,/ /g' hobos/10-27-2016-UP-TSFC.csv | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if (($8=="AM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9; if (($8=="AM") && ($5 >= 12))print $4+2000"-"$2"-"$3"T"$5-12":"$6":"$7, $9; if (($8=="PM") && ($5 >= 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9;  if (($8=="PM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5+12":"$6":"$7, $9}' >! testx
psxy testx -R2016-10-27T23:54/2016-11-11T23:59/5/25 -JX6i/1.5i -Ba1/a5E -W4/blue -K -O -Y6i >> plot_U.ps 

# NOAA water level xy plot
sed 's/,/ /g' env_data/CO-OPS__8452660__wl.csv | awk '{if (NF == 9) print $1"T"$2, $3}' >! test
psxy test -R2016-10-27T23:54/2016-11-11T23:59/-1/2 -J -Ba1WSn -W4 -K -O >> plot_U.ps 



# hobo pressure xy plot
sed 's/,/ /g' hobos/10-27-2016-UP-PTBTM.csv | sed 's/\// /g' | sed 's/:/ /g' | awk '{ if (($8=="AM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9; if (($8=="AM") && ($5 >= 12))print $4+2000"-"$2"-"$3"T"$5-12":"$6":"$7, $9; if (($8=="PM") && ($5 >= 12)) print $4+2000"-"$2"-"$3"T"$5":"$6":"$7, $9;  if (($8=="PM") && ($5 < 12)) print $4+2000"-"$2"-"$3"T"$5+12":"$6":"$7, $9}' >! teste
psxy teste -R2016-10-27T23:54/2016-11-11T23:59/210/230 -J -Ba1/a5E -W4/red -K -O -Y1.5i>> plot_U.ps 

# NOAA water level xy plot
sed 's/,/ /g' env_data/CO-OPS__8452660__wl.csv | awk '{if (NF == 9) print $1"T"$2, $3}' >! test
psxy test -R2016-10-27T23:54/2016-11-11T23:59/-1/2 -J -Ba1WSn -W4 -K -O >> plot_U.ps 




# NOAA wind speed xy plot
sed 's/,/ /g' env_data/CO-OPS_8452660_from_20161027_to_20161111_met.csv | sed 's/\// /g'  | awk '{print $3"-"$1"-"$2"T"$4, $5}'>! testD
psxy testD -R2016-10-27T23:54/2016-11-11T23:59/0/40 -J -Ba10E -W4/green -K -O -Y1.5i >> plot_U.ps 

# NOAA air temp xy plot
sed 's/,/ /g' env_data/CO-OPS_8452660_from_20161027_to_20161111_met.csv | sed 's/\// /g'  | awk '{print $3"-"$1"-"$2"T"$4, $8}' | awk '{ if (NF == 2) print $0}' >! testD
psxy testD -R2016-10-27T23:54/2016-11-11T23:59/0/70 -J -Ba10Wn -W4 -K -O >> plot_U.ps 
