SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
modi_glt_invert.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 !GLT_LIC The GELATO model is a seaice model used in stand-alone or embedded mode.
6 !GLT_LIC It has been developed by Meteo-France. The holder of GELATO is Meteo-France.
7 !GLT_LIC
8 !GLT_LIC This software is governed by the CeCILL-C license under French law and biding
9 !GLT_LIC by the rules of distribution of free software. See the CeCILL-C_V1-en.txt
10 !GLT_LIC (English) and CeCILL-C_V1-fr.txt (French) for details. The CeCILL is a free
11 !GLT_LIC software license, explicitly compatible with the GNU GPL
12 !GLT_LIC (see http://www.gnu.org/licenses/license-list.en.html#CeCILL)
13 !GLT_LIC
14 !GLT_LIC The CeCILL-C licence agreement grants users the right to modify and re-use the
15 !GLT_LIC software governed by this free software license. The exercising of this right
16 !GLT_LIC is conditional upon the obligation to make available to the community the
17 !GLT_LIC modifications made to the source code of the software so as to contribute to
18 !GLT_LIC its evolution.
19 !GLT_LIC
20 !GLT_LIC In consideration of access to the source code and the rights to copy, modify
21 !GLT_LIC and redistribute granted by the license, users are provided only with a limited
22 !GLT_LIC warranty and the software's author, the holder of the economic rights, and the
23 !GLT_LIC successive licensors only have limited liability. In this respect, the risks
24 !GLT_LIC associated with loading, using, modifying and/or developing or reproducing the
25 !GLT_LIC software by the user are brought to the user's attention, given its Free
26 !GLT_LIC Software status, which may make it complicated to use, with the result that its
27 !GLT_LIC use is reserved for developers and experienced professionals having in-depth
28 !GLT_LIC computer knowledge. Users are therefore encouraged to load and test the
29 !GLT_LIC suitability of the software as regards their requirements in conditions enabling
30 !GLT_LIC the security of their systems and/or data to be ensured and, more generally, to
31 !GLT_LIC use and operate it in the same conditions of security.
32 !GLT_LIC
33 !GLT_LIC The GELATO sofware is cureently distibuted with the SURFEX software, available at
34 !GLT_LIC http://www.cnrm.meteo.fr/surfex. The fact that you download the software deemed that
35 !GLT_LIC you had knowledge of the CeCILL-C license and that you accept its terms.
36 !GLT_LIC Attempts to use this software in a way not complying with CeCILL-C license
37 !GLT_LIC may lead to prosecution.
38 !GLT_LIC
39 ! =======================================================================
40 ! ========================= MODULE modi_glt_invert ==========================
41 ! =======================================================================
42 !
43 ! Goal:
44 ! -----
45 ! Solves a system of the form :
46 ! M * X = Y
47 ! where M is a (n,n) matrix), X and Y are two n component vectors
48 ! (Y is given and X is the solution).
49 !
50 ! Method:
51 ! -------
52 ! Use a Gauss-Jordan method (note that the number of inferior diagonals
53 ! should be specified). For example, if in any column of index j, all
54 ! M(i,j) elements are zero for i>j+k (k fixed), and there is an index
55 ! j for which M(j+k,j) is non zero, the number of inferior diagonals is
56 ! k.
57 !
58 ! Created: D. Salas y Melia, 05/02
59 !
60 !
61 ! -------------------- BEGIN MODULE modi_glt_invert -------------------------
62 !
63 !THXS_SFX!MODULE modi_glt_invert
64 !THXS_SFX!INTERFACE
65 !THXS_SFX!!
66 !THXS_SFX!SUBROUTINE glt_invert(kdiag,pmat)
67 !THXS_SFX! INTEGER :: &
68 !THXS_SFX! kdiag
69 !THXS_SFX! REAL, DIMENSION(:,:), INTENT(inout) :: &
70 !THXS_SFX! pmat
71 !THXS_SFX!END SUBROUTINE glt_invert
72 !THXS_SFX!!
73 !THXS_SFX!END INTERFACE
74 !THXS_SFX!END MODULE modi_glt_invert
75 !
76 ! ---------------------- END MODULE modi_glt_invert -------------------------
77 !
78 !
79 !
80 ! -----------------------------------------------------------------------
81 ! ----------------------- SUBROUTINE glt_invert -----------------------------
82 !
83 SUBROUTINE glt_invert(kdiag,pmat)
84  USE modd_glt_param
85  USE modi_gltools_glterr
86 !
87  IMPLICIT NONE
88  INTEGER :: &
89  kdiag
90  REAL, DIMENSION(:,:), INTENT(inout) :: &
91  pmat
92 !
93  INTEGER :: &
94  ji,jpiv,jdiag
95  INTEGER :: &
96  iim,imax
97  REAL :: &
98  zfac
99  REAL, DIMENSION(:,:), ALLOCATABLE :: &
100  zmat
101 !
102 !
103 !
104 ! 1. Initializations
105 ! ==================
106 !
107 ! .. Compute matrix dimension
108 !
109  iim = SIZE(pmat,1)
110 !
111 ! .. Allocate and initialize work matrix
112 !
113  ALLOCATE( zmat(iim,2*iim) )
114  zmat(:,:) = 0.
115  zmat(:,1:iim) = pmat(:,:)
116  DO ji=1,iim
117  zmat(ji,ji+iim) = 1.
118  END DO
119 !
120 !
121 ! 2. Invert the initial matrix
122 ! ============================
123 !
124 ! 2.1. Checks
125 ! -----------
126 !
127  IF ( kdiag<1 .OR. kdiag>iim ) THEN
128  IF(lwg) WRITE(noutlu,*) ' kdiag =',kdiag,' is lower than 1 or', &
129  ' greater than matrix dimension'
130  CALL gltools_glterr( 'invert','','STOP')
131  ENDIF
132 !
133 !
134 ! 2.2. Transformation of the matrix into an upper triangular matrix
135 ! -----------------------------------------------------------------
136 !
137 ! .. We try to get a triangular matrix
138 !
139  DO jpiv=1,iim-1
140  IF ( abs(zmat(jpiv,jpiv))>1.e-10 ) THEN
141  imax = min( jpiv+kdiag,iim )
142  DO jdiag=jpiv+1,imax
143  zfac = zmat(jdiag,jpiv) / zmat(jpiv,jpiv)
144  zmat(jdiag,:) = zmat(jdiag,:) - zfac*zmat(jpiv,:)
145  END DO
146  ELSE
147  IF (lwg) THEN
148  WRITE(noutlu,*) ' This kind of matrix cannot be ', &
149  'inverted by this programme !'
150  WRITE(noutlu,*) ' Current status of the matrix:'
151  DO ji=1,iim
152  WRITE(noutlu,*) ' ',zmat(ji,:)
153  END DO
154  ENDIF
155  CALL gltools_glterr( 'invert','','STOP' )
156  ENDIF
157  END DO
158 !
159 !
160 ! 2.3. Transformation of the upper triangular matrix into identity
161 ! ----------------------------------------------------------------
162 !
163  zmat(iim,:) = zmat(iim,:) / zmat(iim,iim)
164  DO jpiv=iim,2,-1
165  DO ji=1,jpiv-1
166  zmat(ji,:) = zmat(ji,:)-zmat(ji,jpiv)*zmat(jpiv,:)
167  END DO
168  zmat(jpiv-1,:) = zmat(jpiv-1,:) / zmat(jpiv-1,jpiv-1)
169  END DO
170 !
171 !
172 ! 2.4. Output
173 ! -----------
174 !
175  pmat(:,:) = zmat(:,iim+1:2*iim)
176 
177  DEALLOCATE( zmat)
178 END SUBROUTINE glt_invert
179 
180 ! --------------------- END SUBROUTINE glt_invert ---------------------------
181 ! -----------------------------------------------------------------------
subroutine gltools_glterr(hroutine, hmess, hflag)
subroutine glt_invert(kdiag, pmat)