      subroutine lndsea(rlat,rlong,lnd)
c   for given north latitude and east longitude (in degrees) returns
c  the flag lnd = 1 if land, 2 if water (cf paul revere)
c    ***calls ibit
c
      save iwd
      integer*4 iwd
      character*10 filnam
      dimension iwd(291600)
      data ifirst/0/
      data filnam/'lndsea.dat'/
C      character*50 filnam
C      data filnam/'/users/agnew/projects/tidload/converd/lndsea.dat'/
      if(ifirst.ne.1) then
c  on first call, open the file for random access
         ifirst = 1
         call readls(iwd,filnam)
      endif     
      lnd = 2
      rlong2 = rlong
      if(rlong.lt.0) rlong2 = rlong + 360.
      if(rlong.gt.360) rlong2 = rlong - 360.
      clat = 90-rlat
      ilat = int(12*clat)
      ilong = int(12*rlong2)
      ind = 135*32*ilat + ilong
      nwd = ind/32 + 1
      nbit = mod(ind,32) + 1 
      iv = ibit(iwd(nwd),nbit)
      if(iv.eq.1) lnd = 1
      return
      end
      function ibit(id,n)
c
c  function to return the n-th bit (counting to the right) of a long
c  integer id
c
c    ***calls system routine and - this performs a bitwise and on
c       its two arguments
c
      save ibp,ifl
      integer*4 id,ibp(32),it
      data ifl/0/
      if(ifl.eq.1) go to 3
c  on first call, set up an array of integers, each with exactly one bit
c  set at successively lower values. ibp(1) should have only its highest
c  bit set; that this is true should be verified for each machine
      ifl = 1
      ibp(32) = 1
      do 1 i=2,32
 1    ibp(33-i) = 2*ibp(34-i)
 3    it = ispand(id,ibp(n))
      ibit = 0
      if(it.ne.0) ibit = 1
      return
      end
