Writes the header of the PNM image to a file. Required before writing the pixels to the file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(format_pnm), | intent(in) | :: | this | |||
integer, | intent(in) | :: | nunit |
subroutine write_header(this, nunit) type(format_pnm), intent(in) :: this integer, intent(in) :: nunit integer :: i, k ! Write magic number write(nunit,'(a)') this%magic_number ! Write comments k = ceiling(real(len(adjustl(this%comment)))/70.0) if (len(adjustl(this%comment)) /=0 .and. len(adjustl(this%comment)) <= 70) then write(nunit,'(a,a)') '# ',trim(adjustl(this%comment)) else if (len(adjustl(this%comment)) /=0 .and. len(adjustl(this%comment)) > 70 ) then do i = 1, k-1 write(nunit,'(a,a)') '# ',adjustl(this%comment(70*(i-1)+1:70*(i-1)+70)) end do write(nunit,'(a,a)') '# ',trim(adjustl(this%comment(70*(k-1)+1:))) end if ! Write width, height and max_color write(nunit, '(g0,1x,g0)') this%width, this%height if (this%file_format /= 'pbm') write(nunit,'(g0)') this%max_color end subroutine write_header