cccccccccc FORTRAN subroutine crnfwr cccccccccc

c For performing the main computations for the 
c Cornflower Problem.

c Last changed: 02 SEP 2019

      subroutine crnfwr(idmn,n,b,xOmeg1,xOmSym,fv1,fv2,Umat,eigvls,
     +                  ipvt,wk)
      double precision b(idmn),xOmeg1(idmn,idmn),xOmSym(idmn,idmn),
     +                 Umat(idmn,idmn),eigvls(idmn),fv1(idmn),
     +                 fv2(idmn),wk(idmn)
      integer i,k,kd,idmn,matz,ierr,ipvt(idmn),info,n

c     Set various linear algebra routine variables:

      matz = 0
      ierr = 1
      info = 0

      do 10 i = 1,n
     
c        Obtain the current symmetrised Omega1 matrix:

         do 20 k = 1,idmn
            do 30 kd = 1,idmn
                xOmSym(k,kd) = 0.5*(xOmeg1(k,kd) + xOmeg1(kd,k))
30          continue
20       continue

c        Obtain eigenvalues of the current symmetrised Omega1 matrix:

         call rs(idmn,idmn,xOmSym,eigvls,matz,Umat,fv1,fv2,ierr)

c        Obtain current matrix requiring inversion:

         do 40 k = 1,idmn
            do 50 kd = 1,idmn
                xOmeg1(k,kd) = xOmeg1(k,kd) + eigvls(idmn)*b(i)
50          continue
40       continue

c        Carry out required matrix inversion:

         call dgefa(xOmeg1,idmn,idmn,ipvt,info)
         call dgedi(xOmeg1,idmn,idmn,ipvt,wk,wk,01)

10    continue

      return
      end

cccccccccc End of crnfwr cccccccccc
