Hi All,
Actually, anytime we find ourselves writing a repeat loop in Ferret,
it's a good idea to stop and think whether a masking operation or other
definition would do better. It's always preferable to define
expressions in Ferret commands that describe the operation and let
Ferret operate on the entire grid or axis. Ferret's power comes from
its ability to do regridding, or compute integrals or
averages for whole expressions without needing to write loops. So stop
and consider if you are doing some operation to every element of a
variable along an axis. Repeat loops may
unnecessarily complicate your scripts by duplicating Ferret's
capability to operate on entire grids or axes in a single command.
Here's a sequence that lets you define this integration by masking and
using the pseudo-variables for edges of the grid cells, ZBOXLO and
ZBOXHI.
! create mask for vertical layers (use a weighted box on
the bottom
edge of the mixed layer)
LET Zmask1 = IF mld GE ZBOXHI[g=heat] THEN 1 ELSE zmask
LET zmask = IF mld LT ZBOXLO[g=heat] THEN 0 ELSE
(mld-ZBOXLO[g=heat])/ZBOX[g=heat]
! weight the heat content by this mask
LET weighted_heat_dz = heat * zmask * ZBOX[g=heat]
! integrate inZ by summing in the vertical
LET mld_heat = weighted_heat_dz[k=1:30=@sum]
! integrate in XY with the definite integral transformation
LET mld_heat_xyintegral = mld_heat[x=@din, y=@din]
! list the result over 10 time steps
LIST/l=1:10/i=lo:hi/j=lo:hi mld_heat_integral
Peter Szabo wrote:
Hello Yangxing,
The problem occurs from your (at least) two-dimensional MLD data set.
It is not a scalar as ferret says :)
i do not know your horizontal grid, but try something like this to get
what you want.
let beg=0
repeat/i=1:1 (repeat/j=1:1 (let end=mld[d=2]; define symbol
zz=`beg`:`end`; let heat_mld = heat[d=1,z=($zz)@din] ))
you other commands should be placed in the double brackets using after
all a ";" or a "\". you can save out the result-variable to a new
netCDF file by points with this command (placed in the mentioned
brackets):
save/file="heat_mld.nc"/ilimts=1:1/jlimits=1:1/i=`i`/j=`j`/append/clobber
heat_mld
Cheers, Peter
|