<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Arial; font-size: 10pt; color: #000000'><P>John,</P>
<P>I hate to be a pain but am still having problems.</P>
<P><BR>So if my main script is here: c:/grib/a/main_script.gs and the called script is here: c:/grib/b/called.gfs</P>
<P> </P>
<P><FONT face="Courier New">Then I should set gfspath as follows:</FONT></P>
<P><FONT face="Courier New"></FONT> </P>
<P><FONT face="Courier New">rc = gsfpath("../b") </FONT></P>
<P><FONT face="Courier New"></FONT> </P>
<P><FONT face="Courier New">Unfortunately the script hangs on the gfspath command. </FONT></P>
<P><FONT face="Courier New"></FONT> </P>
<P><FONT face="Courier New">I've tried it with both \ and / too. </FONT></P>
<P> </P>
<P>Any suggestions?</P>
<P> </P>
<DIV><FONT size=2>Thanks,<BR>Mark</FONT></DIV><BR><BR>----- Original Message -----<BR>From: "John Huddleston" <Huddleston@cira.colostate.edu><BR>To: "GrADS Users Forum" <gradsusr@gradsusr.org><BR>Sent: Friday, April 23, 2010 11:45:23 AM GMT -08:00 US/Canada Pacific<BR>Subject: Re: [gradsusr] Pass Data via the 'Return' Expression<BR><BR>
<STYLE>P {
        MARGIN: 0px
}
</STYLE>
<STYLE id=owaTempEditStyle></STYLE>
<STYLE title=owaParaStyle><!--P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
--></STYLE>
<DIV style="FONT-FAMILY: Tahoma; DIRECTION: ltr; COLOR: #000000; FONT-SIZE: 13px">
<DIV></DIV>
<DIV dir=ltr><FONT color=#000000 size=2 face=Tahoma>Mark,</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=tahoma></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=tahoma>The Windows builds use the Cygwin<A></A> "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.</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=tahoma></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=tahoma>John Huddleston, PhD</FONT></DIV>
<DIV style="DIRECTION: ltr" id=divRpF374583>
<HR>
<FONT color=#000000 size=2 face=Tahoma><B>From:</B> gradsusr-bounces@gradsusr.org [gradsusr-bounces@gradsusr.org] On Behalf Of Mark Sponsler [msponsler@comcast.net]<BR><B>Sent:</B> Friday, April 23, 2010 9:39 AM<BR><B>To:</B> GrADS Users Forum<BR><B>Subject:</B> Re: [gradsusr] Pass Data via the 'Return' Expression<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>
<DIV style="FONT-FAMILY: Arial; COLOR: #000000; FONT-SIZE: 10pt">
<P>Brian,</P>
<P>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. </P>
<P>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.</P>
<P> </P>
<P>I'm trying to locate 'script b' using gfspath.</P>
<P> </P>
<P>Say 'script a' is here: c:/grib/a (and executed from that location), and 'script b' (the .gsf script) is here: c:/grib/b</P>
<P> </P>
<P>I can't seem to figure out how to get gfspath to go 'up' one directory, then down into directory b <BR></P>
<P>I tried </P>
<P><FONT face="Courier New">rc = gsfpath("./b") but the scripts hangs on the gfspath command. </FONT></P>
<P><FONT face="Courier New"></FONT> </P>
<P><FONT face="Courier New">I'm on a Windows build of Grads. </FONT></P>
<P><BR></P>
<DIV><FONT size=2>Thanks,<BR>Mark</FONT></DIV><BR><BR>----- Original Message -----<BR>From: "Brian Doty" <doty@cola.iges.org><BR>To: "GrADS Users Forum" <gradsusr@gradsusr.org><BR>Sent: Thursday, April 22, 2010 7:42:56 PM GMT -08:00 US/Canada Pacific<BR>Subject: Re: [gradsusr] Pass Data via the 'Return' Expression<BR><BR>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:
<DIV><BR></DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>"run myscript.gs "args</SPAN></FONT></DIV>
<DIV><BR></DIV>
<DIV>and if that script returns something via the <FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>return</SPAN></FONT> statement, then that string is available to the first script in the <FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>result </SPAN></FONT>variable. </DIV>
<DIV><BR></DIV>
<DIV>Example:</DIV>
<DIV><BR></DIV>
<DIV>script a:</DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span><BR></SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>"run b.gs testing"</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>say "--->"result"<---"</SPAN></FONT></DIV>
<DIV><BR></DIV>
<DIV>script b:</DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span><BR></SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>function b(args)</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>return(subwrd(args,1))</SPAN></FONT></DIV>
<DIV><BR></DIV>
<DIV>If you run a.gs from within grads, you should see the following line output:</DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span><BR></SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span size=3 face="'Courier New'"><SPAN style="FONT-SIZE: 13px" class=Apple-style-span>---->testing<----</SPAN></FONT></DIV>
<DIV><BR></DIV>
<DIV>...Brian</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>
<DIV>On Apr 21, 2010, at 8:42 PM, Mark Sponsler wrote:</DIV><BR>
<BLOCKQUOTE>
<DIV>Charles,<BR>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. <BR><BR>
<DIV>Thanks again,<BR>Mark</DIV><BR><BR>----- Original Message -----<BR>From: Charles Seman <BR>To: GrADS Users Forum <BR>Sent: Wed, 21 Apr 2010 23:47:00 +0000 (UTC)<BR>Subject: Re: [gradsusr] Pass Data via the 'Return' Expression<BR><BR>Hi Mark,<BR><BR>Please find attached main.gs (calling script) and add1.gsf (GrADS script <BR>function).<BR><BR>***********************<BR>* Main script<BR>***********************<BR><BR>rc = gsfallow("on")<BR><BR>iVal = 1<BR><BR> say 'iVal = 'iVal<BR> say 'Making Call to GrADS script function "add1"'<BR><BR>oVal = add1(iVal)<BR><BR> say 'Call Made - Checking for Answer'<BR><BR> say 'oVal = 'oVal<BR><BR>Try using GrADS main script as follows:<BR><BR>ga-> main.gs<BR>iVal = 1<BR>Making Call to GrADS script function "add1"<BR>input val = 1<BR>new val = 2<BR>Passing Variable Back to Main Script<BR>Call Made - Checking for Answer<BR>oVal = 2<BR><BR><BR>in main.gs, a call is made to an external user-defined script function <BR>"add1.gsf" (<A href="http://grads.iges.org/grads/gadoc/gsf.html" target=_blank>http://grads.iges.org/grads/gadoc/gsf.html</A>) and can be <BR>called from *outside* of main.gs because of "rc = gsfallow("on")" in <BR>main.gs and because of the suffix "gsf" for "add1.gsf"...<BR><BR>first, if only the line "rc = gsfallow("on")" is commented out (add1.gsf <BR>exists), the result (you can try this):<BR>ga-> main.gs<BR>iVal = 1<BR>Making Call to GrADS script function "add1"<BR>Function not found: add1 <BR> Error occurred on line 12<BR> In file main.gs<BR><BR>next, if the line "rc = gsfallow("on")" is active, but add1.gsf is <BR>renamed to add1.gs (you can try this):<BR>ga-> main.gs<BR>iVal = 1<BR>Making Call to GrADS script function "add1"<BR>Function not found: add1 <BR> Error occurred on line 12<BR> In file main.gs<BR><BR>Hope this helps,<BR>Chuck<BR><BR>Mark Sponsler wrote:<BR>><BR>> Hi Chales,<BR>> I took a look at the script you referenced and was similar to others <BR>> I've seen where the main script and the subscripts are all encased in <BR>> the same physical file. What I'm trying to accomplish is to have a <BR>> main script in one directory and a bunch of scripts of comomonly used <BR>> routines in a separate directory. The idea is to have the main script <BR>> call one of the common routines, then have the common routine pass <BR>> some variable data back to the main script for additional processing. <BR>><BR>> Below is a simple example with both scripts in the same directory. The <BR>> problem is the value _val1 never gets returned to the main script. <BR>> I'm using Grads 1.9 on WinXP.<BR>><BR>> Any thoughts or ideas would be welcome!<BR>><BR>> ***********************<BR>> * Main script<BR>> ***********************<BR>><BR>> rc = gsfallow("on")<BR>><BR>> val = 1<BR>><BR>> say 'Val = 'val<BR>> say 'Making Call to Test_Call'<BR>><BR>> 'run test_call.gs 1'<BR>><BR>> say 'Call Made - Checking for Answer'<BR>><BR>> say 'New val = '_val1<BR>><BR>><BR>> Here's the called script<BR>> ************************<BR>> * Seconadry Script<BR>> ************************<BR>> function main (args)<BR>> if (args='')<BR>> say 'No argument provided. Argument must be a value 1-10'<BR>> return<BR>> else<BR>> val = subwrd(args,1)<BR>> endif<BR>><BR>> say 'Val = 'val<BR>><BR>> _val1 = (val + 1)<BR>><BR>> say 'New Val = '_val1<BR>><BR>> say 'Passing Variable Back to Main Script'<BR>><BR>> return(_val1)<BR>><BR>> Thanks,<BR>> Mark<BR>><BR>><BR>> ----- Original Message -----<BR>> From: Charles Seman<BR>> To: GrADS Users Forum<BR>> Sent: Tue, 20 Apr 2010 21:21:12 +0000 (UTC)<BR>> Subject: Re: [gradsusr] Pass Data via the 'Return' Expression<BR>><BR>> Mark,<BR>><BR>> Don't know if you have resolved this yet, but Bob Hart's "plotskew.gs"<BR>> script has examples of what it appears that you want to do:<BR>> <A href="http://www.iges.org/grads/gadoc/library" target=_blank>http://www.iges.org/grads/gadoc/library</A><BR>> <A href="about:blank" target=_blank>ftp://grads.iges.org/grads/scripts/plotskew.gs</A><BR>><BR>> Hope this helps,<BR>> Chuck<BR>><BR>> Mark Sponsler wrote:<BR>> ><BR>> > I have a script that calls a second script (and passes some arguments<BR>> > to it). That works fine. I'm trying to get the second script to return<BR>> > some data back to the first script, but am having difficulty. I use<BR>> > the 'return' command to have the second script return control back the<BR>> > first script, but cannot seem to get any variable data to pass with<BR>> > it. It seems this is possible per the Grads documentation:<BR>> ><BR>> > <BR>> ><BR>> > <BR>> ><BR>> > To return from a function, use the |return| command:<BR>> ><BR>> > |return /expression/|<BR>> ><BR>> > The |/expression/| is optional; if not provided, a NULL string<BR>> > will be returned. (A null string is: '') The result of the<BR>> > function is the result of the expression specified on the return<BR>> > command.<BR>> ><BR>> > <BR>> ><BR>> > In the second script, the last line is:<BR>> ><BR>> > <BR>> ><BR>> > return val1<BR>> ><BR>> > <BR>> ><BR>> > Where val1 is a variable string<BR>> ><BR>> > <BR>> ><BR>> > Just can't seem to get the first script to read the contents of<BR>> > val1. Could always write the data to a file, but am looking for<BR>> > something a little more elegant.<BR>> ><BR>> ><BR>> > <BR>> ><BR>> > Any help would be appreciated,<BR>> > Mark<BR>> ><BR>> > ------------------------------------------------------------------------<BR>> ><BR>> > _______________________________________________<BR>> > gradsusr mailing list<BR>> > <A href="mailto:gradsusr@gradsusr.org" target=_blank>gradsusr@gradsusr.org</A><BR>> > <A href="http://gradsusr.org/mailman/listinfo/gradsusr" target=_blank>http://gradsusr.org/mailman/listinfo/gradsusr</A><BR>> > <BR>><BR>> -- <BR>><BR>> Please note that <A href="mailto:Charles.Seman@noaa.gov" target=_blank>Charles.Seman@noaa.gov</A> should be considered my NOAA<BR>> email address, not <A href="mailto:cjs@gfdl.noaa.gov" target=_blank>cjs@gfdl.noaa.gov</A>.<BR>><BR>> ********************************************************************<BR>> Charles Seman <A href="mailto:Charles.Seman@noaa.gov" target=_blank>Charles.Seman@noaa.gov</A><BR>> U.S. Department of Commerce / NOAA / OAR<BR>> Geophysical Fluid Dynamics Laboratory voice: (609) 452-6547<BR>> 201 Forrestal Road fax: (609) 987-5063<BR>> Princeton, NJ 08540-6649 <A href="http://www.gfdl.noaa.gov/~cjs/" target=_blank>http://www.gfdl.noaa.gov/~cjs/</A><BR>> ********************************************************************<BR>><BR>> "The contents of this message are mine personally and do not reflect any<BR>> official or unofficial position of the United States Federal Government,<BR>> the United States Department of Commerce, or NOAA."<BR>><BR>> _______________________________________________<BR>> gradsusr mailing list<BR>> <A href="mailto:gradsusr@gradsusr.org" target=_blank>gradsusr@gradsusr.org</A><BR>> <A href="http://gradsusr.org/mailman/listinfo/gradsusr" target=_blank>http://gradsusr.org/mailman/listinfo/gradsusr</A><BR>> ------------------------------------------------------------------------<BR>><BR>> _______________________________________________<BR>> gradsusr mailing list<BR>> <A href="mailto:gradsusr@gradsusr.org" target=_blank>gradsusr@gradsusr.org</A><BR>> <A href="http://gradsusr.org/mailman/listinfo/gradsusr" target=_blank>http://gradsusr.org/mailman/listinfo/gradsusr</A><BR>> <BR><BR>-- <BR><BR>Please note that <A href="mailto:Charles.Seman@noaa.gov" target=_blank>Charles.Seman@noaa.gov</A> should be considered my NOAA<BR>email address, not <A href="mailto:cjs@gfdl.noaa.gov" target=_blank>cjs@gfdl.noaa.gov</A>.<BR><BR>********************************************************************<BR>Charles Seman <A href="mailto:Charles.Seman@noaa.gov" target=_blank>Charles.Seman@noaa.gov</A><BR>U.S. Department of Commerce / NOAA / OAR<BR>Geophysical Fluid Dynamics Laboratory voice: (609) 452-6547<BR>201 Forrestal Road fax: (609) 987-5063<BR>Princeton, NJ 08540-6649 <A href="http://www.gfdl.noaa.gov/~cjs/" target=_blank>http://www.gfdl.noaa.gov/~cjs/</A><BR>********************************************************************<BR><BR>"The contents of this message are mine personally and do not reflect any<BR>official or unofficial position of the United States Federal Government,<BR>the United States Department of Commerce, or NOAA."<BR><BR>_______________________________________________<BR>gradsusr mailing list<BR><A href="mailto:gradsusr@gradsusr.org" target=_blank>gradsusr@gradsusr.org</A><BR>http://gradsusr.org/mailman/listinfo/gradsusr<BR></DIV></BLOCKQUOTE></DIV><BR></DIV><BR>_______________________________________________ gradsusr mailing list gradsusr@gradsusr.org http://gradsusr.org/mailman/listinfo/gradsusr </DIV></DIV></DIV><BR>_______________________________________________ gradsusr mailing list gradsusr@gradsusr.org http://gradsusr.org/mailman/listinfo/gradsusr </div></body></html>