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

Home » Public Forums » archive » Re: reading many files
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
Re: reading many files [message #53025] Tue, 13 March 2007 07:57 Go to next message
Paolo Grigis is currently offline  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 Go to previous messageGo to next message
Ben Panter is currently offline  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 Go to previous message
David Fanning is currently offline  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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: reading many files
Next Topic: Re: New IDLDE

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

Current Time: Wed Oct 08 13:48:28 PDT 2025

Total time taken to generate the page: 0.00615 seconds