Re: Problem to read some data. [message #68406] |
Wed, 28 October 2009 01:25 |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On 27 Okt., 00:35, jkeller <jkel...@uni-bonn.de> wrote:
> On Oct 26, 12:56 pm, David Fanning <n...@dfanning.com> wrote:
>
>> Well, not necessarily. READ_ASCII *does*, necessarily,
>> use a FOR loop. If the data were all numerical (no strings),
>> or regularly spaced (so you could use a FORMAT statement),
>> then it would be much faster to allocate an array of floats
>> (or whatever) and read the data all at once in the IDL way.
>
> Didn_t know that. Thanks for the information.
>
> Regards,
> Jan
Thanks guys.
Dave
|
|
|
Re: Problem to read some data. [message #68420 is a reply to message #68406] |
Tue, 27 October 2009 01:35  |
jkeller
Messages: 35 Registered: October 2009
|
Member |
|
|
On Oct 26, 12:56 pm, David Fanning <n...@dfanning.com> wrote:
> Well, not necessarily. READ_ASCII *does*, necessarily,
> use a FOR loop. If the data were all numerical (no strings),
> or regularly spaced (so you could use a FORMAT statement),
> then it would be much faster to allocate an array of floats
> (or whatever) and read the data all at once in the IDL way.
Didn_t know that. Thanks for the information.
Regards,
Jan
|
|
|
Re: Problem to read some data. [message #68434 is a reply to message #68420] |
Mon, 26 October 2009 04:56  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
jkeller writes:
> Just use the quoted code above. This should read the data into
> variable 'a'. It will be as fast as it could be when reading text
> files with IDL.
Well, not necessarily. READ_ASCII *does*, necessarily,
use a FOR loop. If the data were all numerical (no strings),
or regularly spaced (so you could use a FORMAT statement),
then it would be much faster to allocate an array of floats
(or whatever) and read the data all at once in the IDL way.
Of course, if you don't know the number of columns and rows,
then you have to allocate time to find those things out.
For example, File_Lines has to read the entire file to count
the number of EOL markers in the file to determine how
many rows there are. But, still, even with this overhead
it is often (almost always?) faster to read data the IDL
way than to use READ_ASCII. That is the main reason I've
never used it. Even taking into account the five lines
of code you need to type, doing so was faster than waiting
for READ_ASCII to finish!
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Problem to read some data. [message #68435 is a reply to message #68434] |
Mon, 26 October 2009 02:47  |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On 25 Okt., 23:44, jkeller <jkel...@uni-bonn.de> wrote:
>>>> > a=read_ascii('file.dat')
>>>> > sz=size(a.(0),/dim)
>>>> > ncols=sz[0]
>>>> > nrows=sz[1]
>
>> Just how to speed up reding!!
>
> Just use the quoted code above. This should read the data into
> variable 'a'. It will be as fast as it could be when reading text
> files with IDL.
OKay. thank you very much.
|
|
|
Re: Problem to read some data. [message #68436 is a reply to message #68435] |
Mon, 26 October 2009 00:44  |
jkeller
Messages: 35 Registered: October 2009
|
Member |
|
|
>>>> a=read_ascii('file.dat')
>>>> sz=size(a.(0),/dim)
>>>> ncols=sz[0]
>>>> nrows=sz[1]
>
> Just how to speed up reding!!
Just use the quoted code above. This should read the data into
variable 'a'. It will be as fast as it could be when reading text
files with IDL.
|
|
|
Re: Problem to read some data. [message #68437 is a reply to message #68436] |
Mon, 26 October 2009 00:02  |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On 23 Okt., 06:01, pp <pp.pente...@gmail.com> wrote:
> On Oct 23, 7:42 am, Dav_Poreh <d.po...@gmail.com> wrote:
>
>
>
>
>
>> On 23 Okt., 02:26, pfp <pfpente...@gmail.com> wrote:
>
>>> On Oct 23, 4:59 am, Dav_Poreh <d.po...@gmail.com> wrote:
>
>>>> Folks
>>>> I want to read some data with *.dat format with unknown number of
>>>> columns and rows. I tried to read with*DDREAD.pro* but it does not
>>>> work. Data for each file is like this:
>
>>>> 260.559844971 4.000000000 0.390625000 0.460937500 ……..
>>>> 260.559844971 4.000000000 0.382812500 0.318359375……..
>>>> 260.559844971 4.000000000 0.414062500 0.439453125 ……..
>>>> ……
>>>> …..
>>>> .….
>>>> Actually I don’t know the number of rows and columns (but definitely
>>>> number of rows is less than columns). Does anyone have experience to
>>>> how read this kind of files?
>>>> Any help highly will be appreciated.
>>>> Cheers
>
>>> Try something like
>
>>> a=read_ascii('file.dat')
>>> sz=size(a.(0),/dim)
>>> ncols=sz[0]
>>> nrows=sz[1]
>
>>> ddread is not a built-in routine, so when you mention it you should
>>> say where it is from. Also, "*.dat format" means nothing.
>
>> Thank you
>> that's okay. but is there any way to avoid from loop?
>
> What loop? I do not see any loops.
Just how to speed up reding!!
|
|
|
Re: Problem to read some data. [message #68452 is a reply to message #68437] |
Fri, 23 October 2009 07:01  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Oct 23, 7:42 am, Dav_Poreh <d.po...@gmail.com> wrote:
> On 23 Okt., 02:26, pfp <pfpente...@gmail.com> wrote:
>
>
>
>> On Oct 23, 4:59 am, Dav_Poreh <d.po...@gmail.com> wrote:
>
>>> Folks
>>> I want to read some data with *.dat format with unknown number of
>>> columns and rows. I tried to read with*DDREAD.pro* but it does not
>>> work. Data for each file is like this:
>
>>> 260.559844971 4.000000000 0.390625000 0.460937500 ……..
>>> 260.559844971 4.000000000 0.382812500 0.318359375……..
>>> 260.559844971 4.000000000 0.414062500 0.439453125 ……..
>>> ……
>>> …..
>>> .….
>>> Actually I don’t know the number of rows and columns (but definitely
>>> number of rows is less than columns). Does anyone have experience to
>>> how read this kind of files?
>>> Any help highly will be appreciated.
>>> Cheers
>
>> Try something like
>
>> a=read_ascii('file.dat')
>> sz=size(a.(0),/dim)
>> ncols=sz[0]
>> nrows=sz[1]
>
>> ddread is not a built-in routine, so when you mention it you should
>> say where it is from. Also, "*.dat format" means nothing.
>
> Thank you
> that's okay. but is there any way to avoid from loop?
What loop? I do not see any loops.
|
|
|
Re: Problem to read some data. [message #68453 is a reply to message #68452] |
Fri, 23 October 2009 02:42  |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On 23 Okt., 02:26, pfp <pfpente...@gmail.com> wrote:
> On Oct 23, 4:59 am, Dav_Poreh <d.po...@gmail.com> wrote:
>
>
>
>
>
>> Folks
>> I want to read some data with *.dat format with unknown number of
>> columns and rows. I tried to read with*DDREAD.pro* but it does not
>> work. Data for each file is like this:
>
>> 260.559844971 4.000000000 0.390625000 0.460937500 ……..
>> 260.559844971 4.000000000 0.382812500 0.318359375……..
>> 260.559844971 4.000000000 0.414062500 0.439453125 ……..
>> ……
>> …..
>> .….
>> Actually I don’t know the number of rows and columns (but definitely
>> number of rows is less than columns). Does anyone have experience to
>> how read this kind of files?
>> Any help highly will be appreciated.
>> Cheers
>
> Try something like
>
> a=read_ascii('file.dat')
> sz=size(a.(0),/dim)
> ncols=sz[0]
> nrows=sz[1]
>
> ddread is not a built-in routine, so when you mention it you should
> say where it is from. Also, "*.dat format" means nothing.
Thank you
that's okay. but is there any way to avoid from loop?
|
|
|
Re: Problem to read some data. [message #68454 is a reply to message #68453] |
Fri, 23 October 2009 02:26  |
pfp
Messages: 12 Registered: July 2009
|
Junior Member |
|
|
On Oct 23, 4:59 am, Dav_Poreh <d.po...@gmail.com> wrote:
> Folks
> I want to read some data with *.dat format with unknown number of
> columns and rows. I tried to read with*DDREAD.pro* but it does not
> work. Data for each file is like this:
>
> 260.559844971 4.000000000 0.390625000 0.460937500 ……..
> 260.559844971 4.000000000 0.382812500 0.318359375……..
> 260.559844971 4.000000000 0.414062500 0.439453125 ……..
> ……
> …..
> .….
> Actually I don’t know the number of rows and columns (but definitely
> number of rows is less than columns). Does anyone have experience to
> how read this kind of files?
> Any help highly will be appreciated.
> Cheers
Try something like
a=read_ascii('file.dat')
sz=size(a.(0),/dim)
ncols=sz[0]
nrows=sz[1]
ddread is not a built-in routine, so when you mention it you should
say where it is from. Also, "*.dat format" means nothing.
|
|
|