[gradsusr] Pass Data via the 'Return' Expression
Mark Sponsler
msponsler at comcast.net
Mon Apr 26 15:42:39 EDT 2010
Hi John,
Thanks for the information. I had read the instructions on the use of gsfpath before posting to the list.
I've tried every combination of it as follows with no good result. In the main script I tried:
rc = gsfpath("\mark\b")
rc = gsfpath("/mark/b")
rc = gsfpath("c:\mark\b")
rc = gsfpath("c:/mark/b")
In all instances, the main script hangs on execution of the gsfpath command. It appears to not be able to find the path.
But if the .gsf file is in the same directory as the main script all works fine (with the gfspath command commented out). Grads just doesn't seems to want to navigate to another directory that is at the same level as the directory that it is being executed out of. I've had problem with pathing in the past and had to use the unmount command to resolve it.
But no fear, there is another solution.....
After re-reading Brians suggestions and after having previous limited success with the 'run' command, I have something that works.
*--Main Script (located in c:/mark/a)--
'run c:/mark/b/script2.gs 'var1' 'var2' 'var3
answer = result
*--Second Script (located at c:/mark/b)--
function script2 (args)
vara = subwrd(args,1)
varb = subwrd(args,2)
varc = subwrd(args,3)
--process the variables--
return(final_value)
One can send the results of script 'b' via the return command, and script 'a' can read those results easily by just reading the result variable and setting it equal to some new variable name. This is all I was trying to accomlish with my original post.
So the problem is solved. Thanks everyone for all your help. Hopefully this will be useful to other users.
Thanks,
Mark
----- Original Message -----
From: John Huddleston
To: GrADS Users Forum
Sent: Mon, 26 Apr 2010 14:45:41 +0000 (UTC)
Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
Good morning Mark,
Sorry for the delay, we had nearly three inches of rain followed
by four inches of snow and I was sequestered at home until today.
See http://www.iges.org/grads/gadoc/gadocindex
and click on the gsfpath() indexed item.
There are some steps for you to complete; according to the
instructions on that page.
It does appear that those paths must be the full path, e.g. rc =
gfspath(/home/mark/b /home/mark/a)
Here is a snippet from the page
The private path directory list is an optional list that is
provided via the gsfpath function:
rc = gsfpath("dirlist")
If used, the declaration of the
private path directory list should appear at the top of the main script just
underneath the statement enabling the dynamic script loading.
For example, if our main script "do_eof.gs" is
executed with the command:
run /usr/local/gradslib/do_eof
and this script file contains the following lines at the
front:
rc = gsfallow("on")
rc
= gsfpath("math1 string2")
and the script calls a function str_chop which is not found in the main script, then the search
path would be:
/usr/local/gradslib/str_chop.gsf
/usr/local/gradslib/math1/str_chop.gsf
/usr/local/gradslib/string2/str_chop.gsf
John
John Huddleston, PhD
From: gradsusr-bounces at gradsusr.org
[mailto:gradsusr-bounces at gradsusr.org] On Behalf Of Mark Sponsler
Sent: Friday, April 23, 2010 2:36 PM
To: GrADS Users Forum
Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
John,
I
hate to be a pain but am still having problems.
So if my main script is here: c:/grib/a/main_script.gs and the
called script is here: c:/grib/b/called.gfs
Then I
should set gfspath as follows:
rc =
gsfpath("../b")
Unfortunately the
script hangs on the gfspath command.
I've
tried it with both \ and / too.
Any
suggestions?
Thanks,
Mark
----- Original Message -----
From: "John Huddleston" <Huddleston at cira.colostate.edu>
To: "GrADS Users Forum" <gradsusr at gradsusr.org>
Sent: Friday, April 23, 2010 11:45:23 AM GMT -08:00 US/Canada Pacific
Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
Mark,
The Windows builds use the Cygwin "UNIX" style of
paths. So, if you want to go up one directory and then down into another, use
the ".." parent directory. The "." directory is the current
directory.
John Huddleston, PhD
From:
gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] On Behalf Of Mark
Sponsler [msponsler at comcast.net]
Sent: Friday, April 23, 2010 9:39 AM
To: GrADS Users Forum
Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
Brian,
Excellent
addtional examples. I am using gfsallow right now, and it works fine if
the 'b' script is in the same directory as the 'a' script.
But
now I'm kinda stuck because I want the b script to be in a different
directory. I'm trying to set up a bunch of common scripts
in a standalone directory, so they can be accessed from any grads script
elswhere on the drive. So pathing is now the issue.
I'm
trying to locate 'script b' using gfspath.
Say
'script a' is here: c:/grib/a (and executed from that
location), and 'script b' (the .gsf script) is here: c:/grib/b
I
can't seem to figure out how to get gfspath to go 'up' one directory, then down
into directory b
I
tried
rc =
gsfpath("./b") but the scripts hangs on the gfspath command.
I'm on
a Windows build of Grads.
Thanks,
Mark
----- Original Message -----
From: "Brian Doty" <doty at cola.iges.org>
To: "GrADS Users Forum" <gradsusr at gradsusr.org>
Sent: Thursday, April 22, 2010 7:42:56 PM GMT -08:00 US/Canada Pacific
Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
The "gsfallow" stuff is usually the better solution, but I will also
note that if you have a main script that issues the run command to grads, ie:
"run myscript.gs
"args
and if that script returns something via the return statement, then that string is available to
the first script in the result variable.
Example:
script a:
"run b.gs testing"
say
"--->"result"<---"
script b:
function b(args)
return(subwrd(args,1))
If you run a.gs from within grads, you should see the following
line output:
---->testing<----
...Brian
On Apr 21, 2010, at 8:42 PM, Mark Sponsler wrote:
Charles,
It works perfectly now. Excellent example you provided. I had previous
read the tutorial provided, but never really understood the implications of it
all until I saw your example. It makes perfect sense now.
Thanks so much for taking the time to help. Would have never
figured it out on my own.
Thanks again,
Mark
----- Original Message -----
From: Charles Seman
To: GrADS Users Forum
Sent: Wed, 21 Apr 2010 23:47:00 +0000 (UTC)
Subject: Re: [gradsusr] Pass Data via the 'Return' Expression
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."
_______________________________________________
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
_______________________________________________ gradsusr mailing list
gradsusr at gradsusr.org http://gradsusr.org/mailman/listinfo/gradsusr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20100426/67cd03f8/attachment-0003.html
More information about the gradsusr
mailing list