real a
dimension a(2000000)
call InputMatrix
if (e.eq.0) call InputVector
if (e.eq.0) call Calc
if (e.eq.0) call Output
return
end
subroutine InputMatrix
common /error/e
common /array/a(2000000)
common /maximize/ maxi, maxj
integer i/1/, j/1/, maxi/0/, maxj/0/
open (1,file='Matrix.f',err=10)
read(1,*,err=11) maxi, maxj
if((maxi.lt.0).and.(maxj.lt.0)) e=2
if((maxi*(maxj+2)).gt.2000000) e=1
if(e.ne.0) then
print *, 'Error in maxi, maxj'
return
endif
20 if(j.le.maxj)then
30 if(i.le.maxi)then
if(j.eq.1) then
read(1,*,err=11) a(i+maxi*maxj)
else
read(1,*,err=11) a((j-1)*maxi+i)
endif
i=i+1
goto 30
endif
i=1
j=j+1
goto 20
endif
close(1)
return
10 print *, 'Can not open Matrix.f file.'
goto 12
11 print *, 'Error in Matrix.f file.'
12 e=3
close(1)
return
end
subroutine InputVector
common /error/e
common /array/a(2000000)
common /maximize/ maxi, maxj
integer i/1/
open (2,file='Vector.f',err=50)
60 if(i.le.maxi)then
read(2,*,err=51) a(maxi*(maxj+1)+i)
i=i+1
goto 60
endif
close(2)
return
50 print *, 'Can not open Vector.f file.'
goto 52
51 print *, 'Error in Vector.f file.'
52 e=3
close(2)
return
end
subroutine Calc
common /error/e
common /array/a(2000000)
common /maximize/ maxi, maxj
integer i/1/, j/1/
real s/0/
70 if(j.le.maxi)then
80 if((i.lt.(maxj+j)).and.(i.gt.(j-maxj)))then
if(i.eq.j) then
s=s+a(maxi*maxj+i)*a(maxi*(maxj+1)+i)
endif
if(i.gt.j)then
s=s+a(maxi*(maxj+1)+i)*a(maxi*(i-j)+i)
endif
if(i.lt.j)then
s=s+a(maxi*(maxj+1)+i)*a(maxi*(j-i)+j)
endif
i=i+1
goto 80
endif
a(j)=s
j=j+1
i=(j-maxj)+1
s=0
goto 70
endif
return
end
subroutine Output
common /array/a(2000000)
common /maximize/ maxi, maxj
integer i/1/
open (3,file='Result.csv',err=100)
110 if(i.le.maxi)then
write(3, 111) a(i)
i=i+1
goto 110
endif
close(3)
return
100 print *, 'Can not open Result.csv file.'
return
111 format(E10.4, ';')
end
Программа переводит содержимое тестового файла в бинарный
program ftob
integer i/0/, maxi/0/, maxj/0/
real d/0/
open (1,file='Matrix.f', err=10)
open (2,file='Vector.f', err=10)
open (11,file='Matrix.bin',access='direct',recl=4, err=10)
open (12,file='Vector.bin',access='direct',recl=4, err=10)
read (1,*, err=20) maxi, maxj
write(11,rec=1) maxi
write(11,rec=2) maxj
i=3
100 if(i.le.(maxi*maxj+2))then
read (1,*,err=20) d
write(11,rec=i) d
i=i+1
goto 100
endif
i=1
110 if(i.le.maxi)then
read (2,*, err=20) d
write(12,rec=i) d
i=i+1
goto 110
endif
close(1)
close(2)
close(11)
close(12)
return
10 print *, 'Can not open file'
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.