Re: readcol with empty fields [message #49901] |
Wed, 30 August 2006 10:59  |
news.verizon.net
Messages: 47 Registered: August 2003
|
Member |
|
|
burkina wrote:
> Instead, I need all the lines to be read and, when the field is empty,
> a value of 0 (or, better, something like NULL, something that should be
> ignored) should be put in the vector if it's a number, or simply the
> null string if it's a string field.
>
1. For strings, READCOL should already work as you wish -- an empty
field will be read as an empty string.
2. For numeric fields, try downloading a new version of strnumber.pro
from http://idlastro.gsfc.nasa.gov/ftp/pro/misc/strnumber.pro
In ancient history (1993) , there was a kluge added to strnumber.pro
such that an empty string was not considered a valid number. (At
that time, doing otherwise could corrupt the ~V3.6 IDL session.) I
have now removed this kluge so READCOL will read empty strings into
zero values.
3. For floating point numbers, you probably don't want a zero value
but rather a NaN value. In this case, I'd read the column,say f6, as
a string array, and identify the empty strings before converting to
float.
f6 = strtrim(f6,2)
bad = where(strlen(f6) EQ 0, Nbad)
if Nbad GT 0 then f6[bad] = 'NaN'
f6 = float(f6)
I suppose it would be useful to have a /NAN keyword to READCOL do this
automatically.
--Wayne
|
|
|
Re: readcol with empty fields [message #50086 is a reply to message #49901] |
Thu, 31 August 2006 06:31  |
burkina
Messages: 32 Registered: February 2005
|
Member |
|
|
Thanks Wayne!
I'm using option 3... :)
Stefano
Wayne Landsman wrote:
> burkina wrote:
>
>> Instead, I need all the lines to be read and, when the field is empty,
>> a value of 0 (or, better, something like NULL, something that should be
>> ignored) should be put in the vector if it's a number, or simply the
>> null string if it's a string field.
>>
>
> 1. For strings, READCOL should already work as you wish -- an empty
> field will be read as an empty string.
>
> 2. For numeric fields, try downloading a new version of strnumber.pro
> from http://idlastro.gsfc.nasa.gov/ftp/pro/misc/strnumber.pro
> In ancient history (1993) , there was a kluge added to strnumber.pro
> such that an empty string was not considered a valid number. (At
> that time, doing otherwise could corrupt the ~V3.6 IDL session.) I
> have now removed this kluge so READCOL will read empty strings into
> zero values.
>
> 3. For floating point numbers, you probably don't want a zero value
> but rather a NaN value. In this case, I'd read the column,say f6, as
> a string array, and identify the empty strings before converting to
> float.
>
> f6 = strtrim(f6,2)
> bad = where(strlen(f6) EQ 0, Nbad)
> if Nbad GT 0 then f6[bad] = 'NaN'
> f6 = float(f6)
>
> I suppose it would be useful to have a /NAN keyword to READCOL do this
> automatically.
>
> --Wayne
|
|
|