Hi Fabian,
Unlike some other languages, what you are doing in Ferret is setting
up the algebraic quantities to compute something, until you use or write
the variable you define, it doesn't exist as a number. Your situation is
a case like this -- for each lag the definition is changing so it is
best to write out the results for each lag to a file, then read them
back later.
The most elegant way would be to write to a netCDF file, one time
slice (lag) at a time. But, unless the x-y grid is huge, I typically
write to an ASCII file (one value per record) then define the
appropriate grid and read it back. It would go something like this:
use my_data !(the original xyt dataset containing "myvar")
spawn touch temp.file
repeat/range=1:5/name=lag ( ... define and compute the lagged
correlation variable "correl" from "myvar" ;\
list/nohead/file=temp.file/form=(f12.5) correl )
def axis/t=1:5:1 lagx
def grid/like=myvar[d=1]/t=lagx glag
file/form=free/g=glag/ord=xyt/var=mylagvar temp.file
set var/title="Lagged Correlations" mylagvar
! now you can plot or use them ... or use ferret to write them to a
netCDF file then discard temp.file
save/file=MyLaggedResults.nc mylagvar
Things to note:
1) ";\" continues the repeat statement to the next line
2) the build up lag-by-lag of the results file
3) I just typed this in without doing a demo -- there may be typos but I
hope the gist is clear
Hope it helps,
Mick
PS Look in the user guide for the slice-by-slice construction of a
netCDF file if you like to be more elegant
-------
Fabian Lienert wrote:
Hi Ferreters,
Simple question, couldn't find an answer so far.
In a repeat loop, I am calculating lagged cross correlations:
yes? repeat/range = 1:5:1/Name=lag (let q =
timeseries[d=1,i=1,l=@shf:`lag`]; \
let p = 3dvariable[d=2]; go variance;\
All I want to do is to insert a 2-d field (correl) into a 3-d variable
(x,y,t) at each time step inside the repeat loop, something like the
following.
let lag_corr/l=`lag` = correl)
In other programming languages this is easily done by filling an array:
for (t in 1:5) {
lag_corr[,,t] = correl(t)
}
I am using FERRET v6.1 on Ubuntu Linux.
Any help appreciated,
Fabian