module util
contains
subroutine loclabel(fileid,label,ifound,irewind)
integer fileid,error
integer,optional :: ifound,irewind
character(len=80) :: c80
CHARACTER(LEN=*) label
if ((.not.present(irewind)).or.(present(irewind).and.irewind==1)) rewind(fileid)
do while(.true.)
read(fileid,"(a80)",iostat=ierror) c80
if (index(c80,label)/=0) then
backspace(fileid)
if (present(ifound)) ifound=1
return
end if
if (ierror/=0) exit
end do
if (present(ifound)) ifound=0
end subroutine
end module
program formout
!implicit none
use util
character infilename*200,outfilename*200,ord*8,findtraj*27
integer ntraj,nmax,i,ntmp,j,k,l
logical alive
integer(4),allocatable :: nnum(:)
character(8),allocatable :: bond(:,:)
write(*,*) "Input the .txt filename to be loaded"
do while(.true.)
read(*,"(a)") infilename
inquire(file=infilename,exist=alive)
if (alive) exit
write(*,*) "Cannot found this file, input again"
end do
open(10,file=infilename,status="old")
call loclabel(10,'Trajectory MaxJob')
read(10,"(49x,i12)") ntraj
write(*,"('Number of trajs:',i10)") ntraj
allocate(nnum(ntraj))
nnum=0
do i=1,ntraj
write(findtraj,"(a,i8,a)") 'Traj num',i,' Geometries'
call loclabel(10,findtraj,ifound)
read(10,"(49x,i12)") ntmp
nnum(i)=ntmp
end do
nmax=MaxVal(nnum)
write(*,"('The max step in some traj :',i10)") nmax
close(10)
allocate(bond(nmax,(ntraj+1)))
bond=' '
do i=1,nmax
write(ord,"(i8)") i
bond(i,1)=ord
end do
l=1
do while (l <= ntraj)
open(10,file=infilename,status="old")
write(findtraj,"(a,i8,a)") 'Traj num',l,' Geometries'
call loclabel(10,findtraj,ifound)
read(10,"(49x,i12)") ntmp
l=l+1
!REWIND(10)
!nnum(i)
do k=1,ntmp
read(10,'(a8,$)') bond(k,l) !为了不换行
end do
write(*,*) bond
end do
write(*,*) "aaaaa"
write(*,*) bond
close(10)
print*, "4.0"
write(*,*) "Input the .txt filename to be outputted"
read(*,"(a)") outfilename
open(10,file=outfilename,status="replace")
do i=1,nmax
do j=1,(ntraj+1)
write(10,'(a10,$)') bond(i,j)
end do
write(10,"(/)")
end do
close(10)
pause
end program formout
vvt 发表于 2016-6-14 09:13
看了一遍代码,感觉没有什么值得精简的。
也编译了一下,没有问题。
另外,没搞明白 input.txt 到底应该是 ...
fcode 发表于 2016-6-17 08:23
你给了两段 input.txt 的内容。到底是第一段,还是第二段?还是两端的组合?
或者你可以直接上传该文件。 ...
417 Bytes, 下载次数: 3
252 Bytes, 下载次数: 1
1.62 KB, 下载次数: 2
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |