Hi,
Today I wrote a function "numInt( int[1]: integer)" to count the number of an integer number "int".
I have placed the variable "int" into the local list in this self-defined function. However, the "local list" seems not working for me, because my self-defined function("numInt") changed the value of "int" , and assigned that new value back to the variable "INT" in the main program. This means, I will definitely get a wrong result if I use the variable "INT" in the main program a second time after calling the function "numInt( int[1]: integer)" .
I simplified the script and attached it behind this letter. The detailed information are also as the following:
>ncl -x t.local.ncl
Copyright (C) 1995-2011 - All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 6.0.0
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
+ ;------------------------l------xf-----------------------
+ ; Contour the number of the integers of the input numeric value.
+ undef ("numInt")
+ function numInt(int[1]:integer)
+ local int,numI,intTem ; Placing the local variable's name "int" in the local list !
+ begin
+ numI=0
+ do while (int .ne. 0)
+ int = int/10
+ numI = numI+1
+ end do
+
+ return(numI)
+ end
+
+ ;---------------
+ ; Main program
+ begin
+ INT= 1980
+ print(INT) ; The value in the main program is 1980!
+ num_nt = numInt(INT) ; Call a function.
+ print (" Number of the integers of "+INT+" is "+num_nt)
+ print(INT) ; The value changed to 0. Oberviously, it is changed by the local variable in function "numInt".
+ end
Variable: INT
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes:[1]
Coordinates:
(0)1980
(0) Number of the integers of 0 is 4
Variable: INT
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes:[1]
Coordinates:
(0)0
+
+
Any suggestions or comments are appreciated.
Best Regards,
Li
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2.1.8 : Mon Apr 09 2012 - 13:43:03 MDT