# Re: [ferret_users] working with data of a month over the years

```Hi Ansley and Peter,
This method remains the simplest one, but two points
should be taken careoff:

1. The output of MOD(T[GT=precip], 360) function depends CRUCIALLY on T0
and time units. Hence, a correction for T0 (so that the MOD function
returns 1 for all 01-JAN and 30 for all 30-JAN) is required.

2. Assume that time value 1 implies 01-JAN. Then, multiples of 360 (ie
30-DEC) will result in "0" residue and which is not accounted for
in the present IF statement.

Please have a trial with the stand alone example given below. Use the
second method to get accurate results.

Pleaes let me know if you have any questions.

Best regards,

Jaison

!---------------example starts here-------------------------------
\cancel mode verify
! Description : Example script for extracting January data from a daily
!                  30-year time series on 360-day calendar.
!
!-----------------------------------------------------------------

!--create a dummy variable : 360_DAY calendar, daily, 30-years

define axis/t=01-JAN-1971:30-DEC-2000:1/units=days/calendar=360_DAY\
/t0=30-JAN-1971  t30yr
let var = SIN(t[gt=t30yr]/500)

!---This method will result in wrong answer

let year_days  =  MOD(t[gt=var],360)
let daily_mask =  IF year_days LE 30 THEN 1
let var_jan    = COMPRESSL(var_jan_all)
let jan_pts    = var_jan[l=@NGD]
list jan_pts

!---The accurate method....

! 1.  assume that time units are days
! 2.  remove the effects of T0 on T-values
! 3.  account for 30-DEC (or multiples of 360)

let t_jan_base =  T[gt=var] - t[gt=var,t=01-JAN-1971] + 1  ! step 2
let year_days  =  MOD(t_jan_base,360)
let daily_mask =  IF year_days GE 1 AND year_days LE 30 THEN 1 ! step 3
let var_jan    = COMPRESSL(var_jan_all)
let jan_pts    = var_jan[l=@NGD]
list jan_pts

!---------------example ends   here-------------------------------

On Thu, 03 Jan 2008 09:22:36 -0800, Ansley Manke wrote
> Hi,
> In Ferret, anytime you find yourself using REPEAT loops, it's a good
> idea to think whether there's a way to define an expression that
> will do the same thing.  Here's an FAQ that does something similar
> to what you're trying:
>
> http://ferret.pmel.noaa.gov/FERRET_17sep07/FAQ/analysis/
>
> The example in the FAQ has daily data, as yours is, so you will be
> able to use the example directly to define a mask for days between 1
> and 30.  It looks as if you have a 360-day year, is that correct?
> If so, and if the variable in your file were called precip, then
>
>     yes? LET year_days = MOD(T[GT=precip], 360)
>     yes? LET daily_mask = IF year_days LE 30 THEN 1
>
>     yes? LET precip1 = precip * daily_mask
>
> This will give you a variable with 30 days of precip data, then 330
> days of missing data, and so forth.  Try these commands to see what
> you've done (choosing some location where your data exists to plot
> precip1)
>
>     yes? PLOT/x=180/y=0 precip1
>
> You could use a COMPRESSL function to put all the January data
> together without the gaps if that would be useful for your analysis:
>
> yes? show function compressL
> COMPRESSL(DAT)
>     Returns data, compressed along the L axis: Missing points moved
> to the end    DAT: variable to compress in L yes? LET precip_jan =
> compressL(precip1) ...
>
> Peter Szabo wrote:
> > Dear Ferreters,
> >
> > I am using ferret on XP. I have equally spaced daily data in time (30days*
> > 12months* 30years). I would like to eliminate everything but data of
january
> > over the years i order that i could do other things with the january data.
> >
> > I tried looking it up in the archives and I tried with the following but
> > have not succeeded yet:
> > -----------------
> > repeat/l=1:10800:1 (let precip2=if ((`l` ge 1 and `l` le 30) or (`l` ge
361
> > and `l` ge 390) or (`l` ge 721 and `l` le 750) or (`l` ge 1081 and `l` le
> > 1110) or....(and so on)....) then precip else precip*0.0)
> > -----------------
> > Does anyone can help me?
> >
> > Peter Szabo
> > elte
> >
> >
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

```