1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
36
#include <midas_def.h>
39
#define SWAP(a,b) {float temp=(a);(a)=(b);(b)=temp;}
41
void MO_GAUSSJ(a,n,b,m)
46
int *indxc,*indxr,*ipiv;
47
int i,icol,irow,j,k,l,ll;
52
/* later on, always indexing from 1 to n is used... (KB) */
54
indxc = (int *) osmmget((n+1) * sizeof(int));
55
indxr = (int *) osmmget((n+1) * sizeof(int));
56
ipiv = (int *) osmmget((n+1) * sizeof(int));
58
for (j = 1; j<= n;j++) ipiv[j]=0;
59
for (i = 1; i <= n; i++) {
61
for (j = 1; j <= n; j++)
63
for (k = 1; k <= n; k++) {
65
if (fabs(a[j][k]) >= big) {
72
SCETER(2, "*** FATAL: GAUSSJ: Singular Matrix-1");
76
for (l = 1; l <= n; l++) SWAP(a[irow][l],a[icol][l])
77
for (l = 1; l <= m; l++) SWAP(b[irow][l],b[icol][l])
82
if (a[icol][icol] == 0.0)
83
SCETER(2, "*** FATAL: GAUSSJ - Singular Matrix-2");
84
pivinv = 1.0/a[icol][icol];
86
for (l = 1; l <= n; l++) a[icol][l] *= pivinv;
87
for (l = 1; l <= m; l++) b[icol][l] *= pivinv;
88
for (ll = 1; ll <= n; ll++)
92
for (l = 1; l <= n; l++) a[ll][l] -= a[icol][l]*dum;
93
for (l = 1; l <= m; l++) b[ll][l] -= b[icol][l]*dum;
97
for (l = n; l >= 1; l--) {
98
if (indxr[l] != indxc[l])
99
for (k = 1; k <= n; k++)
100
SWAP(a[k][indxr[l]],a[k][indxc[l]]);
103
osmmfree((char *) ipiv);
104
osmmfree((char *) indxr);
105
osmmfree((char *) indxc);