[Thread Prev][Thread Next][Index]

Re: [ferret_users] How to change the value of an element of a variable?



Hi Xia,

If you need to change just that one element, then what Jaison suggests is exactly what you want to do, but here is a way to keep the name of the variable intact, using the SET VARIABLE/NAME= qualifier as follows. 

example: create a variable and save it in a netcdf file; then open that file and change one element.


   ! Define a variable and save it to a file.
   ! we want to change the value of 300 to the
   ! average of the surrounding points.
  
yes? LET a = {1,5,2,300,7,10,12}
yes? SAVE/CLOBBER/FILE=adat.nc a
 LISTing to file adat.nc

yes? CANCEL VAR/ALL

   ! Open the file and rename the variable to a new name.

yes? USE adat.nc
yes? SET VAR/NAME=a_bad a
yes? SHOW DATA

     currently SET data sets:
    1> ./adat.nc  (default)
 name     title                             I         J         K         L
 a_bad     {1,5,2,300,7,10,12}                1:7       ...       ...       ...
 
yes? LET a = IF I[GX=a_bad] EQ 4 THEN (a_bad[i=3] + a_bad[i=5])/2 ELSE a_bad
yes? LIST a
             VARIABLE : IF I[GX=a_bad] EQ 4 THEN (a_bad[I=3] + a_bad[I=5])/2 ELSE a_bad
             FILENAME : a.nc
             SUBSET   : 6 points (X)
 1   / 1:   1.00
 2   / 2:   5.00
 3   / 3:   2.00
 4   / 4:   4.50
 5   / 5:   7.00
 6   / 6:  10.00

   ! Save the fixed data to the same file.
yes? SAVE/APPEND/FILE=adat.nc a
 LISTing to file adat.nc

   ! Look to see what we did.
yes? CANCEL DATA/ALL
yes? CANCEL VAR/ALL
yes? USE adat.nc
yes? LIST a
             VARIABLE : {1,5,2,300,7,10}
             FILENAME : a.nc
             SUBSET   : 6 points (X)
 1   / 1:   1.00
 2   / 2:   5.00
 3   / 3:   2.00
 4   / 4:   4.50
 5   / 5:   7.00
 6   / 6:  10.00


Note that if you're fixing missing values of a variable, you will want to look at the transformations, such as the @FAV transformation, so that if there were a number of missing values which are marked by a flag, say a=999 then you would do

yes? set var/bad=999 a
yes? let a_fix = a[x=@FAV:3]

and this would fill all the missing data with the average of the two surrounding points.


Ansley

Xia Changshui wrote:
Dear all,

  I have a simple question which puzzles me for a long time. In Ferret how can I change the value of an element of a variable? For instance using set data a.nc I get an array a(100) into Ferret. If I want let the 50th element of the array 

a(50)=(a(49)+a(51))/2.0, How can I achieve this?

 

Thank you.

 

Xia


-- 

~>   ~>   ~>   ~>   ~>   ~>   ~>   ~>   ~>   ~>   ~> 

Ansley Manke, NOAA/PMEL   ansley.b.manke@xxxxxxxx
7600 Sand Point Way NE, Seattle WA
Phone 206-526-6246,  FAX 206-526-6744


[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement