C NCLFORTSTART
      subroutine laplacian (idim,jdim,dx,dy,z,zmsg,kcyc,lap)                                 
      implicit none
c input
      integer  idim, jdim, kcyc
      real     z(idim,jdim), dx(jdim), dy, zmsg
c output
      real     lap(idim,jdim)
C NCLEND

c local
      integer i, j, im1, jm1, ip1, jp1, ib, ie, jb, je

c is data cyclic
      if(kcyc.eq.1) then
         ib = 1
         ie = idim
      else
         ib = 2
         ie = idim-1
      endif
      jb    = 2
      je    = jdim-1

      do j=1,jdim
       do i=1,idim 
          lap(i,j) = zmsg
       end do
      end do
      
      do j=jb,je                                                              
         jm1 = j-1
         jp1 = j+1
       do i=2,im1                                                              
          im1    = i-1
          ip1    = i+1
          if (im1 .lt.    1) im1 = idim
          if (ip1 .gt. idim) ip1 =  1

          if (z( i ,j).ne.zmsg .and. 
     &        z(ip1,j).ne.zmsg .and. z(im1,j).ne.zmsg .and. 
     &        z(i,jp1).ne.zmsg .and. z(i,jm1).ne.zmsg ) then  
              lap(i,j) = (((z(ip1,j)+z(im1,j)-2.*z(i,j))/dx(j)**2
     &                    +(z(i,jp1)+z(i,jm1)-2.*z(i,j))/dy**2))                                           
          end if

       end do
      end do

      return                                                                    
      end


