program corcoef implicit none real*8 as,sx,sy,sxy,sx2,sy2,x,y,cc integer*4 i,N,M,iargc character*80 f1,f2,st if(iargc().eq.0)then write(6,9) 9 format(' Correlate Nth column in file1 with Mth column of file2', 1/,/,' file1: ',$) read(5,'(a)')f1 write(6,91) 91 format(' file2: ',$) read(5,'(a)')f2 write(6,92) 92 format(' N M: ',$) read(5,*)N,M else call getarg(1,f1) call getarg(2,f2) call getarg(3,st) read(st,*)N call getarg(4,st) read(st,*)M endif as=0.0d0 sxy=0.0d0 sx2=0.0d0 sy2=0.0d0 sx=0.0d0 sy=0.0d0 open(9 ,file=f1) open(91,file=f2) 1 read(9 ,*,end=99,err=99)(x,i=1,N) read(91,*,end=99,err=99)(y,i=1,M) as=as+1.0d0 sx=sx+x sy=sy+y sx2=sx2+x**2 sy2=sy2+y**2 sxy=sxy+x*y goto 1 99 close(9) close(9) write(6,*)int(as),' points' if(as.gt.0.0d0)then cc=(as*sxy-sx*sy)/dsqrt(as*sx2-sx**2)/dsqrt(as*sy2-sy**2) write(6,8)cc 8 format(' Correlation coefficient = ',f10.5) endif stop end