program Webify_Logic

  ! Read a List_1_1* text file and make an HTML file with links to
  ! the drawing number

  ! Input format:
  !   1-9: Page numbers
  ! 11-16: Drawing number
  ! 18-22: Figure number
  ! 24-  : Title

  character(255) :: Line


  ! Get title from command line argument
  call getarg ( 1, line )

  ! Begin the file and start a table
  write ( *, '(a)' ) &
    & '<html>', &
    & '<title>1401 Logic drawing browser</title>', &
    & '<h1>1401 Logic drawing browser -- ' // trim(adjustl(line)) // '</h1>', &
    & '', &
    & '<table border="1">', &
    & '<tr>', &
    & '<th>Pages</th>', &
    & '<th>Drawing #</th>', &
    & '<th>Fig #</th>', &
    & '<th>Title</th>', &
    & '</tr>'

  do
    read ( *, '(a)', end=9 ) line
    if ( line(1:1) == 'P' ) cycle
    ! Write a table row
    write ( *, '(a)' ) &
      & '<tr>', &
      & '<td>' // line(1:9) // '</td>',                 & ! Pages
      & '<td><a href=' // line(11:16) // '.pdf>' // &
      &      line(11:16) // '</a></td>',                & ! Drawing #
      & '<td>' // line(18:22) // '</td>',               & ! Fig #
      & '<td>' // trim(adjustl(line(24:))) // '</td>',  & ! Title
      & '</tr>'
  end do

9 continue
  write ( *, '(a)' ) '</table>', &
    &                '</html>'

end program Webify_Logic
