program bits
  use n3bits
  implicit none
  call test1
  call test2
contains

  subroutine test1
    character(4):: cbuf1, cbuf2
    integer:: ibuf1(1)
    cbuf1 = 'ABCD'
    call atoipack(cbuf1, ibuf1, size(ibuf1))
    print '("! ", Z8.8)', ibuf1(1)
    call itoaunpack(ibuf1, size(ibuf1), cbuf2)
    if (cbuf1 == cbuf2) then
      write(*, '(A)') trim(cbuf1) // ': OK'
    else
      write(*, '(A)') trim(cbuf1) // ': NG <' // trim(cbuf2) // '>'
      STOP 16
    endif
  end subroutine

  subroutine test2
    character(80):: cbuf1, cbuf2
    integer:: ibuf1(40)
    cbuf1 = 'Round trip from "character" string'
    call atoipack(cbuf1, ibuf1, size(ibuf1))
    call itoaunpack(ibuf1, size(ibuf1), cbuf2)
    if (cbuf1 == cbuf2) then
      write(*, '(A)') trim(cbuf1) // ': OK'
    else
      write(*, '(A)') trim(cbuf1) // ': NG <' // trim(cbuf2) // '>'
      STOP 16
    endif
  end subroutine

end program
