<div dir="ltr">Prashanth,<div><br></div><div>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>    theta = 20<br>    lons = 10.0 * ispan (0,35,1)<br>    offset = mod (lons + 360 - theta, 360)<br><br>    iq1 = ind (offset .le. 90)<br>    iq2 = ind (offset .ge. 90 .and. offset .le. 180)<br>    iq3 = ind (offset .ge. 180 .and. offset .le. 270)<br>    iq4 = ind (offset .ge. 270)<div><br></div><div>Note that this can create overlapping index points in some cases.  For no overlap, change .le. to .lt. in 3 places.</div><div><br></div><div>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><br></div><div>    <a href="https://en.wikipedia.org/wiki/Modulo_operation">https://en.wikipedia.org/wiki/Modulo_operation</a></div><div><div><br></div><div>--Dave</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 17, 2017 at 1:19 PM, Prashanth Bhalachandran <span dir="ltr"><<a href="mailto:prashanth.bhalachandran@gmail.com" target="_blank">prashanth.bhalachandran@<wbr>gmail.com</a>></span> wrote:<br><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"><font face="Palatino" size="4">Hello all, </font><div><font face="Palatino" size="4">I have a relatively simple question on array indexing. </font></div><div><font face="Palatino" size="4"><br></font></div><div><font face="Palatino" size="4">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><font face="Palatino" size="4"><br></font></div><div><font face="Palatino" size="4">Array : theta [73]</font></div><div><font face="Palatino" size="4">Quadrant 1 : theta(13:31)</font></div><div><font face="Palatino" size="4">Quadrant 2: theta(31:49)</font></div><div><font face="Palatino" size="4">Quadrant 3: theta(49:67)</font></div><div><font face="Palatino" size="4" color="#ff2600">Quadrant 4: theta(67:13)</font></div><div><font face="Palatino" size="4" color="#ff2600"><br></font></div><div><font face="Palatino" size="4">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)">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">            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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">(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)"><span style="font-variant-ligatures:no-common-ligatures">(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)"><span style="font-variant-ligatures:no-common-ligatures">(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)"><span style="font-variant-ligatures:no-common-ligatures">(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)"><span style="font-variant-ligatures:no-common-ligatures">(4)<span class="gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap">     </span>5</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;font-size:16px;line-height:normal;font-family:Courier;color:rgb(77,47,45);background-color:rgb(237,234,212)"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures"></span><br></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"><span style="font-variant-ligatures:no-common-ligatures"></span><br></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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">            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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">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)"><span style="font-variant-ligatures:no-common-ligatures">(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)"><span style="font-variant-ligatures:no-common-ligatures">(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)"><span style="font-variant-ligatures:no-common-ligatures">(2)<span class="gmail-m_-8918605187357359177m_255683083388027187Apple-tab-span" style="white-space:pre-wrap">     </span>3</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font face="Palatino" size="4">What I would have liked it is for it to display 5 1 2 3. </font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font face="Palatino" size="4"><br></font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font face="Palatino" size="4">Please let me know how this is possible. </font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font face="Palatino" size="4"><br></font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font face="Palatino" size="4">Thank you all, </font></span></div><span class="gmail-m_-8918605187357359177HOEnZb"><font color="#888888"><div><font face="Palatino" size="4">Prashanth</font></div></font></span></div></blockquote></div></div></div></div></div>