<div dir="ltr">Hi Mary,<div><br></div><div>Thanks, would you explain me what exactly the previous error dealing with ?</div><div>I did try also to go through this algorithm but not found yet what exactly the error was.</div><div><br></div><div style>Thank you,</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 10, 2014 at 4:00 AM, 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">I had an error in my code. Please see the new code.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I encourage you to learn how to debug this code and understand what's going on so you can extend it for your own use.</div><span class="HOEnZb"><font color="#888888"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><font><font>--Mary</font></font></div><div class="gmail_default" style="font-size:small"><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 3, 2014 at 6:04 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">Hallo Mary,<div><br></div><div>Im sorry for disturbing you with this email.</div><div>No solution so far i got to overcome this issue.</div><div>The algorithmn you suggested is failed once i change the number of sequences.</div><div><br></div><div>Really look fotward to your help.</div><div>Best regards,</div><div><br></div><div>Dr. Verena,</div><div><div><div><br></div><div><br></div><div><br><br>On Sunday, September 28, 2014, Verena Lili <<a href="mailto:verena.prick@gmail.com" target="_blank">verena.prick@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Mary and NCL,<div><br></div><div>The logics still produce errors and are not cosistent once I changed the number of sequences: </div><div>see below my test: I actually only have 5 consecutive series but the result was 7!</div><div><br></div><div><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><br></div><div><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 style="white-space:pre-wrap">        </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 style="white-space:pre-wrap">        </span>Min indexes of runs = 3</b></div><div><b>(1)<span style="white-space:pre-wrap">        </span>Min indexes of runs = 5</b></div><div><b>(2)<span style="white-space:pre-wrap">        </span>Min indexes of runs = 9</b></div><div><b>(3)<span style="white-space:pre-wrap">        </span>Min indexes of runs = 11</b></div><div><b>(4)<span style="white-space:pre-wrap">        </span>Min indexes of runs = 14</b></div><div><b>(5)<span style="white-space:pre-wrap">        </span>Min indexes of runs = 16</b></div><div><b>(6)<span style="white-space:pre-wrap">        </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>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><font color="#888888"><p>--Mary</p></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 20, 2014 at 12:55 AM, Verena Lili <span dir="ltr"><<a>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>ncl-talk@ucar.edu</a>" <<a>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>
</blockquote></div><br><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><br>
</div></div></blockquote></div><br></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>