Advertisement
Guest User

Untitled

a guest
Feb 28th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. program Pearson
  2. implicit none
  3. integer :: dim, i, j, k, l, m, Pminvalue, Subtnorm1value, Subtnorm2value
  4. character(80) :: filename
  5. real(8) :: Smin, Bmin, Pmin, minCoeff, Coeff, DistM, time
  6. real(8), allocatable :: wavenumber(:), S(:), B(:), P(:), Sval(:), Bval(:), Pval(:), tempvector1(:),
  7.  
  8. tempvector2(:)
  9. real(8), allocatable :: Pnormvector(:), Samplenormvector(:)
  10. real(8), allocatable :: Svalmat(:,:), Bvalmat(:,:), Pvalmat(:,:), Snorm(:,:), Bnorm(:,:), Pnorm
  11.  
  12. (:,:), Subtract(:,:)
  13. real(8), allocatable :: Subtractnorm(:,:,:)
  14.  
  15. write(*,*)'Specify the name of the file (format: data.txt):'
  16. 10 read(*,*)filename
  17. open(11,file=filename, status='old',err=20)
  18. goto 30
  19. 20 write(*,*) 'There is no file with this name in the current directory. Please check and try again'
  20. goto 10
  21. 30 continue
  22. dim=0
  23. do
  24. read(11,*,end=40)
  25. dim=dim+1
  26. end do
  27. 40 continue
  28. rewind 11
  29. allocate (wavenumber(dim), S(dim), B(dim), P(dim), Sval(dim), Bval(dim), Pval(dim), tempvector1
  30.  
  31. (dim), tempvector2(dim))
  32. allocate (Pnormvector(dim), Samplenormvector(dim))
  33. allocate (Svalmat(dim,1), Bvalmat(dim,1), Pvalmat(dim,1), Snorm(dim,dim), Bnorm(dim,dim), Pnorm
  34.  
  35. (dim,dim), Subtract(dim,dim))
  36. allocate (Subtractnorm(dim,dim,dim))
  37. do i=1,dim
  38. read(11,*,end=50) wavenumber(i), S(i), B(i), P(i)
  39. enddo
  40. 50 close(11)
  41.  
  42. Smin=minval(S); Sval=S-Smin
  43. Bmin=minval(B); Bval=B-Bmin
  44. Pmin=minval(P); Pval=P-Pmin
  45.  
  46. do i=1,dim
  47. do j=1,dim
  48. Snorm(i,j)=Sval(j)/Sval(i)
  49. Bnorm(i,j)=Bval(j)/Bval(i)
  50. Pnorm(i,j)=Pval(j)/Pval(i)
  51. enddo
  52. enddo
  53.  
  54. Subtract=Snorm-Bnorm
  55.  
  56. do i=1,dim
  57. do j=1,dim
  58. do k=1,dim
  59. Subtractnorm(i,j,k)=Subtract(j,k)/Subtract(j,i)
  60. enddo
  61. enddo
  62. enddo
  63.  
  64. minCoeff=1.0; Pminvalue=0; Subtnorm1value=0; Subtnorm2value=0
  65.  
  66. do i=1,dim
  67. do j=1,dim
  68. tempvector1(j)=Pnorm(i,j)
  69. enddo
  70. do k=1,dim
  71. do l=1,dim
  72. do m=1,dim
  73. tempvector2(m)=Subtractnorm(k,l,m)
  74. enddo
  75.  
  76. Coeff=DistM(tempvector1,tempvector2, dim)
  77. if (Coeff.lt.minCoeff) then
  78. minCoeff=Coeff
  79. Pminvalue=i
  80. Subtnorm1value=k
  81. Subtnorm2value=l
  82. endif
  83. enddo
  84. enddo
  85. enddo
  86.  
  87. print *, 'Minimal Correllation Coefficient: ', minCoeff
  88. print *, 'Pminvalue: ', Pminvalue
  89. print *, 'Subtnorm1value: ', Subtnorm1value
  90. print *, 'Subtnorm2value: ', Subtnorm2value
  91. call CPU_TIME(time)
  92. print *, 'Elapsed time: ', time, 'seconds'
  93.  
  94. open(33,file='ResultsManh.auto')
  95. do i=1,dim
  96. Pnormvector(i)=Pnorm(Pminvalue,i)
  97. Samplenormvector(i)=Subtractnorm(Subtnorm1value,Subtnorm2value,i)
  98. write(33,'(3F10.5)') wavenumber(i), Pnormvector(i),Samplenormvector(i)
  99. enddo
  100. end
  101.  
  102. real(8) function DistM(v, u, dim)
  103. integer dim
  104. real(8) v(dim), u(dim), Distance
  105. Dif=0.0
  106. do i=1, dim
  107. Dif=Dif+((v(i)-u(i))*(v(i)-u(i)))
  108. enddo
  109. Distance=Dif/dim
  110. DistM=Distance
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement