将图像读入数组输出“文件结束”错误

时间:2018-03-03 19:22:55

标签: fortran gfortran sobel

我正在尝试将图像读入数组以将sobel滤镜应用于其中。这是我的代码:

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)

其中吐出以下错误:

At line 43 of file sobel.f90 (unit = 10, file = 'clown.pgm')
Fortran runtime error: End of file

我在使用fortran中的图像方面相当新手。我该如何解决这个错误?我是否正在尝试将图像正确读入数组?

0 个答案:

没有答案