Re: gsn_csm and gsn_code

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 8 Mar 2007 07:06:19 -0700 (MST)

Hello,

NCL's "scoping rules" are the same as Pascal's.

One way to think of this is that within and NCL
script each line of code s only aware of what has previously
been defined. The same applies to functions and procedure.

Example:

[a] x = 5

    function foo(x)
    begin
      return(3.14*x)
    end

    newX = foo(x) ; both 'foo' and 'x' have been defined
                    ; hence, all works fine

[b] x = 5

    newX = foo(x) ; 'x' has been defined
                    ; where is 'foo'?

    function foo(x)
    begin
      return(3.14*x)
    end

    You can see 'foo', I can see 'foo' but NCL can not :-)
    The line "newX=..." is only aware of what has been previously been defined.

NCL is an interpreted language. The behavior is different from that
of compiled languages [fortran, C,..] where a loader/linker allows
functions/subroutines to be created in any order and, later, accessed
during execution.

Now the answer to your question:

gsn_csm.ncl uses functions and procedures defined in gsn_code.ncl
Hence, the following works

 load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl
 load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_csm.ncl

The following does not because gsn_csm is trying to use
functions and procedures that have not yet been defined.

 load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_csm.ncl
 load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl
   

See also:

  http://www.ncl.ucar.edu/Support/talk_archives/2004/0364.html
  The URL in the above is out-of-date, See:
  http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Scoping
Regards,
D
On Thu, 8 Mar 2007, ozan mert gokturk wrote:

> Hi All,
>
> I am having a very strange problem about "gsn_code.ncl" and "gsn_csm.ncl" When I
> call these from nclex directory,
>
> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl
> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_csm.ncl
>
>
> there is no problem. But when they are called from nclscripts directory as,
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
>
>
> following is printed,
>
> fatal:syntax error: line 953 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl before or near \n
> set_attr(tires,axis_res,"")
> --------------------------------^
>
> fatal:syntax error: possibly an undefined procedure
> fatal:syntax error: line 959 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl before or near \n
> set_attr(tires,axis_res,axis_string)
> -----------------------------------------------^
>
> fatal:syntax error: possibly an undefined procedure
> fatal:syntax error: line 965 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl before or near \n
> set_attr(tires,axis_res,axis_string)
> ---------------------------------------------^
>
> with many more lines like these..
>
> What is wrong? Thanks in advance
>
> Ozan
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 08 2007 - 07:06:19 MST

This archive was generated by hypermail 2.2.0 : Mon Mar 12 2007 - 11:26:34 MDT