Input 将一个文件中的一行与另一个文件中的多行进行比较/FORTRAN

Input 将一个文件中的一行与另一个文件中的多行进行比较/FORTRAN,input,fortran,output,Input,Fortran,Output,我正在尝试比较两个文件,因此将一个文件中的一行与另一个文件中的所有行进行比较,直到找到一个差异小于0.003的匹配 这就是我所想的,但我仍然认为这只是逐行比较,而不是一行与所有其他行的比较。任何建议都很好 这就是我到目前为止所做的: program matchCoords implicit none real :: xcoord1, ycoord1,x1,y1,mag1,merr1,sharp1,chi1 real :: xcoord2, ycoord2,x2,y2,mag2,merr2,sh

我正在尝试比较两个文件,因此将一个文件中的一行与另一个文件中的所有行进行比较,直到找到一个差异小于0.003的匹配

这就是我所想的,但我仍然认为这只是逐行比较,而不是一行与所有其他行的比较。任何建议都很好

这就是我到目前为止所做的:

program matchCoords
implicit none

real :: xcoord1, ycoord1,x1,y1,mag1,merr1,sharp1,chi1
real :: xcoord2, ycoord2,x2,y2,mag2,merr2,sharp2,chi2
real, parameter :: arcsec = 0.0003
character (len=50) :: inputfile1, inputfile2, outputfile
integer :: i, j


!Open input file as unit 15
write(*,*) 'Enter inputfile #1:'
read(*,*) inputfile1
write(*,*) 'Enter inputfile #2'
read(*,*) inputfile2
write(*,*) 'Enter output file name:'
read(*,*) outputfile
open(unit=15, file=inputfile1, status='old')
open(unit=16, file=inputfile2, status='old')
open(unit=17, file=outputfile, status='new')


do i=0,37200
read(16,*) xcoord2, ycoord2,x2,y2,mag2,merr2,sharp2,chi2
do j=0,37000
read(15,*) xcoord1(j), ycoord1(j),x1,y1,mag1,merr1,sharp1,chi1

if(ABS(xcoord1(j)-xcoord2).le.arcsec.and.ABS(ycoord1(i)-ycoor&
&d2).le.arcsec) then

write(17,*) xcoord1(j),ycoord1(j),x1,y1,mag1,merr1,&
&sharp1,chi1,xcoord2,ycoord2,x2,y2,&
&mag2,merr2,sharp2,chi2 

谢谢大家!

看起来它正在将每一行与每一行进行比较。如果能看到循环和If语句的完成,那就好了。通过缩进逻辑,您的代码将更易于阅读。文件IO速度非常慢,通过将数据读入数组,然后在这些数组中循环,而不是直接重复读取文件,您更有可能获得更快的运行时间。