subroutine redo(inputline,r,lun)
! if line starts with r word call redol_()
! uses unit 1071
! r
! r string
! ident_1="@(#) M_history redo(3f) open binary direct access file for keeping history"
character(len=*),intent(inout) :: inputline ! user string
character(len=1),intent(in),optional :: r ! character to use to trigger editing
integer,intent(in),optional :: lun
character(len=1) :: r_local ! character to use to trigger editing
integer,save :: iobuf=1071 ! unit number to use for redo history buffer
integer,save :: iredo ! number of lines read from standard input into redo file
logical,save :: lcalled=.false. ! flag whether first time this routine called or not
character(len=READLEN) :: onerecord
integer :: ioparc
integer :: ilast
!-----------------------------------------------------------------------------------------------------------------------------------
if(present(r))then
r_local=r
else
r_local='r'
endif
!-----------------------------------------------------------------------------------------------------------------------------------
! open history file and initialize
if(.not.lcalled)then ! open the redo buffer file
lcalled=.true.
iredo=0 ! number of lines in redo buffer
call open_history_(iobuf,' ','scratch',ioparc) ! redo buffer
if(ioparc /= 0)then
call journal('sc','error creating history file')
return
endif
endif
!-----------------------------------------------------------------------------------------------------------------------------------
ilast=len_trim(inputline)
if(ilast == 1.and.inputline(1:1) == r_local)then ! redo command
call redol_(inputline,iobuf,iredo,READLEN,' ',lun)
ilast=len_trim(inputline)
elseif(inputline(1:min(2,len(inputline))) == r_local//' ')then ! redo command with a string following
call redol_(inputline,iobuf,iredo,READLEN,inputline(3:max(3,ilast)),lun)
ilast=len_trim(inputline)
endif
if(ilast /= 0)then ! put command into redo buffer
iredo=iredo+1
onerecord=inputline ! make string the correct length; ASSUMING inputline IS NOT LONGER THAN onerecord
write(iobuf,rec=iredo)onerecord
endif
end subroutine redo