Re: about local variable in defined function and procedure

From: Karin Meier-Fleischer <meier-fleischer_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 17 2014 - 07:12:59 MDT

Hi,

NCL does not have global variables, but it is possible to simulate a
global variable.
If you initialize the variable x above the procedure dummy(), it works fine.

x = 0

procedure dummy()
begin
....
....
...

See also the FAQ: https://www.ncl.ucar.edu/FAQ/#core_lang_008

Bye, Karin

Am 17.03.14 13:52, schrieb Carl Schreck:
> This is something that still puzzles me too. I'm having trouble coming
> up with an example where a variable doesn't act as local. Consider the
> very simple example below, with no locals defined.
> --
> procedure dummy()
> begin
> print( "Procedure: " + isvar("x") )
> x = 1
> end; dummy
>
> begin; main
> dummy()
> print( "Main: " + isvar("x") )
> x = 5
> print(x)
> dummy()
> print(x)
> end; main
> --
>
> All of the isvar's return false, and dummy doesn't change the value of
> x in main. So what is the non-local behavior?
>
> Carl
>
>
> On Mon, Mar 17, 2014 at 2:10 AM, Jatin Kala <jatin.kala.jk@gmail.com
> <mailto:jatin.kala.jk@gmail.com>> wrote:
>
>
> This is explained here:
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml
> Search for: "The local statement and function and procedure scope"
>
> Those functions which do not have local variables declared, are
> probably for the few functions which do Not define anything new
> within the function, i.e., there is No "x=" within the function
> (hopefully).
>
>
>
>
>
>
> On 17/03/14 4:51 PM, wen wrote:
>> Hi ncl-users and Dennis,
>> I recently define ncl-fuction and procedure by myself to
>> faciliate my processing. I don't think I am familar with the
>> local variable. I find that some functions and procedures
>> pre-defined in "contributed.ncl" and others do not have local
>> variable, but some do. I am wandering when the function or
>> procedure should have local variable. Could you give me some
>> examples to show the necessary to define local variable in a
>> function or procedure. Thank you!
>>
>>
>>
>>
>> --
>> Best regards
>> Guanhuan Wen
>>
>>
>> _______________________________________________
>> 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
>
>
>
>
> --
>
> <http://www.cicsnc.org/>
> <http://www.facebook.com/cicsnc>
> *Carl J. Schreck III, PhD*
> *Research Associate*
> Cooperative Institute for Climate and Satellites NC <http://cicsnc.org/>
> North Carolina State University <http://ncsu.edu/>
> NOAA's National Climatic Data Center <http://ncdc.noaa.gov/>
> 151 Patton Ave, Asheville, NC 28801
> e: cjschrec@ncsu.edu <mailto:cjschrec@ncsu.edu>
> o: +1 828 257 3140
> CycloneCenter.org: Help analyze tropical cyclones
> <http://www.cyclonecenter.org/>
> monitor.cicsnc.org/mjo: See recent MJO diagnostics
> <http://monitor.cicsnc.org/mjo/>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
Dipl. Geophys. Karin Meier-Fleischer
Application Support, Visualization
Deutsches Klimarechenzentrum GmbH      E-Mail:   meier-fleischer@dkrz.de
Bundesstrasse 45a                      Internet: http://www.dkrz.de/
20146 Hamburg                          Phone:    +49 (0)40 460094 126
Germany                                Fax:      +49 (0)40 460094 270
Geschäftsführer: Prof. Dr. Thomas Ludwig
Sitz der Gesellschaft: Hamburg
Amtsgericht Hamburg HRB 39784

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 17 07:13:17 2014

This archive was generated by hypermail 2.1.8 : Fri Mar 21 2014 - 15:49:21 MDT