Re: global variables in procedures

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 31 Jul 2009 08:57:16 -0600

NCL does not have an *explicit* way of defining
"global variables". However, NCL's scoping rules
which are similar to Pascal's, can be used to
simulate "global variables"

The reference manual
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual
specifically, the NCL statement documentation,
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Scoping

I have attached two power point slides from the NCL Workshop
that illustrate defining and usage of 'global' variables.
Of course, the lectures explain the slides in detail.

In a nutshell:

   GRAVITY = 9.8 ; use some naming convention for
                        ; global variables [here, all caps]

   load "..."
   load "..."
   function foo(...)
   local a, b, c, g2

   g2 = GRAVITY^2 ; use 'global' GRAVITY variable
      [more code]
   return (x)
   end

   procedure phooey(...)
   local aa, bb, cc

   dumy = 2*GRAVITY ; use global variable
   [snip]
   end

   Main CODE

Mark.Collier_at_csiro.au wrote:
> Hi,
>
> is it possible to have global variables in procedures? Sometimes it is useful for reducing code amounts but my experiences so far suggest that non-locally defined variables are not available at the calling level. Of course could load ncl script with this sort of code but it is safer to be able to (generally) locally define variables, as exists in procedures.
>
> Thanks,
> Mark.
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Fri Jul 31 2009 - 08:57:16 MDT

This archive was generated by hypermail 2.2.0 : Fri Jul 31 2009 - 14:51:03 MDT