program Reseq

! resequence a deck in 72-75 and emit constant into 76-89

  integer :: seqno
  character(len=4) :: emit
  character(len=80) :: line

  call getarg ( 1, emit )
  if ( emit == '' ) then
    call getarg ( 0, line )
    print *, 'Usage: ', trim(line), ' seqstart emit < in > out'
    stop
  end if
  read ( emit, '(i4)', err=9 ) seqno
  call getarg ( 2, emit )

  do
    read ( *, '(a)', end=1 ) line
    write ( line(72:75), '(i4.4)' ) seqno
    if ( line(40:40) /= 'L' .and. line(40:40) /= 'N' ) cycle
    seqno = seqno + 1
    line(76:) = emit
    print '(a)', line
  end do

1 stop

9 print *, 'Argument 1 is not an integer: ', emit

end program Reseq
