!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!
! Copyright D.J. Jeffery, 2015jan01.
!
! A fortran-95 program to create report forms from laboratory exercises. 
! The compile command is f95 report.f.
! The run command is a.out. 
!
!-----------------------------------------------------------------------
!
      program report
      implicit none
!
      character :: afile_in*180     ! Input laboratory exercise.
      character :: afile_out*180    ! Output laboratory exercise. 
!
      integer :: i,j,k,l,m,n
      integer :: icopy
      integer :: itell
!
      character :: record*512
      character :: tmp*512
!
      print*,'Input the laboratory exercise name.'
      read(*,'(a)') afile_in 
      open(unit=1,file=afile_in,status='old',action='read')
      afile_out=afile_in(1:len_trim(afile_in)-4)//'_report.php'
      write(*,'(a,1x,a)') afile_in(1:len_trim(afile_in)),                          &
     &                    afile_out(1:len_trim(afile_out))
!      write(*,'(2i5)') len_trim(afile_in),len_trim(afile_out)
      open(unit=2,file=afile_out,status='unknown',action='write')
!      
      icopy=0
      itell=0
      do
        read(1,'(a)',end=100) record
        tmp=adjustl(record)
        if(tmp(1:10) .eq. '<! ISTART:') then
            icopy=1
            if(itell .eq. 1) then
               write(2,'(/a/)') '<li>'
            end if
          else if(tmp(1:8) .eq. '<! IEND:') then
            icopy=0
            if(itell .eq. 0) then
               itell=1
               write(2,'(a/a//a)')                                                    &
     &          '<h1>Name:</h1>',                                                  &
     &          '<h1>Partner Names:</h1><br><br>','</p>'
               write(2,'(/a/)') '<ol>'
            end if
        end if
!        write(*,'(i5,1x,a)') icopy,record(1:len_trim(record))
        if(icopy .eq. 1) then
           i=index(record,'<li>')
           if(i .eq. 0) then
              write(2,'(a)') record(1:len_trim(record))
            else
              write(2,'(a)') record(i+4:len_trim(record))
           end if
         end if
      end do
!
  100 continue
      close(unit=2)
      close(unit=1)
!
      end program report
!
!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
