這樣可能更好一些:CODE: program ei
implicit none
real, dimension(:,:), allocatable :: px,ppx
character(len=256) :: line
character(len=40) :: fm
integer :: nrow, ncol, i, j, k, ios, n, m
open(unit=12, file='nc3h7-r2-sto-eiv.out', status='old')
open(unit=13, file='nc3h7-r2-sto-pai.out', status='new')
do
read(12,'(a)', iostat=ios) line
if (ios /= 0) exit
if (index(line,'Eigenvalues') /= 0) then
nrow=0
ncol=0
do
read(12,'(a)', iostat=ios) line
if (ios /= 0) exit
if (line(1:4) == ' ') exit
ncol=ncol+1
if (index(line, '2PZ') /= 0) nrow=nrow+1
end do
exit
end if
end do
write (*,*) nrow, ncol
rewind (12)
allocate(px(nrow,ncol),ppx(nrow,ncol))
i=0
j=0
do
read(12,'(a)', iostat=ios) line
if (ios /= 0) exit
if (i == nrow) then
i=0
j=j+n
end if
if (index(line, '2PZ') /= 0) then
line = line(21:)
! write(*,*) trim(line)
i=i+1
n = len_trim(line)/10
m = mod(len_trim(line),10)
! write (*,*) m, n
if (m /= 0) then
write(fm,'(a,i0,a,i0,a)') '(tr',m,',',n,'f10.5)'
else
write(fm,'(a,i0,a)') '(',n,'f10.5)'
end if
! write (*,*) fm
! write(*,*) j
read(line,fm) ppx(i,(j+1):(j+n))
end if
end do
k=0
do
write(*,*) 'please input a number between 1 and ',nrow,',
& end the program by 0.'
read(*,*) i
if(i==0) exit
k=k+1
ppx(:,k) = px(:,i)
end do
!write(*,*) k/5, mod(k,5)
if (k>=5) then
do j=1,k/5
do i=1,nrow
write(13,'(5f10.5)') ppx(i,(j-1)*5+1:j*5)
end do
write(13,*)
end do
end if
if (mod(k,5) /=0) then
write(fm,'(a,i0,a)') '(', mod(k,5), 'f10.5)'
do i=1,nrow
write(13, fm) ppx(i,(k/5*5+1):k)
end do
end if
end program ei