<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Nafiseh,<div class=""><br class=""></div><div class="">I’m sorry for the delay in responding to you.</div><div class=""><br class=""></div><div class="">I’ve looked into gc_onarc() to determine how it is supposed to be used, and in the interest of clarifying things for you and others I’d like to share my experience.</div><div class=""><br class=""></div><div class="">For the calculation you’re trying to do, the two rightmost arguments represent arc segments of the circle generated by nggcog(). For example, if clon_outer_core was (/0, 1, 2, 3/) after running nggcog(), your clon_outer_core_2d should be (/(/0, 1/), (/1, 2/), (/2, 3/), (/3, 0/)/); each of the four pairs of longitudes would represent the start- and end-points of the great circle arcs that approximate a circle around lat_location and lon_location. The method you used below (using reshape()) will actually skip half of the arcs and would look like this: (/(/0, 1/), (/2, 3/)/). The following snippet of code should generate the necessary clat_outer_core_2d and clon_outer_core_2d arrays containing all arcs:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">clat_outer_core_2d = new((/clat_outer_core_size, 2/), typeof(clat_outer_core))<br class="">clon_outer_core_2d = new((/clon_outer_core_size, 2/), typeof(clon_outer_core))<br class=""><br class="">clat_outer_core_2d(:,0) = clat_outer_core<br class="">clat_outer_core_2d(0:clat_outer_core_size-2,1) = clat_outer_core(1:)<br class="">clat_outer_core_2d(clat_outer_core_size-1,1) = clat_outer_core(0)<br class="">clon_outer_core_2d(:,0) = clon_outer_core<br class="">clon_outer_core_2d(0:clat_outer_core_size-2,1) = clon_outer_core(1:)<br class="">clon_outer_core_2d(clat_outer_core_size-1,1) = clon_outer_core(0)</font><br class=""></div><div class=""><br class=""></div><div class="">The sizes of the arguments passed to gc_onarc() must match because gc_onarc checks to see if the nth point in the first two arguments is on the arc defined by the nth index of the last two arguments. This means that if you want to check if a particular point is on any of the 144 arcs, your first two arguments will need to be arrays containing the same value 144 times. Mary’s solution below almost works, but needs to be adjusted to account for having the same value 144 times:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">npts = dimsizes(lat_2d_outer_core_to_1d)<br class="">onarc_outer_core = new(npts,logical)<br class=""><br class="">do n=0,npts-1</font></div><div class=""><font face="Menlo" class=""> conform_lat = conform_dims(clat_outer_core_size, lat_2d_outer_core_to_1d(n), -1)<br class=""> conform_lon = conform_dims(clat_outer_core_size, lon_2d_outer_core_to_1d(n), -1)<br class=""> onarc_outer_core(n) = any(gc_onarc(conform_lat,conform_lon,clat_outer_core_2d,clon_outer_core_2d))<br class="">end do<br class=""></font><br class=""></div><div class="">Note that I also added the “any” function around the gc_onarc call — this is because the output of gc_onarc is a logical/boolean array “dimsizes(clat_outer_core_2d)” long which tells you which arc index your point was on. I suspect in this case that you don’t care <i class="">which particular</i> arc segment the point was on, just if it was on <i class="">any</i> arc segment of the circle.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Also, I investigated the source code for gc_inout() and found that it treats any points that are “on arc” as being “in”; under the hood, gc_inout() calls the same Fortran function used by gc_onarc() in addition to its own “in/out” checks. As such, I believe you could actually eliminate the gc_onarc section of your program.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Finally, I have some ideas to make this program a little simpler and possibly quicker and more accurate. Because the shape you’re using for gc_inout() and gc_onarc() is a circle instead of an arbitrary polygon, instead of calling those functions you could simply see if the distance between two points is less than or equal to a specified radius in degrees:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">distance = gc_latlon(lat_2d_outer_core_to_1d(n), lon_2d_outer_core_to_1d(n), lat_location, lon_location, 2, 2)</font></div><div class=""><font face="Menlo" class="">if(distance .le. radius_outer_core) then</font></div><div class=""><font face="Menlo" class=""> if(distance .eq. radius_outer_core) then</font></div><div class=""><font face="Menlo" class=""> print("on")</font></div><div class=""><font face="Menlo" class=""> else</font></div><div class=""><font face="Menlo" class=""> print("in")</font></div><div class=""><font face="Menlo" class=""> end if</font></div><div class=""><font face="Menlo" class="">else</font></div><div class=""><font face="Menlo" class=""> print("out")</font></div><div class=""><font face="Menlo" class="">end if</font></div><div class=""><br class=""></div><div class="">I have attached an NCL script that defines “on_circle” and “in_circle” functions that mimic the behavior of gc_onarc and gc_inout, respectively.</div><div class=""><br class=""></div><div class="">Please let me know if you have any further questions.</div><div class=""><br class=""></div><div class="">I hope this helps!</div><div class="">Kevin</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 19, 2018, at 2:35 PM, Mary Haley via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">Hi Nafiseh,</font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">Thanks for your patience. I was unable to respond to this question until I had a chance to look at the documentation.</font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">You are correct, this function is confusing. I admit I wasn't familiar with it until I started looking at the internal code and tried to figure out why the restriction is placed on it.</font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">As far as I can tell, there's no reason the two sets of arguments should have the weird set of restrictions of dimensionality placed on them. </font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">The first two input arrays should be allowed to be any dimensionality of lat/lon points that you want to loop through and check if it's on the given lat/lon great circle, specified by the second two arguments.</font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">I've created a trouble-ticket for this, NCL-2717, and marked it as a high priority for NCL V6.5.0.</font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class="gmail_default" style="font-size:small"><font face="arial, helvetica, sans-serif" class="">Meanwhile, the only work-around I can think of is to loop through each of your points and pass them individually to gc_onarc. This means you will need to create the output array before you call the function, and then subscript it as you go. Something like this (UNTESTED, because I'm not sure of the exact dimensionality of your arrays):</font></div><div class="gmail_default" style="font-size:small"><br class=""></div><div class="gmail_default" style=""><font face="monospace, monospace" style="" class="">npts = dimsizes(<span style="" class="">lat_2d_outer_core_to_</span><wbr style="" class=""><span style="" class="">1d)</span></font></div><div class="gmail_default" style=""><font face="monospace, monospace" class=""><span style="" class="">onarc_outer_core = new(npts</span><span style="" class="">,logical)</span><br class=""></font></div><div class="gmail_default" style=""><span style="" class=""><font face="monospace, monospace" class=""><br class=""></font></span></div><div class="gmail_default" style=""><span style="" class=""><font face="monospace, monospace" class="">do n=0,npts-1</font></span></div><div class="gmail_default" style=""><font face="monospace, monospace" class=""><span style="" class=""> onarc_outer_core(n) = gc_onarc(lat_2d_outer_core_to_</span><wbr style="" class=""><span style="" class="">1d(n),lon_2d_outer_core_to_1d(n),</span><wbr style="" class=""><span style="" class="">clat_outer_core_2d,clon_outer_</span><wbr style="" class=""><span style="" class="">core_2d)</span><br style="" class=""></font></div><div class="gmail_default" style=""><span style="" class=""><font face="monospace, monospace" style="" class="">end do</font></span></div><div class="gmail_default" style="font-size:small"><span style="font-family: serif; font-size: 13.3333px;" class=""><br class=""></span></div><div class="gmail_default" style="font-size:small"><span style="font-size: 13.3333px;" class=""><font face="arial, helvetica, sans-serif" class="">This is going to be slower than calling the function once, but hopefully it still works.</font></span></div><div class="gmail_default" style="font-size:small"><span style="font-size: 13.3333px;" class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></span></div><div class="gmail_default" style="font-size:small"><span style="font-size: 13.3333px;" class=""><font face="arial, helvetica, sans-serif" class="">--Mary</font></span></div><div class="gmail_default" style="font-size:small"><span style="font-size: 13.3333px;" class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></span></div><div class="gmail_default" style="font-size:small"><br class=""></div><div class="gmail_default" style="font-size:small"><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Jan 17, 2018 at 11:41 PM, nafiseh pegahfar via ncl-talk <span dir="ltr" class=""><<a href="mailto:ncl-talk@ucar.edu" target="_blank" class="">ncl-talk@ucar.edu</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
<div style="font-size: 13.3333px; font-family: serif; font-weight: 400; font-style: normal;" class="">
To whom it may concern,</div>
<div style="font-size: 13.3333px; font-family: serif; font-weight: 400; font-style: normal;" class="">
I decided to use wrf outputs and a tropical cyclone center location (from
JTWC) to define some circular nests around TC center with fixed radiuses. To
this aim, I used nggcog and gc_inout functions to define the circular nest
and determine the points that are in the defined circle. Now I need to now
which points are located on the circle. So I used gc_onarc function, but
defining the inputs for this function confused me. the two rightmost inputs
for gc_onarc are nggcog out puts with (/72,2/)dimension and dimension of the
last two left gc_onarc inputs are 3600. I do highly appreciate if help me.
The sample of code are attached as below:<br class="">
<br class="">
<br class="">
<br class="">
;<wbr class="">oooooooooooooooooooooooooooooo<wbr class="">oooooooooooooooooooooooooooo**<wbr class="">*************<br class="">
;<br class="">
;<br class="">
load "/usr/share/ncarg/nclscripts/<wbr class="">csm/gsn_code.ncl"<br class="">
load "/usr/share/ncarg/nclscripts/<wbr class="">csm/gsn_csm.ncl"<br class="">
load "/usr/share/ncarg/nclscripts/<wbr class="">csm/contributed.ncl"<br class="">
load "/usr/share/ncarg/nclscripts/<wbr class="">csm/shea_util.ncl"<br class="">
load "/usr/share/ncarg/nclscripts/<wbr class="">wrf/WRFUserARW.ncl"<br class="">
load "/usr/share/ncarg/nclscripts/<wbr class="">csm/skewt_func.ncl"<br class="">
<br class="">
begin<br class="">
;<wbr class="">oooooooooooooooooooooooooooooo<wbr class="">oooooooooooooooooooooooooooo**<wbr class="">************<br class="">
; add data from file<br class="">
;<wbr class="">ooooooooooooooooooooooooooooo*<wbr class="">********<br class="">
DATADir =
"/home/pegahfar/inio/haiyan/<wbr class="">data/wrfout_18_6_haiyan_MPI_8/<wbr class="">"<br class="">
FILES = systemfunc (" ls -1 " + DATADir +"wrfout*")<br class="">
print ("FILES="+FILES)<br class="">
<br class="">
lat_center = (/(/5.8, 5.8, 6.1, 6.1,6.1, 6.2, 6.3, 6.5,6.5, 6.5, 6.9,
7.1,7.3, 7.6, 7.9, 8.2,8.7, 9.3, 10.2, 10.6,11.0, 11.4, 11.9, 12.2,12.3,
13.5, 14.4, 15.4,16.5, 17.9, 19.4, 20.4,21.5, 22.4, 22.4 , 22.4/)/)<br class="">
;;;print (lat_center)<br class="">
<br class="">
lon_center =
(/(/157.2,157.2,155.5,153.3,<wbr class="">152.2,150.4,148.8,147.2,145.9,<wbr class="">144.6,142.9,141.3,139.7,138.0,<wbr class="">136.2,134.4,132.8,131.1,129.1,<wbr class="">126.9,124.8,122.5,120.5,118.0,<wbr class="">116.6,114.8,113.1,111.4,110.3,<wbr class="">109.0,108.0,107.5,107.1,107.7,<wbr class="">107.7,107.7/)/)<br class="">
<br class="">
do ifil =1,35,1<br class="">
<br class="">
a= addfile(FILES(ifil),"r") ; Open the next file<br class="">
times := wrf_user_getvar(a,"times",-1) ; get all times in
the file<br class="">
ntimes = dimsizes(times) ;
number of times in the file<br class="">
<br class="">
lat_wrf := a->XLAT(0,:,:)<br class="">
lon_wrf := a->XLONG(0,:,:)<br class="">
<br class="">
radius_outer_core=(7*RMW_km(<wbr class="">ifil))/110<br class="">
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;<br class="">
;;;;;;;;; /\ /\ /\ /\ start of define circle sized structure /\
/\ /\ /\ /\;;;;;;;;;;;;;;;;;;;;;;;;;;<br class="">
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;<br class="">
<br class="">
npoint_outer_core=144<br class="">
<br class="">
clat_outer_core = new(npoint_outer_core,float) ; arrays
to hold great circle<br class="">
clon_outer_core = new(npoint_outer_core,float)<br class="">
<br class="">
lat_location = lat_center(ifil) <br class="">
lon_location = lon_center(ifil)<br class="">
<br class="">
nggcog(lat_location,lon_<wbr class="">location,radius_outer_core,<wbr class="">clat_outer_core,clon_outer_<wbr class="">core)
; Calculate great circle<br class="">
<br class="">
min_lat_outer_core = min(clat_outer_core)
<br class="">
min_lon_outer_core = min(clon_outer_core)<br class="">
max_lat_outer_core = max(clat_outer_core)<br class="">
max_lon_outer_core = max(clon_outer_core)<br class="">
<br class="">
extrem_outer_core_lat=(/min_<wbr class="">lat_outer_core , max_lat_outer_core /)<br class="">
extrem_outer_core_lon=(/min_<wbr class="">lon_outer_core , max_lon_outer_core /)<br class="">
<br class="">
extrem_outer_core_inds=getind_<wbr class="">latlon2d (lat_wrf,lon_wrf,
extrem_outer_core_lat, extrem_outer_core_lon)<br class="">
<br class="">
;---Subset the desired rectagle of data<br class="">
<br class="">
loc_outer_core_circle:= getind_latlon2d (lat_wrf,lon_wrf, clat_outer_core,
clon_outer_core)<br class="">
<br class="">
lat_ind_over_c=loc_outer_core_<wbr class="">circle(:,0)<br class="">
lon_ind_over_c=loc_outer_core_<wbr class="">circle(:,1)<br class="">
<br class="">
;---Set points that are outside of the circle of data to missing<br class="">
<br class="">
lat_2d_outer_core:=lat_wrf(<wbr class="">extrem_outer_core_inds
(0,0):extrem_outer_core_inds(<wbr class="">1,0),extrem_outer_core_inds(0,<wbr class="">1):extrem_outer_core_inds(1,1)<wbr class="">)<br class="">
lon_2d_outer_core:=lon_wrf(<wbr class="">extrem_outer_core_inds
(0,0):extrem_outer_core_inds(<wbr class="">1,0),extrem_outer_core_inds(0,<wbr class="">1):extrem_outer_core_inds(1,1)<wbr class="">)<br class="">
<br class="">
in_circle_outer_core :=
gc_inout(lat_2d_outer_core,<wbr class="">lon_2d_outer_core,clat_outer_<wbr class="">core,clon_outer_core)<br class="">
<br class="">
size_in_circle_outer_core=<wbr class="">dimsizes(in_circle_outer_core)<br class="">
<br class="">
;;;;;;;;;;;;;; on arc ;;;;;;;;;;;<br class="">
<br class="">
clat_outer_core_size = dimsizes(clat_outer_core)<br class="">
print("clat_outer_core_size="+<wbr class="">clat_outer_core_size)<br class="">
<br class="">
clat_outer_core_2d=reshape(<wbr class="">clat_outer_core,(/<wbr class="">floattointeger(clat_outer_<wbr class="">core_size/2),2/))<br class="">
clon_outer_core_2d=reshape(<wbr class="">clon_outer_core,(/<wbr class="">floattointeger(clat_outer_<wbr class="">core_size/2),2/))<br class="">
<br class="">
size_lat_2d_outer_core=<wbr class="">dimsizes(lat_2d_outer_core)<br class="">
<br class="">
lat_2d_outer_core_reshape =
reshape(lat_2d_outer_core,(/<wbr class="">size_lat_2d_outer_core(0)*<wbr class="">size_lat_2d_outer_core(1),2/))<br class="">
lon_2d_outer_core_reshape =
reshape(lon_2d_outer_core,(/<wbr class="">size_lat_2d_outer_core(0)*<wbr class="">size_lat_2d_outer_core(1),2/))<br class="">
<br class="">
lat_2d_outer_core_to_1d = ndtooned(lat_2d_outer_core)<br class="">
lon_2d_outer_core_to_1d = ndtooned(lon_2d_outer_core)<br class="">
<br class="">
onarc_outer_core =
gc_onarc(lat_2d_outer_core_to_<wbr class="">1d,lon_2d_outer_core_to_1d,<wbr class="">clat_outer_core_2d,clon_outer_<wbr class="">core_2d)<br class="">
<br class="">
;;;;;;;;;;;;; on arc ;;;;;;;;;;;<br class="">
<br class="">
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;<br class="">
;;;;;;;;; /\ /\ /\ /\ end of define circle sized structure /\
/\ /\ /\ /\;;;;;;;;;;;;;;;;;;;;;;;;;;<br class="">
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<wbr class="">;;;;;;;;;;;;;;;;;;;;;<br class="">
end</div>
<div style="font-size: 13.3333px; font-family: serif; font-weight: 400; font-style: normal;" class="">
</div>
<div style="font-size: 13.3333px; font-family: serif; font-weight: 400; font-style: normal;" class="">
</div>
<div style="font-size: 13.3333px; font-family: serif; font-weight: 400; font-style: normal;" class="">
</div>
<div style="font-size: 13.3333px; font-family: serif; font-weight: 400; font-style: normal;" class="">
</div>
<div style="font-family: serif; font-size: 13.3333px; font-weight: 400; font-style: normal;" class="">
Best Regards<br class="">
==============================<wbr class="">===<br class="">
Nafiseh Pegahfar<br class="">
Assistant Professor<br class="">
Iranian National Institute for Oceanography and Atmospheric Science<br class="">
(<a href="http://www.inio.ac.ir/" target="_blank" class="">http://www.inio.ac.ir</a>)<br class="">
Phone: (0098)21- 66944873-5 Ext. 224<br class="">
Fax: (0098)21- 66944869<br class="">
Email: (<a href="mailto:pegahfar@inio.ac.ir" target="_blank" class="">pegahfar@inio.ac.ir</a>)<br class="">
(<a href="mailto:pegahfar@ut.ac.ir" target="_blank" class="">pegahfar@ut.ac.ir</a>)<br class="">
==============================<wbr class="">===</div>
</div>
<br class="">______________________________<wbr class="">_________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/<wbr class="">mailman/listinfo/ncl-talk</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">ncl-talk mailing list<br class=""><a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">List instructions, subscriber options, unsubscribe:<br class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</div></blockquote></div></div></body></html>