Re: Maximum number of consecutive days

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Jun 21 2012 - 16:06:04 MDT

A 'simple' example to determine the max run length

   x = (/1,0,1,0,1,1,1,0,1,1,0,1,1,0/)
   r0 = dim_numrun_n (x, 0, 0) ; ==> r0=(/9,4,1,0,0,0,0,0,0,0,0,0,0,0/)
   indmx = ind(r0.ne.0) ; ==> (/0, 1, 2 /)
   print(indmx)

   mxrun = indmx(dimsizes(indmx)-1) + 1 ; add one to NCL 0-based indexing
   print(mxrun) ; ==> mxrun=3

====

A sample function and test script is attached. It must be loaded prior
to use

   x = where(prec.gt.5, 1, 0) ; set prec>5 to 1 else 0
   runs = dim_num_n(x) ; calculate runs
   maxrun = maxrunlen( runs ) ; max run length(s) at each grid point

Good Luck
D

On 6/20/12 9:12 PM, debasish@sca.uqam.ca wrote:
> Dear Dennis,
>
> Thanks for your suggestion. It works. "dim_numrun_n" counts the number of
> sequences 1. However I need to calculate maximum number of days.
> For example:
> x = (/1,0,1,0,1,1,1,0,1,1,0,1,1,0/)
> r0 = dim_numrun_n (x, 0, 0) ; ==> r0=(/9,4,1,0,0,0,0,0,0,0,0,0,0,0/)
> here maximum number of days =3 (or the 3rd index of r0)
> I am not sure how do I calculate this
>
> Any suggestion will be appreciated.
>
>
>>>
>>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_numrun_n.shtml
>>>>
>>>> Available in version 6.1.0-beta and later.
>>>>
>>>>
>>>> On 6/20/12 1:12 PM, debasish@sca.uqam.ca wrote:
>>>>> Dear NCL users,
>>>>>
>>>>> I have a variable x(days). I need to calculate maximum number of
>>>>> consecutive days where x is less than 5.
>>>>>
>>>>> How do I solve this in NCL
>>>>>
>>>>> with regards
>>>>>
>>>>> Deb
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>
>>
>

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

Received on Thu Jun 21 16:06:21 2012

This archive was generated by hypermail 2.1.8 : Mon Jun 25 2012 - 09:57:23 MDT