comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: question on READ_CSV
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: question on READ_CSV [message #83461] Tue, 05 March 2013 04:37 Go to previous message
jeffnettles4870 is currently offline  jeffnettles4870
Messages: 111
Registered: October 2006
Senior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: question on READ_CSV
Next Topic: Re: setintersection assumes sets have no repetitions?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:51:59 PDT 2025

Total time taken to generate the page: 0.00452 seconds