[Thread Prev][Thread Next][Index]

Preserving variables between function calls

I have a slight problem when using Ferret to define new variables from a
function call since Ferret calls the function everything I need to use the

I've been writing some Ferret external functions, which work ok, but
suppose I do the following:

  let newpv = bb2reg( x[gx=xax], y[gy=yay], pv[k=1,l=1] )

where pv is a 4D variable read from a netCDF file. Now, because of the way
ferret works, newpv (and therefore the call to bb2reg) won't be made until
newpv is actually required. So, let's say I do:

  shade newpv[k=1,l=1]

All ok so far. The problem comes when I want to do something else with
newpv, let's say:

  contour newpv[k=1,l=1]

Now, what happens is that the function 'bb2reg' is called a second time to
compute newpv. Unfortunately, because bb2reg is interpolating from the
model grid to a regular grid, this is a bit time consuming. In the normal
programming sense, newpv would be computed once only, but because Ferret
has defined the variable in terms of its expression, the function will be
called everytime I need to use newpv - at least that's how I understand it.
I admit to being a novice Ferret user so I'm hoping this is easy to get

I could obvious save newpv to a file the first time newpv is invoked and
then read from the file, but this is a bit self-defeating since it's not
much easier than using an external program to interpolate the whole file
anyway; I wanted to avoid making more files by using external functions.

I can't see how to tell Ferret to use the 'cached' value of newpv rather
than have to recompute it from the expression? Is this possible?


Dr. Glenn Carver, Senior Research Associate,
Centre for Atmospheric Science, Chemistry Dept., Cambridge University, UK
   Glenn.Carver@atm.ch.cam.ac.uk     http://www.atm.ch.cam.ac.uk/~glenn/

         "Genius is one percent inspiration and ninety nine
          percent perspiration"   Thomas Edison.

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement