[Fortran] 纯文本查看 复制代码
module typedef
type sm
real(kind=4) v,n1
end type
end module
program main
use typedef
implicit none
type(sm)::s1(100),s2(100),s3(100),s4(100),s5(100),s6(100),s7(100),s8(100),s9(100),s10(100),s11(100),s12(100),s13(100)
character::file1="length.txt",file2="length(2).txt",file3="length(3).txt",file4="length(4).txt",file5="length(5).txt",file6="length(6).txt"
integer::i,status=0
real::d1(50),d2(50),d3(50),d4(50),d5(50),d6(50)
forall(i=1:50)
d1(i)=0
d2(i)=0
d3(i)=0
d4(i)=0
d5(i)=0
d6(i)=0
end forall
open(11,file="length1.txt",status="old")
do i=1,50
read(11,*,iostat=status) s1(i)%v,s1(i)%n1
if(status/=0) exit
d1(s1(i)%v)=s1(i)%n1
write(*,*) s1(i)%v,s1(i)%n1
end do
open(12,file="length(2).txt",status="old")
do i=1,50
read(12,*,iostat=status) s2(i)%v,s2(i)%n1
d2(s2(i)%v)=s2(i)%n1
if(status/=0) exit
end do
open(13,file="length(3).txt",status="old")
do i=1,50
read(13,*,iostat=status) s3(i)%v,s3(i)%n1
d3(s3(i)%v)=s3(i)%n1
if(status/=0) exit
end do
open(14,file="length(4).txt",status="old")
do i=1,50
read(14,*,iostat=status) s4(i)%v,s4(i)%n1
d4(s4(i)%v)=s4(i)%n1
if(status/=0) exit
end do
open(15,file="length(5).txt",status="old")
do i=1,50
read(15,*,iostat=status) s5(i)%v,s5(i)%n1
d5(s5(i)%v)=s5(i)%n1
if(status/=0) exit
end do
open(16,file="length(6).txt",status="old")
do i=1,50
read(16,*,iostat=status) s6(i)%v,s6(i)%n1
d6(s6(i)%v)=s6(i)%n1
if(status/=0) exit
end do
open(17,file="length7.txt")
do i=1,50
write(17,*) i, real(d1(i)+d2(i)+d3(i)+d4(i)+d5(i)+d6(i))/real(6)
end do
end program