[ncl-talk] Plotting a field from an ascii data file

Karin Meier-Fleischer meier-fleischer at dkrz.de
Fri Mar 10 06:40:16 MST 2017


Hi Petroula,

you do not have to create two plots, just use the min and max function 
of NCL to get the minimum and maximum of lat and lon. See attached 
script and plot.

How to install the rangs/gshhs zip files read the page

    http://ncl.ucar.edu/Document/Graphics/rangs.shtml

Bye,
Karin

Am 10.03.17 um 13:16 schrieb Petroula Louka:
>
> Dear sir/madam
>
> I am new to the ncl graphics and I'm trying to plot a field from the 
> ascii file attached. As you may see it is a 3-column file 
> (lon,lat,indicator). I have used the file plotAscii.ncl given below to 
> create the plot and receive the following error:
>
> -----------------------
> fatal:Cannot create triangular mesh: supply additional resources or 
> build with Triangle package
> fatal:ContourPlotDraw: draw error
> fatal:ContourPlotDraw: draw error
> fatal:PlotManagerDraw: error in plot draw
> fatal:_NhlPlotManagerDraw: Draw error
> -----------------------
>
> I only get a png image with the map of the corresponding area in low 
> res (as it's the default).
> Could you please help me with the script?
> Also, if I want to use highres for the coeastlines in which directory 
> should I add the GSHHS file?
>
> The version of ncl installed (already built from ncl homepage) is 6.3.0 .
>
> Thank you for any help.
>
> Best regards,
> Petroula
>
>
> -----------------------
> plotAscii.ncl
> -----------------------
>
> load 
> "~/WRF/LIBRARIES/ncl_ncarg-6.3.0/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load 
> "~/WRF/LIBRARIES/ncl_ncarg-6.3.0/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> begin
>
>   fname = "~/FlyingRoute/OUTPUT/storm_2014071412_12.dat"
>   n_col = numAsciiCol(fname)
>   n_var = n_col
>   n_pt  = numAsciiRow(fname)
>   dataf  = asciiread(fname,(/n_pt,n_var/),"float")
> ;---read longitude
>   lon = dataf (:,0)
> ;---read latitude
>   lat = dataf (:,1)
> ;---read data for presence of convective cloud
>   storm = dataf (:,2)
> ;---define the workstation (plot type and name)
>   wks = gsn_open_wks("png","plot_field")
> ;--set resources
>   res                     = True
>   res at sfXArray            = lon
>   res at sfYArray            = lat
>   res at cnFillOn            = True        ; Turn on contour fill.
>   res at cnLinesOn           = False       ; Turn off contour lines
> ;-- First create just a contour plot in order to retrieve
> ; --the start/end limits of the actual location of the data.
> ; --Don't draw the contour plot.
>   res at gsnDraw  = False
>   res at gsnFrame = False
>   contour = gsn_csm_contour(wks,storm,res)
> ;-- gsnDraw and gsnFrame are on for the next plot.
>   res at gsnDraw  = True
>   res at gsnFrame = True
> ;-- Retrieve the actual start and end limits of the data
>   getvalues contour at data
>     "sfXCActualStartF" : xs
>     "sfXCActualEndF"   : xe
>     "sfYCActualStartF" : ys
>     "sfYCActualEndF"   : ye
>   end getvalues
>
>   res at mpLimitMode           = "LatLon"
>   res at mpMinLonF             = xs
>   res at mpMaxLonF             = xe
>   res at mpMinLatF             = ys
>   res at mpMaxLatF             = ye
>
>   res at tiMainString = "Areas of convective cloud"
>   res at pmTickMarkDisplayMode = "Always"        ; Turn on map tickmarks.
>
>    plot = gsn_csm_contour_map(wks,storm,res)
>
> end
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
Dipl. Geophys. Karin Meier-Fleischer
Visualization, NCL
Application Support

Deutsches Klimarechenzentrum GmbH (DKRZ)
Bundesstrasse 45a - D20146 Hamburg - Germany

Phone:    +49 (0)40 460094 126
Fax:      +49 (0)40 460094 270
E-Mail:   meier-fleischer at dkrz.de
URL:      www.dkrz.de

Geschäftsführer: Prof. Dr. Thomas Ludwig
Sitz der Gesellschaft: Hamburg
Amtsgericht Hamburg HRB 39784

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170310/09cbf824/attachment.html 
-------------- next part --------------
begin

  fname = "~/FlyingRoute/OUTPUT/storm_2014071412_12.dat"

  n_col = numAsciiCol(fname)
  n_var = n_col
  n_pt  = numAsciiRow(fname)
  dataf  = asciiread(fname,(/n_pt,n_var/),"float")
  
;---read longitude
  lon = dataf (:,0)
  
;---read latitude
  lat = dataf (:,1)
  
;---read data for presence of convective cloud
  storm = dataf (:,2)
  
;---define the workstation (plot type and name)
  wks = gsn_open_wks("png","plot_field")
  
;--set resources
  res                     = True
  res at gsnMaximize         = True
  
  res at mpDataBaseVersion   = "MediumRes"   ;-- map resolution
  res at mpMinLonF           = min(lon)
  res at mpMaxLonF           = max(lon)
  res at mpMinLatF           = min(lat)
  res at mpMaxLatF           = max(lat)

  res at sfXArray            = lon
  res at sfYArray            = lat
  
  res at cnFillOn            = True        ; Turn on contour fill.
  res at cnLinesOn           = False       ; Turn off contour lines

;-- create the contour map plot
  contour = gsn_csm_contour_map(wks,storm,res)

end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot_field.png
Type: image/png
Size: 55706 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170310/09cbf824/attachment.png 


More information about the ncl-talk mailing list