#!/bin/csh 

##### This script is to be used ONLY if there is an issue with the production of the NPJ phase diagram products. (i.e., the
##### U-wind files do not all download correctly). Do not use this script if there is an issue with the files needed to produce
##### the synoptic maps. Must re-run modified version of the main script (jet_phasespace_RT_WPC_patch.csh) first before running this script

##### (1) NEED TO CHANGE THE DIRECTORIES ######
##### (2) CHANGE THE DATE AT THE BOTTOM FOR VERIFICATION ########

cd /lb13/aw732728/tigge/jetclimo/wpc_npj_files

############################### Deterministic plots #############################

##### Convert deterministic NPJ phase diagram to GIF ######
convert -density 400 /winterslab_rit/realtime/images/phase_diagrams/deterministic.pdf deterministic.gif
convert deterministic.gif -crop 2800x2300+150+100 +repage deterministic.gif

#### Stitch deterministic NPJ phase diagram to existing synoptic maps ####
set filenum = {'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20'}
set daynum = {'0','1','2','3','4','5','6','7','8','9'}

foreach a (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)

convert deterministic.gif /lb13/aw732728/wpc/realtime/images/250hPaJet_deterministic_$filenum[$a].gif +append 250hPaJet_deterministic_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_deterministic_$filenum[$a].gif
mv 250hPaJet_deterministic_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

convert deterministic.gif /lb13/aw732728/wpc/realtime/images/500hPa_deterministic_$filenum[$a].gif +append 500hPa_deterministic_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/500hPa_deterministic_$filenum[$a].gif
mv 500hPa_deterministic_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

convert deterministic.gif /lb13/aw732728/wpc/realtime/images/precip_deterministic_$filenum[$a].gif +append precip_deterministic_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/precip_deterministic_$filenum[$a].gif
mv precip_deterministic_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

convert deterministic.gif /lb13/aw732728/wpc/realtime/images/sfcT_deterministic_$filenum[$a].gif +append sfcT_deterministic_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/sfcT_deterministic_$filenum[$a].gif
mv sfcT_deterministic_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

end

rm -f deterministic.gif

############################### Probability and Scatter plots ######################

##### Stitch probabilistic and ensemble scatterplot NPJ phase diagrams to existing NPJ phase diagram products #####
set filenum = {'1','2','3','4','5','6','7','8','9','10'}
set daynum = {'0','1','2','3','4','5','6','7','8','9'}
set prcpfil = {'D0','024','048','072','096','120','144','168','192','216','240'}

convert -density 400 /winterslab_rit/realtime/images/phase_diagrams/probdiagram.pdf probdiagram.gif
convert probdiagram.gif -crop 2800x2300+150+100 +repage probdiagram.gif

foreach a (1 2 3 4 5 6 7 8 9 10)

convert -density 400 /winterslab_rit/realtime/images/phase_diagrams/D$daynum[$a]ens.pdf D$daynum[$a]ens.gif
convert D$daynum[$a]ens.gif -crop 2800x2300+150+100 +repage D$daynum[$a]ens.gif

convert probdiagram.gif /lb13/aw732728/wpc/realtime/images/250hPaJet_prob_$filenum[$a].gif +append 250hPaJet_prob_$filenum[$a].gif
convert D$daynum[$a]ens.gif /lb13/aw732728/wpc/realtime/images/250hPaJet_scat_$filenum[$a].gif +append 250hPaJet_scat_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_prob_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_scat_$filenum[$a].gif
mv 250hPaJet_prob_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images
mv 250hPaJet_scat_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

convert probdiagram.gif /lb13/aw732728/wpc/realtime/images/500hPa_prob_$filenum[$a].gif +append 500hPa_prob_$filenum[$a].gif
convert D$daynum[$a]ens.gif /lb13/aw732728/wpc/realtime/images/500hPa_scat_$filenum[$a].gif +append 500hPa_scat_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/500hPa_prob_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/500hPa_scat_$filenum[$a].gif
mv 500hPa_prob_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images
mv 500hPa_scat_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

convert probdiagram.gif /lb13/aw732728/wpc/realtime/images/precip_prob_$filenum[$a].gif +append precip_prob_$filenum[$a].gif
convert D$daynum[$a]ens.gif /lb13/aw732728/wpc/realtime/images/precip_scat_$filenum[$a].gif +append precip_scat_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/precip_prob_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/precip_scat_$filenum[$a].gif
mv precip_prob_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images
mv precip_scat_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

convert probdiagram.gif /lb13/aw732728/wpc/realtime/images/sfcT_prob_$filenum[$a].gif +append sfcT_prob_$filenum[$a].gif
convert D$daynum[$a]ens.gif /lb13/aw732728/wpc/realtime/images/sfcT_scat_$filenum[$a].gif +append sfcT_scat_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/sfcT_prob_$filenum[$a].gif
rm -f /lb13/aw732728/wpc/realtime/images/sfcT_scat_$filenum[$a].gif
mv sfcT_prob_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images
mv sfcT_scat_$filenum[$a].gif /lb13/aw732728/wpc/realtime/images

rm -f D$daynum[$a]ens.gif

end

rm -f probdiagram.gif

#################### Dprog/Dt plots #######################################

###### Stitch D0 NPJ phase diagram plots to corresponding synoptic maps for the Dprog/Dt products
rm -f /lb13/aw732728/wpc/realtime/images/dprogdt_scatjet_10.gif
cp /lb13/aw732728/wpc/realtime/images/250hPaJet_scat_1.gif dprogdt_scatjet_10.gif
mv dprogdt_scatjet_10.gif /lb13/aw732728/wpc/realtime/images

rm -f /lb13/aw732728/wpc/realtime/images/dprogdt_scatvort_10.gif
cp /lb13/aw732728/wpc/realtime/images/500hPa_scat_1.gif dprogdt_scatvort_10.gif
mv dprogdt_scatvort_10.gif /lb13/aw732728/wpc/realtime/images

rm -f /lb13/aw732728/wpc/realtime/images/dprogdt_scatprecip_10.gif
cp /lb13/aw732728/wpc/realtime/images/precip_scat_1.gif dprogdt_scatprecip_10.gif
mv dprogdt_scatprecip_10.gif /lb13/aw732728/wpc/realtime/images

rm -f /lb13/aw732728/wpc/realtime/images/dprogdt_scattemp_10.gif
cp /lb13/aw732728/wpc/realtime/images/sfcT_scat_1.gif dprogdt_scattemp_10.gif
mv dprogdt_scattemp_10.gif /lb13/aw732728/wpc/realtime/images

rm -f /lb13/aw732728/wpc/realtime/images/dprogdt_prob_10.gif
cp /lb13/aw732728/wpc/realtime/images/250hPaJet_prob_1.gif dprogdt_prob_10.gif
mv dprogdt_prob_10.gif /lb13/aw732728/wpc/realtime/images

rm -f /lb13/aw732728/wpc/realtime/images/dprogdt_deterministic_10.gif
cp /lb13/aw732728/wpc/realtime/images/250hPaJet_deterministic_11.gif dprogdt_deterministic_10.gif	
mv dprogdt_deterministic_10.gif /lb13/aw732728/wpc/realtime/images

#################### Verification images ###################################

###### Stitch together the verified NPJ phase diagram products with existing synoptic maps

convert -density 400 /winterslab_rit/realtime/images/phase_diagrams/verif_deterministic.pdf verif_deterministic.gif
convert verif_deterministic.gif -crop 2800x2300+150+100 +repage verif_deterministic.gif

convert -density 400 /winterslab_rit/realtime/images/phase_diagrams/verif_probdiagram.pdf verif_probdiagram.gif
convert verif_probdiagram.gif -crop 2800x2300+150+100 +repage verif_probdiagram.gif

set daynummap = {'D9','D8','D7','D6','D5','D4','D3','D2','D1','000'}
set filenum = {'1','2','3','4','5','6','7','8','9','10'}

foreach d (1 2 3 4 5 6 7 8 9 10)
	
	rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_verif_deterministic_$filenum[$d].gif
	convert verif_deterministic.gif /winterslab_rit/realtime/images/jet/250hPaJet_gfs_$daynummap[$d].gif +append 250hPaJet_verif_deterministic_$filenum[$d].gif
	
	mv 250hPaJet_verif_deterministic_$filenum[$d].gif /lb13/aw732728/wpc/realtime/images
	
	rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_verif_prob_$filenum[$d].gif
	convert verif_probdiagram.gif /winterslab_rit/realtime/images/jet/250hPaJet_gfs_$daynummap[$d].gif +append 250hPaJet_verif_prob_$filenum[$d].gif
	
	mv 250hPaJet_verif_prob_$filenum[$d].gif /lb13/aw732728/wpc/realtime/images
	
end

rm -f verif_deterministic.gif
rm -f verif_probdiagram.gif

set daynumdiag = {'D1','D2','D3','D4','D5','D6','D7','D8','D9'}
set daynummap = {'D8','D7','D6','D5','D4','D3','D2','D1','000'}
set filenum = {'2','3','4','5','6','7','8','9','10'}

foreach d (1 2 3 4 5 6 7 8 9)
	
	rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_verif_scat_$filenum[$d].gif
	convert -density 400 /winterslab_rit/realtime/images/phase_diagrams/verif_$daynumdiag[$d]ens.pdf verif_$daynumdiag[$d]ens.gif
	convert verif_$daynumdiag[$d]ens.gif -crop 2800x2300+150+100 +repage verif_$daynumdiag[$d]ens.gif
	
	convert verif_$daynumdiag[$d]ens.gif /winterslab_rit/realtime/images/jet/250hPaJet_gfs_$daynummap[$d].gif +append 250hPaJet_verif_scat_$filenum[$d].gif
	
	mv 250hPaJet_verif_scat_$filenum[$d].gif /lb13/aw732728/wpc/realtime/images
	
	rm -f verif_$daynumdiag[$d]ens.gif
	
end

rm -f /lb13/aw732728/wpc/realtime/images/250hPaJet_verif_scat_1.gif

########### MUST CHANGE THE DATE BELOW IN "D0ens_MMDD.pdf" to correspond to 9 days ago ###################

convert -density 400 /winterslab_rit/realtime/images/old_phase_diagrams/D0ens_0513.pdf verif_D0ens.gif

#########################################################################################################

convert verif_D0ens.gif -crop 2800x2300+150+100 +repage verif_D0ens.gif

convert verif_D0ens.gif /winterslab_rit/realtime/images/jet/250hPaJet_gfs_D9.gif +append 250hPaJet_verif_scat_1.gif

mv 250hPaJet_verif_scat_1.gif /lb13/aw732728/wpc/realtime/images

rm -f verif_D0ens.gif


