<div dir="ltr">Hi Mary and NCL,<div><br></div><div style>The logics still produce errors and are not cosistent once I changed the number of sequences: </div><div style>see below my test: I actually only have 5 consecutive series but the result was 7!</div><div style><br></div><div style><b>x = (/</b>-999,-999<b>,9,5,4,6</b>,-999,-999<b>,6,5,</b>-999<b>,7,</b>-999<b>,25,17,3,2,13,</b>-999<b>,-5,</b>-999<b>/)</b></div><div style><br></div><div style><div>x@_FillValue = -999</div><div><br></div><div>nx = dimsizes(x)</div><div><br></div><div>run_inds = new(nx,integer) ; array to hold minimum indexes of runs</div><div>beg_ind = -1 ; variables to hold begin and end indexes</div><div>end_ind = -1 ; of consecutive sequences of numbers</div><div>irun = 0 ; counter for number of runs</div><div><br></div><div>;---Loop through each element and collect groups of runs.</div><div>do n=0,nx-1</div><div> if(ismissing(x(n))) then</div><div>;---Check for a run</div><div> if(beg_ind.ne.-1) then</div><div> run_inds(irun) = beg_ind + minind(x(beg_ind:end_ind))</div><div> irun = irun + 1</div><div> beg_ind = -1 ; reset back to -1</div><div> end if</div><div> continue</div><div> end if</div><div> if(beg_ind.eq.-1) then</div><div>;---Start a new run</div><div> beg_ind = n</div><div> end_ind = n</div><div> prev_ind = n ; to keep track of consecutive inds</div><div> else</div><div>;---Still in a run</div><div> if((n-prev_ind).eq.1) then</div><div> end_ind = n</div><div> else</div><div>;---End a current run</div><div> run_inds(irun) = beg_ind + minind(x(beg_ind:end_ind))</div><div> irun = irun + 1</div><div> beg_ind = -1 ; reset back to -1</div><div> end if</div><div> end if</div><div>;---Special case if on the last number</div><div> if(n.eq.(nx-1).and.beg_ind.ne.-1) then</div><div> run_inds(irun) = beg_ind + minind(x(beg_ind:end_ind))</div><div> irun = irun + 1</div><div> end if</div><div>end do</div><div><br></div><div>print("Number of runs = " + irun)</div><div>print("Min indexes of runs = " + run_inds(0:irun-1))</div><div><br></div><div><br></div><div><div><b>ncl 43> print("Number of runs = " + irun)</b></div><div><b>(0)<span class="" style="white-space:pre">        </span>Number of runs = 7</b></div><div><b><br></b></div><div><b>ncl 44> print("Min indexes of runs = " + run_inds(0:irun-1))</b></div><div><b>(0)<span class="" style="white-space:pre">        </span>Min indexes of runs = 3</b></div><div><b>(1)<span class="" style="white-space:pre">        </span>Min indexes of runs = 5</b></div><div><b>(2)<span class="" style="white-space:pre">        </span>Min indexes of runs = 9</b></div><div><b>(3)<span class="" style="white-space:pre">        </span>Min indexes of runs = 11</b></div><div><b>(4)<span class="" style="white-space:pre">        </span>Min indexes of runs = 14</b></div><div><b>(5)<span class="" style="white-space:pre">        </span>Min indexes of runs = 16</b></div><div><b>(6)<span class="" style="white-space:pre">        </span>Min indexes of runs = 19</b></div></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 22, 2014 at 12:26 PM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@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 class="gmail_default" style="font-size:small">Lili,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">In the future, please do not post questions to individual developers when you don't get a response on ncl-talk. It's okay to repost to ncl-talk after a few days, because we generally try to answer all questions.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You will need to loop through your array and get the start and end index of each consecutive sequence of numbers, and then use NCL's minind function to get the index of the minimum of this subset, "i = minind(x(beg_index:end_index)". There may be a "cleaner" way to do this, but this script should work.</div><div class="gmail_default" style="font-size:small">
<p>See attached script which uses a slightly more complex input array.</p><span class="HOEnZb"><font color="#888888"><p>--Mary</p></font></span></div><div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 20, 2014 at 12:55 AM, Verena Lili <span dir="ltr"><<a href="mailto:verena.prick@gmail.com" target="_blank">verena.prick@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 dir="ltr"><div><div><div>Hi Mary,<br><br></div>I posted this email to ncl talk (see below) and not getting any response since then. Would you please help me on this simple issue?<br></div>I've been struggling to figure this out, but not yet get a conclusive<br>result<br><br></div>thank you<br><br><br><div><div><div><div><div class="gmail_quote">=======================<br>Subject: how to get min index within different sequences<br>To: "<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>" <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><div><div><br><br><br><div dir="ltr"><div><div><div>Hallo,<br><br></div>Anyone can suggest how to get the index of the minimum values within different<br></div>sequences:<br><br>e.g.:<br><br></div> x = (/-3, -2, -1, 4, 5, 6, 0, -2, 5/)<br><br> x@_FillValue=-999 <br> x = where(x.gt.3,x, x@_FillValue) ; only x>3<br><div> print(x)<br><br>Variable: x<br>(0) -999<br>(1) -999<br>(2) -999<br>(3) 4<br>(4) 5<br>(5) 6<br>(6) -999<br>(7) -999<br>(8) 5<br><br></div><div>; then, how to get <b>index</b> pointing the minimum value within these two sequences (3)-(5) and (8),<br>so that the out put will be index:<br><br></div><div><b>3 and 8</b><br><br></div><div>Thank you.<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div><br clear="all"></div><div><div><div><div><div><br>-- <br><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Regards,</div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Dr. Verena.</div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="verdana, sans-serif">School of Marine and Atmospheric Sciences<br>Stony Brook University</font><div><span style="font-family:verdana,sans-serif">homepage: </span><a href="http://www.somas.stonybrook.edu/" target="_blank">http://www.somas.stonybrook.edu/</a></div></div></div>
</div></div></div></div></div></font></span></div>
</div></div></div><div><div><br><br clear="all"><br>-- <br><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Regards,</div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Dr. Verena.</div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="verdana, sans-serif">School of Marine and Atmospheric Sciences<br>Stony Brook University</font><div><span style="font-family:verdana,sans-serif">homepage: </span><a href="http://www.somas.stonybrook.edu/" target="_blank">http://www.somas.stonybrook.edu/</a></div></div></div>
</div></div></div></div></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Regards,</div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Dr. Verena.</div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="verdana, sans-serif">School of Marine and Atmospheric Sciences<br>Stony Brook University</font><div><span style="font-family:verdana,sans-serif">homepage: </span><a href="http://www.somas.stonybrook.edu/" target="_blank">http://www.somas.stonybrook.edu/</a></div></div></div>
</div>