Last change
on this file since 2613 was
1796,
checked in by bclmd, 7 years ago
|
Adding photochemistry to LMDZ Generic
|
-
Property svn:executable set to
*
|
File size:
2.5 KB
|
Rev | Line | |
---|
[1796] | 1 | SUBROUTINE inv(A,N) |
---|
| 2 | |
---|
| 3 | implicit none |
---|
| 4 | |
---|
| 5 | c======================================================================= |
---|
| 6 | c Scheme A |
---|
| 7 | c |
---|
| 8 | c subject: |
---|
| 9 | c -------- |
---|
| 10 | c |
---|
| 11 | c Inversion of a matrix: |
---|
| 12 | c Combinaison des routines ludcmp.f et lubksb.f du Numerical Recipes |
---|
| 13 | c======================================================================= |
---|
| 14 | |
---|
| 15 | real TINY |
---|
| 16 | PARAMETER (TINY=1.0E-20) |
---|
| 17 | real AAMAX,DUM,SUM |
---|
| 18 | integer IMAX,I,II,J,K,L,LL,N |
---|
| 19 | real A(N,N),INDX(N),VV(N,N) |
---|
| 20 | |
---|
| 21 | IMAX = 0 |
---|
| 22 | do I=1,N |
---|
| 23 | AAMAX=0. |
---|
| 24 | do J=1,N |
---|
| 25 | IF (ABS(A(I,J)).GT.AAMAX) AAMAX=ABS(A(I,J)) |
---|
| 26 | enddo |
---|
| 27 | if (AAMAX.EQ.0.) then |
---|
| 28 | write(*,*) 'Singular matrix.' |
---|
| 29 | stop |
---|
| 30 | endif |
---|
| 31 | VV(I,1)=1./AAMAX |
---|
| 32 | enddo |
---|
| 33 | do J=1,N |
---|
| 34 | IF (J.GT.1) THEN |
---|
| 35 | do I=1,J-1 |
---|
| 36 | SUM=A(I,J) |
---|
| 37 | IF (I.GT.1)THEN |
---|
| 38 | do K=1,I-1 |
---|
| 39 | SUM=SUM-A(I,K)*A(K,J) |
---|
| 40 | enddo |
---|
| 41 | A(I,J)=SUM |
---|
| 42 | ENDIF |
---|
| 43 | enddo |
---|
| 44 | ENDIF |
---|
| 45 | AAMAX=0. |
---|
| 46 | do I=J,N |
---|
| 47 | SUM=A(I,J) |
---|
| 48 | IF (J.GT.1)THEN |
---|
| 49 | do K=1,J-1 |
---|
| 50 | SUM=SUM-A(I,K)*A(K,J) |
---|
| 51 | enddo |
---|
| 52 | A(I,J)=SUM |
---|
| 53 | ENDIF |
---|
| 54 | DUM=VV(I,1)*ABS(SUM) |
---|
| 55 | IF (DUM.GE.AAMAX) THEN |
---|
| 56 | IMAX=I |
---|
| 57 | AAMAX=DUM |
---|
| 58 | ENDIF |
---|
| 59 | enddo |
---|
| 60 | IF (J.NE.IMAX)THEN |
---|
| 61 | do K=1,N |
---|
| 62 | DUM=A(IMAX,K) |
---|
| 63 | A(IMAX,K)=A(J,K) |
---|
| 64 | A(J,K)=DUM |
---|
| 65 | enddo |
---|
| 66 | VV(IMAX,1)=VV(J,1) |
---|
| 67 | ENDIF |
---|
| 68 | INDX(J)=IMAX |
---|
| 69 | if(abs(A(J,J)).LT.TINY) then |
---|
| 70 | write(*,*) 'Pivot too small.' |
---|
| 71 | stop |
---|
| 72 | endif |
---|
| 73 | IF(J.NE.N)THEN |
---|
| 74 | DUM=1./A(J,J) |
---|
| 75 | do I=J+1,N |
---|
| 76 | A(I,J)=A(I,J)*DUM |
---|
| 77 | enddo |
---|
| 78 | ENDIF |
---|
| 79 | enddo |
---|
| 80 | |
---|
| 81 | do I=1,N |
---|
| 82 | do J=1,N |
---|
| 83 | VV(I,J) = 0. |
---|
| 84 | enddo |
---|
| 85 | VV(I,I) = 1. |
---|
| 86 | enddo |
---|
| 87 | |
---|
| 88 | do L=1,N |
---|
| 89 | II=0 |
---|
| 90 | do I=1,N |
---|
| 91 | LL=INDX(I) |
---|
| 92 | SUM=VV(LL,L) |
---|
| 93 | VV(LL,L)=VV(I,L) |
---|
| 94 | IF (II.NE.0)THEN |
---|
| 95 | do J=II,I-1 |
---|
| 96 | SUM=SUM-A(I,J)*VV(J,L) |
---|
| 97 | enddo |
---|
| 98 | ELSE IF (SUM.NE.0.) THEN |
---|
| 99 | II=I |
---|
| 100 | ENDIF |
---|
| 101 | VV(I,L)=SUM |
---|
| 102 | enddo |
---|
| 103 | do I=N,1,-1 |
---|
| 104 | SUM=VV(I,L) |
---|
| 105 | IF(I.LT.N)THEN |
---|
| 106 | do J=I+1,N |
---|
| 107 | SUM=SUM-A(I,J)*VV(J,L) |
---|
| 108 | enddo |
---|
| 109 | ENDIF |
---|
| 110 | VV(I,L)=SUM/A(I,I) |
---|
| 111 | enddo |
---|
| 112 | enddo |
---|
| 113 | |
---|
| 114 | do I=1,N |
---|
| 115 | do L=1,N |
---|
| 116 | A(I,L)=VV(I,L) |
---|
| 117 | enddo |
---|
| 118 | enddo |
---|
| 119 | |
---|
| 120 | return |
---|
| 121 | END |
---|
Note: See
TracBrowser
for help on using the repository browser.