c*c start grtcirle
c
c*******************************************************
c
      subroutine grtcircle(time,objclose)
c
c*******************************************************
c
c     CSC/CSCI: object/utilities
c
c     author: Paul Vogel/Ann Dotts
c
c     project: ADISC2, MMC-I&CS
c
c     function: compute the motion of an object along
c               a great circle routine.  newdest initializes
c               the parameters for this routine for any
c               flightpath leg.
c
c     parameters:
c     variable   i/o   type   size   description
c     time        i    R*4           simulation time
c     objclose    o    logical       flag to say object has
c                                    reached end of route leg
#include "commonblkparams.cmn"
#include "objects.cmn"
#include "constants.cmn"
#include "platformchar.cmn"
c
      logical objclose
      real*4 time, timedelta
      real*8 factor, invfactor
      real*4  objpxyz(3)
      real*4 disttravelled
      real*4 rangetofly
      real*4 latdest
      real*4 longdest
      real*4 bearing
      real*4 cerange
      real*4 altdest
      real*4 ceaz
      real*4 finallat
      real*4 finallong
      real*4 llrange
c
      integer*4 i
c
c
cend
c
c   initialize working variables
      objclose = .false.
      timedelta = time - lastupdatetime
      if (timedelta.lt.1.) return
c
c   compute distance travelled this time step and to travel  on leg
      disttravelled = objspeed*timedelta/SECONDS_PER_HOUR
      rangetofly = amax1(disttravelled*.99,cerange(objxyz, objdxyz))
c
c   compute how far object can travel on great circle route in allotted time
      invfactor = disttravelled/rangetofly
      factor = 1.- invfactor
      if (invfactor.gt. .67) objclose = .true.
      if (motioncond.eq.7) then
        write(6,*) 'objspeed, timedelta, rangetofly, invfactor ',
     1              objspeed, timedelta, rangetofly, invfactor
      end if
c
c   compute next intended point on great circle route
      objpxyz(1) =  factor*objxyz(1) + invfactor*objdxyz(1)
      objpxyz(2) =  factor*objxyz(2) + invfactor*objdxyz(2)
      objpxyz(3) =  factor*objxyz(3) + invfactor*objdxyz(3)
      call vnorm(objpxyz)
      call ecrll(latdest, longdest, altdest, objpxyz)
      bearing = ceaz(objlat, objlong, latdest, longdest,
     1               llrange(objlat, objlong, latdest, longdest))
c
c   * if steady state has not been reached
        if (objnotsteadys) then
c
c     then limit object to turn rate
           call turnlimit(bearing, turntbl, timedelta,
     1           objspeed, objalt, objheading)
           call cnvrhtoll(objlat, objlong, disttravelled,
     1               objheading, finallat, finallong )
           objlat = finallat
           objlong = finallong
           call lluecr(objlat,objlong,objalt,objxyz)
           if (abs(objheading-bearing).lt..1) objnotsteadys = .false.
c
c     else let object follow great circle route
        else
           objlat = latdest
           objlong = longdest
           objheading = bearing
           do i = 1, 3
             objxyz(i) = objpxyz(i)
           end do
c
c   * end if
      end if
c
c*c end grtcircle
c
       return
       end
 
