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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: question on READ_CSV [message #83461] Tue, 05 March 2013 04:37
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
Re: question on READ_CSV [message #83462 is a reply to message #83461] Mon, 04 March 2013 23:40 Go to previous message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den tisdagen den 5:e mars 2013 kl. 05:28:36 UTC+1 skrev andry:
>
> I guess you are right, if I just stick -9999 at the very first line, then everything works fine.

A space works, too. In case you want to continue using your code when you suddenly have data that could involve large negative numbers.
Re: question on READ_CSV [message #83463 is a reply to message #83462] Mon, 04 March 2013 20:28 Go to previous message
andry is currently offline  andry
Messages: 7
Registered: March 2013
Junior Member
On Tuesday, March 5, 2013 12:50:15 AM UTC-3:30, 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.")

Thanks David,

I guess you are right, if I just stick -9999 at the very first line, then everything works fine.
Re: question on READ_CSV [message #83464 is a reply to message #83463] Mon, 04 March 2013 20:20 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
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:15:54 PDT 2025

Total time taken to generate the page: 0.00616 seconds