<div dir="ltr"><div>Never underestimate Aussie brute force! <br></div><div><br></div><div><br></div><div>==========<br>undef("gibson_young")<br>function gibson_young(q[*]:numeric)<br>local nq, qsum, n, t <br>begin<br> nq = dimsizes(q)<br> qsum = conform(q, 0, -1) ; initialize to 0<br><br> do n=0,nq-1<br> if (q(n).eq.0) then<br> t = 0<br> end if<br><br> if (q(n).eq.1) then<br> qsum(n) = t<br> t = t + 1<br> end if<br> end do<br><br> return(qsum)<br>end<br>;<br>; desired result: 0 0 0 0 1 0 0 1 2 3 4 0 0 1 2 0<br> q = (/0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0/)<br> qsum = gibson_young(q)<br> print(q+" "+qsum)<br><br>===<br><br><br><br>(0) 0 0<br>(1) 0 0<br>(2) 0 0<br>(3) 1 0<br>(4) 1 1<br>(5) 0 0<br>(6) 1 0<br>(7) 1 1<br>(8) 1 2<br>(9) 1 3<br>(10) 1 4<br>(11) 0 0<br>(12) 1 0<br>(13) 1 1<br>(14) 1 2<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 7, 2017 at 9:19 PM, Griffith Young <span dir="ltr"><<a href="mailto:griffith.young@bom.gov.au" target="_blank">griffith.young@bom.gov.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-AU">
<div class="m_5748270439688318660WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hello Peter,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Not if you go to the casino and are doubling up your bet.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">This code seems to work...<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">v = {vector or array of 1's and 0's}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">c = v<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">t = 0<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">do i = 0, dimsizes(v) - 1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> if v(i) .eq. 0 then<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> c(i) = 0<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> t = 0<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> end if<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> if (v(i) .eq. 1) then<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> c(i) = t<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> t = t + 1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> end if<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">end do<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Caveat: "Since NCL is an interpreted language, it is best to avoid do loops as much as possible. They can cause considerable slow downs. Small loops should
not be a problem."<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Regards, Griff.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US"> <a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a> [mailto:<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.<wbr>edu</a>]
<b>On Behalf Of </b>Dennis Shea<br>
<b>Sent:</b> Wednesday, 8 March 2017 2:59 PM<br>
<b>To:</b> Peter Gibson<br>
<b>Cc:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
<b>Subject:</b> Re: [ncl-talk] running sequence of 0s and 1s<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Sorry, no. Pretty specialized function ...<u></u><u></u></p>
</div>
<p class="MsoNormal">: 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 ... input: 1st 1 is a flag<u></u><u></u></p>
<div>
<p class="MsoNormal">: 0 0 0 0 1 0 0 1 2 3 4 0 0 1 2 0<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, Mar 7, 2017 at 8:17 PM, Peter Gibson <<a href="mailto:peter.gibson@unsw.edu.au" target="_blank">peter.gibson@unsw.edu.au</a>> wrote:<u></u><u></u></p>
<div>
<div id="m_5748270439688318660m_-7703457688712157601divtagdefaultwrapper">
<div>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:black">Hello,<br>
<br>
Is there a function to calculate the running length of 0/1s in a sequence in NCL?<br>
<br>
for example if I had a vector v : 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 ...<br>
the running sequence would be : 0 0 0 0 1 0 0 1 2 3 4 0 0 1 2 0 ...<br>
<br>
I see the function dim_numrun counts the number of unique sequence lengths which is similar but not exactly what I am after .... <u></u><u></u></span></p>
</div>
<p><span style="font-family:"Calibri","sans-serif";color:black"><u></u> <u></u></span></p>
<p><span style="font-family:"Calibri","sans-serif";color:black">Thanks,<u></u><u></u></span></p>
<p><span style="font-family:"Calibri","sans-serif";color:black">Peter<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</blockquote></div><br></div>