[Thread Prev][Thread Next][Index]

Re: Calls of an external function to evaluate Ferret expressions



Hi Arindam,
When possible, Ferret uses cached results in memory when
a variable has been computed and a subset of it is needed
again for a calculation.

At the point in Ferret execution when they are called, external
functions are all treated as "grid-changing functions", since Ferret
does not know whether they may indeed have an output whose grid
is different from the grid of the arguments.  For instance, in the FFT
functions, the very structure of the output grid (the frequency axis)
will vary depending upon the input region. In fact there is enough
information that Ferret could potentially check whether there is a
custom axis defined and determine when an external function MAY
be grid changing, but this has not been implemented.

In any event, when your last command is executed

 plot/vs/over/line=8 binxy[j=1],binxy[j=2]

Ferret does not know whether the computation of variable
"vary" made earlier can safely be used to compute binxy,
and it redoes the computation.

Note that when you call the external functions multiple times
on subsets of the data, Ferret uses only the subset of data
needed for the computation, so it is not repeating the entire
computation.  You can readily see this with SET MODE
DIAGNOSTIC.  Here is a simple example with the example
function SUBTRACT.   Look at the output lines that start with
"eval" to see what calculation is made, and which data is used.
For the entire unrestricted data region, the LOAD command uses
i=1:180, j=1:90, L=1:12  but for the PLOT command, C is
computed using only i=1:180, j=45:45, L=1:1

yes? use coads_climatology
yes? let c = subtract(sst, airt)
yes? set mode diag
yes? load c

yes? plot/l=1/y=0 c

Compare this with the output when you define
yes? let c = sst - airt

Finally, if the computation is large and your computation winds up
repeating many calculations, you can write one or more variables
to intermediate files and read the data back in. That is, you might
write var1 or vary to a file, cancel the original data and the definitions
of these variables, and then read the variable(s) back from your file
before proceeding to use var1 in your binning function.

Ansley Manke

Arindam Chakraborty wrote:

Hello Ferreters,
        I'm doing scatter plot between two variables (varx vs. vary).
One of these variables are calculated using an external function.
Next, both these variables are used to 'bin' the data and plot line
graph over the previous view itself. So the sequence of commands
are something like this:

...

let varx = ... ! uses ferret expressions and file variables
               ! (without a function call).

let vary1 = extfun1(v1,v2,v3,...) ! v1, v2, v3 are file variables.
! Now there's a condition to get final vary
let vary = if vary1 gt 0 then vary1
! and plot it
plot/vs varx, vary
! The regions are not specified explicitly but given in []'s while
!  defining the variables.
! At this point, a single write(*,*) statement from extfun1()
! displays:
Hi from extfun1
Hi from extfun1
! which means extfun1() is being called twice. This is most probably
! due to the definition of vary which involves vary1 twice. (A simple
! check with let vary = if vary1 gt 0 then (vary1 + vary1)*0.5 prints
! the message 3 times.)

! Now I try to bin this variables:
 let binxy = bin_1d(varx,vary,xi,xf,xw) ! This is another external
             ! function which returns 2D result along abstract axes.
! and plot
 plot/vs/over/line=8 binxy[j=1],binxy[j=2]
! but again those messages appear:
Hi from extfun1
Hi from extfun1
! which shows that extfun1() was called again two times.

Since everything remains same (data and region) between the scatter
and bin-ed line plots, there is not need to call extfun1() again.
If the variable (from external function) is being calculated every
time it appears in an expression, then it may become time consuming
especially if the external function does a huge set of computations.

Is there any way I can reduce these 4 calls of extfun1() by a
single call? Or any tricks in re-arranging these statements
(commands) to reduce the time taken by the whole procedure?

Many thanks in advance,

arindam chakraborty
------------------------------------------
 ARINDAM CHAKRABORTY
 Centre for Atmospheric & Oceanic Sciences
 Indian Institute of Science
 Bangalore 560 012; INDIA
 Tel: +91-80-2932505, +91-80-3600450
 Fax: +91-80-3600865
__________________________________________

--
Ansley Manke  Pacific Marine Environmental Laboratory  Seattle WA
 


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement