<div dir="ltr"><div>Yes, the following are prototyped as requiring type 'logical'<br></div><div><br></div><div><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/num.shtml"><b>num</b></a>, <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_num.shtml"><b>dim_num</b></a>, <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_num_n.shtml"><b>dim_num_n</b></a></div><div><br></div><div>---</div><div>I prefer strong typing also. <br></div><div>---<br></div><div>I went back over previous releases to see if the '<b>num</b>' prototyping had been 'relaxed'.</div><div><br></div><div>6.1.0: October 28, 2012: <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_num_n.shtml" target="_blank"><b>dim_num_n</b></a> => <b><span style="color:rgb(255,0,0)">fixed a bug in the prototyping
of this function</span></b></div><div> No idea what the 'bug' was.<br></div><div>6.0.0: 30 May 2011: <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/num.shtml" target="_blank"><b>num</b></a> - a long will be returned if
you're on a 64-bit system and the count is >= 2 GB</div><div>5.1.1: June 16, 2009: <b>dim_num_n </b>added to built-in library</div><div>4.2.0.a027: 30 December 2002: <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_num.shtml"><strong>dim_num</strong>:</a> Counts the number of <b>True</b> values of the n-1 rightmost
dimension for all dimensions 0...n-2 <br></div><div><br></div><div>---</div>%> cat > tst_num.ncl<br>A = (/True,False,False,True/)<br>a = (/ 1 , 0, 0 , 1 /) <br>nA = num(A)<br>na = num(a) ;<b> warning message</b><br>print(nA)<br><div>print(na)</div><div><br></div><div>===</div><div>%> ncl tst_num.ncl</div><div><br></div><div><b>warning:</b>Argument 0 of the current function or procedure was <b>coerced to the appropriate type </b>and thus will not change if the function or procedure modifies its value</div><div><br></div><div>Both 'nA' and 'na' = 2 so it worked for integer 0,1<br></div><div><br></div><div>I **speculate** <b>NCL's coercion</b> is the culprit. <b><br></b></div><div><b>Speculation^2</b>: Likely, this has been present since 1995!!! Yikes.<br></div><div><br></div><div>This subtle issue is not likely to be altered ... especially now.</div><div><br></div><div>===</div><div>I'll add something to the documentation of these functions.</div><div><br></div><div>D<br></div><div><br></div><div><strong></strong></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 14, 2019 at 10:41 AM Dave Allured - NOAA Affiliate via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Please note that in the documented prototypes for the functions num, dim_num, etc., the stated input data type is logical only. It looks like the ability for numeric input was added as an afterthought, then the documentation was not properly updated. In my opinion this complicates the use and understanding of these functions. I would prefer that the num family functions accept only type logical, and return a type error for numeric input.<div><br></div><div>If you want functions that count non-zero numeric values, then add them explicitly with new names. This is just my opinion, but I prefer strong type safety when programming.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 14, 2019 at 8:19 AM Rashed Mahmood via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi Rick, <br></div><div>Thanks for the answer. <br></div><div>I thought it should be 7, so that it is equal to the results from dimsizes. But, of course, this is not a good comparison, comparing two different functions. <br></div><div></div><div>I agree that it would consider 0 values as False, as is written in documents.</div><div><br></div><div>Cheers,</div><div>Rashed<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 14, 2019 at 3:55 PM Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi Rashed,</div><div><br></div><div>It seems to me the functions are working as advertised, given that they are counting "true" values, not counting number of non-missing values. And as you likely know, its quite common in many programming languages (C/C++, Go, Python, Javascript) for a 0 value to represent boolean False, and anything non-zero to be True.</div><div><br></div><div>In your example here:</div><div><br></div><div><span style="color:rgb(255,0,0)">cd = (/9,10,0,0,0,5,8./)</span></div><div><span style="color:rgb(255,0,0)"><br></span></div><div>are you suggesting the answer should be 7 or 4?</div><div><br></div><div>Rick<br></div><div><span style="color:rgb(255,0,0)"><br></span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 14, 2019 at 3:25 AM Rashed Mahmood via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi All,<br></div><div>My concern is ignoring "0" when the num and it's relatives (dim_num*) functions do a counting when NOT evaluating a certain condition. I do know that it is clearly written in the documents that "All numerical values <b>except for 0</b> evaluate to True."</div><div><br></div><div><span style="color:rgb(255,0,0)">My concern is that<b> if someone forgets about this "0" exception</b></span>, things could go very wrong: Here is how:</div><div> <br></div><div><span style="color:rgb(255,0,0)">ab = fspan(0,30,20)<br> print(num(ab)+" ... "+dim_num_n(ab,0)+" ... "+num(ab.ge.0)+" ... "+dimsizes(ab))</span></div><div><span style="color:rgb(255,0,0)">(0) 19 ... 19 ... 20 ... 20</span></div><div><span style="color:rgb(255,0,0)"><br></span></div><div><span style="color:rgb(255,0,0)"> cd = (/9,10,0,0,0,5,8./)<br> print(num(cd)+" ... "+dim_num_n(cd,0)+" ... "+dimsizes(cd))</span></div><div><span style="color:rgb(255,0,0)">(0) 4 ... 4 ... 7</span></div><div><br></div><div></div><div>But these does not fail and give fatal error when used without any condition, although there is not so helpful warning message. The concern is that if these cannot provide right answer these must give error message suggesting that 0 values occurred while counting or something similar?</div><div><br></div><div>Cheers,</div><div>Rashed</div></div></blockquote></div></blockquote></div></blockquote></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote></div>