Re: testing for a blank (null) character

From: Jonathan Vigh <vigh_at_nyahnyahspammersnyahnyah>
Date: Tue, 05 Jun 2007 23:11:03 +0000

Hmmmmm, I found a workaround (actually I think I've solved this before,
but forgot my solution).

Since I originally read each line into a string, I can use NCL's string
function 'strlen' to check if each string has a nonzero length:

       if (strlen(tStr(i)) .gt. 0) then ; do some stuff to keep line

I'm still curious to know how one would test whether a character
variable was null however. I don't think I was able to get a test using
ismissing to work.

Jonathan

On Tue, 2007-06-05 at 22:22 +0000, Jonathan Vigh wrote:
> Greetings,
> I'm reading in a mixed type irregular ascii text file. Some of the
> lines are completely blank (no spaces). I'd like to test against this
> and take out the blank lines. Is there any way to test to see if the
> first character of a line is null?
>
> First I read my file as a unlimited dimensioned array of strings (each
> line is one string).
>
> tStr = asciiread("foo.txt", -1,"string")
>
> Then I convert the 1D string array into a 2D character array:
>
> tChr = stringtochar(tStr)
>
> Next, the first character of the i-th row in the character array is read
> into a character variable called FIRST:
>
> FIRST = tChr(i,0)
>
> Now I test to see if it's an exclamation point (a comment line):
> if (FIRST .ne. "!") then . . .
>
> This test works, but if I test to see if the first character is entirely
> blank, the test fails and the script goes merrily on:
>
> if (FIRST .ne. " ") then
>
> This is because the FIRST is apparently equal to the null character '/0'
> and not a space. Is there a way to test if a character variable is
> null?
>
> I'm guessing that there is something that can be done using the
> FillValue or missing value attributes, but I guess I'm at a loss as how
> to properly do this.
>
> I've attached an example script and example input file if anyone wants
> to look at this.
>
> Thanks,
> Jonathan
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jun 05 2007 - 17:11:03 MDT

This archive was generated by hypermail 2.2.0 : Thu Jun 14 2007 - 09:39:54 MDT