I'm attempting to read an image into an array to apply the sobel filter to it. Here is my code:
program edges
implicit none
integer, dimension(:,:), allocatable :: inp, outim, GX, GY
integer, parameter :: dp = selected_real_kind(15,300)
integer :: ky, kx, x, y, out_unit = 10, M, N, sx, sy, i, j, P2, W, H, mxgr
real(kind=dp) :: G
M = 5
N = 5
W = 50
H = 50
mxgr = 1
allocate(inp(M,N))
allocate(outim(M-2,N-2))
allocate(GX(3,3))
allocate(GY(3,3))
open(file = 'clown.pgm',unit=out_unit,status= 'unknown') !opening file to write to inp
read (out_unit,11) P2 !pgm magic number
read (out_unit,12) W,H !width, height
read (out_unit,13) mxgr !max gray value
do M=-25,25
do N=-25,25
read (out_unit,*) inp(M,N)
end do
end do
11 format(a2)
12 format(i3,1x,i3)
13 format(i5)
open(file = 'outclown.pgm',unit=out_unit,status= 'unknown') !opening file to write to inp
write (out_unit,15) P2 !pgm magic number
write (out_unit,16) W,H !width, height
write (out_unit,17) mxgr !max gray value
do M=-25,25
do N=-25,25
write (out_unit,*) imout(M,N)
end do
end do
close (unit=out_unit)
15 format(a2)
16 format(i3,1x,i3)
17 format(i5)
Which spits out the following error:
At line 43 of file sobel.f90 (unit = 10, file = 'clown.pgm')
Fortran runtime error: End of file
I'm fairly new to working with images in fortran. How can I fix this error? Am I attempting to read the image into the array correctly?