[ncl-talk] using scoping to create global variables

Rick Brownrigg brownrig at ucar.edu
Mon Jul 2 16:23:06 MDT 2018


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180702/af9f435d/attachment.html>


More information about the ncl-talk mailing list