[ncl-talk] sub: read ascii error

dale zuri dalezuri at gmail.com
Tue Mar 30 10:24:29 MDT 2021


Dear NCL user,
I would appreciate any help to plot this data. I'm getting this error.

Thanks in advance
DZ

fatal:Variable (lat) is undefined
fatal:["Execute.c":8637]:Execute: Error occurred at or near line 18 in file
test.ncl




begin
nlat=720
nlon=1440

ncol  = 6
nhead = 1

fname = "avhrr_seaice"
data = readAsciiTable("avhrr_seaice", ncol, "float", nhead)
temp12D = onedtond(data(2,:),(/nlat,nlon/)) ; convert 1D array to a 2D array
temp22D = onedtond(data(3,:),(/nlat,nlon/)) ; convert 1D array to a 2D array
templat = data(0,:) ; convert 1D array to a 2D array
templon = data(1,:) ; convert 1D array to a 2D array
; Assign named dimensions
  temp12D!0 = "lat"
  temp12D!1 = "lon"
  temp12D&lat =  templat               ; assign coord variables
  temp12D&lon =  templon
  temp22D!0 = "lat"
  temp22D!1 = "lon"
  temp22D&lat =  templat               ; assign coord variables
  temp22D&lon =  templon
    temp12D&lat at units = "degrees_north"
    temp12D&lon at units = "degrees_east"
    temp22D&lat at units = "degrees_north"
    temp22D&lon at units = "degrees_east"
; Assign coordinate variables
  printVarSummary(temp12D)
  printVarSummary(temp22D)

wks = gsn_open_wks("x11","test")               ; send graphics to PNG file

 plot = new(2,graphic)
  cmap = read_colormap_file("UKM_hadcrut"); choose colormap
;

res                      = True               ; plot mods desired
  res at cnFillOn             = True               ; turn on color
;res at mpShapeMode  = "FreeAspect"
res at vpWidthF      = 0.3
res at vpHeightF     = 0.2
;  res at cnFillPalette  2     = "grads_rainbow"     ; choose colormap
  res at cnFillPalette        = cmap     ; choose colormap
  res at gsnPolar           = "NH"               ; specify the hemisphere
res at gsnDraw              = False
 res at gsnFrame    = False
 res at gsnTickMarksOn         = False
  res at mpMinLatF            = 50                 ; specify min lat
;  res at mpMinLatF            = minlatt                 ; specify min lat
;res at mpMaxLatF            = maxlatt
  res at trGridType           = "TriangularMesh"
  res at cnLinesOn            = False        ; True is default
;res at mpFillOn             = False              ; turns off continent gray
  res at cnLineLabelsOn       = False        ; True is default
res at mpGridAndLimbOn = False
res at mpLabelFontHeightF = "22"
res at mpPerimLineThicknessF = 2
res at mpOutlineOn           = True
; res at mpLandFillColor       = "tan"
;res at tiMainString    = ""+type+"-"+mon+""
  res at lbLabelBarOn         = False        ; turn off individual lb's

 res at gsnLeftString    = ""    ; no titles
  res at gsnRightString   = ""
  res at tiXAxisString    = ""
  res at tiYAxisString    = ""
  res at cnLevelSelectionMode = "ManualLevels"     ; set manual contour levels
  res at cnMinLevelValF       =  0;0              ; set min contour level
  res at cnMaxLevelValF       = 100 ;6                ; set max contour level
  res at cnLevelSpacingF      =  10;0.5              ; set contour spacing


;res at lbOrientation        = "Horizontal"
;res at lbLabelFontHeightF = 0.014
;res at lbLabelFont = "22"
;  res at lbTitleString    = ""+type+""
;  res at lbTitleString        = " (deg C)" ; bar title
;  res at lbTitlePosition      = "Right"                           ; title
location
;  res at lbTitleDirection     = "Across"                          ; letter
angle
;  res at lbTitleAngleF        = 90.                               ; title
angle
;  res at lbTitleFontHeightF   = 0.02                              ; font
height
 res at gsnStringFont              = "helvetica-bold"  ; will be used for
gsnCenterString later
    res at gsnCenterStringFontHeightF = 0.014
res at gsnCenterString    = "NDJFM"
  plot(0) = gsn_csm_contour_map_polar(wks,temp12D(:,0),res)
res at gsnCenterString    = "JJAS"
  plot(1) = gsn_csm_contour_map_polar(wks,temp22D(:,1),res)
;********************************
;;;;;Contour plot;;;;;;;;;;;;;;;
;********************************
; panel plot only resources
;********************************
; panel plot only resources
; panel plot only resources
  resP                     = True         ; modify the panel plot
  resP at gsnMaximize         = True         ; large format
  resP at gsnPanelLabelBar    = True         ; add common colorbar
resP at lbLabelFontHeightF = 0.012
 resP at gsnPanelBottom   = 0.2;;;increases figure size                    ;
shrink panel plot by setting bottom edge of plot
 resP at gsnPanelTop      = 0.9                    ; shrink panel plot by
setting top edge of plot
 resP at pmLabelBarWidthF  = 0.50                 ; make thinner/small number
;  resP at pmLabelBarHeightF = 0.05
 resP at pmLabelBarHeightF = 0.08
resP at pmLabelBarOrthogonalPosF = -0.016
; resP at gsnPanelYWhiteSpacePercent = 5.           ; increase spacing along
Y-axis between panel plots
 resP at gsnPanelYWhiteSpacePercent = 2;;increases the figure size           ;
increase spacing along Y-axis between panel plots
res at lbLabelFontHeightF = 0.018
resP at lbLabelFont = "22"
;  resP at lbTitleString    = ""+tic+""
 resP at cnLinesOn       = False                   ; turn off contour lines
  resP at lbLabelFont    = "helvetica-bold"          ; add common colorbar
  resP at lbTitleFont    = "helvetica-bold"          ; add common colorbar
  resP at lbTitleFontHeightF= .015                 ; make title smaller
  resP at cnLineLabelsOn  = False
  resP at txFontHeightF   = 0.03
  resP at txFont   = "helvetica-bold"

gsn_panel(wks,plot,(/1,2/),resP)
;---This will maximize the size of all the paneled stuff.
;end do

end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210330/bcb9abd9/attachment.html>


More information about the ncl-talk mailing list