C spectra2d.f
C Interfaces to the subroutines in the fftpack5 library

C NCLFORTSTART
      subroutine spectra2di (L, M, KDIM, LENSAV, IER, wsave)
      integer L, M, KDIM, LENSAV, IER
      real    wsave(LENSAV)
C NCLEND

      call rfft2i (L,M,wsave,LENSAV,IER)
      if (IER .ne. 0) then
        print *,"Error in call to rfft2i"
        return
      end if

	END


C NCLFORTSTART
      subroutine spectra2df (L, M, KDIM, LENSAV, RD, SD, IER, wsave)
      integer L, M, KDIM, LENSAV, IER
      real    RD(L,M), SD(KDIM,M)
	real wsave(LENSAV)
C NCLEND
      real    work(2*KDIM*M), R(2*KDIM,M)
      integer LDIM, LENWRK

      LDIM = 2*KDIM
      LENWRK = 2*KDIM*M

C     Load R array with RD input data array 
      R(1:L,:) = RD
      call rfft2f (LDIM,L,M,R,wsave,LENSAV,work,LENWRK,IER)
      if (IER .ne. 0) then
        print *,"Error in call to rfft2f"
        return
      end if

C     2D spectral density
      do j = 1, M
        do i = 1, KDIM 
          SD(i,j) = R(2*i-1,j)**2 + R(2*i,j)**2
        end do
      end do

      end

