	subroutine otide(gtlon,gtlat,time,tide)

c****** This subroutine creates a tidal height for
c****** a specified time and place.
   
        integer im,jm,nt,ns,nc   
C        parameter(im=719,jm=267)	! desai
C        parameter(im=1801,jm=657)
        parameter(im=1801,jm=729)
        parameter(nt=3,ns=2,nc=30)
        real tide,gtlon,gtlat
        real ud(nt,ns),vd(nt,ns)
        double precision udi(nt,ns),vdi(nt,ns),dgtime
        double precision time

        save
        logical init
C       real u(im,jm,nt,ns),v(im,jm,nt,ns)
        real u,v
        data init/.TRUE./
        COMMON/OTD/u(im,jm,nt,ns),v(im,jm,nt,ns) 

c****** Read in orthotides and grid lat,lon.
        if (init) then
          open(50, file='gtd.ortd.all',status='old')
          read(50,12) u,v
12        format(8(1PE10.3))
          close(50)
          init=.FALSE.
          write(*,*) 'Init CU tide'
        endif
c****** Determine u and v at the specified location.

C	write(*,*) 'calling cotid'
        call cotid(gtlon,gtlat,im,jm,
     &           nt,u,v,ns,ud,vd)

c****** Determine tide at the specified time and location.

c       Check for tide's exsistance at specified location.
        if(ud(1,1).ne.999.0) then
c         Convert ud and vd into double precision.
          do 787 next = 1,ns
          do 787 no = 1,nt
            udi(no,next) = dble(ud(no,next))
            vdi(no,next) = dble(vd(no,next))
787       continue

c************************************************************************
c             time = # seconds past Jan 1, 1992 (midnight) in MJD seconds
c             4.2009408D9 = Jan 1, 1992 (midnight) in MJD seconds
c             4.0116384D9 = Jan 1, 1986 (00:00) in MJD seconds
c************************************************************************
          dgtime = 4.2009408D9 + time
C          write(*,*) time,dgtime
          call kgettide(dgtime,gtlat,gtlon,udi,vdi,tide)
        else
          tide=-9999.0
        endif

	return
        end
