module typedef
type para
character(len=2) line
integer :: column,addcolumn
character(len=3) stateindex
character(len=1) colon
character(len=1) pressure
character(len=1) commaa
character(len=15) variables
real(kind=8) :: porosity,Numcon1,Numcon2,Numcon3,Numcon4
end type
end module
program main
use typedef
implicit none
integer,parameter :: fileid = 3 ! number of save.txt
integer,parameter :: fileids = 4 ! number of INCON.txt
integer,parameter :: linenum = 2 ! the number of lines,can change
integer,parameter :: columnnum = 150 ! the number of column,can change
character(len=80) title
type(para) :: s(linenum) ! save the parameters of save.txt
type(para) :: a(columnnum) ! save the parameters of columnnum
integer i,j,error,truecolumn
truecolumn=5
open( fileid,file="save.txt",status="old",iostat=error)
if(error/=0)then
write(*,*)"open save.txt fail."
stop
end if
OPEN(UNIT=fileids,FILE='INCON.txt',FORM='FORMATTED',STATUS='NEW',IOSTAT=error)
if(error/=0) then
write(*,*)"open elem_elem.txt fail"
stop
end if
read(fileid,*) title
write(fileids,"(A80)") title
do i=1,linenum
read(fileid,FMT = 5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
write(fileids,FMT=5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
a(i)%addcolumn = s(i)%column
a(i)%line = s(i)%line
a(i)%porosity = s(i)%porosity
a(i)%stateindex = s(i)%stateindex
a(i)%colon = s(i)%colon
a(i)%pressure = s(i)%pressure
a(i)%commaa = s(i)%commaa
a(i)%variables = s(i)%variables
a(i)%Numcon1 = s(i)%Numcon1
a(i)%Numcon2 = s(i)%Numcon2
a(i)%Numcon3 = s(i)%Numcon3
a(i)%Numcon4 = s(i)%Numcon4
do j=1,truecolumn
a(j)%addcolumn=a(j)%addcolumn+j
write(fileids,FMT=5001) a(i)%line,a(j)%addcolumn,a(i)%porosity,a(i)%stateindex,a(i)%colon,a(i)%pressure,a(i)%commaa,a(i)%variables,a(i)%Numcon1,a(i)%Numcon2,a(i)%Numcon3,a(i)%Numcon4
end do
end do
! do i=1,linenum
! write(fileids,FMT=5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
! end do
! stop
5001 FORMAT(A2,A3,11X,ES14.8,2X,A3,A1,1X,A1,A1,5X,A15/1X,ES19.13,1X,ES19.13,1X,ES19.13,1X,ES19.13)
end program
1.png (98.16 KB, 下载次数: 279)
图一
2.png (118.12 KB, 下载次数: 297)
图二
3.png (28.41 KB, 下载次数: 303)
图三
4.png (25.37 KB, 下载次数: 286)
图四
5.png (63.13 KB, 下载次数: 298)
图五
图六.png (150.83 KB, 下载次数: 283)
图六
vvt 发表于 2018-4-17 01:08
对于大段的代码,请直接复制粘贴,不截图。
对于输入文件也是一样。
module typedef
type para
character(len=3) line
integer :: column
character(len=3) stateindex
character(len=1) colon
character(len=1) pressure
character(len=1) commaa
character(len=15) variables
real(kind=8) :: porosity,Numcon1,Numcon2,Numcon3,Numcon4
end type
end module
program main
use typedef
implicit none
integer,parameter :: fileid = 3 ! number of save.txt
integer,parameter :: fileids = 4 ! number of INCON.txt
integer,parameter :: linenum = 2 ! the number of lines,can change
integer,parameter :: columnnum = 150 ! the number of column,can change
character(len=80) title
type(para) :: s(linenum) ! save the parameters of save.txt
integer i,j,error,truecolumn
truecolumn=5
open( fileid,file="save.txt",status="old",iostat=error)
if(error/=0)then
write(*,*)"open save.txt fail."
stop
end if
OPEN(UNIT=fileids,FILE='INCON.txt',FORM='FORMATTED',STATUS='NEW',IOSTAT=error)
if(error/=0) then
write(*,*)"open elem_elem.txt fail"
stop
end if
read(fileid,*) title
write(fileids,"(A80)") title
do i=1,linenum
read(fileid,FMT = 5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
write(fileids,FMT=5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
do j=1,truecolumn
s(i)%column=MOD(j,100)
write(fileids,FMT=5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
end do
end do
! do i=1,linenum
! write(fileids,FMT=5001) s(i)%line,s(i)%column,s(i)%porosity,s(i)%stateindex,s(i)%colon,s(i)%pressure,s(i)%commaa,s(i)%variables,s(i)%Numcon1,s(i)%Numcon2,s(i)%Numcon3,s(i)%Numcon4
! end do
! stop
5001 FORMAT(A3,I2.2,11X,ES14.8,2X,A3,A1,1X,A1,A1,5X,A15/1X,ES19.13,1X,ES19.13,1X,ES19.13,1X,ES19.13)
end program
type para
character(len=3) line
integer :: column
real(8) :: porosity
character(len=3) stateindex
character(len=1) colon
character(len=1) pressure
character(len=1) commaa
character(len=15) variables
real(kind=8) :: Numcon(4)
end type
fcode 发表于 2018-4-17 22:04
[mw_shl_code=fortran,true]其实你可以这样定义结构体
type para
character(len=3) line
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |