1
C===========================================================================
2
C Copyright (C) 1995-2005 European Southern Observatory (ESO)
4
C This program is free software; you can redistribute it and/or
5
C modify it under the terms of the GNU General Public License as
6
C published by the Free Software Foundation; either version 2 of
7
C the License, or (at your option) any later version.
9
C This program is distributed in the hope that it will be useful,
10
C but WITHOUT ANY WARRANTY; without even the implied warranty of
11
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
C GNU General Public License for more details.
14
C You should have received a copy of the GNU General Public
15
C License along with this program; if not, write to the Free
16
C Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
C Correspondence concerning ESO-MIDAS should be addressed as follows:
20
C Internet e-mail: midas@eso.org
21
C Postal address: European Southern Observatory
22
C Data Management Division
23
C Karl-Schwarzschild-Strasse 2
24
C D 85748 Garching bei Muenchen
26
C===========================================================================
28
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
C.COPYRIGHT: Copyright (c) 1987 European Southern Observatory,
32
C.VERSION: 1.0 ESO-FORTRAN Conversion, AA 16:02 - 19 NOV 1987
34
C.LANGUAGE: F77+ESOext
45
C REGRESSION/POL table dep_var ind_var1[,ind_var2] deg1[,deg2] [outkey]
47
C REGRESSION/POL table dep_var ind_var1[,ind_var2,...] ? [outkey]
51
C Tables, Multiple linear regression, POLYNOMIAL FIT
55
C uses table interface routines
56
C fitting algorithm using Householder transformation
61
C-----------------------------------------------------------
66
LOGICAL NULL(9), SEL, IPOL, NEXT
69
INTEGER IVAR(9),IDEG(2),IPAR(13)
70
INTEGER NROW,NCOL, NAC, NAR, I, ISTAT, STATUS
71
INTEGER IAV, TID, NSC1, NN, NVAR, I1, I2, K, L, N, LL, N1
72
INTEGER IROW, KMIN, NPAR, NM1, K1
73
INTEGER INDEX, KUN, KNUL, TYPE, MAXPAR, INDKEY
74
INTEGER NOELM,BYTELM,DEGMAX
75
PARAMETER (MAXPAR=100)
77
REAL ERROR,RPAR1(4),RPAR(13)
79
DOUBLE PRECISION XMIN,XMAX,YMIN,YMAX
80
DOUBLE PRECISION VAL(9)
81
DOUBLE PRECISION G(MAXPAR,MAXPAR),X(MAXPAR)
84
CHARACTER*80 TABLE,LINE,SELE
86
CHARACTER*17 COLUMN(9)
87
CHARACTER*8 FORM,TYPKEY
88
CHARACTER*20 CPAR, KEYNAM, INPNAM
90
INCLUDE 'MID_INCLUDE:TABLES.INC'
91
INCLUDE 'MID_INCLUDE:TABLED.INC'
93
DATA MSG/'ERR:TREGRMUL'/
99
C ... GET INPUT PARAMETERS
107
CALL TDPGET(PARVAL,NPAR,ISTAT)
109
IF (ISTAT.NE.0) GO TO 70
117
INDKEY = INDEX(KEYNAM,' ') - 1
122
INPNAM = KEYNAM(1:INDKEY)//'D'
123
CALL STKFND(INPNAM,TYPKEY,NOELM,BYTELM,ISTAT)
124
CALL STKWRD(INPNAM,X,1,NOELM,KUN,ISTAT)
126
CALL STKRDR('INPUTR',1,2,IAV,RPAR1,KUN,KNUL,ISTAT)
131
IF (IDEG(2).GT.0) DEGMAX = IDEG(1)
133
IF (DEGMAX.GT.8) THEN
134
CALL STETER(9,'REGRES/POLY: degree along X is limited to 8')
137
IF (IDEG(2).GT.8) THEN
138
CALL STETER(9,'REGRES/POLY: degree along Y is limited to 8')
141
C ... READ INPUT TABLE
144
CALL TBTOPN(TABLE,F_I_MODE,TID,ISTAT)
145
CALL TBIGET(TID,NCOL,NROW,NSC1,NAC,NAR,ISTAT)
146
CALL TDRSEL(TID,SELE,ISTAT)
148
C ... DECODE PARAMETERS
150
COLUMN(1) = TPARBF(2)
153
NN = INDEX(LINE,' ') - 1
165
COLUMN(NVAR) = LINE(I1:I2-1)
167
IF (I1.LT.NN) GO TO 20
170
IF (K.EQ.0 .AND. L.EQ.0) THEN
183
C ... SEARCH FOR COLUMNS AND CHECK FORMAT
186
CALL TBCSER(TID,COLUMN(I),IVAR(I),ISTAT)
187
IF (ISTAT.NE.0) GO TO 70
188
IF (IVAR(I).EQ.-1) THEN
192
CALL TBFGET(TID,IVAR(I),FORM,LL,TYPE,ISTAT)
193
IF (TYPE.EQ.D_C_FORMAT) THEN
198
CALL STTPUT(TABLE,ISTAT)
200
C ... SOLVE LEAST SQUARE PROBLEM
209
CALL TBSGET(TID,IROW,SEL,ISTAT)
211
CALL TBRRDD(TID,IROW,NVAR,IVAR,VAL,NULL,ISTAT)
212
NEXT = ( .NOT. NULL(1)) .AND. ( .NOT. NULL(2)) .AND.
213
+ ( .NOT. NULL(3)) .AND. ( .NOT. NULL(4)) .AND.
214
+ ( .NOT. NULL(5)) .AND. ( .NOT. NULL(6)) .AND.
215
+ ( .NOT. NULL(7)) .AND. ( .NOT. NULL(8)) .AND.
220
XMIN = MIN(XMIN,VAL(2))
221
XMAX = MAX(XMAX,VAL(2))
222
YMIN = MIN(YMIN,VAL(3))
223
YMAX = MAX(YMAX,VAL(3))
224
CALL TDSET2(LL+1,VAL(2),VAL(3),VAL(1),K,L,G,X,N,
227
CALL TDSET1(LL+1,VAL(2),VAL(1),NM1,G,X,N,MAXPAR)
232
CALL TDHHTR(K1,LL+1,G,X,N,MAXPAR)
239
CALL TDSOLV(G,X,N,MAXPAR)
240
ERROR = ABS(G(N+1,N+1))
242
C ... COPY RESULT OF REGRESSION
257
IPAR(I+3) = IVAR(I+1)
264
RPAR(5) = SQRT((ERROR*ERROR)/IPAR(1))
266
INPNAM = KEYNAM(1:INDKEY)//'C'
267
CALL STKWRC(INPNAM,1,CPAR,1,20,KUN,ISTAT)
268
INPNAM = KEYNAM(1:INDKEY)//'I'
269
CALL STKWRI(INPNAM,IPAR,1,13,KUN,ISTAT)
270
INPNAM = KEYNAM(1:INDKEY)//'R'
271
CALL STKWRR(INPNAM,RPAR,1,5,KUN,ISTAT)
272
INPNAM = KEYNAM(1:INDKEY)//'D'
273
CALL STKWRD(INPNAM,X,1,N,KUN,ISTAT)
277
IF (SELE(1:1).NE.'-') THEN
278
LINE = ' SELECT '//SELE
279
CALL STTPUT(LINE,ISTAT)
282
CALL TDRDIS(CPAR,IPAR,RPAR,X,ISTAT)
283
IF (ISTAT.NE.0) GO TO 70
287
CALL DSCUPT(TID,TID,' ',ISTAT)
288
CALL TBTCLO(TID,ISTAT)
289
70 IF (ISTAT.NE.0) THEN
290
WRITE (MSG(13:16),9000) ISTAT
291
CALL TDERRR(ISTAT,MSG,STATUS)