1! This software is Copyright (c) 2012-2015 The Regents of the 2! University of California. All Rights Reserved. 3! 4! Permission to copy and modify this software and its documentation 5! for educational, research and non-profit purposes, without fee, 6! and without a written agreement is hereby granted, provided that 7! the above copyright notice, this paragraph and the following three 8! paragraphs appear in all copies. 9! 10! Permission to make commercial use of this software may be obtained 11! by contacting: 12! 13! Technology Transfer Office 14! 9500 Gilman Drive, Mail Code 0910 15! University of California 16! La Jolla, CA 92093-0910 17! (858) 534-5815 18! invent@ucsd.edu 19! 20! This software program and documentation are copyrighted by The 21! Regents of the University of California. The software program and 22! documentation are supplied "as is", without any accompanying 23! services from The Regents. The Regents does not warrant that the 24! operation of the program will be uninterrupted or error-free. The 25! end-user understands that the program was developed for research 26! purposes and is advised not to rely exclusively on the program for 27! any reason. 28! 29! IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY 30! PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 31! DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS 32! SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF 33! CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34! THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY 35! WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 36! OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 37! SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE 38! UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE 39! MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 40 41 SUBROUTINE GE (N, A, B) 42 43 IMPLICIT NONE 44 45 INTEGER, INTENT(IN) :: N 46 REAL*8, INTENT(IN) :: A(N,N) 47 REAL*8, INTENT(INOUT) :: B(N) 48 49 INTEGER m, ipv, i, j 50 REAL*8 pivot, saveEl 51 REAL*8, ALLOCATABLE :: C(:,:) 52 53 IF (N .EQ. 2) THEN 54 pivot = A(1,1)*A(2,2) - A(2,1)*A(1,2) 55 saveEl = (B(1)*A(2,2) - B(2)*A(1,2))/pivot 56 B(2) = (B(2)*A(1,1) - B(1)*A(2,1))/pivot 57 B(1) = saveEl 58 RETURN 59 END IF 60 ALLOCATE(C(N,N+1)) 61 62 C(:N,:N) = A 63 C(:,N+1) = B 64 65 DO m=1,N-1 66 ipv = m 67 pivot = ABS(C(m,m)) 68 DO i=m+1,N 69 IF (ABS(C(i,m)) .GT. pivot) THEN 70 ipv = i 71 pivot = ABS(C(i,m)) 72 END IF 73 END DO 74 IF (pivot .LT. 2D0*EPSILON(pivot)) THEN 75 PRINT *, 'Singular matrix' 76 STOP 77 END IF 78 IF (ipv .NE. m) THEN 79 DO j=m, N+1 80 saveEl = C(m,j) 81 C(m,j) = C(ipv,j) 82 C(ipv,j) = saveEl 83 END DO 84 DO j=1, m-1 85 END DO 86 END IF 87 88 DO i=m+1,N 89 saveEl = C(i,m)/C(m,m) 90 C(i,m) = 0D0 91 DO j=m+1,N+1 92 C(i,j) = C(i,j) - saveEl*C(m,j) 93 END DO 94 END DO 95 END DO 96 97 DO j=N,1,-1 98 DO i=j+1,N 99 C(j,N+1) = C(j,N+1) - C(j,i)*C(i,N+1) 100 END DO 101 C(j,N+1) = C(j,N+1)/C(j,j) 102 END DO 103 104 B = C(:,N+1) 105 106 DEALLOCATE(C) 107 108 RETURN 109 END SUBROUTINE GE 110