Re: Read several files into one big data array? [message #89508 is a reply to message #89507] |
Wed, 22 October 2014 14:23   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
lucesmm@gmail.com writes:
>
> I have tons of data files in the same folder. They are named correctly with the last 5 digits representing the order
> Example
> FILE_00001.dat
> FILE_00002.dat
> ....
> Within this files I have data formatted like this, The length of the data varies from file to file
> _____________________________________
> seconds Time data1 data2
> 189 00:03:09 111.20 770.62
> 3785 01:03:05 200.15 255.66
> 7345 02:02:25 198.83 779.16
> 10983 03:03:03 200.01 555.55
>
> #Comments
> #Comments
> #Comments
>
> ____________________________________
>
>
> I want to read all the files and storage the data in the following format
> _________________________________________
> data=[
> 00001 4189 00:03:09 111.20 770.62
> 00001 3785 01:03:05 200.15 255.66
> 00001 745 02:02:25 198.83 779.16
> 00001 10983 03:03:03 200.01 555.55
> 00002 532 02:56:00 888.01 998.20
> 00002 200 23:59:52 222.00 000.10
> ....]
> _________________________________________
> So this is what I have so far. But I am stock with getting the data from the title
> PRO
> files = file_search('\folder','*.dat', COUNT=nfiles)
>
> for i=0, nfiles-1 do begin
>
> nlines = FILE_LINES(files[i])
> data = FLTARR(nlines)
> OPENR, lunit, files[i], /get_lun
> READF, lunit, data, FORMAT='(6(I, C(CHI.2, ':', CMI.2, ':', CSI.2),2F))'
> CLOSE, lunit
> FREE_LUN, lunit
> endfor
I would add these two lines between your OPENR and READF lines:
header = ""
READF, lunit, header
If you want the name of each column, you could do this after you read
the header line:
names = StrSplit(header, /Extract)
The variable "names" will be a four-element array containing the names
of the four columns of data.
By the way, you don't need the "CLOSE, lunit" statement in your code.
FREE_LUN will close the file unit for you while it is freeing it up to
be used again.
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.")
|
|
|