[ncl-talk] running sequence of 0s and 1s [SEC=UNCLASSIFIED]

Griffith Young griffith.young at bom.gov.au
Tue Mar 7 21:19:41 MST 2017

```Hello Peter,

Not if you go to the casino and are doubling up your bet.

This code seems to work...

v = {vector or array of 1's and 0's}
c = v
t = 0
do i = 0, dimsizes(v) - 1
if v(i) .eq. 0 then
c(i) = 0
t = 0
end if
if (v(i) .eq. 1) then
c(i) = t
t = t + 1
end if
end do

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."

Regards, Griff.

From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Dennis Shea
Sent: Wednesday, 8 March 2017 2:59 PM
To: Peter Gibson
Cc: ncl-talk at ucar.edu
Subject: Re: [ncl-talk] running sequence of 0s and 1s

Sorry, no. Pretty specialized function ...
: 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 ...  input: 1st 1 is a flag
: 0 0 0 0 1 0 0 1 2 3 4 0 0 1 2 0

On Tue, Mar 7, 2017 at 8:17 PM, Peter Gibson <peter.gibson at unsw.edu.au<mailto:peter.gibson at unsw.edu.au>> wrote:
Hello,

Is there a function to calculate the running length of 0/1s in a sequence in NCL?

for example if I had a vector     v : 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 ...
the running sequence would be   : 0 0 0 0 1 0 0 1 2 3 4 0 0 1 2 0 ...

I see the function dim_numrun counts the number of unique sequence lengths which is similar but not exactly what I am after ....

Thanks,

Peter

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170308/c9c98f5d/attachment.html
```