# Re: [ferret_users] hand-editing a variable

```Hi Emilie,
Though it is easy to find a logic to do that, it is bit
tricky to get it done in Ferret. Here is the logic and an example.

1. List the "L" values of 12 time points (where all the variable to be
set to zero) to a text file. Read this 12 values to a new variable
and define a time axis (abstract one, NOT calendar) based on these
values.

2. Use the "L" values of original variable to define an abstract time axis.
Regrid the above time axis to this one using @XACT transformation.

3. Use IF condition to get 0 value at propoer time step (define a mask).

4. Multiply original variable with this mask .... done !!!

Please have a look at the example below. You may change the dataset
numbers accordingly (d=1, d=2 stuff). Let me know if you face any problems.

Hope this helps

Regards

Jaison

!--------Example------------------------------------------------------
\ cancel mode verify
!
! 3D variable (lon,lat,time), dt = 30 minutes,  time size = 1 year
!
! to do : set var=0 at each time when the time step equals the first of every
!           month
!-------------------------------------------------------------------------

! let us create a dummy variable

define axis/x=30:120:2/units=longitudes xlon
define axis/y=-30:30:2/units=latitudes  ylat
define axis/t="01-JAN-2003:00":"31-DEC-2003:00":30/units=minutes\
/T0="31-DEC-2002:00" tmin

let var = SIN(X[gx=xlon]/20) + COS(y[gy=ylat]/20) + TAN(t[gt=tmin]/15)

fill/l=1 var

! Extract the time points where var is to be set to zero

cancel reg/all  ! very important...keep it here itself

let l_start = `var,r=lstart`  ! let l_start = `var[d=1],r=lstart`
let l_end   = `var,r=lend`    ! let l_end   = `var[d=1],r=lend`

let months = TSEQUENCE({"JAN","FEB","MAR","APR","MAY","JUN","JUL",\
"AUG","SEP","OCT","NOV","DEC"})
sp rm -f dummy_L.dat
REPEAT/RANGE=1:12:1/NAME=mm ( ;\
define symbol mon = `mm`  ;\
L[gt=var,t="01-`months[l=(\$mon)]`-2003:00"] ;\
)

! Read in the extracted time points

define axis/t=1:12:1 tax
define grid/t=tax    gfile

FILE/grid=gfile/var=lindex dummy_L.dat ! the default dataset now

! do it !!

define axis/t=`l_start`:`l_end`:1 tabs

define axis/t/from_data tabs_12=lindex[d=1]  ! in ur case, lindex[d=2]

let t_mask_0 = t[gt=tabs_12]*0 + 100

! remove intermediate files

sp rm -f dummy_L.dat

!----------end of example---------------------------------------------------

On Wed, 26 Apr 2006, Emilie Vanvyve wrote:

```
```Hi everyone,

Isearched in the online help and the mail archives and couldn't find a solution
to my problem, so here I am.

I have a 3D variable (lon,lat,time), with a 30-minutes time step over a whole
year. I'd like to replace my variable value by 0 each time the time step equals
the first of every month, i.e.:
if "we are on the 1st of January 0:00" then "reset variable to zero" else "keep it
as it is"
if "we are on the 1st of February 0:00" then "reset variable to zero" else "keep
it as it is"
etc.

How can I achieve this? I tried with a simple if, it didn't work (here after, let's
say the time step at which the variable "var" must be reset to 0 is the time
step 100):

if `L eq 100` then let new_var = 0*var else let new_var = var
or
let new_var = if `L eq 100` then 0*var else var

It doesn't work. I always get something like:
**ERROR: invalid command: grave accent doesnt evaluate to scalar
L eq 100

I don't mind if the solution takes time to be implemented, as long as it works.
I've only 12 changes to make in the variable.

Thanks in advance for any suggestion!

Emilie V.

------------------------------------------------------
Emilie VANVYVE
Physicist, PhD student

Université catholique de Louvain (UCL)
Institut d'astronomie et de géophysique G. Lemaître (ASTR)
Chemin du Cyclotron, 2, B-1348 Louvain-la-Neuve, Belgium
Phone: +32-(0)10-473300   Fax: +32-(0)10-474722
E-mail: vanvyve@astr.ucl.ac.be   Web : www.astr.ucl.ac.be/u/vanvyve

```