<div dir="ltr">I was looking at the source as well -- not easy to understand. The function gives the correct answer for some simple test cases (eg, GC along prime meridian and a test point equator 90-degrees away). But clearly a wrong answer for your case, and seems wrong if the routine is using the entire great circle (?)<div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 10, 2017 at 10:41 AM, Joe Grim <span dir="ltr"><<a href="mailto:grim@ucar.edu" target="_blank">grim@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I wonder if gc_pnt2gc uses the entire great circle around the globe, and not just the shortest section between the two points defining the great circle, in calculating the distance.<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 10, 2017 at 10:39 AM, Joe Grim <span dir="ltr"><<a href="mailto:grim@ucar.edu" target="_blank">grim@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Alan,<br><br></div>That is a great workaround for this problem! I'll try your approach unless I can find a way to get gc_pnt2gc to work the way I want it to.<br><br></div>I looked up the source code, which is located at ncl/ni/src/lib/nfpfort/sg_tool<wbr>s.f, under FORTRAN function XDPGCDP, and was written by David Kennison. It would take me a while to figure it all out, so hopefully your workaround is fast enough for my purposes.<br><br></div>Thanks again!<span class="m_-147886874246614735HOEnZb"><font color="#888888"><br><br></font></span></div><span class="m_-147886874246614735HOEnZb"><font color="#888888">Joe<br></font></span></div><div class="m_-147886874246614735HOEnZb"><div class="m_-147886874246614735h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 10, 2017 at 9:55 AM, Alan Brammer <span dir="ltr"><<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">As another person who uses gc_latlon extensively but didn't know gc_pnt2gc existed. <br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">You could use gc_latlon to recreate gc_pnt2gc(). Definitely seems like that function is doing some weird stuff. <br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Though this wouldn't be directional but that could be worked out relatively easily. </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><div class="gmail_default"><br></div><div class="gmail_default">p_lat = 41.6</div><div class="gmail_default">p_lon = -76.84 </div><div class="gmail_default"><br></div><div class="gmail_default">lat = (/52.9921,55.3543/)</div><div class="gmail_default">lon = (/-168.693,-160.346/)</div><div class="gmail_default">dist = gc_pnt2gc(p_lat,p_lon,lat,lon)</div><div class="gmail_default"><br></div><div class="gmail_default">line = gc_latlon( lat(0), lon(0), lat(1), lon(1), 1000, 2) ;; create the GC path</div><div class="gmail_default">distances = gc_latlon(p_lat, p_lon, line@gclat, line@gclon, 0, 2) ;; find distances to GC path</div><div class="gmail_default">shortest = minind(distances)</div><div class="gmail_default"><br></div><div class="gmail_default">print ("The gc_pnt2gc distance is: " + dist)</div><div class="gmail_default">print ("The gc_latlon distance is: " + distances(shortest) )</div><div class="gmail_default"><br></div><div class="gmail_default"><span style="white-space:pre-wrap">; </span>The gc_pnt2gc distance is: -0.105952<br></div><div class="gmail_default">; The gc_latlon distance is: 53.5385<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 10, 2017 at 10:46 AM, Joe Grim <span dir="ltr"><<a href="mailto:grim@ucar.edu" target="_blank">grim@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Thank you, Dennis. Yes, I have used the gc_latlon function many times; it is very useful!<br><br>But, I am hoping to use a function that finds the distance between a point, and where it is closest to a line. If I can't, I'll just have to write my own function in FORTRAN instead to do that.<br><br></div>Hopefully someone else is familiar with the <b>gc_pnt2gc</b> function.<span class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472HOEnZb"><font color="#888888"><br><br></font></span></div><span class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472HOEnZb"><font color="#888888">Joe<b><br></b></font></span></div><div class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472HOEnZb"><div class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 10, 2017 at 8:12 AM, Dennis Shea <span dir="ltr"><<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi Joe,<br></div><div><br></div>I have never used the '<b>gc_pnt2gc</b>' function. Hopefully, somebody will address that function.<br><br></div><div>There us an alternative:<br> <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/gc_latlon.shtml" target="_blank">https://www.ncl.ucar.edu/Docum<wbr>ent/Functions/Built-in/gc_latl<wbr>on.shtml</a><br><br></div>Try the following interactively<br><br></div>%> ncl <return><br></div><div>Then enter the following<br></div><div><div><span><br>p_lat = 41.6<br>p_lon = -76.84<br>lat = (/52.9921,55.3543/)<br>lon = (/-168.693,-160.346/)<br></span>dist = gc_latlon(p_lat,p_lon,lat,lon,<wbr>10,2)<br></div><div>print(dist)<br></div><div><br>Variable: dist<br>Type: float<br>Total Size: 8 bytes<br> 2 values<br>Number of Dimensions: 1<br>Dimensions and sizes: [2]<br>Coordinates: <br>Number Of Attributes: 4<br> units : degrees<br> gclon : <ARRAY of 20 elements><br> gclat : <ARRAY of 20 elements><br> spacing : ( 6.551194, 5.948726 )<br><br>(0) 58.96074<br>(1) 53.53853<br><br>===<br></div><div>Cheers<br></div><div>D<br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472m_5731772318593252345h5">On Wed, Aug 9, 2017 at 1:21 PM, Joe Grim <span dir="ltr"><<a href="mailto:grim@ucar.edu" target="_blank">grim@ucar.edu</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472m_5731772318593252345h5"><div dir="ltr"><div><div><div><div><div><div>Hi,<br><br></div>I have used the function
gc_pnt2gc, but it doesn't appear to be doing what I think it should be
doing. I assume this is because I am misunderstanding it. What I think
it does is give the distance in degrees between a lat/lon point (p_lat,
p_lon), and its closest approach to the great circle line between two
other lat/lon pairs (lat[2], lon[2]: and I assume that this great circle
line is the shortest greatest circle line between these lat/lon
pairs.) Here is an example snippet of what I am trying to do:<br><br> p_lat = 41.6<br> p_lon = -76.84<br> lat = (/52.9921,55.3543/)<br> lon = (/-168.693,-160.346/)<br> dist = gc_pnt2gc(p_lat,p_lon,lat,lon)<br> print ("The distance is: " + dist)<br><br></div>Here is the output:<br>(0) The distance is: 0.105952<br><br></div>I would expect the distance to be something around 53 degrees.<br><br></div>Could
someone please explain to me what I am misunderstanding about this
function? And, do you know of another function that does what I am
trying to do? (That is, find the shortest distance between a point and a
line on the Earth.)<br><br></div>Thank you!<span class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472m_5731772318593252345m_-6134214703216481583HOEnZb"><font color="#888888"><br><br></font></span></div><span class="m_-147886874246614735m_-7453196106184047091m_-6280377129885226472m_5731772318593252345m_-6134214703216481583HOEnZb"><font color="#888888">Joe Grim<br></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>