On Monday, March 4, 2013 11:20:15 PM UTC-5, David Fanning wrote:
> andry writes:
>
>
>
>> I have a CSV file (example below)
>
>>
>
>> 1,11,06,30,12,57,30,00,,69,39
>
>> 2,11,06,30,13,17,30,00,,68,39
>
>> 3,11,06,30,13,37,30,00,,77,52
>
>> 4,11,06,30,13,57,30,00,,70,44
>
>> 5,11,06,30,14,17,30,00,,72,64
>
>>
>
>> When I read the above file with READ_CSV
>
>> a=READ_CSV(flnm, missing_value=-9999)
>
>>
>
>> I expect the column 9 (starting from 1) to be -9999. However, it skips that column as if there is no column with missing value at all.
>
>>
>
>> Does somebody know how I can force the function to assign the right missing value to that column?
>
>
>
> Here is the problem:
>
>
>
> IDL> str = '1,11,06,30,12,57,30,00,,69,39'
>
> IDL> parts = StrSplit(str, ',', /Extract)
>
> IDL> Help, parts
>
> PARTS STRING = Array[10]
>
> IDL> FOR j=0,N_Elements(parts)-1 DO Print, parts[j]
>
> 1
>
> 11
>
> 06
>
> 30
>
> 12
>
> 57
>
> 30
>
> 00
>
> 69
>
> 39
>
>
>
> You see, the column has disappeared.
>
>
>
> I don't think whoever wrote this program envisioned an entire COLUMN
>
> going missing. They were thinking about specific values in otherwise
>
> intact columns going missing.
>
>
>
> I think I would try to find a way to stick my -9999 between those two
>
> extra commas in the data file.
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
You can get around this with the /preserve_null keyword to strsplit():
NVI> str = '1,11,06,30,12,57,30,00,,69,39'
ENVI> parts = StrSplit(str, ',', /Extract, /Preserve_Null)
ENVI> idx = where(parts eq '', count)
ENVI> if count gt 0 then parts[idx] = '-9999'
ENVI> Help, parts
PARTS STRING = Array[11]
ENVI> FOR j=0,N_Elements(parts)-1 DO Print, parts[j]
1
11
06
30
12
57
30
00
-9999
69
39
ENVI>
Cheers,
Jeff
|