[gradsusr] Pass Data via the 'Return' Expression

Charles Seman Charles.Seman at noaa.gov
Wed Apr 21 19:47:00 EDT 2010


Hi Mark,

Please find attached main.gs (calling script) and add1.gsf (GrADS script 
function).

***********************
* Main script
***********************

rc = gsfallow("on")

iVal = 1

  say 'iVal = 'iVal
  say 'Making Call to GrADS script function "add1"'

oVal = add1(iVal)

  say 'Call Made - Checking for Answer'

  say 'oVal = 'oVal

Try using GrADS main script as follows:

ga-> main.gs
iVal = 1
Making Call to GrADS script function "add1"
input val = 1
new val = 2
Passing Variable Back to Main Script
Call Made - Checking for Answer
oVal = 2


in main.gs, a call is made to an external user-defined script function 
"add1.gsf" (http://grads.iges.org/grads/gadoc/gsf.html) and can be 
called from *outside* of main.gs because of "rc = gsfallow("on")" in 
main.gs and because of the suffix "gsf" for "add1.gsf"...

first, if only the line "rc = gsfallow("on")" is commented out (add1.gsf 
exists), the result (you can try this):
ga-> main.gs
iVal = 1
Making Call to GrADS script function "add1"
Function not found: add1           
  Error occurred on line 12
  In file main.gs

next, if the line "rc = gsfallow("on")" is active, but add1.gsf is 
renamed to add1.gs (you can try this):
ga-> main.gs
iVal = 1
Making Call to GrADS script function "add1"
Function not found: add1           
  Error occurred on line 12
  In file main.gs

Hope this helps,
Chuck

Mark Sponsler wrote:
>
> Hi Chales,
> I took a look at the script you referenced and was similar to others 
> I've seen where the main script and the subscripts are all encased in 
> the same physical file.  What I'm trying to accomplish is to have a 
> main script in one directory and a bunch of scripts of comomonly used 
> routines in a separate directory. The idea is to have the main script 
> call one of the common routines, then have the common routine pass 
> some variable data back to the main script for additional processing. 
>
> Below is a simple example with both scripts in the same directory. The 
> problem is the value  _val1  never gets returned to the main script.  
> I'm using Grads 1.9 on WinXP.
>
> Any thoughts or ideas would be welcome!
>
> ***********************
> * Main script
> ***********************
>
> rc = gsfallow("on")
>
> val = 1
>
>   say 'Val = 'val
>   say 'Making Call to Test_Call'
>
> 'run test_call.gs 1'
>
>   say 'Call Made - Checking for Answer'
>
>   say 'New val = '_val1
>
>
> Here's the called script
> ************************
> * Seconadry Script
> ************************
> function main (args)
> if (args='')
>   say 'No argument provided.  Argument must be a value 1-10'
>   return
> else
>   val = subwrd(args,1)
> endif
>
>  say 'Val = 'val
>
> _val1 = (val + 1)
>
>  say 'New Val = '_val1
>
>  say 'Passing Variable Back to Main Script'
>
>   return(_val1)
>
> Thanks,
> Mark
>
>
> ----- Original Message -----
> From: Charles Seman
> To: GrADS Users Forum
> Sent: Tue, 20 Apr 2010 21:21:12 +0000 (UTC)
> Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
>
> Mark,
>
> Don't know if you have resolved this yet, but Bob Hart's "plotskew.gs"
> script has examples of what it appears that you want to do:
> http://www.iges.org/grads/gadoc/library
> ftp://grads.iges.org/grads/scripts/plotskew.gs
>
> Hope this helps,
> Chuck
>
> Mark Sponsler wrote:
> >
> > I have a script that calls a second script (and passes some arguments
> > to it). That works fine. I'm trying to get the second script to return
> > some data back to the first script, but am having difficulty.  I use
> > the 'return' command to have the second script return control back the
> > first script, but cannot seem to get any variable data to pass with
> > it. It seems this is possible per the Grads documentation:
> >
> >  
> >
> >  
> >
> > To return from a function, use the |return| command:
> >
> >     |return /expression/|
> >
> >     The |/expression/| is optional; if not provided, a NULL string
> >     will be returned. (A null string is: '') The result of the
> >     function is the result of the expression specified on the return
> >     command.
> >
> >  
> >
> > In the second script, the last line is:
> >
> >  
> >
> > return val1
> >
> >  
> >
> > Where val1 is a variable string
> >
> >  
> >
> > Just can't seem to get the first script to read the contents of
> > val1. Could always write the data to a file, but am looking for
> > something a little more elegant.
> >
> >
> >  
> >
> > Any help would be appreciated,
> > Mark
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > gradsusr mailing list
> > gradsusr at gradsusr.org
> > http://gradsusr.org/mailman/listinfo/gradsusr
> >  
>
> -- 
>
> Please note that Charles.Seman at noaa.gov should be considered my NOAA
> email address, not cjs at gfdl.noaa.gov.
>
> ********************************************************************
> Charles Seman                                Charles.Seman at noaa.gov
> U.S. Department of Commerce / NOAA / OAR
> Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
> 201 Forrestal Road                              fax: (609) 987-5063
> Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
> ********************************************************************
>
> "The contents of this message are mine personally and do not reflect any
> official or unofficial position of the United States Federal Government,
> the United States Department of Commerce, or NOAA."
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
> ------------------------------------------------------------------------
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>   

-- 

Please note that Charles.Seman at noaa.gov should be considered my NOAA
email address, not cjs at gfdl.noaa.gov.

********************************************************************
 Charles Seman                                Charles.Seman at noaa.gov
 U.S. Department of Commerce / NOAA / OAR
 Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
 201 Forrestal Road                              fax: (609) 987-5063
 Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
********************************************************************

"The contents of this message are mine personally and do not reflect any
official or unofficial position of the United States Federal Government,
the United States Department of Commerce, or NOAA."

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: main.gs
Url: http://gradsusr.org/pipermail/gradsusr/attachments/20100421/45c07c1c/attachment-0003.pl 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add1.gsf
Type: application/x-font-type1
Size: 265 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20100421/45c07c1c/attachment-0003.bin 


More information about the gradsusr mailing list