program corcoefm implicit none real*8 as,sx,sy,sxy,sx2,sy2,x,y integer*4 i,j,N,iargc,il,nlines,ic,jc character*80 f1,st real*8 ,allocatable::xm(:,:),cm(:,:) c write(6,9) 9 format(' Correlate all columns in a file with each other') if(iargc().eq.0)then write(6,91) 91 format(' Filename: ',$) read(5,'(a)')f1 write(6,92) 92 format(' Number of columns: ',$) read(5,*)N else call getarg(1,f1) call getarg(2,st) read(st,*)N endif nlines=0 open(9,file=f1) 101 read(9,*,end=99,err=99) nlines=nlines+1 goto 101 99 close(9) write(6,*)nlines,' lines' allocate(xm(nlines,N),cm(N,N)) open(9,file=f1) do 2 il=1,nlines 2 read(9,*)(xm(il,ic),ic=1,N) close(9) write(6,*)' read in' do 10 ic=1,N do 10 jc=1,N as=0.0d0 sxy=0.0d0 sx2=0.0d0 sy2=0.0d0 sx=0.0d0 sy=0.0d0 cm(ic,jc)=0.0d0 do 11 il=1,nlines x=xm(il,ic) y=xm(il,jc) as=as+1.0d0 sx=sx+x sy=sy+y sx2=sx2+x**2 sy2=sy2+y**2 11 sxy=sxy+x*y 10 if(as.gt.0.0d0) 1cm(ic,jc)=(as*sxy-sx*sy)/dsqrt(as*sx2-sx**2)/dsqrt(as*sy2-sy**2) write(6,601) 601 format('Correlation matrix:') write(6,605) 605 format(6(1H ),$) write(6,602)(i,i=1,N) 602 format(12i6) do 12 i=1,N write(6,604)i 604 format(i6,$) 12 write(6,603)(cm(i,j),j=1,N) 603 format(12f6.2) stop end