      subroutine corcoe 
     I     ( x, y, nser, ist, ien, nobs, xmiss, ymiss,
     O       cor )
*
*     calculate correlation coeffocient between x and y
*
      implicit none

      integer nser, ist, ien, nobs

      real*4  xmiss, ymiss, cor
      real*4  x( nser ), y( nser )
      real*4  df, t, betai
*
      real*4  xm, ym, sx, sy, sxy
      real*4  sxmn, symn
      integer nc, i

      data  sxmn / 1.E-8 /
      data  symn / 1.E-8 /
*
*     mean
*
      nc = 0
      xm = 0.
      ym = 0.
      do i = ist, ien
         if( x( i ) .ne. xmiss .and.
     &       y( i ) .ne. ymiss          ) then
            nc = nc + 1
            xm = xm + x( i )
            ym = ym + y( i )
         endif
      enddo
      if( nc .lt. nobs ) then
         cor = xmiss
         return
      endif
      xm = xm / float( nc )
      ym = ym / float( nc )
*
*     correlation
*
      nc  = 0
      sx  = 0.
      sy  = 0.
      sxy = 0.
      cor = 0.
      do i = ist, ien
         if( x( i ) .ne. xmiss .and.
     &       y( i ) .ne. ymiss          ) then
            nc = nc + 1
            sx  = sx  + ( x( i ) - xm )**2
            sy  = sy  + ( y( i ) - ym )**2
            sxy = sxy + ( x( i ) - xm )*( y( i ) - ym )
         endif
      enddo
      if( abs( sx ) .lt. sxmn .or.
     &    abs( sy ) .lt. symn       ) then
         cor = xmiss
         return
      endif
      sx = sqrt( sx / float( nc ) )
      sy = sqrt( sy / float( nc ) )
      cor = sxy / ( sx * sy * float( nc ) )

      return
      end
