MODULE rc_mod
INTERFACE get_rc
  MODULE PROCEDURE get_rc4, get_rc8
END INTERFACE get_rc
CONTAINS
SUBROUTINE get_rc4(n,SX,SXX,SY,SYY,SXY,rc)
! calculation of correlation coeff 
       IMPLICIT NONE
       REAL sx,sy,sxx,syy,sxy,t1,t2
       REAL rc
       INTEGER n
       
       t1=sxx-sx**2/n
       t2=syy-sy**2/n       
       
       IF (t1<=0. .OR. t2<=0.) THEN
!         PRINT*,'SXX-SX**2/N, SYY-SY**2/N, N :',t1,t2,n
         rc=0.
       ELSE
         rc=(sxy-sx*sy/n)/sqrt(t1*t2)
       END IF
END SUBROUTINE get_rc4
SUBROUTINE get_rc8(n,SX,SXX,SY,SYY,SXY,rc)
! calculation of correlation coeff 
       IMPLICIT NONE
       REAL(kind(1.d0)) sx,sy,sxx,syy,sxy,t1,t2
       REAL(kind(1.d0)) rc
       INTEGER n
       
       t1=sxx-sx**2/n
       t2=syy-sy**2/n       
       
       IF (t1<=0. .OR. t2<=0.) THEN
!         PRINT*,'SXX-SX**2/N, SYY-SY**2/N, N :',t1,t2,n
         rc=0.
       ELSE
         rc=(sxy-sx*sy/n)/sqrt(t1*t2)
       END IF
END SUBROUTINE get_rc8
END MODULE rc_mod

