Dear Mingwu,
try the following. It will read all values from data[1-....].txt, and write
them to data.txt.
The parameter nrcolumns will specify how many values (i.e. columns) will be
read.
Hope this works.
program dataput
!
implicit none
!
logical :: fexist
integer, parameter :: nrcolumns = 1
integer :: i,idata=10,id=11,last,iostatus
real, dimension(nrcolumns) :: rval
character (len=10) :: sfx
!
open (idata,file='data.txt')
!
i = 0
lp1: &
do
i = i + 1
call getsuffix(i,sfx,last)
inquire (file='data'//sfx(1:last)//'.txt',exist=fexist)
if (.not.fexist) exit lp1
open (id,file='data'//sfx(1:last)//'.txt')
lp2: &
do
read (id,fmt=*,iostat=iostatus) rval
if (iostatus /= 0) exit lp2
write (idata,*) rval
enddo lp2
close (id,status='keep')
enddo lp1
!
close (idata,status='keep')
!
contains
subroutine getsuffix(itid, strtid, last)
!
implicit none
!
integer :: itid, last, i, j, itot
!
character (len=*) :: strtid
character (len=len(strtid)) :: revstr
!
character (len=1), dimension(0:9) ::
digits=(/'0','1','2','3','4','5','6','7','8','9'/)
!
strtid = ' '
!
i = 1 ; last = 0 ; itot = 0
do
j = itid / (10*i)
j = (itid - 10*i*j - itot) / i
last = last + 1
revstr(last:last) = digits(j)
itot = itot + i*j
if (itot >= itid) exit
i = i * 10
enddo
!
do i=1,last
strtid(last+1-i:last+1-i) = revstr(i:i)
enddo
!
end subroutine getsuffix
end program dataput
>Dear Sir,
>
>I want to put all the data in thousands of data files (data1.txt,
>data2.txt,...) into ONE file (data.txt).
>To simply the question, there is one column data in every files. Using
>(Microsoft) Fortran
>PowerStation 4.0, however, the program does not work.
>Please try according to following three data files, for example, by saving
>three data files into working directionary.
>
>
>Looking forward to your advise.
>
>Thank you a lot.
>
>Mingwu Bai, Ph. D
>Tohoku University
>Japan
>
>
>----------------------
>character :: file*12
> open(10,file='data.txt')
> do i=1,3
> write(file,'("data",i0,".txt")') i
> open(11,file=file)
> do
> read(11,iostat=ios) aa
> if (ios /= 0) exit
> write(10,*) aa
> end do
> close (11)
> end do
> end
>
>
>example of data files:
>data1.txt
>1.1
>2.2
>3.3
>4.4
>5.5
>6.6
>7.7
>
>data2.txt
>11.1
>22.2
>33.3
>44.4
>55.5
>
>data3.txt
>111.1
>222.2
>333.3
>444.4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|