<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">"run myscript.gs "args</span></font></div><div><br></div><div>and if that script returns something via the <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">return</span></font> statement, then that string is available to the first script in the <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">result </span></font>variable. </div><div><br></div><div>Example:</div><div><br></div><div>script a:</div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">"run b.gs testing"</span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">say "--->"result"<---"</span></font></div><div><br></div><div>script b:</div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">function b(args)</span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">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" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">---->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 type="cite"><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">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">http://www.iges.org/grads/gadoc/library</a><br>> <a href="ftp://grads.iges.org/grads/scripts/plotskew.gs">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">gradsusr@gradsusr.org</a><br>> > <a href="http://gradsusr.org/mailman/listinfo/gradsusr">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>> > <br>><br>> -- <br>><br>> Please note that <a href="mailto:Charles.Seman@noaa.gov">Charles.Seman@noaa.gov</a> should be considered my NOAA<br>> email address, not <a href="mailto:cjs@gfdl.noaa.gov">cjs@gfdl.noaa.gov</a>.<br>><br>> ********************************************************************<br>> Charles Seman <a href="mailto:Charles.Seman@noaa.gov">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/">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">gradsusr@gradsusr.org</a><br>> <a href="http://gradsusr.org/mailman/listinfo/gradsusr">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________<br>> gradsusr mailing list<br>> <a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>> <a href="http://gradsusr.org/mailman/listinfo/gradsusr">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>> <br><br>-- <br><br>Please note that <a href="mailto:Charles.Seman@noaa.gov">Charles.Seman@noaa.gov</a> should be considered my NOAA<br>email address, not <a href="mailto:cjs@gfdl.noaa.gov">cjs@gfdl.noaa.gov</a>.<br><br>********************************************************************<br>Charles Seman <a href="mailto:Charles.Seman@noaa.gov">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/">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">gradsusr@gradsusr.org</a><br>http://gradsusr.org/mailman/listinfo/gradsusr<br></div></blockquote></div><br></div></body></html>