[Thread Prev][Thread Next][Index]

Re: Fwd: ferret question



Hi Gary Strand,
                In Ferret we can define an "array" with let command. But 
we can't assign values to successive array locations "directly" (as often
we do in Fortran) by let command. In this kind of situations I used to 
write the values calculated inside the repeat loop to an ascii/netCDF 
file (if it is a temporary variable then ascii file or if I need that 
variable for later use then netCDF file) and then read it back 
for further calculations/plotting.

!Let us make a dummy variable with x,y & z dimensions 
!----------------------------------------------------

   define axis/y=11:15:1/units=latitudes    ylat
   define axis/x=-75:-5:5/units=longitudes  xlon
   define axis/z=1:10:1/units="levels"      zlev  ! only 10 levels

   let vel = sin(x[gx=xlon]+y[gy=ylat]+z[gz=zlev])

!use set reg/ instead of specifying x & y explicitly
!--------------------------------------------------------

   set reg/y=11n/x=-65:-10
   set list/precision=7    ! set to required precision
   
! 1. Ascci file method
!-----------------

   repeat/k=1:10 ( let trpall=vel[x=@din]/10e6 ; list/nohead/file=trpall.dat/append trpall)
   ! note that k=1@din doesn't makes sense & inside a repeat loop with 
   !   "k" index, at each time the calculations will be done for the 
   !   respective "k" level.

   ! read it back
   cancel variable trpall ! since we are reading an already defined variable
                          !    from a new file
   define axis/y=11:11:1/units=latitudes y11  !  proper grids to 
   define grid/y=y11/z=vel grd                !    read trpall

   file/grid=grd/var="trpall" trpall.dat
   list trpall
   ! after all plotting/calculation remove the trpall.dat file 
   sp  rm -f trpall.dat

! 2. netCDF file method
!----------------------
! we can open a netcdf file for wrting in successive steps as follows:   
!    Our transport variable will have levels(depth) and latitude infor-
!    mation. Hence we will create a new netCDF file with /JLIMITS and 
!    /KLIMITS qualifiers at the first step. For successive steps we will
!    append the data with spefying the respective J & K positions.
! If you have any problems with appending to a netcdf file in this way
! please refer this mail in the archive
! http://ferret.pmel.noaa.gov/Ferret/Mail_Archives/fu_2001/msg00282.html

   let trpall    = vel[x=@din,k=1]/10e6 
   set var/title="Transport over 65W-10W"/units="sv" trpall 
   SAVE/file=trpall.nc/JLIMITS=1:1/KLIMITS=1:10/J=1/k=1/CLOBBER trpall

   repeat/k=2:10 ( let trpall=vel[x=@din]/10e6 ; save/file=junk.nc/J=1/K=`k`/APPEND trpall)

   ! read it back
   cancel var trpall  ! since we are reading an already declared variable
                      !    from a new file
   set data trpall.nc
   list trpall

   ! after all plotting/calculation remove the trpall.dat file 
   sp rm -f trpall.nc


Hope This Helps

With Regards

Jaison 



On Tue, 10 Aug 2004, Gary Strand wrote:

>  From a colleague:
> > I calculate the oceanic volume transport by layer along a zonal section
> > in the Equatorial Atlantic.
> >
> > For example, at a zonal section on 11N, I made:
> >
> > let tranp1=vvel[y=11n,x=-65:-10@din,k=1@din]/10e6 - I have the 
> > transport
> > (sv) at the first layer.
> > let tranp2=vvel[y=11n,x=-65:-10@din,k=2@din]/10e6 - at the second 
> > layer.
> >
> > I try to create a repeat command to do this for all the 22 layers:
> >
> > rep/k=1:22:1 (let tranpall=vvel[y=11n,x=-65:-10@din,k=`k`@din]/10e6)
> >
> > But every variable "transpall" record only the last value o K and not
> > the 22 layers.
> > You have any idea how can I put all the transport values in the same
> > variable??
> 
> I've forgotten how to do this. TIA!
> 
> Gary Strand
> strandwg@ucar.edu
> http://www.cgd.ucar.edu/ccr/strandwg
> 

-- 
___________________________________________________

    Jaison Kurian                           
    Centre for Atmospheric and Oceanic Sciences
    Indian Institute of Science
    B A N G A L O R E   560 012
    Ph: +91-80-3942505
        +91-80-3600450
    Fax:+91-80-3600865
___________________________________________________



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement