Изучение псевдодинамического распределения памяти на языке ФОРТРАН. Изучение форматов хранения матриц большой размерности, страница 3

        goto 30

20      print *, 'Error in file'

30    close(1)

      close(2)

      close(11)

      close(12)

      end


Программа создаёт матрицу и вектор заданной размерности и ширины ленты

program tester

      integer n/0/, m/0/, i/1/, j/1/, k/3/

      real h/0/

      open (1,file='Matrix.bin',access='direct',recl=4,err=100)

      open (2,file='Vector.bin',access='direct',recl=4,err=110)

10      print *, 'Please. Input size matrix and number lines.'

        read *, m, n

        if((m.le.0).or.(m*(n+2).gt.2000000).or.(n.le.0).or.(n.gt.m))then

            print *, 'Error. Input other numbers.'

            goto 10

        endif

        write(1,rec=1) m

        write(1,rec=2) n

20      if(j.le.n)then

21          if(i.le.m)then

                if(j-i.gt.0)then

                    h=0

                else

                    h=j

                endif

                write(1,rec=k) h

                i=i+1

                k=k+1

                goto 21

            endif

            j=j+1

            i=1

            goto 20

        endif

        i=1

30      if(i.le.m)then

            h=i

            write(2,rec=(i)) h

            i=i+1           

            goto 30

        endif

      close (1)

      close (2)

      return

110     print *, 'Error in Vector.bin'

        goto 120

100     print *, 'Error in Matrix.bin'

120     close (1)

        close (2)

      return

      end

Программа распечатывает матрицу из бинарного файла, в .csv файл, в плотном виде

program printer

      implicit none

      common /error/e

      common /array/a

      integer e/0/

      real a

      dimension a(2000000)

      call InputMatrix

      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/, k/2/, q/0/

      open (1,file='Matrix.bin',access='direct',recl=4,err=10)

       read(1,rec=1,err=11) maxi

       read(1,rec=2,err=11) maxj

       if((maxi.lt.0).and.(maxj.lt.0)) e=2

       if((maxi*maxj).gt.2000000) e=1

       if(maxi.gt.100)then

            print *, 'A you sure? You want print very big Matrix'

            print *, 'If you realy want print this matrix press 1, else

     *press other any key'

            read *, q

            if(q.ne.1) goto 13

       endif

       if(e.ne.0) return

20      if(j.le.maxj)then

30          if(i.le.maxi)then

                k=k+1

                if(j.eq.1) then

                    read(1,rec=k,err=11) a(i)

                else

                    read(1,rec=k,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

13    print *, 'You does right choice'

      goto 12

10    print *, 'Can not open Matrix.bin file.'

      goto 12

11    print *, 'Error in Matrix.bin file.'

12    e=3

      close(1)

      return

      end

      subroutine Output

      common /array/a(2000000)

      common /maximize/ maxi, maxj

      integer i/1/, j/1/, k/1/

      real h/0/

      open (3,file='Matrix.csv',err=100)

70      if(j.le.maxi)then

80          if(i.le.maxi)then

                if(i.eq.j) then

                    h=a(i)

                endif

                if((i.gt.j).and.((i-j).lt.maxj)) then

                    h=a(maxi*(i-j)+i)

                endif

                if((i.lt.j).and.((j-i).lt.maxj)) then

                    h=a(maxi*(j-i)+j)

                endif

                i=i+1

                if(k.ne.j)then

                    write(3,*) ';'