program RelFuncSplit

! Split relocatable functions into separate files

  character(80) :: Card
  character(255) :: Path  ! Basic path.  -#.s is appended, where
                          ! # is a sequence number.
  character(3) :: SeqC    ! Sequence number as characters

  integer :: Seq

  call getarg ( 1, path )

  seq = 0

  do
    seq = seq + 1
    write ( seqc, '(i0)' ) seq
    open ( 10, file=trim(path) // trim(adjustl(seqc)), form='formatted' )
    do
      read ( *, '(a)', end=9 ) card
      write ( 10, '(a)' ) card
      if ( card(68:68) == 'B' ) then
        close ( 10 )
        exit
      end if
    end do
  end do
9 close ( 10 )
end program RelFuncSplit
