<html><head><style> body {height: 100%; color:#000000; font-size:10pt; font-family:Arial;}</style></head><body>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><font size=2>Thanks again,<br>Mark</font></DIV><br><br>----- Original Message -----<br>From: Charles Seman <CHARLES.SEMAN@NOAA.GOV><br>To: GrADS Users Forum <GRADSUSR@GRADSUSR.ORG><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" (http://grads.iges.org/grads/gadoc/gsf.html) 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>> http://www.iges.org/grads/gadoc/library<br>> ftp://grads.iges.org/grads/scripts/plotskew.gs<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>> > gradsusr@gradsusr.org<br>> > http://gradsusr.org/mailman/listinfo/gradsusr<br>> > <br>><br>> -- <br>><br>> Please note that Charles.Seman@noaa.gov should be considered my NOAA<br>> email address, not cjs@gfdl.noaa.gov.<br>><br>> ********************************************************************<br>> Charles Seman Charles.Seman@noaa.gov<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 http://www.gfdl.noaa.gov/~cjs/<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>> gradsusr@gradsusr.org<br>> http://gradsusr.org/mailman/listinfo/gradsusr<br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________<br>> gradsusr mailing list<br>> gradsusr@gradsusr.org<br>> http://gradsusr.org/mailman/listinfo/gradsusr<br>> <br><br>-- <br><br>Please note that Charles.Seman@noaa.gov should be considered my NOAA<br>email address, not cjs@gfdl.noaa.gov.<br><br>********************************************************************<br>Charles Seman Charles.Seman@noaa.gov<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 http://www.gfdl.noaa.gov/~cjs/<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></body></html>