Re: reading many files [message #53025] |
Tue, 13 March 2007 07:57  |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
george wrote:
> Hi folks,
>
> I have to write a short program that however have to read very many
> files with similar names like
>
> data49-5.0-4.0.dat
> data50-5.0-4.0.dat
> ...
> data49-5.0-3.0.dat
> data50-5.0-3.0.dat
> ....
>
> i.e. with the following form
> data**-5.0-**.dat
You can use file_search first to find all matching files
Result = FILE_SEARCH('/yourdirectory/subdir/data*-5.0-*.dat')
and then loop through the result array to read them in one by one.
Ciao,
Paolo
>
> The number of files is quite large, indeed, so I rather than to type
> any single file, I was wondering if there is any (I'm sure there's)
> way to read all this file with a FOR cicle like (obviosuly I don't
> know if the example is correct, since it's what I'm asking...)
>
> for j=49, 80 do begin
> for i=-4, 0 do begin
> readcol,somethings.....
> endfor
> endfor
>
>
> Thanks so much!
> G.
>
> Thanks a lot!
>
|
|
|
Re: reading many files [message #53026 is a reply to message #53025] |
Tue, 13 March 2007 07:55   |
Ben Panter
Messages: 102 Registered: July 2003
|
Senior Member |
|
|
george wrote:
> data49-5.0-4.0.dat
> data50-5.0-4.0.dat
> ...
> data49-5.0-3.0.dat
> data50-5.0-3.0.dat
> ....
>
> i.e. with the following form
> data**-5.0-**.dat
Hi George,
I think you might want the STRING command with a FORMAT code. This
takes a number and puts it into a string format which you can then add
into your for loop. Off the top of my head, try something like
filename='data'+STRING(j,FORMAT='(I02)')+'-5.0-'+STRING(i,FO RMAT='(I1)')+'.0.dat
readcol, filename, ....
cheers,
Ben
--
Ben Panter, Edinburgh, UK.
Email false, http://www.benpanter.co.uk
or you could try ben at ^^^^^^^^^^^^^^^
|
|
|
Re: reading many files [message #53027 is a reply to message #53026] |
Tue, 13 March 2007 08:49  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
george writes:
> The number of files is quite large, indeed, so I rather than to type
> any single file, I was wondering if there is any (I'm sure there's)
> way to read all this file with a FOR cicle like (obviosuly I don't
> know if the example is correct, since it's what I'm asking...)
FILE_SEARCH should be able to collect all those files in
one place for you. :-)
theFiles = File_Search('data??-5.0-??.dat')
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.")
|
|
|