[ncl-talk] using scoping to create global variables
Dennis Shea
shea at ucar.edu
Mon Jul 2 16:45:52 MDT 2018
Attached is a small file that I used for global constants. Yes, *clumsy
naming" but
I could not think of any other way to accomplish global scope and
eliminate
possible overwriting of the constants.
load "/....../CAS_common.ncl"
I tried to encourage people to try this approach but, alas, I was not
successful.
NOTE: NCL *automatically* loads a large number of libraries. In fact, NCL
6.5.0:
https://www.ncl.ucar.edu/future_release.shtml
loads [imports] every library [I think!]. What I had envisioned was:
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/*CAS_common.ncl*" ; <=== *NOT* done
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/bootstrap.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/extval.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/crop.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/heat_stress.ncl"
"$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
That way, the 'global variable constants' could be used for consistency
within all libraries.
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
>>
>>
>
> _______________________________________________
> 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/b59080e0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CAS_common.ncl
Type: application/octet-stream
Size: 4350 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180702/b59080e0/attachment.obj>
More information about the ncl-talk
mailing list