Re: possible bug or change regarding logical variables in NCL 5.1.0

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 9 Mar 2009 17:35:01 -0600

Hi Jonathan,

It appears that a change we made to logicals has some unintended
consequences.

It used to be that a logical had a default missing of value of -1,
which doesn't really
make sense. So, this was changed to be "Missing" instead. However,
apparently this
also broke some working code.

For now, try using "_Missing" instead of "False". (The error is also
misleading, as it
mentions "Missing" and not "_Missing".)

What you are doing should probably be allowed, but logicals are a
weird issue, so we'll need to sort this out.

--Mary

On Mar 9, 2009, at 4:10 PM, Jonathan Vigh wrote:

>
> Greetings,
> Upon upgrading to the new version of NCL (5.1.0), one of my
> functions stopped working. I now get the following error:
>
> warning:Logical type variable (whitespace) missing value can only be
> set
> to Missing: setting to Missing
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading tChr
> fatal:Execute: Error occurred at or near line 322 in file
> ./module_read_vdm.ncl
>
> As you'll see in this function, I'm defining the _FillValue for a
> logical variable (whitespace) to be False rather than the default (-1)
> so that I can use it do some mask operations. For some reason, the new
> NCL doesn't seem to like this. Has there been a change to the behavior
> or handling of logical variables? My function code is below.
>
> Jonathan
>
>
>
> ;----------------------------------------------------------------------
> ; This function parses a string into an array holding each
> ; of the strings ("words" or space- or tab-delimited items) with
> ; whitespace removed.
> ;
> ; It changes all the characters to upper case
> ;
> ; Author: Jonathan Vigh
> ;----------------------------------------------------------------------
> undef("parse_by_whitespace")
> function parse_by_whitespace(tStr[1]:string)
> local
> space
> ,tab
> ,ii
> ,is
> ,tStr
> ,tChr
> ,nchars
> ,stringOn
> ,string_begin
> ,string_end
> ,string_begin_indices,string_end_indices,nparsed_strings,output_array
>
> begin
> space = inttochar(32)
> tab = inttochar(9)
> nullChar = inttochar(0)
>
> tChr = stringtochar(tStr)
> nchars = dimsizes(tChr)
>
> ; Get indices where there are no whitespaces .
> ii = ind(tChr.ne.space.and.tChr.ne.tab.and.tChr.ne.nullChar)
>
> if (.not.all(ismissing(ii))) then ; First check to make sure the
> tStr isn't completely devoid of whitespace delimiters
>
> ; mask out a logical array that starts off being filled with 'True',
> then falsified by tests (using mask)
> whitespace = new(nchars+2,"logical") ; make this bigger than
> the
> actual character array by adding a phantom space in the beginning and
> end
>
> whitespace = True ; all positions are assumed to be
> whitespace at first (including the first and last positions which are
> really phantom positions)
> whitespace@_FillValue = False
>
> notwhitespace = whitespace ; transfer to another array
> which
> we will later make the opposite of whitespace
> notwhitespace(0) = False ; the first position in the array
> is phantom and must always be whitespace
> notwhitespace(nchars+1) = False ; the last position in the
> array
> is phantom and must always be whitespace
>
> whitespace(1:nchars) =
> mask
> (whitespace
> (1:nchars),tChr.ne.space.and.tChr.ne.tab.and.tChr.ne.nullChar,False)
> ; mask all the nonwhitespace positions to be False, so what's left are
> the whitespaces (as True)
> notwhitespace(1:nchars) =
> mask
> (notwhitespace
> (1:nchars),tChr.eq.space.or.tChr.eq.tab.or.tChr.eq.nullChar,False)
> ; mask all the whitespace positions to be False, so what's left are
> the
> nonwhitespaces (as True)
>
> ; explanation of the logic - the only way a string can begin is if the
> current character position is NOT whitespace, so we start with an
> array
> of all positions where this is True
> ; next we mask out all the possible ways a string can NOT start
> (i.e. if
> the previous character position is also NOT whitespace)
> string_begin =
> mask(notwhitespace(1:nchars),notwhitespace(0:nchars-1),False)
>
> ; and now we mask out all the possible ways a string can NOT end (i.e.
> if the next character position is also NOT whitespace)
> string_end =
> mask(notwhitespace(1:nchars),notwhitespace(2:nchars+1),False) ;
> now
> mask as True all positions where the next character is whitespace but
> the current one isn't
>
> string_begin_indices = ind(string_begin.eq.True)
> string_end_indices = ind(string_end.eq.True)
>
> ; Now load the parsed strings into a return array of strings
> nparsed_strings = dimsizes(string_begin_indices)
>
> ; Set up the output array filled with empty strings
> output_array = new(nparsed_strings,"string",string_FillValue)
>
> if (nparsed_strings .ge. 1) then
> do is = 0, nparsed_strings-1
> output_array(is) =
> chartostring(tChr(string_begin_indices(is):string_end_indices(is)))
> ; <- this is line 322 in the original file - the error message
> references this line
> end do
> else
> output_array = string_FillValue
> end if
>
> else
> output_array = tStr
> end if
>
> return(output_array)
> end
>
> _______________________________________________
> 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 Mon Mar 09 2009 - 17:35:01 MDT

This archive was generated by hypermail 2.2.0 : Mon Mar 09 2009 - 21:47:10 MDT