#!/bin/csh
echo "##############################################################"
echo "##### "$0
echo "##### "$1
echo "##### "$2
echo "#####  Usage is as follows:"  
echo "#####   csh 20100125www99UUVVTest.csh u3d_2008121100.nc v3d_2008121100.nc "
echo "#####                                                         "
echo "##############################################################"

set UUFileName77 = $1
set VVFileName77 = $2

set Year77     = `echo $UUFileName77 | cut -c5-8`

echo "##############################################################"
echo "##"
echo "## Year is: $Year77"
echo "##"
echo "##############################################################"

set Month77     = `echo $UUFileName77 | cut -c9-10`

echo "##############################################################"
echo "##"
echo "## Month is: $Month77"
echo "##"
echo "##############################################################"

set Day77     = `echo $UUFileName77 | cut -c11-12`

echo "##############################################################"
echo "##"
echo "## Day77 is: $Day77"
echo "##"
echo "##############################################################"

set Hour77     = `echo $UUFileName77 | cut -c13-14`

echo "##############################################################"
echo "##"
echo "## Hour77 is: $Hour77"
echo "##"
echo "##############################################################"

set File_Name_Arg1 = 'UUFileName99="'"$UUFileName77"'"'
set File_Name_Arg2 = 'VVFileName99="'"$VVFileName77"'"'
set File_Name_Arg3 = Year99="$Year77"
set File_Name_Arg4 = Month99="$Month77"
set File_Name_Arg5 = Day99="$Day77"
set File_Name_Arg6 = Hour99="$Hour77"

/usr/local/bin/ncl \
$File_Name_Arg1 \
$File_Name_Arg2 \
$File_Name_Arg3 \
$File_Name_Arg4 \
$File_Name_Arg5 \
$File_Name_Arg6 \
 << EEOOFF
;*************************************************
; U-V Vectory Plot procedure (png) file generation  
;************************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/wind_rose.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/ccm_func.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/popRemap.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/diagnostics_cam.ncl"

begin

print(UUFileName99)

print(VVFileName99)

print(Year99)

print(Month99)

print(Day99)

print(Hour99)

  MonthAA = (/" ","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"/)

  NumberArray = (/"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32"/)

  HourAA = (/"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","00"/)

  DepthArray = (/"0000.0","0002.5","0005.0","0007.5","0010.0","0015.0","0020.0","0025.0","0030.0","0035.0","0040.0","0045.0","0050.0","0060.0","0070.0","0080.0","0090.0","0100.0","0125.0","0150.0","0200.0","0250.0","0300.0","0400.0","0500.0","0600.0","0700.0","0800.0","0900.0","1000.0"/)


;************************************************
; read in "UU" netCDF file
;************************************************
  nc_uu_file_in ="/home/mccormik/GulfBreeze/Data/OceanCurrentFiles/2008121100_2008121323/"+UUFileName99
  uf = addfile(nc_uu_file_in,"r")

;************************************************
; read in "VV" netCDF file
;************************************************
  nc_vv_file_in ="/home/mccormik/GulfBreeze/Data/OceanCurrentFiles/2008121100_2008121323/"+VVFileName99
  vf = addfile(nc_vv_file_in,"r")


;  do idepth = 0,29
 do idepth = 0,4

  u  = uf->U_Velocity(0,idepth,:,:)   ; Get (time, dep, lat, lon)  data.
  v  = vf->V_Velocity(0,idepth,:,:)
  speed = sqrt(u^2+v^2) 

  lat = vf->v&Latitude
  lon = vf->v&Longitude 

  wks = gsn_open_wks("x11","max") ; Open a workstation.


FileNameOut99 = "/home/mccormik/GulfBreeze/Data/OceanCurrentFiles/2008121100_2008121323/Depth"+DepthArray(idepth)+"/uv3d_"+Year99+NumberArray(Month99)+NumberArray(Day99)+NumberArray(Hour99)

; wks = gsn_open_wks("png",FileNameOut99) ; open png file

; setvalues wks            
;  "wkColorMap"        : "rainbow"  
; "wkForegroundColor" : (/0.2,0.1,0.0/)  
; "wkBackgroundColor" : (/0.9,0.9,0.7/) 
; "wkWidth"           : 1920
; "wkHeight"          : 1340
;  end setvalues 


; wks = gsn_open_wks("png","color") ; Open a workstation.
  gsn_define_colormap(wks, "rainbow")


  nlon = dimsizes(lon)
  nlat = dimsizes(lat)

; #####################################################################
; #####################################################################
; ###     
; ### Map Base for U-V plot -- ("mapbase")    
; ### 
; #####################################################################
; #####################################################################
;
; levels = (/30,35,40,45,50,55,60,65,70,75,80,85,90,95,100/)
; labels = (/"30","35","40","45","50","55","60","65","70","75","80", "85",\
; "90","95","100"/)
; nlevels = dimsizes(levels) 
;
;

  res = True 
  res@gsnAddCyclic         = False
  res@gsnSpreadColors      = True       ; use full colormap
  res@gsnScalarContour     = True               ; contours desired
  res@gsnMajorLatSpacing   = 1              ; change maj lat tm spacing
  res@gsnMajorLonSpacing   = 1              ; change maj lon tm spacing
  res@gsnDraw              = False          ;  draw picture
  res@gsnFrame             = False          ;  advance frame
  res@gsnContourZeroLineThicknessF = 3.5
; res@gsnPaperOrientation  = "auto"
; res@gsnPaperHeight       = 11.0
; res@gsnPaperMargin       = 0.5
; res@gsnOrientation  = "auto"
  res@gsnLeftString              = "Date- "+Year99+"-"+MonthAA(Month99)+"-"+Day99   
  res@gsnRightString            = "Hour- "+HourAA(Hour99)+" GMT"  ;right string title
  res@gsnCenterString             = " "     ;right string title
  res@gsnMaskLambertConformal     = True
  res@gsnBoxMargin                = 5.0

  res@vfXCStartV  = lon(0)      ; Define lat/lon corners
  res@vfXCEndV    = lon(nlon-1) ; for vector plot.
  res@vfYCStartV  = lat(0)
  res@vfYCEndV    = lat(nlat-1)
  res@vfMissingUValueV        = -99.0
  res@vfMissingVValueV        = -99.0


  u@missing_value = -99.0
  v@missing_value = -99.0


  res@vcMinFracLengthF     = 0.33   ; Increase length of
  res@vcRefMagnitudeF      = 1.0
  res@vcRefLengthF         = 0.045 
; res@vcGlyphStyle         = "LineArrow"
  res@vcMonoLineArrowColor = True  ; Draw vectors in color.
  res@vcLineArrowColor     = "black"           ; change vector color
  res@vcMinMagnitudeF      = 0.005   ; vectors.
  res@vcLineArrowThicknessF   = 0.002  ; change vector thickness
  res@vcMinDistanceF       = 0.04      ; thin out vectors
  res@vcFillArrowsOn           = True  ; Fill the vector arrows
  res@vcFillArrowEdgeColor     = 1     ; Draw the edges in black.
  res@vcFillArrowWidthF        = 0.0005 ; Make vectors thinner.

  res@vcRefAnnoString1On    = True
  res@vcRefAnnoString1      = "Ref Magnitude = 1 Met/sec"
  res@vcRefAnnoFontAspectF  =  2.0
  res@vcRefAnnoFont         = 22
  res@vcRefAnnoBackgroundColor = "(/0.2,0.9,0.5/)"
  res@vcRefAnnoFontThicknessF  = 24.0
  res@vcMinAnnoArrowLineColor  = True 
; res@vcRefAnnoString2      = "Ref Magnitude = 1 Met/sec"
  res@vcMinAnnoFontHeightF  = 4.0
; res@vcMinAnnoArrowFillColor  
; res@vcMinAnnoFontThicknessF = .003
  res@vcLabelFontHeightF      = .08

  res@vcScalarMissingValColor = True


; ###############################################################
; cn Stuff
; ###############################################################
; res@cnLevelSelectionMode = "ManualLevels"     ; set manual contour levels
; res@cnMinLevelValF       =  -1.               ; set min contour level
; res@cnMaxLevelValF       =   1.               ; set max contour level
; res@cnLevelSpacingF      =   .5               ; set contour spacing
; res@cnLinesOn            = True               ; contour lines
  res@cnFillOn             = True               ; turn on color fill
; res@cnLineLabelBackgroundColor  = 0           ; white bckgrnd around label
; res@cnMissingValPerimOn         = True
; res@cnFillDrawOrder             = "PreDraw"    ; Put continents on top
  res@cnMissingValFillColor       = "(/20.8,20.8,20.8/)"
  res@cnMissingValFillPattern     = 16
; res@cnLineLabelsOn              = False       ; turn line labels off

; ###############################################################
; lb Stuff
; ###############################################################
  res@lbLabelStride            = 1                 ; stride on label bar
  res@lbOrientation            = "vertical"      ; ncl default is vertical
  res@lbTitleString            = ""
  res@lbTitlePosition          = "Right"
  res@lbTitleOffsetF           = 0.05
  res@lbTitleAngleF            = 90.0
  res@lbTitleDirection         = "Up"
  res@lbLabelFontHeightF       = .00
  res@lbLabelOffsetF           = 0.05
  res@lbTitleFontHeightF       = .000
  res@lbFillScaleF             = True
; res@lbAutoManage             = True


; ###############################################################
; sf Stuff
; ###############################################################
  res@sfXArray             = lon
  res@sfYArray             = lat

; ###############################################################
; mp Stuff
; ###############################################################
  res@mpFillOceanColor       = "(/0.0,0.2,0.2/)"       ; (white)
  res@mpLimitMode       = "Corners"  ; Zoom in on the plot area.
  res@mpLeftCornerLonF  = lon(0)
  res@mpRightCornerLonF = lon(nlon-1)
  res@mpLeftCornerLatF  = lat(0)
  res@mpRightCornerLatF = lat(nlat-1)
  res@mpDefaultFillColor    = "(/0.1,0.1,0.1/)" 
  res@mpFillColors          = "(/0.2,0.2,0.2/)"  ;globe is filled white
  res@mpFillOn               = True
  res@mpOutlineOn          = True              ; turn on map outline
  res@mpMaskAreaSpecifiers = "USStatesLand"
  res@mpGridAndLimbOn        = True               ; lat/lon lines on
  res@mpGridLineColor        =  1                 ; Turn on grid lat/lon lines
  res@mpGridSpacingF         =  1.0               ; lat/lon lines every 2 deg
  res@mpGridLineDashPattern  =  2                  ; lat/lon lines as dashed
  res@mpTickMarkDisplayMode  = "Always"           ; turn on tickmarks
  res@mpProjection           = "CylindricalEquidistant"
  res@mpUSStateLineColor     = "(/10.0,0.0,0.0/)"       ; sets color of US State boundaries
  res@mpMinLatF              =  27.5                ; map area
  res@mpMaxLatF              =  30.7                ; map area
  res@mpMinLonF              = -92.2
  res@mpMaxLonF              = -86.0
  res@mpOutlineBoundarySets   =  "Geophysical"
  res@mpGeophysicalLineColor  = "(/20,20,20/)"
  res@mpGeophysicalLineThicknessF  = 0.08
  res@mpNationalLineColor         = "(/20.9,20.9,20.9/)"
  res@mpNationalLineThicknessF    = 0.08
  res@mpUSStateLineColor         = "Background"
  res@mpUSStateLineDashPattern   = "SolidLine"
  res@mpUSStateLineThicknessF    = 0.08
  res@mpLandFillColor         = "(/0.3,0.3,0.3/)"         ; set to white
  res@mpShapeMode             = "FreeAspect"
  res@mpFillBoundarySets      = "National" ; state boundaries


; ###############################################################
; ti Stuff
; ###############################################################
  res@tiMainString         = "Northern Gulf of Mexico Model Output  "   ; add titles
  res@tiMainFontHeightF    = .031
  res@tiXAxisString        = "Longitude (Degrees W.) - [Depth from MSL] = "+DepthArray(idepth)+" meters"
  res@tiXAxisFontHeightF   = 0.022                ; resize tick
  res@tiXBLabelFontHeightF = 0.020                 ; resize tick labels
  res@tiXAxisOffsetYF      =  0.01
  res@tiXAxisOffsetXF      =  0.00

  res@tiYAxisString        = "Latitude (Degrees N.) "
  res@tiYBLabelFontHeightF = 0.018
  res@tiYAxisFontHeightF   = 0.028                ; resize tick
  res@tiYAxisOffsetYF      = 0.04
  res@tiYAxisOffsetXF      = -0.07 


; ###############################################################
; vp Stuff
; ###############################################################
  res@vpWidthF              = 0.67                ; change aspect ratio of plot
  res@vpHeightF             = 0.60
  res@vpXF                  = 0.13
  res@vpYF                  = 0.84
  u@_FillValue = -99.
  v@_FillValue = -99.

; vplot = gsn_vector(wks,u,v,res) 
; scal_plot = gsn_csm_contour_map(wks,speed,res) 
; draw(vplot)
; frame(wks)

; vec_plot = gsn_vector_scalar(wks,u,v,res)  ; Draw a vector plot of u and v.  
; vmap = gsn_vector_scalar(wks,u,v,False,res)    ; Draw a vector plot of u and v.  
  vec_plot = gsn_csm_vector_map(wks,u,v,res)
  draw(vec_plot)
  frame(wks) 

; vplot = gsn_vector_map(wks,u,v,res)    ; Draw a vector plot of u and v.  
; draw(vplot)
; frame(wks) 

; overlay(scal_plot, vec_plot)
; draw(scal_plot)
; frame(wks) 

  end do

; draw(vec_plot)

; overlay(mapbase,vplot)
; draw(mapbase)
; frame(wks)

; vmap = gsn_vector_scalar(wks,u,v,False,res)    ; Draw a vector plot of u and v.  
; plot = gsn_vector_scalar(wks,u,v,res)  ; Draw a vector plot of
;  map = gsn_vector_map(wks,u,v,res)  ; Draw a vector plot of
                                           ; u and v over a map.
end

EEOOFF

exit(22) 

set DepthArray = ("0000.0" "0002.5" "0005.0" "0007.5" "0010.0" "0015.0" "0020.0" "0025.0" "0030.0" "0035.0" "0040.0" "0045.0" "0050.0" "0060.0" "0070.0" "0080.0" "0090.0" "0100.0" "0125.0" "0150.0" "0200.0" "0250.0" "0300.0" "0400.0" "0500.0" "0600.0" "0700.0" "0800.0" "0900.0" "1000.0")

set Month77 = `printf "%02.0f" $Month77`
set Day77 = `printf "%02.0f" $Day77`
set Hour77 = `printf "%02.0f" $Hour77`

set dd99 = 0
 
while ( $dd99 < 31 )

set LocFileName01 = "/home/mccormik/GulfBreeze/Software02/uv3d_"$Year77$Month77$Day77$Hour77"_nc_ascii"$DepthArray[$dd99]".png"

echo "###########################################"
echo "#### From:  "$LocFileName01
echo "###########################################"

set RemFileName01 = "/home/mccormik/GulfBreeze/Data/OceanCurrentFiles/2009061100_2009061323/Depth"$DepthArray[$dd99]"/uv3d_"$Year77$Month77$Day77$Hour77"_nc_ascii"$DepthArray[$dd99]".png"

echo "###########################################"
echo "#### To:  "$RemFileName01 
echo "###########################################"
echo " "
echo " "
echo " "

mv -f $LocFileName01 $RemFileName01

@ dd99 = ($dd99 + 1) 

end


exit(99)


