[Thread Prev][Thread Next][Index]

Re: Preserving variables between function calls

Hi Glenn,

To get cache hits, it's important that you give a complete region
specification. In your example, since pv is a 4-dimensional variable try

  yes? let newpv = bb2reg( x[gx=xax], y[gy=yay],
pv[k=1,l=1,I=1:IMAX,J=1:JMAX] )
  yes? shade newpv
  yes? contour newpv   ! <== should be fast -- result retrieved from

That said, the BETA release of the external function framework that is
available in V4.91 is fussy about making cache hits. For best results
with caching include the full specification of region limits inside the
arguments passed to your external function -- as I have done in the
example, above. 

	- steve


Glenn Carver wrote:
> 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
> variable.
> 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
> around.
> 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?
>     Glenn
> ----
> 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.

Steve Hankin
NOAA/PMEL, 7600 Sand Point Way NE, Seattle, WA 98115-0070
ph. (206) 526-6080 -- FAX (206) 526-6744

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement