program Webify

  ! Read a List_1_7-7_7* text file and make an HTML file with links to
  ! the drawing number.

  ! Input format
  !     1: Book number
  !  3-11: Page numbers
  ! 13-18: Drawing number
  ! 20-29: Logic number
  ! 31-35: Frame / Channel
  ! 37-40: Subsystem
  ! 42-  : 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 ALD drawing browser</title>', &
    & '<h1>1401 ALD drawing browser -- ' // trim(adjustl(line)) // '</h1>', &
    & '', &
    & '<table border="1">', &
    & '<tr>', &
    & '<th>Book</th>', &
    & '<th>Pages</th>', &
    & '<th>Drawing #</th>', &
    & '<th>Logic #</th>', &
    & '<th>FR CH</th>', &
    & '<th>Sys</th>', &
    & '<th>Title</th>', &
    & '</tr>'

  do
    read ( *, '(a)', end=9 ) line
    if ( line(1:1) == 'B' ) cycle
    ! Write a table row
    write ( *, '(a)' ) &
      & '<tr>', &
      & '<td>' // line(1:1) // '</td>',                 & ! Book
      & '<td>' // line(3:11) // '</td>',                & ! Pages
      & '<td><a href=' // line(1:1) // '_7/' // line(13:18) // '.pdf>' // &
      &      line(13:18) // '</a></td>',                & ! Drawing #
      & '<td>' // line(20:29) // '</td>',               & ! Logic #
      & '<td>' // line(31:35) // '</td>',               & ! FR CH
      & '<td>' // line(37:40) // '</td>',               & ! Sys
      & '<td>' // trim(adjustl(line(42:))) // '</td>',  & ! Title
      & '</tr>'
  end do

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

end program Webify
