Read data as array structure [message #79202] |
Fri, 03 February 2012 00:32  |
Tasos
Messages: 4 Registered: February 2012
|
Junior Member |
|
|
Hello,
I am trying to define an array structure having a string parameter and
floats, in order to read a data file. The problem is, when I define
the first parameter of the structure as a string and then read the
file, this string parameter contains the data of the whole line and
not the first data entry. I guess by giving you an example would be
much easier to understand my problem...
Let's say that I have the data file below with this entries...
name 0.386216 1286.08
name 0.391236 1080.36
I first create the array structure...
dataStruct = { name:'' p2:0.0, p3:0.0 }
...with two lines
data = replicate(dataStruct, 2)
and then read the data.
readf, lun, data
I then get the error --> % READF: Input conversion error. Unit: 100
How I can avoid the problem of the string variable reading the whole
line of the data file?
PS. Of course I would like an answer which is related on the array
structure and not how to just read the data from the file!
Thanks!
Tas
|
|
|
Re: Read data [message #79263 is a reply to message #79202] |
Sun, 19 February 2012 11:07  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
Based on the file Dave showed me, it seems that it is always one
record per line, with 13 fields per record, with records separated by
whitespace. I could read the file into a nice 13,52 array with
lines=strarr(file_lines('psi_input.txt'))
openr,unit,'psi_input.txt',/get_lun
readf,unit,lines
free_lun,unit
slines=strsplit(lines,/extract)
linesarr=transpose(slines.toarray())
From there you can convert some columns into other types. I am
guessing some would be integers, some would be reals.
On Feb 18, 11:31 am, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Feb 18, 1:26 am, DavePoreh <d.po...@gmail.com> wrote:
>
>> as you can see, i have different format per each line (Number- date
>> (15-Oct-2003)- file address , etc.) i just need to read this file and
>> then call it during my code.
>
> Actually I cannot see. I do not know where the line breaks are in the
> file or just show up because of the message. Can you make the file (or
> a few lines of it) available somewhere?
|
|
|
Re: Read data [message #79271 is a reply to message #79202] |
Sat, 18 February 2012 05:31  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Feb 18, 1:26 am, DavePoreh <d.po...@gmail.com> wrote:
> as you can see, i have different format per each line (Number- date
> (15-Oct-2003)- file address , etc.) i just need to read this file and
> then call it during my code.
Actually I cannot see. I do not know where the line breaks are in the
file or just show up because of the message. Can you make the file (or
a few lines of it) available somewhere?
|
|
|
Re: Read data [message #79272 is a reply to message #79202] |
Fri, 17 February 2012 19:59  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
DavePoreh writes:
> as you can see, i have different format per each line (Number- date
> (15-Oct-2003)- file address , etc.) i just need to read this file and
> then call it during my code.
> Can somebody please help,
How much money do you have in your budget? ;-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|