function op_same_time, event, og_table, verbose=verbose
;+
; NAME:
;  op_same_time
; PURPOSE:
;  Called by op_edit (by op_first_guess) to resolve conflicting OG times.
;
; PROCEDURE:
;  There are three rules:
;  1. If the conflict involes OP STOP and anything, 
;		move the OP STOP later by 32 sec
;  2. If the conflict involves the OP DAY, move later than 32 sec (unless
;		rule 1 applies).
;  3. If the conflict involves the DSN REPRO command and an antenna change 
;     command, back the antenna change command up by 32 s and make it a
;     "ANT CHNG TO X" command.
;  4. If the conflict involves any other type of conflict, just warn the user.
; HISTORY:
;  30-nov-93, JRL, Written
;  30-jun-94, JRL, When warning the user, give the same event number as
;		   shows up in the printout.
;  27-jul-94, JRL, Make the warning more prominent.  Added Case 3 above.
;-

event2 = event				; Save a copy of the original
repeat begin
; Don't look at out of range og's or night og's
  jj = where((event2.og ge og_table(0).og) and (event2.og le og_table(127).og) 	$
	  and event2.og ne og_table(5).og)
  jj = jj(1:*)				; The first event is the KSC AOS

; ---------------------------------------------------------------------
; This next bit of code is messy.  Its purpose is to try to get the 
; numbering of the warning message to match the printout OP number in case
; of a conflict.  Normally, one should just start at the NOP command.
; However, if a DAY command occurs at the same time as the NOP, it will
; be shifted past the NOP, so one has to check for the case of a DAY OG at
; the same time as the NOP.

  if event2(jj(0)).og ne og_table(0).og then begin	; Is the NOP first jj event?
    kk = where(event2(jj).og eq 0,nc)	; Get indices of all NOPs
    if nc gt 0 then begin		; Could there not be NOPs?
      kk = min(kk)			; Get the first NOP
; The next two lines of code keeps the DAY OG or anything else (what it could 
; it be, though?) if it is at the same time as the first NOP.
      if addtime(event2(jj(kk)).timarr,diff=event2(jj(kk-1)).timarr) ne 0. then jj = jj(1:*)
    endif				; nc gt 0
  endif
; ---------------------------------------------------------------------

  str_event = fmt_og(event2(jj))	; Format the information
  finished = 1
  npts = n_elements(jj)
  for i=0,npts-2 do begin
    xx = addtime(event2(jj(i)).timarr,diff=event2(jj(i+1)).timarr)
    if xx eq 0 then begin
       if keyword_set(verbose) then begin
         print,'*********************************************'
         print,'** Warning identical times for the following:'
         print,str_event(i:i+1),format='(x,a)'
         print,'*********************************************'
       endif
; Case 1:  involving op stop:
       if (event2(jj(i)).og eq og_table(127).og) or (event2(jj(i+1)).og eq og_table(127).og) then begin
	  ii = (where(event2(jj(i:i+1)).og eq og_table(127).og))(0) + i
	  sgg = +1			; Move later
          if keyword_set(verbose)then print,'   (will move the OP Stop 32 sec later: '+	$
		string((addtime(event2(jj(ii)).timarr,del=sgg*32.d0/60.))(0:2),format='(3i2.2)')+')'
; Case 2:  involving Day OG:
       endif else if (event2(jj(i)).og   eq og_table(55).og) or $
		     (event2(jj(i+1)).og eq og_table(55).og) then begin
	  ii = (where(event2(jj(i:i+1)).og eq og_table(55).og))(0) + i
	  sgg = +1			; Move later
	  if keyword_set(verbose) then print,'   (will move the DAY OG 32 sec later: '+	$
		string((addtime(event2(jj(ii)).timarr,del=sgg*32.d0/60.))(0:2),format='(3i2.2)')+')'
; Case 3:  involving BDR REP and an antenna change command.
       endif else if ((event2(jj(i)).og   eq og_table(19).og) or 		$ ; DSN REPRO
		      (event2(jj(i+1)).og eq og_table(19).og)) and 		$
		     ((event2(jj(i)).og   eq og_table(20).og) or 		$ ; DSN PAUSE-A/B
		      (event2(jj(i+1)).og eq og_table(20).og) or		$
		      (event2(jj(i)).og   eq og_table(21).og) or 		$ ; DSN PAUSE-B/A
		      (event2(jj(i+1)).og eq og_table(21).og) or		$
		      (event2(jj(i)).og   eq og_table(24).og) or 		$ ; ANT CHNG TO A
		      (event2(jj(i+1)).og eq og_table(24).og) or		$
		      (event2(jj(i)).og   eq og_table(25).og) or 		$ ; ANT CHNG TO B
		      (event2(jj(i+1)).og eq 25)) then begin			 
	  ii = (where(event2(jj(i:i+1)).og ne og_table(19).og))(0) + i
	  sgg = -1			; Move earlier
	  if event2(jj(ii)).og eq og_table(20).og then begin
	      event2(jj(ii)).og  = og_table(25).og
	      event2(jj(ii)).com = og_table(25).og_comm
	  endif else if event2(jj(ii)).og eq og_table(21).og then begin
	      event2(jj(ii)).og  = og_table(24).og
	      event2(jj(ii)).com = og_table(24).og_comm
	  endif
	  if keyword_set(verbose) then print,'   (will move the Ant Change OG 32 sec earlier: '+ $
		string((addtime(event2(jj(ii)).timarr,del=sgg*32.d0/60.))(0:2),format='(3i2.2)')+')'
       endif else begin
	  ii = -1
          if not keyword_set(verbose) then begin
            print,'*********************************************'
            print,'** Warning identical times for the following:'
            print,str_event(i:i+1),format='(x,a)'
            print,'*********************************************'
          endif
          print,'   (you must fix with opogedt)' & tbeep,5
          ans = '' & read,'* Enter <cr> to continue:',ans
       endelse
       if ii ne -1 then begin
            event2(jj(ii)).timarr = addtime(event2(jj(ii)).timarr,del=sgg*32.d0/60.)
	    event2(jj(ii)).offset = event2(jj(ii)).offset + sgg*32.d0/60.
	    finished = 0			; We shifted something, so not finished yet
       endif
    endif
  endfor
  if not finished then begin
; ----------------------------------------
;  Time order everything

    ex2int,event2.timarr,msod,DS79      ; Convert to internal format

    Day = DS79-min(DS79)
    T_sec = msod/1000L+Day*24L*3600

    event2 = event2(bsort(T_sec))       ; Don't re-order identical times
;   event2 = make_32( event2 )          ; Align to 32 sec boundaries
; ----------------------------------------
  endif					; not finished
endrep until finished

return,event2
end
