; =================================================;
; popvec_4.ncl
; =================================================;
;
; These files are loaded by default in NCL V6.2.0 and newer
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"   
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"   
; =================================================;
 begin
  f = addfile("/work/yhtseng00/scratch/cesm2/archive/G_JRA55_test1_vdc013l/ocn/hist/G_JRA55_test1_vdc013l.pop.h.0001-01.nc","r")
  u           = f->UVEL
  v           = f->VVEL
  rot         = f->ANGLE
  ssh         = f->SSH 
 
;  urot        = u(0,0,:,:)
;  vrot        = v(0,0,:,:)
  urot        = u(0,0,:,:)*cos(rot) - v(0,0,:,:)*sin(rot)  
  vrot        = u(0,0,:,:)*sin(rot) + v(0,0,:,:)*cos(rot)
  SSH         = ssh(0,:,:)

printVarSummary(urot)
printVarSummary(SSH)
;--------------------------------------------------------------
;************************************************
; this data only has an missing_value, so we are
; copying this to _FillValue for plotting purposes
;************************************************
  assignFillValue(vrot,urot)                           ; in contributed.ncl   
  assignFillValue(urot,vrot)
;--------------------------------------------------------------
  lat2d       = f->ULAT
  lon2d       = f->ULONG

  urot@lon2d  = lon2d
  urot@lat2d  = lat2d
  vrot@lon2d  = lon2d
  vrot@lat2d  = lat2d
  
  SSH@lat2d   = lat2d
  SSH@lon2d   = lon2d
; =================================================;
; create plots
; =================================================;
  wks  = gsn_open_wks("png","popvec")              ; send graphics to PNG file

;  res                       = True                 ; plot mods desired
;  res@vcRefMagnitudeF       = 30.0                 ; define vector ref mag
;  res@vcRefLengthF          = 0.045                ; define length of vec ref
;  res@vcMinDistanceF        = 0.017                ; thin out vectors
;  res@vcGlyphStyle          = "CurlyVector"        ; turn on curly vectors
;  res@gsnLeftString         = "Surface Currents"   ; change left string
;  res@tiMainString          = "Orthographic Projection"   ; title
;  res@vcLineArrowThicknessF = 3.

  
;  res@mpProjection         = "Orthographic"       ; choose projection
;;  res@mpProjection          = "LambertConformal"   ;
;;  res@mpProjection          = "Stereographic"      ;
;  res@mpLandFillColor       = "darkgoldenrod"       ; default is gray
;  res@mpCenterLonF          = 0.                    ; choose center lon  [-120]
;  res@mpCenterLatF          = 90.                   ; choose center lat  [50]
;  res@mpPerimOn             = False

;  res@gsnAddCyclic          = True                  ; add cyclic point

; plot = gsn_csm_vector_map(wks,urot,vrot,res)

  res            = True                         ; plot mods desired
  res@gsnPolar   = "SH"                         ; specify the hemisphere
  res@mpMinLatF  = 60                           ; minimum lat to plot
  res@mpFillOn   = False

  res@cnFillOn          = True                  ; color fill
  res@cnLevelSpacingF   = 3.                    ; interval spacing
  res@cnLinesOn         = False                 ; no contour lines

  res@gsnSpreadColorEnd     = -3
  res@gsnScalarContour      = True              ; vectors over scalars
  res@vcRefMagnitudeF       = 20.0              ; vec magnitude
  res@vcRefLengthF          = 0.04              ; size of ref vector
  res@vcLineArrowColor      = "black"           ; white vectors
  res@vcMinDistanceF        = 0.02              ; thins arrows near pole  
  res@vcGlyphStyle          = "CurlyVector"       ; turns on curly vectors  [CurlyVector]

  res@vcRefAnnoArrowLineColor   = "black"       ; black ref vector
  res@vcRefAnnoArrowUseVecColor = False 

  plot = gsn_csm_vector_scalar_map_polar(wks,urot,vrot,SSH,res)

 end
