[ncl-talk] using scoping to create global variables

Jon Meyer jonathan.meyer at aggiemail.usu.edu
Mon Jul 2 18:02:14 MDT 2018


Thanks Rick and Dennis.

Will try some things out here. My main program loads the library of my
local functions similar to what Dennis is recommending. I'm curious to try
setting the global variables in the main program outside of the begin/end
block and see if it is passed to the loaded library functions. If that
doesn't work, I'm happy to hardcode a set of variables at the top of each
main and function library.

On Mon, Jul 2, 2018 at 4:23 PM, Rick Brownrigg <brownrig at ucar.edu> wrote:

> Any variable declared/defined outside of the scope of a
> procedure/function/outer-begin-end block will be in the global scope.  It
> has to have been defined before it is ever referenced.
>
>  a = 3.14
>
> procedure foo()
> begin
>    print("foo sees a: " + a)
> end
>
> procedure bar()
> begin
>    print("bar sees a: " + a)
> end
>
> begin
>    print("main sees a: " + a)
>    foo()
>    bar()
> end
> (0)    main sees a: 3.14
> (0)    foo sees a: 3.14
> (0)    bar sees a: 3.14
>
>
> On Mon, Jul 2, 2018 at 1:43 PM, Jon Meyer <jonathan.meyer at aggiemail.usu.
> edu> wrote:
>
>> Hello,
>>
>> I'm hoping to streamline some automated cron job NCL code I've written
>> that could greatly benefit from having global variables set that the main
>> program and functions/procedures can all share..mainly, the directory
>> system I'm navigating around so I don't have to hardcode or pass directory
>> strings in and out of variables.
>>
>> I know NCL isn't directly able to do global variables, but some reading
>> into this shows the ability to take advantage of NCL's scoping to
>> essentially create global variables.
>>
>> I've looked through past ncl-talk threads but the discussion on how to
>> accomplish this is light other than it can be done, and the scoping
>> discussion on the ncl page isn't as visually helpful on how to do this.
>> After a few attempts, I've failed trying to follow the basic example
>> included in the few ncl-talk threads from the past so I'm hoping someone
>> can elaborate or provide an example for setting string (or other type)
>> variables to be accessible to functions/procedures called from main code
>> where the strings are set.
>>
>> Any help of time is appreciated.
>>
>> --
>> Jonathan D.D. Meyer, Ph.D.
>> Utah State University
>> Department of Plants, Soils & Climate
>> Utah Climate Center
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>


-- 
Jonathan D.D. Meyer, Ph.D.
Utah State University
Department of Plants, Soils & Climate
Utah Climate Center
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180702/9730f507/attachment.html>


More information about the ncl-talk mailing list