       implicit real*8 (a-h, o-z)
       dimension r(480000),g(480000),b(480000),h(3,3)
       character p3*2,mozi*35
          read(*,'(a2)') p3
          read(*,'(a35)') mozi
           write(*,*) 'マジックナンバー：',p3
           write(*,*) 'コメント行：',mozi
          read(*,*) m,n
          write(*,*) '幅：',m
          write(*,*) '高さ：',n
           mn=m*n  !全ドット数
		   print*, '全ドット数',mn
          read(*,*) max !最大輝度値(255)
          write(*,*) '最大値輝度値：',max
		  do i=1,mn
		  read(*,*) r(i)
		  read(*,*) g(i)
		  read(*,*) b(i)
		  print*, i
		  end do
! 
open(7,file='henkanm')
do i=1,3
read(7,*) (h(i,j),j=1,3)
end do
close(7)
!
open(9,file='hoseigo.ppm')
write(9,'(a2)')'P3'
write(9,'(a10)') '# henkango'
write(9,*)m,n
write(9,*)max
do i=1,mn
rgbr=h(1,1)*r(i)+h(1,2)*g(i)+h(1,3)*b(i)
rgbg=h(2,1)*r(i)+h(2,2)*g(i)+h(2,3)*b(i)
rgbb=h(3,1)*r(i)+h(3,2)*g(i)+h(3,3)*b(i)
		  write(9,'(i3)') nint(rgbr) 
		  write(9,'(i3)') nint(rgbg)
		  write(9,'(i3)') nint(rgbb)
		  end do
		  close(9)
! 
!open(8,file='kakunin')
!do i=1,3
!write(8,*) (h(i,j),j=1,3)
!end do
!close(8)
!
end 

