;----------------------------------------------------------------------
; vector_1.ncl
;
; Concepts illustrated:
;   - Overlaying vectors and filled contours on a map
;   - Manually attaching lat/lon coordinate arrays to a variable
;   - Changing the length of the smallest vector as a fraction of the reference vector
;   - Moving the vector reference annotation to the top right of the plot
;   - Drawing curly vectors
;   - Setting the color for vectors
;   - Making the labelbar be vertical
;   - Increasing the thickness of vectors
;----------------------------------------------------------------------
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"   
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"    
;************************************************
begin
;************************************************
; open netCDF file
;************************************************
  a = addfile("test_u_238_12.nc","r")
;************************************************
; Read in Sea Surface Temperature Anomalies
; Read in U and V at 1000 mb [subscript 0]
; Determine the subscripts corresponding to Jan 88
;************************************************
  sst      = a->layer_temperature(0,0,:,:)
  u        = a->u_velocity(0,0,:,:)
  v        = a->v_velocity(0,0,:,:)
  lat_uv   = a->Latitude(:)
  lon_uv   = a->Longitude(:)
;************************************************
; create plot
;************************************************
  wks = gsn_open_wks("ps","sst_238_12")             ; open a ps file
  gsn_define_colormap(wks,"BlAqGrYeOrRevi200")  ; choose color map

  res                      = True               ; plot mods desired

  res@cnFillOn             = True               ; turn on color for contours
  res@cnLinesOn            = False              ; turn off contour lines
  res@cnLineLabelsOn       = False              ; turn off contour line labels
;  res@gsnScalarContour     = True               ; contours desired
  res@gsnSpreadColors      = True               ; use full color map
  res@gsnSpreadColorStart  = 30  ;17                 ; start at color 17
  res@gsnSpreadColorEnd    = 180                ; end at color 200
;
; This is not necessary in V6.1.0 and later. Named colors can
; be used without having to first add them to the color map.
;
  i = NhlNewColor(wks,0.7,0.7,0.7)              ; add gray to colormap
  res@mpLandFillColor       = "gray"            ; set land to be gray
  res@gsnAddCyclic = False

  res@mpMinLonF            =  -80 ;lon_uv(0)    ;-98.               ; select a subregion
  res@mpMaxLonF            =  -65 ;lon_uv(dimsizes(lon_uv)-1)    ;-53.
  res@mpMinLatF            =  20  ;lat_uv(0)   ; 5.8 
  res@mpMaxLatF            =  35  ;lat_uv(dimsizes(lat_uv)-1);32.

  res@lbOrientation            = "Vertical"     ; vertical label bar
  res@pmLabelBarOrthogonalPosF = -0.01          ; move label bar closer
  res@lbLabelStride            = 4

; note, when doing a subregion, NCL determines the range of the data from
; the full domain. If you wish to just consider the domain you are plotting,
; you must manually set those levels.

  res@cnLevelSelectionMode = "ManualLevels"     ; set manual contour levels
  res@cnMinLevelValF       = 24.0               ; set min contour level
  res@cnMaxLevelValF       = 33.0                 ; set max contour level
  res@cnLevelSpacingF      = 0.5               ; set contour spacing


  vres = True
  vres@vcRefMagnitudeF           = 0.3             ; define vector ref mag
  vres@vcRefLengthF              = 0.015           ; define length of vec ref
  vres@vcRefAnnoOrthogonalPosF   = -1.0            ; move ref vector
  vres@vcRefAnnoArrowLineColor   = "black"         ; change ref vector color
  vres@vcRefAnnoArrowUseVecColor = False           ; don't use vec color for ref
  vres@vcMinDistanceF           = 0.015 

  vres@vcGlyphStyle            = "CurlyVector"     ; turn on curley vectors
;  vres@vcLineArrowColor        = "white"           ; change vector color
  vres@vcLineArrowThicknessF   = 2.0               ; change vector thickness
;  vres@vcVectorDrawOrder       = "PostDraw"        ; draw vectors last
  vres@gsnAddCyclic = False
;  vres@mpMinLonF            =  -98.               ; select a subregion
;  vres@mpMaxLonF            =  -53.
;  vres@mpMinLatF            =   5.8
;  vres@mpMaxLatF            =  32.
  vres@gsnDraw          = False                    ; turn off draw and frame
  vres@gsnFrame         = False                    ; b/c this is an overlay plot

;  plotV   = gsn_csm_vector(wks,u,v,vres)

;  plot=gsn_csm_vector_scalar_map_ce(wks,u(:,:),v(:,:),\
;                                    sst(:,:),res)

   plot = gsn_csm_contour_map(wks,sst,res)

end