[Thread Prev][Thread Next][Index]

Re: [ferret_users] Looping over arrays



Hi Karthik,
To read in the data, here's what the commands look like.  Say the file is called points.dat, and that the sst data is in some dataset (a netcdf dataset?)  called sst_data.nc
FILE/VAR="xloc,yloc,tloc" points.dat
USE sst_data.nc
For more about reading in data from ASCII files, see "ASCII data" in the Users Guide -- particularly the entry under "reading, examples".


Now, in Ferret you do not need to write loops yourself.  You define expressions and Ferret will loop over the entire grid, or over any part of the grid that you specify. This is explained in  the Users Guide introduction. It will help you to read this section; it is not long: http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/introduction/GETTING-STARTED


So after the above two commands to open the datasets, your script would continue, defining a variable that contains a list of sst at the locations, and then another variable with the difference of the data at index (n+1) - (n)

LET sst_at_loc = SAMPLEXYT(sst[d=2], xloc[d=1], yloc[d=1], tloc[d=1]) 
LET sst_change = sst_at_loc[i=@SHF:1] - sst_at_loc 
When you PLOT or LIST the data, Ferret will do the computations over the whole list.
LIST sst_at_loc ! this will list the sampled data at i=1:n
LIST sst_change ! will list out the differences

To save to a file, LIST/FILE=filename.dat will write out the data to an ascii file. See LIST in the documentation for various options.


Balaguru, Karthik wrote:
  Hi Ansley,

     Thank you so much for your reply. Yes, you are right. The three 1-dimensional variables, which are x, y, and t values, are locations in the the grid of an XYT variable sst. The values of time are index values. The problem I have is that I have the (x,y,t) locations as three columns in a text file. I need to load that into ferret and run a loop such that for i=1:n (n = number of points), something like

   for i=1:n
   sst_at_loc = SAMPLEXYT(sst, xloc, yloc, tloc)
   sst_change(i) = sst_at_loc[i=@SHF:1] - sst_at_loc
   end

    It'll be great to know how this can be done. Thanks a lot!

   Karthik.










----- Original Message -----
From: "Ansley Manke" <Ansley.B.Manke@xxxxxxxx>
To: "Karthik Balaguru" <karthiknaidu@xxxxxxxxxxxx>
Cc: "oar pmel ferret users" <oar.pmel.ferret_users@xxxxxxxx>
Sent: Wednesday, October 14, 2009 5:47:08 PM GMT -06:00 US/Canada Central
Subject: Re: [ferret_users] Looping over arrays

Hi Karthik, 
I think I understand what you want to do. You have three 1-dimensional variables, which are x, y, and t values that are locations in the the grid of an XYT variable sst. Is that correct? Are the values in the time array times, or index values? That is, do they have units of days, or hours, or other time-units since the start? Or are they index values 1, 2, ... NT? 

Assuming that the data in l(i) are in the same units of time as the time axis of sst, then you can use the SAMPLEXYT function to get the values of variable sst at each of your scattered xyt locations. 

Say the 1-dimensional variables are called xloc, yloc, tloc. 


yes? let sst_at_loc = SAMPLEXYT(sst, xloc, yloc, tloc) 
When this is evaluated, it will be a 1-dimensional variable, sst at each of the scattered locations. Then to subtract the value of sst at ( xloc(i+1), yloc(i+1), tloc(i+1) ) minus sst at ( xloc(i), yloc(i), tloc(i) ), the _expression_ is 


yes? let sst_change = sst_at_loc[i=@SHF:1] - sst_at_loc 
yes? list sst_at_loc, sst_change 

Ansley 

Balaguru, Karthik wrote: 

Hi all,

      I have a problem with arrays in ferret. I have an array with three colums [x(i) y(i) l(i)], which are lat, lon and time respectively. The problem is they are not continuous, i.e; for each i, x,y and l are random. I have the corresponding sst data.
Now for i=1:n I want to read in the array data and then calculate the sst change, like 

 sst_change(i) = sst(x(i),y(i),l(i) + 1) - sst(x(i),y(i),l(i) + 1)

      It'll be great if somebody can help me out with this. Thanks!


   Truly,
   Karthik. 
  

[Thread Prev][Thread Next][Index]

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

Privacy Policy | Disclaimer | Accessibility Statement