<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="">Dave, <div class="">This is a very elegant solution. My sincere appreciation. </div><div class=""><br class=""></div><div class="">Prashanth <br class=""><div><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" class="">dave.allured@noaa.gov</a>> wrote:</div><br class="Apple-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" class="">https://en.wikipedia.org/wiki/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@<wbr class="">gmail.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 face="Palatino" size="4" class="">Hello all, </font><div class=""><font face="Palatino" size="4" class="">I have a relatively simple question on array indexing. </font></div><div class=""><font face="Palatino" size="4" class=""><br class=""></font></div><div class=""><font face="Palatino" size="4" 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 face="Palatino" size="4" class=""><br class=""></font></div><div class=""><font face="Palatino" size="4" class="">Array : theta [73]</font></div><div class=""><font face="Palatino" size="4" class="">Quadrant 1 : theta(13:31)</font></div><div class=""><font face="Palatino" size="4" class="">Quadrant 2: theta(31:49)</font></div><div class=""><font face="Palatino" size="4" class="">Quadrant 3: theta(49:67)</font></div><div class=""><font face="Palatino" size="4" color="#ff2600" class="">Quadrant 4: theta(67:13)</font></div><div class=""><font face="Palatino" size="4" color="#ff2600" class=""><br class=""></font></div><div class=""><font face="Palatino" size="4" 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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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 face="Palatino" size="4" 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 face="Palatino" size="4" class=""><br class=""></font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="Palatino" size="4" class="">Please let me know how this is possible. </font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="Palatino" size="4" class=""><br class=""></font></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="Palatino" size="4" class="">Thank you all, </font></span></div><span class="gmail-m_-8918605187357359177HOEnZb"><font color="#888888" class=""><div class=""><font face="Palatino" size="4" class="">Prashanth</font></div></font></span></div></blockquote></div></div></div></div></div>
</div></blockquote></div><br class=""></div></body></html>