Looping data files

This is a discussion on Looping data files within the Fortran forums in Programming Languages category; Greetings all, I have some simple data files that are named in numerical order, such as 01.dat, 02.dat, 03.dat, etc.. These files are not binary files, just ordinary files that can be viewed in a text editor. I have a fortran 77 program that needs to open each file one at a time, do some stuff with it, close it, then open the next one automatically. So the files need to be opened in some sort of do loop. However, there doesn't appear to be any easy way to do this that I know of. Can someone please help me? ...

Go Back   Application Development Forum > Programming Languages > Fortran

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-20-2008, 01:27 PM
torn8o2001@yahoo.com
Guest
 
Default Looping data files

Greetings all,

I have some simple data files that are named in numerical order, such
as 01.dat, 02.dat, 03.dat, etc.. These files are not binary files,
just ordinary files that can be viewed in a text editor. I have a
fortran 77 program that needs to open each file one at a time, do some
stuff with it, close it, then open the next one automatically. So the
files need to be opened in some sort of do loop. However, there
doesn't appear to be any easy way to do this that I know of.

Can someone please help me?

Thanks,
Brad
Reply With Quote
  #2  
Old 08-20-2008, 01:39 PM
Steven G. Kargl
Guest
 
Default Re: Looping data files

In article <95f7c7f3-24bc-44e8-b331-d4a585333a67@w7g2000hsa.googlegroups.com>,
torn8o2001@yahoo.com writes:
> Greetings all,
>
> I have some simple data files that are named in numerical order, such
> as 01.dat, 02.dat, 03.dat, etc.. These files are not binary files,
> just ordinary files that can be viewed in a text editor. I have a
> fortran 77 program that needs to open each file one at a time, do some
> stuff with it, close it, then open the next one automatically. So the
> files need to be opened in some sort of do loop. However, there
> doesn't appear to be any easy way to do this that I know of.
>
> Can someone please help me?



program torn
implicit none
integer i, fd
character(len=10) name
fd = 10
do i = 1, 10
write(name,'(I2.2)') i ! Internal write
name = trim(name) // '.dat' ! Append suffix
open(file=name, unit=fd, status='old') ! Open file
!
! Do you processing here.
!
close(fd) ! Close file
end do
end program torn


--
Steve
http://troutmask.apl.washington.edu/~kargl/
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:07 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.