I have two problems to run the following code, (1) can not read ascii file, if I copy the file to the code it works well but (2) I can not the saved file. Any body could offer the solution, I really apprreciate it.
Thank you..
Juki
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
; -------read data
ncols = 10
nrows = 3
; data = asciiread("ncldatasample.txt", (/nrows,ncols/), "float")
; lon =data(:,1);
; lat =data(:,2);
; R = data(:,3);
;-------Options--------
arr = (/0.5,1.,1.5,2.,2.5,3.,4., 5./) ; bin settings (bin0 = < 0.,
; bin1 = 0.:4.999, etc.)
colors = (/10,30,38,48,56,66,74,94/); marker colors, dimsizes must
; be equal to dimsizes(arr)+1
labels = new(dimsizes(arr)+1,string) ; Labels for legend.
;---------------------------
npts = 10
lon= (/126., 156.2,132.1,151.6,84.3, 131.7, 117.6, 75.4, 78.3, 81.7/)
lat = (/7.4, 5.7, 9.3,-9.3, -8.4,9.1, 8.7, -8.5, -8.1, 6.5/)
R =(/1.54, 0.96,1.3,1.1,1.01,2.02,0.84,0.92,1.18,1.53/)
;------------------------------
; Create X and Y arrays to hold the points for each range and initialize
; them to missing values. We want to use num_distinct_markers
; different colors, so we need num_distinct_markers sets of X and
; Y points.
;
num_distinct_markers = dimsizes(arr)+1 ; number of distinct markers
lat_new = new((/num_distinct_markers,dimsizes(R)/),float,-999)
lon_new = new((/num_distinct_markers,dimsizes(R)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;
do i = 0, num_distinct_markers-1
if (i.eq.0) then
indexes = ind(R.lt.arr(0))
labels(i) = "x < " + arr(0)
end if
if (i.eq.num_distinct_markers-1) then
indexes = ind(R.ge.max(arr))
labels(i) = "x >= " + max(arr)
end if
if (i.gt.0.and.i.lt.num_distinct_markers-1) then
indexes = ind(R.ge.arr(i-1).and.R.lt.arr(i))
labels(i) = arr(i-1) + " <= x < " + arr(i)
end if
;
; Now that we have the set of indexes whose values fall within
; the given range, take the corresponding lat/lon values and store
; them, so later we can color this set of markers with the appropriate
; color.
;
if (.not.any(ismissing(indexes))) then
npts_range = dimsizes(indexes) ; # of points in this range.
lat_new(i,0:npts_range-1) = lat(indexes)
lon_new(i,0:npts_range-1) = lon(indexes)
end if
delete(indexes) ; Necessary b/c "indexes" may be a different
; size next time.
end do
;===========================================================================
; Begin plotting section.
;
; wks = gsn_open_wks("x11","test") ; Open a workstation and
wks = gsn_open_wks ("png", "test" )
gsn_define_colormap(wks,"WhViBlGrYeOrRe") ; define a different colormap.
nc1 = NhlNewColor(wks,.8,.8,.8) ; Add light gray to colormap,
; for continents.
;
; Set up some map resources.
;
mpres = True
mpres_at_gsnMaximize = True ; Maximize plot in frame.
mpres_at_gsnFrame = False ; Don't advance the frame
;
; Zoom in on United States.
;
mpres_at_mpMinLatF = -10.
mpres_at_mpMaxLatF = 10.
mpres_at_mpMinLonF = 70.
mpres_at_mpMaxLonF = 160.
mpres_at_mpFillColors = (/-1,-1,nc1,-1/) ;assign light gray to land masses
mpres_at_tiMainString = "Dummy station data colored and~C~sized according to range of values"
map = gsn_csm_map(wks,mpres)
;
; Create logical variables to hold the marker and text resources.
; These markers are different than the XY markers, because they are not
; associated with an XY plot. You can put these markers on any plot.
;
gsres = True
gsres_at_gsMarkerIndex = 16 ; Use filled dots for markers.
txres = True
txres_at_txFontHeightF = 0.015
;
; Loop through each grouping of markers, and draw them one set at
; a time, assigning the proper color and size with gsn_marker.
;
; At the same time, draw a legend showing the meaning of the markers.
;
xleg = (/0.07,0.07,0.32,0.32,0.57,0.57,0.82,0.82/) ; Location of
xtxt = (/0.16,0.16,0.41,0.41,0.66,0.66,0.91,0.91/) ; legend markers
yleg = (/0.22,0.17,0.22,0.17,0.22,0.17,0.22,0.17/) ; and text
ytxt = (/0.22,0.17,0.22,0.17,0.22,0.17,0.22,0.17/) ; strings.
do i = 0, num_distinct_markers-1
if (.not.ismissing(lat_new(i,0)))
gsres_at_gsMarkerColor = colors(i)
gsres_at_gsMarkerThicknessF = 0.7*(i+1)
gsn_polymarker(wks,map,lon_new(i,:),lat_new(i,:),gsres)
;
; Add marker and text for the legend.
;
gsn_polymarker_ndc(wks, xleg(i),yleg(i),gsres)
gsn_text_ndc (wks,labels(i),xtxt(i),ytxt(i),txres)
end if
end do
frame(wks) ; Advance the frame.
end
________________________________
From: Dennis Shea <shea_at_ucar.edu>
To: juki juki <juky_emc2_at_yahoo.com>
Cc: NCL Talk <ncl-talk_at_ucar.edu>; Mary Haley <haley_at_ucar.edu>
Sent: Friday, May 25, 2012 3:14 AM
Subject: Re: [ncl-talk] plot circle in contour map
See Example 4
http://www.ncl.ucar.edu/Applications/polyg.shtml
Just read the lat and lon values.
You must repeat the last point to complete the circle.
lat = (/7.4, 5.7, ... , 6.5, 7.4/)
lon = (/126.5, 156.6, ..., 81.7, 126.5/)
On 5/24/12 12:02 PM, juki juki wrote:
> Dear all,
>
> I want plot circles in a contourmap in 70-160E and 10S-10N. For example
> we know the position of the circle and the radius in degree. Data example:
>
> 126.5000000000007.400000000000001.53890401039422
> 156.2000000000005.700000000000000.957461472963439
> 132.1000000000009.300000000000001.26660247369343
> 151.600000000000-9.300000000000001.12837916709551
> 84.3000000000000-8.400000000000001.01554125038596
> 131.7000000000009.100000000000002.01850601761613
> 117.6000000000008.700000000000000.836828387188401
> 75.4000000000000-8.500000000000000.916699568847508
> 78.3000000000000-8.100000000000001.18345405454064
> 81.70000000000006.500000000000001.52644304409478
>
> First column is longitude position, latitude is in the second and last
> one is the radius. Are there ncl example regarding this matter, to plot
> circle in contourmap or in topographymap ?. Thanks for sharing,
>
> Regards,
> Juki
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2.1.8 : Fri May 25 2012 - 08:35:50 MDT