C subroutine get_sacotime
C    calculate the times of the saco time nodes, 
C    count the number of time steps and 
C    get the actual final time
C    CGH 22 Nov, 1998
C    untested
C
C This is supposed to be identical to the stop algorithm in saco.
C If the stop algorithm in saco is changed then this should be changed. 

        subroutine get_sacotime(kd0,sec0,kdl,secl,delt,
     $                     kdf,secf,kd_saco,sec_saco,nsteps,NSTEPDIM)

           integer kd0,kdl,kdf
	   real    sec0,secl,secf
	   real    delt
	   integer nsteps
	   integer kd_saco(NSTEPDIM)
	   real    sec_saco(NSTEPDIM)
	   integer NSTEPDIM

           integer kd
	   real    seckd

	   kd    = kd0
	   seckd = sec0
	   nsteps = 0

100        continue
              seckd = seckd + delt
              nsteps = nsteps + 1 
              if(nsteps.gt.NSTEPDIM) then
                 write(2,*)'get_sacotime: too many time steps. ',
     $                'Increase NSTEPDIM ',NSTEPDIM       
                 write(*,*)'get_sacotime: too many time steps. ',
     $                'Increase NSTEPDIM ',NSTEPDIM
                 stop
             endif


              if(seckd.ge.86400.)call up_date(kd,seckd)
	      kd_saco(nsteps) = kd
	      sec_saco(nsteps) = seckd
              if(kd.lt.kdl) goto 100
	      if((kd.eq.kdl).and.(seckd.lt.secl)) goto 100
101        continue
           kdf = kd
	   secf = seckd
	   kd_saco(nsteps) = kdf
	   sec_saco(nsteps) = seckd

	return
	end
