      PROGRAM GENE
      implicit none
      include 'mpif.h'

      integer R,M,size,rank,s,lp

      call MPI_Init(ierr)
      call MPI_Comm_Size(MPI_Comm_World,size,ierr)
      call MPI_Comm_Rank(MPI_Comm_World,rank,ierr)
      lp=size
       s=rank
      
      open(unit=20,file='GENEDATA')
      rewind(20)
      read(20,*) R
      
      close(20)
      M=lp*(R+1)-1
      call SUBGENE(lp,s,R,M)
      call MPI_Finalize(ierr)
      
      stop 100
      end

      subroutine SUBGENE(lp,s,R,M)
      implicit none
      include 'mpif.h'
      integer s,lp,R,M,j,k
      real*8 A,D,F,O,E,Q
c     STALE
      O=real(0)
      E=real(1)
      Q=real(4)
      
c     TWORZENIE A I D
      do k=0,M,1
      A(k)=E+real(E/100)*k
      D(k)=Q-real(E/100)*k
      enddo
      
c     TWORZENIE F
      F(0)=Q
      do k=1,M,1
      F(k)=A(k)+D(k)
      enddo
      
c     A,D,F=>FILE A,D,F NA DYSK
      open(unit=21,file='A')
      rewind(21)
      do k=0,M,1
      write(21,*) A(k)
      enddo
      
      open(unit=22,file='D')
      rewind(22)
      do k=0,M,1
      write(22,*) D(k)
      enddo
      
      open(unit=23,file='F')
      rewind(23)
      do k=0,M,1
      write(23,*) F(k)
      enddo
      
      close(21)
      close(22)
      close(23)
      
      return
      end
      
      
      
      open(unit=21,file='A')
      rewind(21)
      do k=0,M,1
      write(21,*) A(k)
      
      
      

