export_pnm Subroutine

private impure subroutine export_pnm(this, file_name, encoding)

Writes the PNM image to a file.

Type Bound

format_pnm

Arguments

Type IntentOptional Attributes Name
class(format_pnm), intent(inout) :: this
character(len=*), intent(in) :: file_name
character(len=*), intent(in), optional :: encoding

Calls

proc~~export_pnm~~CallsGraph proc~export_pnm format_pnm%export_pnm proc~set_format format_pnm%set_format proc~export_pnm->proc~set_format proc~write_header write_header proc~export_pnm->proc~write_header

Called by

proc~~export_pnm~~CalledByGraph proc~export_pnm format_pnm%export_pnm proc~save color%save proc~save->proc~export_pnm program~demo_ppm demo_ppm program~demo_ppm->proc~export_pnm program~test test program~test->proc~export_pnm program~test1 test1 program~test1->proc~export_pnm program~test10 test10 program~test10->proc~export_pnm program~test11 test11 program~test11->proc~export_pnm program~test12 test12 program~test12->proc~export_pnm program~test13 test13 program~test13->proc~export_pnm program~test14 test14 program~test14->proc~export_pnm program~test17 test17 program~test17->proc~export_pnm program~test18 test18 program~test18->proc~export_pnm program~test19 test19 program~test19->proc~export_pnm program~test2 test2 program~test2->proc~export_pnm program~test20 test20 program~test20->proc~export_pnm program~test21 test21 program~test21->proc~export_pnm program~test22 test22 program~test22->proc~export_pnm program~test23 test23 program~test23->proc~export_pnm program~test24 test24 program~test24->proc~export_pnm program~test25 test25 program~test25->proc~export_pnm program~test3 test3 program~test3->proc~export_pnm program~test4 test4 program~test4->proc~export_pnm program~test6 test6 program~test6->proc~export_pnm program~test7 test7 program~test7->proc~export_pnm program~test8 test8 program~test8->proc~export_pnm program~test9 test9 program~test9->proc~export_pnm

Source Code

   impure subroutine export_pnm(this, file_name, encoding)
      class(format_pnm), intent(inout)            :: this
      character(*),      intent(in)               :: file_name
      character(*),      intent(in), optional     :: encoding
      integer                                     :: nunit
      integer                                     :: iostat

      if (present(encoding)) then
         call this%set_format(encoding)

         select case (this%encoding)
          case ('ascii','plain')
            select case (this%file_format)
             case ('pbm')
               this%magic_number = 'P1'
             case ('pgm')
               this%magic_number = 'P2'
             case ('ppm')
               this%magic_number = 'P3'
            end select
          case ('binary','raw')
            select case (this%file_format)
             case ('pbm')
               this%magic_number = 'P4'
             case ('pgm')
               this%magic_number = 'P5'
             case ('ppm')
               this%magic_number = 'P6'
            end select
         end select
      end if

      select case (this%magic_number)
       case ('P1', 'P2', 'P3')
         open (newunit = nunit, file = file_name//'.'//this%file_format,&
         status='replace', iostat=iostat, form='formatted', action='write')
         if (iostat /= 0) error stop 'Error opening the file.'
         call write_header(this, nunit)
         close(nunit)

         open (newunit = nunit, file = file_name//'.'//this%file_format,&
         status='old', iostat=iostat, form='formatted', action='write', position='append')
         if (iostat /= 0) error stop 'Error opening the file.'
         write(nunit, '(*(g0,1x))', advance='no') transpose(this%pixels)
         close(nunit)
       case ('P4', 'P5', 'P6')
         open (newunit = nunit, file = file_name//'.'//this%file_format,&
         status='replace', iostat=iostat, form='formatted', action='write')
         if (iostat /= 0) error stop 'Error opening the file.'
         call write_header(this, nunit)
         close(nunit)

         open (newunit = nunit, file = file_name//'.'//this%file_format,&
         status='old', iostat=iostat, access='stream', form='unformatted', action='write', position='append')
         if (iostat /= 0) error stop 'Error opening the file.'
         write(nunit) transpose(achar(this%pixels))
         close(nunit)
      end select
   end subroutine export_pnm