program SplitDump

! Split the dump of a simh tape, creating a separate file for each record.

  character(132) :: Dir
  character(132) :: Line

  call getarg ( 1, line )  ! Get input file
  open ( 10, file=trim(line), status='old', form='formatted' )

  call getarg ( 2, dir )   ! get output directory

  do
    read ( 10, '(a)', end=9 ) line
    if ( line(111:116) /= 'Record' ) cycle
    open ( 11, file=trim(dir) // adjustl(line(118:)), form='formatted' )
    do
      write ( 11, '(a)' ) trim(line)
      read ( 10, '(a)', end=9 ) line
      if ( line(111:116) == 'Record' ) exit
    end do
    close ( 11 )
    backspace ( 10 )
  end do
9 stop
end program SplitDump
