program SPS_to_Autocoder
  implicit None

  integer :: A(6) = (/ 48, 51, 55, 58, 62, 65 /) ! Autocoder SW addresses 

  character(71) :: B(3) = (/ & ! Clear, Clear, Boot for Autocoder
    & ',008015,019026,030,034041,045,053,0570571026                           ', &
    & 'L068112,102106,113/101099/I99,027A070028)027B0010270B0261,001/001113I0 ', &
    & ',008015,022029,036040,047054,061068,072/061039              ,0010011040' /)

  integer :: I
  character(80) :: Line
  integer :: N
  character(71) :: Out
  integer :: S(6) = (/ 63, 67, 39, 43, 47, 51 /) ! SPS SW instructions

  ! Skip boot cards
  do n = 1, 3
    read ( *, '(a)' ) line
  end do

  ! Emit Autocoder boot cards
  do n = 1, 3
    write ( *, '(a,i4.4,a)' ) b(n), n, line(76:80)
  end do

  do
    read ( *, '(a)', end=9 ) line
    out(1:38) = line(1:38)    ! The image
    out(39:39) = ''
    out(40:46) = line(56:62)  ! The load or clear core instruction
    if ( out(40:40) == '/' ) then
      out(47:71) = ''
    else
      out(47:71) = ',040040,040040,0400401040'
      do i = 1, 6
        if ( line(s(i):s(i)) /= ',' ) exit
        out(a(i):a(i)+2) = line(s(i)+1:s(i)+3)
      end do
    end if
    write ( *, '(a,i4.4,a)' ) out, n, line(76:80)
    n = n + 1
  end do
9 stop

end program SPS_to_Autocoder
