Fwd: lats4d for defined variable

Arlindo da Silva dasilva at ALUM.MIT.EDU
Fri Apr 4 12:45:45 EDT 2008


Semyon.

 There is a bug bug in LATS that causes it crash when used more than oce in
a GrADS session. Starts a fresh grads session and do this:

ga-> open ../sst/sst_month
ga-> set x 1 360
ga-> sst1 = sst - 273
ga-> lats4d -o qq -func sst1 -time nov1981 dec2007 -vars sst

Now, if your modification of the sst field can expressed as a simple
expression you could have said (this time from the command line for
simplicity):

% lats4d.sh -nc -i ./sst/sst_month -o new_sst -func '@-273' -v

and the new file "new_sst.nc" will be written for all times and variables in
the input file (since it only had sst I didn't bother specifying -vars).

Now, suppose your modification of SST is something complicated that cannot
easily be done with a single line. In the case you can write a GrADS
expression function by means of a script function. I know, we've always been
taught that these kinds of functions do not mix. However, the GsUDF
extension does just that:

            http://opengrads.org/doc/udxt/gsudf/

OK, now you create a file "sstfunc.gsf" where you implement this function:

function sstfunc(sst)
  'define sst1 = sst - 273'
  return 'sst1'

In this function you simply define a variable and then return its name. Next
you will need to modify lats4d/gs to initialize the GsUDF package (I'll fix
this in future versions): just add the line

'gsudf init'

in the beginning of the lats4d.gs script. Now, you enter at the command
line:

% lats4d.sh -nc -i ./sst/sst_month -o new_sst -func 'sstfunc(@)'  -v

The '@' is replaced with the name of each variable on file. For this to work
you need to install the newest version of the OpenGrADS extensions just
released.

  Good luck and please let's keep this discussion on gradsusr.

      Arlindo


---------- Forwarded message ----------
From: Semyon Grodsky <senya at atmos.umd.edu>
Date: Fri, Apr 4, 2008 at 8:21 AM
Subject: Re: lats4d for defined variable
To: Arlindo da Silva <dasilva at alum.mit.edu>


Arlindo,
what I try to do is to save results of a script in a file that will be used
by other project participants. We decided to output into *.nc to achieve
portability into applications other than GRADS.

I tried what you suggested by doing a simple exersise.

**********************************************************

> gradsnc
>

Grid Analysis and Display System (GrADS) Version 1.9b4
Copyright (c) 1988-2005 by Brian Doty and IGES
Center for Ocean-Land-Atmosphere Studies (COLA)
Institute for Global Environment and Society (IGES)
GrADS comes with ABSOLUTELY NO WARRANTY
See file COPYRIGHT for more information

Config: v1.9b4 32-bit little-endian readline sdf/xdf netcdf lats printim

Issue 'q config' command for more information.

Landscape mode? (no for portrait):  n
GX Package Initialization: Size = 8.5 11
***************************************************
ga-> open ../sst/sst_month
Scanning description file:  ../sst/sst_month
Data file ../sst/sst_month_v2_%y4.dat is open as file 1
LON set to 0 360
LAT set to -89.5 89.5
LEV set to 0 0
Time values set: 1981:11:1:0 1981:11:1:0
*******************************************************

ga-> set t 1 last
Time values set: 1981:11:1:0 2007:12:1:0

*****now I define sst1
ga-> sst1=sst
Define memory allocation size = 81840960 bytes

ga-> q file
File 1 : OI_sst_V2 Reynolds&Smith
 Descriptor: ../sst/sst_month.ctl
 Binary: ../sst/sst_month_v2_%y4.dat
 Type = Gridded
 Xsize = 360  Ysize = 180  Zsize = 1  Tsize = 314
 Number of Variables = 1
   sst 0 99 surface temperature
ga-> set x 1 360
LON set to 0.5 359.5
ga-> set y 1 180
LAT set to -89.5 89.5

********Now I try what (I believe) you suggested
********************************************************
ga-> lats4d -o qq -func sst1 -time nov1981 dec2007 -vars ps
ylats4d: All invalid sfc/upper variables:  ps
lats4d: error creating coards file qq.nc
<RC> n1 </RC>
</IPC>
n1

*******if variable <ps> is replaced by defined name sst1, grads crashes
***********************************************************
ga-> lats4d -o qq -func sst1 -time nov1981 dec2007 -vars sst1
Segmentation fault

****************************************************************
lats4d -h

NAME

    lats4d - LATS for Dummies (Version 1.9.4 of 28 Nov 2007)
***************************************************************

I am sorry in advance for taking your time. I would really appreciate any
help.
Regards,
--Senya



 On Thu, 3 Apr 2008, Arlindo da Silva wrote:

 On Thu, Apr 3, 2008 at 3:26 PM, Semyon Grodsky <senya at atmos.umd.edu> wrote:
>
>  Folks,
> > I am a beginner with lats4d.
> >
> > I would like to output a defined variable (that is a result of
> > calculations) into a netcdf. Is it possible with lats4d?
> >
> >
>
> Yes, you should be able to do it. Here is an example:
>
> % gradsnc -l
> ga-> open model.ctl
> ga-> set x 1 72
> ga-> speed = sqrt(ua*ua+va*va)
> ga-> lats4d -o myfile -func speed -time 0z1jan1987 -vars ps
> ga-> quit
>
> and it will create a netcdf file named "myfile.nc" with a variable called
> "ps" but actually containing the defined variable "speed". There are other
> tricks you can play to have the variable name come right, but I'll stop
> here
> since I don't know what you are trying to do exactly.
>
>     Arlindo
>
>
>
>
>
>
> --
> Arlindo da Silva
> dasilva at alum.mit.edu
>
>
-----------------------------------------------------------
Semyon Grodsky
Computer and Space Science Building (Bldg. #224), Room 2409
Department of Atmospheric and Oceanic Science
University of Maryland
College Park, MD 20742

Phone:  301-405-5330
Fax:    301-314-9482
E-mail: senya at atmos.umd.edu



--
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080404/3e72c288/attachment.html 


More information about the gradsusr mailing list