Фортран задача (декомпозиция, есть двумерный массив А и массив С, если значения С лежат на интервале P T, сосчитать Х)
Имеются следующие ошибки в говнокоде, которые я не имею понятия, как исправить, кто-то может с этим помочь?
сам говнокод:
subroutine red2D (i,j,n,m,K,infile,iso)
integer, intent (out) :: iso,n,m,i
integer, intent (in) :: infile
real,allocatable, intent (out) :: K(:,:)
open (infile, file='in.txt',iostat=iso)
if (iso/=0) then
stop 'open file error'
end if
read (infile,*) n,m
print *, n
print *, m
allocate (K(n,m))
do i=1,n
read (infile,*) (K(i,j),j=1,m)
print *, K(i,j)
end do
close (infile)
i=0
j=0
end subroutine red2D
subroutine red1D (i,n1,L,infile2,iso)
integer, intent (in) :: infile2
real,allocatable :: L(:)
integer, intent (out) :: n1,iso,i
open (infile2,file ='in2.txt',iostat=iso)
if (iso/=0) then
stop 'file open error'
end if
read (infile2,*) n1
allocate (L(n))
print *,n1
do i=1,n1
read (infile2,*) L(i)
print *,L(i)
end do
close (infile2)
i=0
end subroutine red1D
subroutine cocheck (A,B,G,infile3,iso,i,n1,semam)
real,intent (out) :: A,B
integer, intent (in) :: infile3,n1
real,allocatable,intent (out) :: G(:)
integer,intent (out) :: iso,semam,i
semam=0
open (infile3,file='in3.txt',iostat=iso)
if(iso/=0) stop 'file open error'
allocate (G(n1))
read (infile3,*) A,B
print *, A
print *, B
close (infile3)
if(A<B) then
do i=1,n1
if(G(i)<A .or. G(i) >B) then
semam=1
stop 'G doesnt belong to an interval'
end if
end do
else
do i=1,n1
if (G(i) >A .or. G(i) <B) then
semam=1
stop 'G doesnt belong to an interval'
end if
end do
end if
i=0
end subroutine cocheck
subroutine newcr (V,i,j,outfile,iso,H)
real,allocatable,intent (out) :: V(:,:)
integer,intent (in) :: outfile
real,allocatable,intent (out) :: H(:)
integer, intent (out) :: i,j
allocate (V(n,m))
allocate (H(n))
do i=1,n
H(i)=0
do j=1,m
H(i)=H(i)+V(i,j)
end do
end do
close (outfile)
i=0
j=0
end subroutine newcr
subroutine wr(i,H,outfile)
integer :: outfile
integer,intent (out) :: i
real, intent (in) :: H(n)
open (outfile,file='out.txt',iostat=iso)
if (iso/=0) stop 'file open error'
do i=1,n
write (outfile, '(f9.2,x)') H(i)
end do
end subroutine wr
program gambling
implicit none
integer i,j,n,m,iso,infile,infile2,infile3,outfile,n1,semam
real, allocatable :: A (:,:)
real, allocatable :: C(:)
real,allocatable :: X(:)
real P
real T
infile=1
infile2=2
infile3=3
outfile=4
call red1D(i,n1,C,infile2,iso)
call cocheck(P,T,C,infile3,iso,i,n1,semam)
call red2D(i,j,n,m,A,infile,iso)
call newcr(A,i,j,outfile,iso,X)
call wr (i,X,outfile)
end program gambling
и такие ошибки:
113 | call red1D(i,n1,C,infile2,iso)
| 1
Error: Explicit interface required for ‘red1d’ at (1): allocatable argument
114 | call cocheck(P,T,C,infile3,iso,i,n1,semam)
| 1
Error: Explicit interface required for ‘cocheck’ at (1): allocatable argument
115 | call red2D(i,j,n,m,A,infile,iso)
| 1
Error: Explicit interface required for ‘red2d’ at (1): allocatable argument
116 | call newcr(A,i,j,outfile,iso,X)
| 1
Error: Explicit interface required for ‘newcr’ at (1): allocatable argument
Бред написан. В логику не вникал (с чего бы?)
в 1м и 2м вызове происходит аллок для одного и того же идентификатора, два(!) раза
один и тот же идентификатор используется как скаляр и как матрица (А)
за каким то интересом i/j тянутся из одного вызова в другой без видимого смысла
за таким же интересом для каждого файла даются разные указатели, хотя файлы там же и закрываются
В фортране есть модули. Очень полезная весчь. Начал было исправлять, но с такими обломами смысла не вижу
да кто на нём вообще пишет, да и ещё столько ошибкок делает на 1 строчку 77374723 ошибок