[Thread Prev][Thread Next][Index]

Re: [ferret_users] Define, change/add/remove element in an array.




With SET VARIABLE/NAME, you can get around the downside of renaming variables. Say a variable in a datset is called TEMP and you want to keep that name.

yes? use mydata
yes? set var/name=temp_in temp
yes? let/units="Deg K"/title="`temp_in,return=title`"  temp = temp_in + 273.15
The same thing works with user-defined variables.  Also, Nicholas, here's how to add more elements to your variable with the XCAT function:
yes? let temp = {1,2,3}
yes? let temp2 = {4,5}

! Rename the first variable
yes? set var/name=temp1 temp

! Append new values, giving the new variable the desired original name
yes? let temp = XCAT(temp1,temp2)

yes? show var
 Created by DEFINE VARIABLE:
 >>> Definitions that replace any file variable of same name:
     TEMP = XCAT(TEMP1,TEMP2)
     TEMP2 = {4,5}
     TEMP1 = {1,2,3}

yes? list temp
             VARIABLE : XCAT(TEMP1,TEMP2)
             SUBSET   : 5 points (X)
 1   / 1:  1.000
 2   / 2:  2.000
 3   / 3:  3.000
 4   / 4:  4.000
 5   / 5:  5.000




On 8/20/2014 12:09 AM, rahul s wrote:
Hello NIcolas

you can replace array elements if you can afford to rename your variable


set region/i=1:4 !! this is to limit abstract axis length to number of elements in the array
let var={1,3,5,7}
let new=if i[g=var] eq 3 then 0 else var !!! will replace third element to 0


Ofcourse , the whole point of your question may be that  you dont want to rename your variable. Then its difficult to do it ferret i guess. 


Rahul 



Date: Wed, 20 Aug 2014 13:24:20 +0800
Subject: [ferret_users] Define, change/add/remove element in an array.
From: nicolas.freychet@xxxxxxxxx
To: ferret_users@xxxxxxxx

Hi everyone,

Is there a simple comand to change/add elements inside an array.

For instance, I defined a single row array with :

         let listTemp = {`temp1`,`temp2`,`temp3`,`temp4`}

But then, I'd like to add new values `temp5`, `temp6`.... or change `temp1` to a new value.
I tried something like : "listTemp[i=1] = `temp5`" but it doesn't work.

If anyone knows how to do it....

Thanks,
Nicolas


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement