|
如图一,画红圈的是我读取文件的单元名称,我需要将这个读入的数据变成图二的样式。规律是画红圈的部分,前两个字符不变,后面的字符从末尾气依次加一。前两个字符相同的单元号,其后面对应的数值也不变,我编的程序如图三,图四所示,但是导出的文件的结果如图五所示,通过程序编译,可知问题应该是发生在图六画红圈的部分,但是我不知如何修改吗,希望大神能帮我看一下应该如何修改?
代码如下:
[Fortran] 纯文本查看 复制代码 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, 下载次数: 278)
图一
-
2.png
(118.12 KB, 下载次数: 297)
图二
-
3.png
(28.41 KB, 下载次数: 302)
图三
-
4.png
(25.37 KB, 下载次数: 286)
图四
-
5.png
(63.13 KB, 下载次数: 298)
图五
-
图六.png
(150.83 KB, 下载次数: 282)
图六
|