read_header Subroutine

private subroutine read_header(this, nunit, pos)

Reads the header of the PNM image from a file. Required before reading the pixels from the file.

Arguments

Type IntentOptional Attributes Name
class(format_pnm), intent(inout) :: this
integer, intent(in) :: nunit
integer, intent(out) :: pos

Called by

proc~~read_header~~CalledByGraph proc~read_header read_header proc~import_pnm format_pnm%import_pnm proc~import_pnm->proc~read_header program~demo_ppm demo_ppm program~demo_ppm->proc~import_pnm program~test10 test10 program~test10->proc~import_pnm program~test11 test11 program~test11->proc~import_pnm program~test12 test12 program~test12->proc~import_pnm program~test13 test13 program~test13->proc~import_pnm program~test14 test14 program~test14->proc~import_pnm program~test7 test7 program~test7->proc~import_pnm program~test8 test8 program~test8->proc~import_pnm program~test9 test9 program~test9->proc~import_pnm

Source Code

   subroutine read_header(this, nunit, pos)
      class(format_pnm), intent(inout) :: this
      integer, intent(in)           :: nunit
      integer, intent(out)          :: pos
      character(len=70) :: comment
      character :: temp
      integer :: i, k

      read(nunit,*)
      k = 0
      do
         read(nunit,'(a)') temp
         if (temp /= '#') exit
         k = k + 1
      end do
      inquire(nunit, pos=pos)
      
      rewind(nunit)
      read(nunit,*) this%magic_number
      this%comment = ''
      do i = 1, k
         read(nunit,'(a,a,a)') temp, temp, comment
         this%comment = this%comment//comment
      end do
      read(nunit,*) this%width, this%height
      inquire(nunit, pos=pos)

      if (this%file_format == 'pgm' .or. this%file_format == 'ppm') then
         read(nunit,*) this%max_color
         inquire(nunit, pos=pos)
      end if
   end subroutine read_header