possible bug or change regarding logical variables in NCL 5.1.0

From: Jonathan Vigh <vigh_at_nyahnyahspammersnyahnyah>
Date: Mon, 09 Mar 2009 22:10:46 +0000

    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

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.


; 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
function parse_by_whitespace(tStr[1]:string)

  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

     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 all the nonwhitespace positions to be False, so what's left are
the whitespaces (as True)
     notwhitespace(1:nchars) =
; 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 =

; 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) =
  ; <- this is line 322 in the original file - the error message
references this line
        end do
        output_array = string_FillValue
     end if

     output_array = tStr
  end if


ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Mon Mar 09 2009 - 16:10:46 MDT

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