      SUBROUTINE TIME(T)          
      REAL T(3)     
      INTEGER HOURS,MINS,AM,PM,SECS    
      DATA AM/'AM'/PM/'PM'/       
      T1=TIM(0)     
      SECS=TIM(5)  
      HOURS=T1/60   
      MINS=T1-HOURS*60             
      IF (HOURS .GE. 12)GO TO 2   
      N = AM       
      GO TO 1      
    2 N = PM       
      HOURS=HOURS-12              
    1 IF(HOURS.EQ.0)HOURS=12
      IF(MINS .LE. 9 .AND. SECS .LE. 9)GO TO 6
      IF(SECS .LE. 9)GO TO 8
      IF (MINS .LE. 9)GO TO 5
      ENCODE(12,3,T)HOURS,MINS,SECS,N   !MINS & SECS >= 10   
    3 FORMAT(I2,':',I2,':',I2,' ',A2,' ')    
      RETURN       
    5 ENCODE(12,4,T)HOURS,MINS,SECS,N    !MINS < 10
    4 FORMAT(I2,':0',I1,':',I2,' ',A2,' ')
      RETURN
    6 ENCODE(12,7,T)HOURS,MINS,SECS,N
    7 FORMAT(I2,':0',I1,':0',I1,' ',A2,' ')  !MINS & SECS <10
      RETURN
    8 ENCODE(12,9,T)HOURS,MINS,SECS,N
    9 FORMAT(I2,':',I2,':0',I1,' ',A2,' ')   !SECS < 10
      RETURN
      END          
