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

Home » Public Forums » archive » Error using data structures while reading ASCII file with different data types
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
Error using data structures while reading ASCII file with different data types [message #87438] Mon, 03 February 2014 08:51 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have the following data in an ASCII file (filename.txt):

2006-01-31 08:59:26 65.04 22.92 0.207226 0.150028 0.000000 0.057198
2006-01-31 08:59:26 65.22 22.92 0.231006 0.167339 0.000000 0.063667
2006-01-31 08:59:26 65.40 22.92 0.273280 0.201961 0.000000 0.071319
2006-01-31 08:59:26 65.58 22.92 0.255984 0.190420 0.000000 0.065564
2006-01-31 08:59:26 65.76 22.92 0.303038 0.225042 0.000000 0.077996
...
...
...


I tried to read this file with the following lines in IDL:
; ----------------------------------
PRO test.pro

nlines=FILE_LINES('filename.txt')
file_data=STRARR(nlines)
OPENR,lun,'filename.txt',/GET_LUN
READF,lun,file_data
CLOSE,lun & FREE_LUN,lun

dataStruct= { yyyy:0, mm:0, dd:0, hr:0, mi:0, sec:0, $
lon:0.0, lat:0.0, p1:0.0, p2:0.0, p3:0.0, p4:0.0 }

data=REPLICATE(dataStruct,nlines)
FOR ii=0,(nlines-1) DO BEGIN

str=file_data[ii]

str_array=STRSPLIT(str,' ',/EXTRACT)
yyyymmdd=STRSPLIT(str_array(0),'-',/EXTRACT)
hhmmss=STRSPLIT(str_array(1),':',/EXTRACT)

year=FIX(yyyymmdd(0)) & month=FIX(yyyymmdd(1)) & day=FIX(yyyymmdd(2))
hour=FIX(hhmmss(0)) & minutes=FIX(hhmmss(1)) & seconds=FIX(hhmmss(2))
long=FLOAT(str_array(2)) & lat=FLOAT(str_array(3))
par1=FLOAT(str_array(4)) & par2=FLOAT(str_array(5))
par3=FLOAT(str_array(6)) & par4=FLOAT(str_array(7))

data[*,ii]=[year,month,day,hour,minutes,seconds, $
long,lat,par1,par2,par3,par4]

ENDFOR

END
;-------------------------------------------------

I get the following error ...
% Conflicting data structures: POLDER_DATA,<FLOAT Array[12]>.

Can anyone suggest me where I am going wrong and what my mistake was? Any solution to my problem?

Thanks in advance ...
Re: Error using data structures while reading ASCII file with different data types [message #87439 is a reply to message #87438] Mon, 03 February 2014 09:21 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
You have an array of data structures, so you need to pass in a structure. Right now you are passing an array. Instead of this:

data[*,ii]=[year,month,day,hour,minutes,seconds, $
long,lat,par1,par2,par3,par4]

try:

data[ii].year = year
data[ii].month = month
data[ii].day = day
...
...

Or look at the Struct_Assign procedure
http://exelisvis.com/docs/STRUCT_ASSIGN.html
Re: Error using data structures while reading ASCII file with different data types [message #87440 is a reply to message #87438] Mon, 03 February 2014 09:41 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> Can anyone suggest me where I am going wrong and what my mistake was? Any solution to my problem?

Try doing a .reset and running your program again. I think IDL is just
confused. :-)

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.")
Re: Error using data structures while reading ASCII file with different data types [message #87448 is a reply to message #87439] Tue, 04 February 2014 02:12 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Thanks Matthew ...This works!!!
Re: Error using data structures while reading ASCII file with different data types [message #87455 is a reply to message #87448] Tue, 04 February 2014 06:07 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
On Tuesday, February 4, 2014 5:12:25 AM UTC-5, Madhavan Bomidi wrote:
> Thanks Matthew ...This works!!!

You are welcome! After thinking a little more, you could also use a structure, similar to the original:

data[ii] = { YYYY:year, MM:month, DD:day, HR:hour, MI:minutes, SEC:seconds, $
LON:long, LAT:lat, P1:par1, P2:par2, P3:par3, P4:par4 }


By using square brackets, you created a numeric array and forced all of your numbers to be floats. An array of floats cannot fit into an array of structures. You can, however, use curly brackets to create a structure.
Re: Error using data structures while reading ASCII file with different data types [message #87466 is a reply to message #87455] Wed, 05 February 2014 01:04 Go to previous message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
It's been a great learning experience on data structures. This also work fine ... Matthew!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: name a variable with number
Next Topic: Theil–Sen estimator anyone?

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

Current Time: Wed Oct 08 15:17:33 PDT 2025

Total time taken to generate the page: 0.00896 seconds