<div dir="ltr">See Example 2 & 3<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 17, 2017 at 3:22 PM, Prashanth Bhalachandran <span dir="ltr"><<a href="mailto:prashanth.bhalachandran@gmail.com" target="_blank">prashanth.bhalachandran@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Dave, <div>This is a very elegant solution. My sincere appreciation. </div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888">Prashanth </font></span><div><div class="h5"><br><div><blockquote type="cite"><div>On Oct 17, 2017, at 2:10 PM, Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:</div><br class="m_8363830991614580715Apple-interchange-newline"><div><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" target="_blank">https://en.wikipedia.org/wiki/<wbr>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@gmail<wbr>.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 size="4" face="Palatino">Hello all, </font><div><font size="4" face="Palatino">I have a relatively simple question on array indexing. </font></div><div><font size="4" face="Palatino"><br></font></div><div><font size="4" face="Palatino">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 size="4" face="Palatino"><br></font></div><div><font size="4" face="Palatino">Array : theta [73]</font></div><div><font size="4" face="Palatino">Quadrant 1 : theta(13:31)</font></div><div><font size="4" face="Palatino">Quadrant 2: theta(31:49)</font></div><div><font size="4" face="Palatino">Quadrant 3: theta(49:67)</font></div><div><font size="4" face="Palatino" color="#ff2600">Quadrant 4: theta(67:13)</font></div><div><font size="4" face="Palatino" color="#ff2600"><br></font></div><div><font size="4" face="Palatino">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="m_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)"><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="m_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)"><span style="font-variant-ligatures:no-common-ligatures">(1)<span class="m_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)"><span style="font-variant-ligatures:no-common-ligatures">(2)<span class="m_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)"><span style="font-variant-ligatures:no-common-ligatures">(3)<span class="m_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)"><span style="font-variant-ligatures:no-common-ligatures">(4)<span class="m_8363830991614580715gmail-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="m_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)"><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="m_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)"><span style="font-variant-ligatures:no-common-ligatures">(1)<span class="m_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)"><span style="font-variant-ligatures:no-common-ligatures">(2)<span class="m_8363830991614580715gmail-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 size="4" face="Palatino">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 size="4" face="Palatino"><br></font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font size="4" face="Palatino">Please let me know how this is possible. </font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font size="4" face="Palatino"><br></font></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><font size="4" face="Palatino">Thank you all, </font></span></div><span class="m_8363830991614580715gmail-m_-8918605187357359177HOEnZb"><font color="#888888"><div><font size="4" face="Palatino">Prashanth</font></div></font></span></div></blockquote></div></div></div></div></div>
</div></blockquote></div><br></div></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>