21 use pkind, only: spi,sp,dp,spc,dpc
50 real(sp),
intent(inout) :: d(:), e(:)
51 real(sp) :: tv(size(d))
61 real(dp),
intent(inout) :: d(:), e(:)
62 real(dp) :: tv(size(d))
72 complex(dpc),
intent(inout) :: d(:), e(:)
73 complex(dpc) :: tv(size(d))
82 real(sp),
dimension(:,:),
intent(INOUT):: a
85 if(ff)stop
'In sinvmt; Unable to invert matrix'
93 real(dp),
dimension(:,:),
intent(inout):: a
96 if(ff)stop
'In dinvmt; Unable to invert matrix'
104 complex(dpc),
dimension(:,:),
intent(inout):: a
107 if(ff)stop
'In cinvmt; Unable to invert matrix'
117 real(sp),
dimension(:,:),
intent(inout):: a
118 logical,
intent( out):: ff
119 integer(spi) :: m,i,j,jp,l
121 integer(spi),
dimension(size(a,1)):: ipiv
123 if(m /=
size(a,2))stop
'In sinvmtf; matrix passed to sinvmtf is not square'
127 print
'(" In sinvmtf; failed call to sldumf")'
131 do i=1,m; a(i,i)=u1/a(i,i);
enddo
133 do j=i+1,m; a(i,j)=-a(j,j)*dot_product(a(i:j-1,j),a(i,i:j-1));
enddo
137 do i=jp,m; a(i,j)=-a(i,j)-dot_product(a(jp:i-1,j),a(i,jp:i-1));
enddo
141 do i=1,j; a(i,j)=a(i,j)+dot_product(a(jp:m,j),a(i,jp:m));
enddo
142 do i=jp,m; a(i,j)=dot_product(a(i:m,j),a(i,i:m));
enddo
145 do j=m-1,1,-1; l=ipiv(j); call
sswpvv(a(:,j),a(:,l));
enddo
154 real(dp),
dimension(:,:),
intent(inout):: a
155 logical,
intent( out):: ff
156 integer(spi) :: m,i,j,jp,l
158 integer(spi),
dimension(size(a,1)) :: ipiv
160 if(m /=
size(a,2))stop
'In inv; matrix passed to dinvmtf is not square'
164 print
'(" In dinvmtf; failed call to dldumf")'
168 do i=1,m; a(i,i)=1_dp/a(i,i);
enddo
170 do j=i+1,m; a(i,j)=-a(j,j)*dot_product(a(i:j-1,j),a(i,i:j-1));
enddo
174 do i=jp,m; a(i,j)=-a(i,j)-dot_product(a(jp:i-1,j),a(i,jp:i-1));
enddo
178 do i=1,j; a(i,j)=a(i,j)+dot_product(a(jp:m,j),a(i,jp:m));
enddo
179 do i=jp,m; a(i,j)=dot_product(a(i:m,j),a(i,i:m));
enddo
182 do j=m-1,1,-1; l=ipiv(j); call
dswpvv(a(:,j),a(:,l));
enddo
192 complex(dpc),
dimension(:,:),
intent(INOUT):: a
193 logical,
intent( OUT):: ff
194 integer(spi) :: m,i,j,jp,l
196 integer(spi),
dimension(size(a,1)):: ipiv
198 if(m /=
size(a,2))stop
'In inv; matrix passed to cinvmtf is not square'
202 print
'(" In cinvmtf; failed call to cldumf")'
206 do i=1,m; a(i,i)=c1/a(i,i);
enddo
208 do j=i+1,m; a(i,j)=-a(j,j)*sum(a(i:j-1,j)*a(i,i:j-1));
enddo
212 do i=jp,m; a(i,j)=-a(i,j)-sum(a(jp:i-1,j)*a(i,jp:i-1));
enddo
216 do i=1,j; a(i,j)=a(i,j)+sum(a(jp:m,j)*a(i,jp:m));
enddo
217 do i=jp,m; a(i,j)=sum(a(i:m,j)*a(i,i:m));
enddo
220 do j=m-1,1,-1; l=ipiv(j); call
cswpvv(a(:,j),a(:,l));
enddo
230 real(sp),
dimension(:,:),
intent(inout):: a,b
233 if(ff)stop
'In slinmmt; unable to invert linear system'
243 real(dp),
dimension(:,:),
intent(inout):: a,b
246 if(ff)stop
'In dlinmmt; unable to invert linear system'
256 complex(dpc),
dimension(:,:),
intent(inout):: a,b
259 if(ff)stop
'In clinmmt; unable to invert linear system'
270 real(sp),
dimension(:,:),
intent(inout):: a,b
271 logical,
intent( out):: ff
272 integer(spi),
dimension(size(a,1)) :: ipiv
276 if(m /=
size(a,2))stop
'In inv; matrix passed to slinmmtf is not square'
278 stop
'In inv; matrix and vectors in slinmmtf have unmatched sizes'
281 print
'("In slinmmtf; failed call to sldumf")'
295 real(dp),
dimension(:,:),
intent(inout):: a,b
296 logical,
intent( out):: ff
297 integer(spi),
dimension(size(a,1)):: ipiv
301 if(m /=
size(a,2))stop
'In inv; matrix passed to dlinmmtf is not square'
303 stop
'In inv; matrix and vectors in dlinmmtf have unmatched sizes'
306 print
'("In dlinmmtf; failed call to dldumf")'
320 complex(dpc),
dimension(:,:),
intent(INOUT):: a,b
321 logical,
intent( OUT):: ff
322 integer(spi),
dimension(size(a,1)):: ipiv
326 if(m /=
size(a,2))stop
'In inv; matrix passed to dlinmmtf is not square'
328 stop
'In inv; matrix and vectors in dlinmmtf have unmatched sizes'
331 print
'("In clinmmtf; failed call to cldumf")'
344 real(sp),
dimension(:,:),
intent(inout):: a
345 real(sp),
dimension(:),
intent(inout):: b
348 if(ff)stop
'In slinmvt; matrix singular, unable to continue'
358 real(dp),
dimension(:,:),
intent(inout):: a
359 real(dp),
dimension(:),
intent(inout):: b
362 if(ff)stop
'In dlinmvt; matrix singular, unable to continue'
372 complex(dpc),
dimension(:,:),
intent(inout):: a
373 complex(dpc),
dimension(:),
intent(inout):: b
376 if(ff)stop
'In clinmvt; matrix singular, unable to continue'
386 real(sp),
dimension(:,:),
intent(inout):: a
387 real(sp),
dimension(:),
intent(inout):: b
388 logical,
intent( out):: ff
389 integer(spi),
dimension(size(a,1)) :: ipiv
391 if(
size(a,1) /=
size(a,2).or.
size(a,1) /=
size(b))&
392 stop
'In inv; In slinmvtf; incompatible array dimensions'
395 print
'("In slinmvtf; failed call to sldumf")'
408 real(dp),
dimension(:,:),
intent(inout):: a
409 real(dp),
dimension(:),
intent(inout):: b
410 logical,
intent( out):: ff
411 integer(spi),
dimension(size(a,1)) :: ipiv
413 if(
size(a,1) /=
size(a,2).or.
size(a,1) /=
size(b))&
414 stop
'In inv; incompatible array dimensions passed to dlinmvtf'
417 print
'("In dlinmvtf; failed call to dldumf")'
430 complex(dpc),
dimension(:,:),
intent(inout):: a
431 complex(dpc),
dimension(:),
intent(inout):: b
432 logical,
intent( out):: ff
433 integer,
dimension(size(a,1)) :: ipiv
435 if(
size(a,1) /=
size(a,2).or.
size(a,1) /=
size(b))&
436 stop
'In inv; incompatible array dimensions passed to clinmvtf'
439 print
'("In clinmvtf; failed call to cldumf")'
452 integer(spi),
dimension(:,:),
intent(INOUT):: imat
453 logical,
intent( OUT):: ff
454 real(dp),
parameter :: eps=1.e-6_dp
455 real(dp),
dimension(size(imat,1),size(imat,1)):: dmat
456 integer(spi) :: m,i,j
458 if(m /=
size(imat,2))stop
'In inv; matrix passed to iinvf is not square'
459 dmat=imat; call
inv(dmat,ff)
463 imat(i,j)=nint(dmat(i,j));
if(abs(dmat(i,j)-imat(i,j))>eps)ff=t
477 real(sp),
intent(inout) :: a(:,:)
478 real(sp),
intent( out) :: d
479 integer(spi),
intent( out) :: ipiv(:)
482 if(ff)stop
'In sldum; matrix singular, unable to continue'
493 real(dp),
intent(inout) :: a(:,:)
494 real(dp),
intent( out) :: d
495 integer(spi),
intent( out) :: ipiv(:)
498 if(ff)stop
'In dldum; matrix singular, unable to continue'
509 complex(dpc),
intent(inout) :: a(:,:)
510 complex(dpc),
intent(out ) :: d
511 integer(spi),
intent(out ) :: ipiv(:)
514 if(ff)stop
'In cldum; matrix singular, unable to continue'
527 real(sp),
intent(inout) :: a(:,:)
528 real(sp),
intent( out) :: d
529 integer(spi),
intent( out) :: ipiv(:)
530 logical,
intent( out) :: ff
531 integer(spi):: m,i, j, jp, ibig, jm
532 real(sp) :: s(size(a,1)), aam, aa, abig, ajj, ajji, aij
542 print
'("In sldumf; row ",i6," of matrix vanishes")',i
552 abig=s(j)*abs(a(j,j))
565 call
sswpvv(a(j,:),a(ibig,:))
571 print
'(" failure in sldumf:"/" matrix singular, rank=",i3)',jm
579 a(i,jp:m) = a(i,jp:m) - aij*a(j,jp:m)
593 use pietc, only: u0,u1
594 real(dp),
intent(inout) :: a(:,:)
595 real(dp),
intent( out) :: d
596 integer,
intent( out) :: ipiv(:)
597 logical(spi),
intent( out) :: ff
598 integer(spi) :: m,i, j, jp, ibig, jm
599 real(dp) :: s(size(a,1)), aam, aa, abig, ajj, ajji, aij
609 print
'("In dldumf; row ",i6," of matrix vanishes")',i
619 abig=s(j)*abs(a(j,j))
632 call
dswpvv(a(j,:),a(ibig,:))
638 print
'(" Failure in dldumf:"/" matrix singular, rank=",i3)',jm
646 a(i,jp:m) = a(i,jp:m) - aij*a(j,jp:m)
660 use pietc, only: u0,u1,c0,c1
661 complex(dpc),
intent(inout) :: a(:,:)
662 complex(dpc),
intent( out) :: d
663 integer(spi),
intent( out) :: ipiv(:)
664 logical,
intent( out) :: ff
665 integer(spi) :: m,i, j, jp, ibig, jm
666 complex(dpc) :: ajj, ajji, aij
667 real(dp) :: aam,aa,abig
668 real(dp),
dimension(size(a,1)):: s
678 print
'("In cldumf; row ",i6," of matrix vanishes")',i
688 abig=s(j)*abs(a(j,j))
701 call
cswpvv(a(j,:),a(ibig,:))
707 print
'(" Failure in cldumf:"/" matrix singular, rank=",i3)',jm
715 a(i,jp:m) = a(i,jp:m) - aij*a(j,jp:m)
731 integer(spi),
dimension(:),
intent(in) :: ipiv
732 real(sp),
dimension(:,:),
intent(in) :: a
733 real(sp),
dimension(:,:),
intent(inout) :: b
734 integer(spi):: m,i, k, l
742 s = s - sum(b(1:i-1,k)*a(i,1:i-1))
748 b(i,k) = b(i,k) - sum(b(i+1:m,k)*a(i,i+1:m))
765 integer(spi),
dimension(:),
intent(in ) :: ipiv
766 real(dp),
dimension(:,:),
intent(in ) :: a
767 real(dp),
dimension(:,:),
intent(inout) :: b
768 integer(spi):: m,i, k, l
776 s = s - sum(b(1:i-1,k)*a(i,1:i-1))
782 b(i,k) = b(i,k) - sum(b(i+1:m,k)*a(i,i+1:m))
799 integer(spi),
dimension(:),
intent(in ) :: ipiv
800 complex(dpc),
dimension(:,:),
intent(in ) :: a
801 complex(dpc),
dimension(:,:),
intent(inout) :: b
802 integer(spi):: m,i, k, l
803 complex(dpc):: s,aiii
810 s = s - sum(b(1:i-1,k)*a(i,1:i-1))
816 b(i,k) = b(i,k) - sum(b(i+1:m,k)*a(i,i+1:m))
832 integer(spi),
dimension(:),
intent(in ):: ipiv
833 real(sp),
dimension(:,:),
intent(in ):: a
834 real(sp),
dimension(:),
intent(inout):: b
835 integer(spi):: m,i, l
842 s = s - sum(b(1:i-1)*a(i,1:i-1))
848 b(i) = b(i) - sum(b(i+1:m)*a(i,i+1:m))
863 integer(spi),
dimension(:),
intent(in ) :: ipiv(:)
864 real(dp),
dimension(:,:),
intent(in ) :: a(:,:)
865 real(dp),
dimension(:),
intent(inout) :: b(:)
866 integer(spi):: m,i, l
873 s = s - sum(b(1:i-1)*a(i,1:i-1))
879 b(i) = b(i) - sum(b(i+1:m)*a(i,i+1:m))
894 integer(spi),
dimension(:),
intent(in ) :: ipiv(:)
895 complex(dpc),
dimension(:,:),
intent(in ) :: a(:,:)
896 complex(dpc),
dimension(:),
intent(inout) :: b(:)
897 integer(spi):: m,i, l
898 complex(dpc):: s,aiii
904 s = s - sum(b(1:i-1)*a(i,1:i-1))
910 b(i)= b(i) - sum(b(i+1:m)*a(i,i+1:m))
921 real(sp),
intent(in ):: a(:,:)
922 real(sp),
intent(inout):: b(:,:)
925 if(ff)stop
'In sl1lm; matrix singular, unable to continue'
934 real(dp),
intent(in ):: a(:,:)
935 real(dp),
intent(inout):: b(:,:)
938 if(ff)stop
'In dl1lm; matrix singular, unable to continue'
949 real(sp),
intent(in ):: a(:,:)
950 real(sp),
intent(inout):: b(:,:)
951 logical,
intent( out):: ff
952 integer(spi):: m,j, jm, jp, i
959 s = a(j,j) - sum(b(j,1:jm)*b(j,1:jm))
962 print
'("sL1Lmf detects nonpositive a, rank=",i6)',jm
968 s = a(i,j) - sum(b(i,1:jm)*b(j,1:jm))
982 use pietc, only: u0,u1
983 real(dp),
intent(in ) :: a(:,:)
984 real(dp),
intent(inout) :: b(:,:)
985 logical,
intent( out) :: ff
986 integer(spi):: m,j, jm, jp, i
993 s = a(j,j) - sum(b(j,1:jm)*b(j,1:jm))
996 print
'("dL1LMF detects nonpositive A, rank=",i6)',jm
1002 s = a(i,j) - sum(b(i,1:jm)*b(j,1:jm))
1016 real(sp),
intent(in ):: a(:,:)
1017 real(sp),
intent(inout):: b(:,:)
1018 real(sp),
intent( out):: d(:)
1021 if(ff)stop
'In sldlm; matrix singular, unable to continue'
1022 end subroutine sldlm
1031 real(dp),
intent(in ):: a(:,:)
1032 real(dp),
intent(inout):: b(:,:)
1033 real(dp),
intent( out):: d(:)
1036 if(ff)stop
'In dldlm; matrix singular, unable to continue'
1037 end subroutine dldlm
1048 real(sp),
intent(in ):: a(:,:)
1049 real(sp),
intent(inout):: b(:,:)
1050 real(sp),
intent( out):: d(:)
1051 logical,
intent( out):: ff
1052 integer(spi):: m,j, jm, jp, i
1059 d(j)=a(j,j) - sum(b(1:jm,j)*b(j,1:jm))
1063 print
'("In sldlmf; singularity of matrix detected")'
1064 print
'("Rank of matrix: ",i6)',jm
1069 b(j,i)=a(i,j) - dot_product(b(1:jm,j),b(i,1:jm))
1084 use pietc, only: u0,u1
1085 real(dp),
intent(IN ) :: a(:,:)
1086 real(dp),
intent(INOUT) :: b(:,:)
1087 real(dp),
intent( OUT) :: d(:)
1088 logical,
intent( OUT) :: ff
1089 integer(spi):: m,j, jm, jp, i
1093 do j=1,m; jm=j-1; jp=j+1
1094 d(j)=a(j,j) - sum(b(1:jm,j)*b(j,1:jm))
1098 print
'("In dldlmf; singularity of matrix detected")'
1099 print
'("Rank of matrix: ",i6)',jm
1104 b(j,i)=a(i,j) - dot_product(b(1:jm,j),b(i,1:jm))
1117 real(sp),
dimension(:,:),
intent(inout):: a
1118 a=transpose(a); call
sinvl(a); a=transpose(a)
1119 end subroutine sinvu
1127 real(dp),
dimension(:,:),
intent(inout):: a
1128 a=transpose(a); call
dinvl(a); a=transpose(a)
1129 end subroutine dinvu
1137 real(sp),
intent(inout) :: a(:,:)
1138 integer(spi):: m,j, i
1144 a(i,j)=-a(i,i)*sum(a(j:i-1,j)*a(i,j:i-1))
1147 end subroutine sinvl
1154 use pietc, only: u0,u1
1155 real(dp),
intent(inout) :: a(:,:)
1156 integer(spi):: m,j, i
1162 a(i,j)=-a(i,i)*sum(a(j:i-1,j)*a(i,j:i-1))
1165 end subroutine dinvl
1174 real(sp),
intent(in ) :: a(:,:)
1175 real(sp),
intent(inout) :: u(:)
1177 if(
size(a,1) /=
size(a,2) .or.
size(a,1) /=
size(u))&
1178 stop
'In slinlv; incompatible array dimensions'
1179 do i=1,
size(u); u(i)=(u(i) - sum(u(:i-1)*a(i,:i-1)))/a(i,i);
enddo
1189 real(dp),
intent(in ) :: a(:,:)
1190 real(dp),
intent(inout) :: u(:)
1192 if(
size(a,1) /=
size(a,2) .or.
size(a,1) /=
size(u))&
1193 stop
'In dlinlv; incompatible array dimensions'
1194 do i=1,
size(u); u(i)=(u(i) - sum(u(:i-1)*a(i,:i-1)))/a(i,i);
enddo
1204 real(sp),
intent(in ) :: a(:,:)
1205 real(sp),
intent(inout) :: u(:)
1207 if(
size(a,1) /=
size(a,2) .or.
size(a,1) /=
size(u))&
1208 stop
'In linuv; incompatible array dimensions'
1209 do i=
size(u),1,-1; u(i)=(u(i) - sum(a(i+1:,i)*u(i+1:)))/a(i,i);
enddo
1219 real(dp),
intent(in ) :: a(:,:)
1220 real(dp),
intent(inout) :: u(:)
1222 if(
size(a,1) /=
size(a,2) .or.
size(a,1) /=
size(u))&
1223 stop
'In dlinuv; incompatible array dimensions'
1224 do i=
size(u),1,-1; u(i)=(u(i) - sum(a(i+1:,i)*u(i+1:)))/a(i,i);
enddo
subroutine dldum(a, ipiv, d)
Perform L*D*U decomposition, with pivoting, of square matrix.
subroutine cldumf(a, ipiv, d, ff)
Perform l-d-u decomposition of square matrix a in place with pivoting.
subroutine sudlmv(a, b, ipiv)
Use l-u factors in A to back-substitute for 1 rhs in B, using ipiv to define the pivoting permutation...
subroutine dl1lmf(a, b, ff)
Cholesky, M -> L*U, U(i,j)=L(j,i)
subroutine cldum(a, ipiv, d)
Perform L*D*U decomposition, with pivoting, of square matrix.
subroutine dinvu(a)
Invert the upper triangular matrix in place by transposing, calling invl, and transposing again...
subroutine dudlmv(a, b, ipiv)
Use l-u factors in A to back-substitute for 1 rhs in B, using ipiv to define the pivoting permutation...
subroutine dlinuv(a, u)
Solve linear system involving upper triangular system matrix.
subroutine slinmvt(a, b)
Invert linear system with single right-hand side vector.
subroutine dlinmvtf(a, b, ff)
Invert linear system with single right-hand side vector.
subroutine dlinmmt(a, b)
Invert linear system with multiple right-hand side vectors.
subroutine sldumf(a, ipiv, d, ff)
Perform l-d-u decomposition of square matrix a in place with pivoting.
subroutine dinvmtf(a, ff)
Invert a double precision matrix in place, or flag if process fails.
subroutine cinvmt(a)
Invert complex matrix in place.
subroutine sinvu(a)
Invert the upper triangular matrix in place by transposing, calling invl, and transposing again...
subroutine slinlv(a, u)
Solve linear system involving lower triangular system matrix.
subroutine clinmvtf(a, b, ff)
Invert complex linear system with single right-hand side vector.
subroutine cudlmv(a, b, ipiv)
Use l-u factors in A to back-substitute for 1 rhs in B, using ipiv to define the pivoting permutation...
subroutine dl1lm(a, b)
Cholesky, M -> L*U, U(i,j)=L(j,i)
subroutine sinvmtf(a, ff)
Invert a single precision matrix in place, or flag if process fails.
subroutine sldlmf(a, b, d, ff)
Modified Cholesky decompose Q –> L*D*U, U(i,j)=L(j,i)
subroutine sldum(a, ipiv, d)
Perform L*D*U decomposition, with pivoting, of square matrix.
subroutine clinmmtf(a, b, ff)
Invert linear system with multiple right-hand side vectors, or flag failure.
subroutine sinvl(a)
Invert lower triangular matrix in place.
subroutine slinuv(a, u)
Solve linear system involving upper triangular system matrix.
subroutine slinmmt(a, b)
Invert linear system with multiple right-hand side vectors.
subroutine dswpvv(d, e)
Swap a pair of double precision vectors.
subroutine sl1lm(a, b)
Cholesky, M -> L*U, U(i,j)=L(j,i)
subroutine iinvf(imat, ff)
Invert integer square matrix, imat, if possible, but flag ff=.true.
Standard integer, real, and complex single and double precision kinds.
subroutine sl1lmf(a, b, ff)
Cholesky, M -> L*U, U(i,j)=L(j,i)
subroutine sudlmm(a, b, ipiv)
Use l-u factors in A to back-substitute for several rhs in B, using ipiv to define the pivoting permu...
subroutine dinvl(a)
Invert lower triangular matrix in place.
subroutine dinvmt(a)
Invert double precision matrix in place.
subroutine dldumf(a, ipiv, d, ff)
Perform l-d-u decomposition of square matrix a in place with pivoting.
subroutine sldlm(a, b, d)
Modified Cholesky decompose Q –> L*D*U, U(i,j)=L(j,i)
subroutine cinvmtf(a, ff)
Invert a complex matrix in place, or flag if process fails.
Some of the commonly used constants (pi etc) mainly for double-precision subroutines.
subroutine dldlm(a, b, d)
Modified Cholesky decompose Q –> L*D*U, U(i,j)=L(j,i)
subroutine sinvmt(a)
Invert single precision matrix in place.
subroutine dudlmm(a, b, ipiv)
Use l-u factors in A to back-substitute for several rhs in B, using ipiv to define the pivoting permu...
subroutine clinmvt(a, b)
Invert linear system with single right-hand side vector.
subroutine dlinmvt(a, b)
Invert linear system with single right-hand side vector.
subroutine cswpvv(d, e)
Swap a pair of complex vectors.
subroutine dlinmmtf(a, b, ff)
Invert linear system with multiple right-hand side vectors, or flag failure.
subroutine dlinlv(a, u)
Solve linear system involving lower triangular system matrix.
subroutine slinmvtf(a, b, ff)
Invert linear system with single right-hand side vector.
subroutine sswpvv(d, e)
Swap a pair of single precision vectors.
subroutine dldlmf(a, b, d, ff)
Modified Cholesky Q –> L*D*U, U(i,j)=L(j,i)
subroutine slinmmtf(a, b, ff)
Invert linear system with multiple right-hand side vectors, or flag failure.
subroutine cudlmm(a, b, ipiv)
Use l-u factors in A to back-substitute for several rhs in B, using ipiv to define the pivoting permu...
subroutine clinmmt(a, b)
Invert complex linear system with multiple right-hand side vectors.