.gsf function return value doesnt work

Jennifer Adams jma at COLA.IGES.ORG
Fri May 15 13:33:41 EDT 2009


Hi, Pablo --
I am unable to duplicate this problem. I tried it on my mac and on our  
64-bit linux server. I copied your addit.gsf and modified it to create  
addit2.gsf and they both seem to work fine and return a value to  
test.gs. Here is my code, plus the text of the GrADS session:

addit.gsf:

function addit(var1,var2)
sum=var1+var2
say 'addit: 'var1'+'var2'='sum
return (sum)

addit2.gsf      :

function addit2(args)
var1=subwrd(args,1)
var2=subwrd(args,2)
sum=var1+var2
say 'addit2: 'var1'+'var2'='sum
return (sum)

test.gs:

rc = gsfallow("on")
tx=addit(2,3)
say 'addit returned 'tx

args="2 3"
tx=addit2(args)
say 'addit2 returned 'tx


  # /usr/local/grads/2.0/2.0.a5/grads -lbc test

Grid Analysis and Display System (GrADS) Version 2.0.a5
Copyright (c) 1988-2008 by Brian Doty and the
Institute for Global Environment and Society (IGES)
GrADS comes with ABSOLUTELY NO WARRANTY
See file COPYRIGHT for more information

Config: v2.0.a5 little-endian readline printim grib2 netcdf hdf4-sds  
geotiff
Issue 'q config' command for more information.
GX Package Initialization: Size = 11 8.5
Running in Batch mode
addit: 2+3=5
addit returned 5
addit2: 2+3=5
addit2 returned 5
ga->


--Jennifer

--
Jennifer M. Adams
IGES/COLA
4041 Powder Mill Road, Suite 302
Calverton, MD 20705
jma at cola.iges.org


On Mar 11, 2009, at 1:37 PM, Pablo Romero wrote:

> I'm reposting this question, since I dont know if the listserver  
> rejected it the first time...
>
> I've never been able to get the following to work: use the  
> 'return(varname)' statement within a .gsf function to return a value.
>
> I've only been able to accomplish the passing of variables around  
> between scripts by using '_varname' global variables, but this  
> defeats the whole purpose of creating a script function.
>
> I want to create a .gsf function that can actually return a value  
> that can be directly assigned to a variable in a .gs file.
>
> example:
>
> *gsf file, addit.gsf
>
> function addit(var1,var2)
> sum=var1+var2
> return (sum)
>
> *test gs file, tst.gs
>
> rc = gsfallow("on")
> tx=addit(2,3)
> say '2+3 is 'tx
>
> however, this doesnt work...
> it simply prints '2+3 is ', so the gsf function is NOT returning the  
> value of the 'sum' variable...
>
> Is this by design or am I doing something incorrectly?
> are global variables the ONLY way to pass variables between script/ 
> script function files?
>
> If this *is* by design, then I would please like to submit a request  
> to COLA to consider fixing this in future versions.
>
> P.Romero
> _________________________________________________________________
> Windows Live™ Contacts: Organize your contact list.
> http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20090515/1f56393c/attachment.html 


More information about the gradsusr mailing list