any good way to count no. of specified events

From: Saji N. Hameed <saji_at_nyahnyahspammersnyahnyah>
Date: Thu, 4 Jun 2009 18:58:00 +0900

Dear NCL-ers,

  Suppose I have a 1D array of binaries (/1,1,1,0,0,0,1,0,0,1,1,1,1/)
  and I want to calculate number of 3 or more sucessive 1's
  (in this example, there are two such events)

  is there a good way to do that? FYI, I am trying to make an
  index of number of warm spells in a given period. I can write
  an algorithm with some do loops, but was wondering if there is
  a simpler way?

saji

ps: in ruby, i could have done perhaps this way
   irb> a=[1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1]
   irb> b=a.join.split(/[0]+/) # array to string, split string at multiple 0's
     => ["111", "1", "1111"]
   irb> b.map! {|num| (num.to_i>=111)? num=1 : num=nil}
     => [1, nil, 1]
   irb> b.nitems
     => 2

-- 
Saji N. Hameed
APEC Climate Center          				
1463 U-dong, Haeundae-gu,                               +82 51 745 3951
BUSAN 612-020, KOREA                    		saji_at_apcc21.net
Fax: +82-51-745-3999
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jun 04 2009 - 03:58:00 MDT

This archive was generated by hypermail 2.2.0 : Mon Jun 08 2009 - 09:30:31 MDT