<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="">Great job of immediately putting it up as an example accessible to everyone. That reply was certainly helpful. <div class=""><br class=""></div><div class="">Prashanth </div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 18, 2017, at 12:47 PM, Dennis Shea <<a href="mailto:shea@ucar.edu" class="">shea@ucar.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Oops!<br class=""><br class=""><a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/mod.shtml" class="">https://www.ncl.ucar.edu/Document/Functions/Contributed/mod.shtml</a><br class=""><br class=""></div>Examples 2 & 3<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Oct 18, 2017 at 1:46 PM, Dennis Shea <span dir="ltr" class=""><<a href="mailto:shea@ucar.edu" target="_blank" class="">shea@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 dir="ltr" class="">See Example 2 & 3<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote"><div class=""><div class="h5">On Tue, Oct 17, 2017 at 3:22 PM, Prashanth Bhalachandran <span dir="ltr" class=""><<a href="mailto:prashanth.bhalachandran@gmail.com" target="_blank" class="">prashanth.bhalachandran@<wbr class="">gmail.com</a>></span> wrote:<br class=""></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class="h5"><div style="word-wrap:break-word" class="">Dave, <div class="">This is a very elegant solution. My sincere appreciation. </div><span class="m_3384585704593649385HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div></font></span><div class=""><span class="m_3384585704593649385HOEnZb"><font color="#888888" class="">Prashanth </font></span><div class=""><div class="m_3384585704593649385h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Oct 17, 2017, at 2:10 PM, Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank" class="">dave.allured@noaa.gov</a>> wrote:</div><br class="m_3384585704593649385m_8363830991614580715Apple-interchange-newline"><div class=""><div dir="ltr" class="">Prashanth,<div class=""><br class=""></div><div class="">I like using a modulo calculation and vector subscripting for cyclic indexing. This reduces possible errors from hard coded indexing. Something like this:</div><br class=""> theta = 20<br class=""> lons = 10.0 * ispan (0,35,1)<br class=""> offset = mod (lons + 360 - theta, 360)<br class=""><br class=""> iq1 = ind (offset .le. 90)<br class=""> iq2 = ind (offset .ge. 90 .and. offset .le. 180)<br class=""> iq3 = ind (offset .ge. 180 .and. offset .le. 270)<br class=""> iq4 = ind (offset .ge. 270)<div class=""><br class=""></div><div class="">Note that this can create overlapping index points in some cases. For no overlap, change .le. to .lt. in 3 places.</div><div class=""><br class=""></div><div class="">In the mod expression, it is important to add an extra 360 degrees, to prevent negative values in the first mod argument. What this really does is convert the NCL mod function to a true mathematical modulo function for cyclic applications. Understand the difference here:</div><div class=""><br class=""></div><div class=""> <a href="https://en.wikipedia.org/wiki/Modulo_operation" target="_blank" class="">https://en.wikipedia.org/wiki/<wbr class="">Modulo_operation</a></div><div class=""><div class=""><br class=""></div><div class="">--Dave</div><div class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Oct 17, 2017 at 1:19 PM, Prashanth Bhalachandran <span dir="ltr" class=""><<a href="mailto:prashanth.bhalachandran@gmail.com" target="_blank" class="">prashanth.bhalachandran@gmail<wbr class="">.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><font size="4" face="Palatino" class="">Hello all, </font><div class=""><font size="4" face="Palatino" class="">I have a relatively simple question on array indexing. </font></div><div class=""><font size="4" face="Palatino" class=""><br class=""></font></div><div class=""><font size="4" face="Palatino" class="">Say, I have an array that is cyclic that contains values from 0 to 360 in steps of 5 degrees (dimension [72]). And I am trying to divide into four quadrants starting from a given theta. Say that the index of the given theta is 13 (out of 73), I define my quadrants that are each 90 degrees as follows : </font></div><div class=""><font size="4" face="Palatino" class=""><br class=""></font></div><div class=""><font size="4" face="Palatino" class="">Array : theta [73]</font></div><div class=""><font size="4" face="Palatino" class="">Quadrant 1 : theta(13:31)</font></div><div class=""><font size="4" face="Palatino" class="">Quadrant 2: theta(31:49)</font></div><div class=""><font size="4" face="Palatino" class="">Quadrant 3: theta(49:67)</font></div><div class=""><font size="4" face="Palatino" color="#ff2600" class="">Quadrant 4: theta(67:13)</font></div><div class=""><font size="4" face="Palatino" color="#ff2600" class=""><br class=""></font></div><div class=""><font size="4" face="Palatino" class="">Now, as you’ll notice, having an index of 67:13 doesn’t imply 67:72 and 0:13, it simply implies 13:67 backwards. How do I index the array such that it takes it in a cyclic fashion? For example (what I don’t want is), in a simpler array of just five dimensions : </font><span style="color:rgb(77,47,45);font-family:Courier;font-size:16px;background-color:rgb(237,234,212)" class="">Variable: a</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Type: integer</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Total Size: 20 bytes</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 5 values</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of Dimensions: 1</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Dimensions and sizes:<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>[5]</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Coordinates: </span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(0)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>1</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(1)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>2</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(2)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>3</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(3)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>4</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(4)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>5</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">ncl 3> print(a(4:2)) </span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212);min-height:19px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212);min-height:19px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Variable: a (subsection)</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Type: integer</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Total Size: 12 bytes</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 3 values</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of Dimensions: 1</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Dimensions and sizes:<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>[3]</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Coordinates: </span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(0)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>5</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(1)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>4</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(2)<span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap"> </span>3</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font size="4" face="Palatino" class="">What I would have liked it is for it to display 5 1 2 3. </font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font size="4" face="Palatino" class=""><br class=""></font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font size="4" face="Palatino" class="">Please let me know how this is possible. </font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font size="4" face="Palatino" class=""><br class=""></font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font size="4" face="Palatino" class="">Thank you all, </font></span></div><span class="m_3384585704593649385m_8363830991614580715gmail-m_-8918605187357359177HOEnZb"><font color="#888888" class=""><div class=""><font size="4" face="Palatino" class="">Prashanth</font></div></font></span></div></blockquote></div></div></div></div></div>
</div></blockquote></div><br class=""></div></div></div></div><br class=""></div></div><span class="">______________________________<wbr class="">_________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" target="_blank" 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/mailma<wbr class="">n/listinfo/ncl-talk</a><br class="">
<br class=""></span></blockquote></div><br class=""></div>
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>