1
C @(#)cmdsif.for 19.1 (ES0-DMD) 02/25/03 13:27:32
2
C===========================================================================
3
C Copyright (C) 1995 European Southern Observatory (ESO)
5
C This program is free software; you can redistribute it and/or
6
C modify it under the terms of the GNU General Public License as
7
C published by the Free Software Foundation; either version 2 of
8
C the License, or (at your option) any later version.
10
C This program is distributed in the hope that it will be useful,
11
C but WITHOUT ANY WARRANTY; without even the implied warranty of
12
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
C GNU General Public License for more details.
15
C You should have received a copy of the GNU General Public
16
C License along with this program; if not, write to the Free
17
C Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
C Corresponding concerning ESO-MIDAS should be addressed as follows:
21
C Internet e-mail: midas@eso.org
22
C Postal address: European Southern Observatory
23
C Data Management Division
24
C Karl-Schwarzschild-Strasse 2
25
C D 85748 Garching bei Muenchen
27
C===========================================================================
29
C-----------------------------------------------------------------------
37
C F. Murtagh, ST-ECF, Garching. Version 1.0 17 June 1986
38
C F. Murtagh Version 2.0 Oct. 1988
43
C Pass parameters to, and execute, CMDS
44
C (Classical - Torgerson's, Gower's - Multidimensional Scaling,
45
C Factor Analysis of a Distances Matrix, Principal Coordinates Analysis).
49
C P1 - P3 contain parameters; these are: input table name, output
50
C table name, number of principal coordinates wanted (optional, - default
55
C . uses Midas Table interface routines;
56
C . input table is assumed to contain entries in single precision;
57
C . no select or null values
58
C . all input table is sent to the CMDS routine;
59
C . description of the CMDS routine is in the corresponding program;
60
C . the output produced consists of a table, and descriptors associated
61
C with this (eigenvalues): view with
62
C READ/DESC outtable.TBL *
63
C . storage is limited only by the Midas Table system, and by the
64
C overall system limitations;
67
C NEW STANDARD INTERFACES, F. MURTAGH, AUG. 88
68
C New Table File System, M. Peron , SEP91
70
C-----------------------------------------------------------------------
73
CHARACTER*60 NAMEIN, NAMEOUT
75
CHARACTER*16 UNIT, LABEL, LABEL2
76
INTEGER MADRID, KUN, KNUL, DTYPE
77
INTEGER NACTV,ISTAT,TID1,NROW,NCOL,NSORTC
78
INTEGER NAC,NAR,IPTR,I,LEN,NSEL,NTOT,INULL
79
INTEGER IACTV,NCOLOUT,TID,IPTROUT
80
INTEGER IADD0,IADD1,IADD2,IADD3,KUNIT
81
INCLUDE 'MID_INCLUDE:TABLES.INC/NOLIST'
83
INCLUDE 'MID_INCLUDE:TABLED.INC/NOLIST'
84
DATA FORM/'G14.6'/, UNIT/' '/
86
C ... Assuming this is our first action ...
91
C ... Get table name as a keyword passed in the command line.
93
CALL STKRDC('P1',1,1,60,NACTV,NAMEIN,KUN,KNUL,ISTAT)
95
C ... Read input table.
97
CALL TBTOPN(NAMEIN,0,TID1,ISTAT)
98
CALL TBIGET(TID1,NCOL,NROW,NSORTC,NAC,NAR,ISTAT)
99
CALL TBCMAP(TID1,0,IPTR,ISTAT)
101
C ... Some error checking on input.
103
IF (NROW.LT.1.OR.NCOL.LT.1) THEN
104
CALL STTPUT(' Nos. of rows/columns are less than 1.',ISTAT)
105
CALL STTPUT(' What sort of a table is this ??',ISTAT)
110
CALL TBFGET(TID1,I,FORM,LEN,DTYPE,ISTAT)
111
IF (DTYPE.NE.D_R4_FORMAT) THEN
112
CALL STTPUT(' Illegal format:',ISTAT)
113
CALL STTPUT(' Only R*4 column type allowed.',ISTAT)
118
CALL CHSEL(MADRID(IPTR),NROW,NSEL)
119
IF (NSEL.NE.NROW) THEN
120
CALL STTPUT(' Not all rows are SELECTed. ',ISTAT)
121
CALL STTPUT(' In current implementation, MUST select all.',
126
CALL TBCMAP(TID1,1,IPTR,ISTAT)
128
CALL CHNULL(MADRID(IPTR),NTOT,INULL)
131
X (' Null entries in the table are not allowed.',ISTAT)
133
X (' Use SELECT, and then construct another table.',
138
C ... OUTPUT TABLE - PREPARE
140
C ... First get the output table name and no. cols. via keywords.
142
CALL STKRDC('P2',1,1,60,IACTV,NAMEOUT,KUN,KNUL,ISTAT)
143
CALL STKRDI('INPUTI',1,1,IACTV,NCOLOUT,KUN,KNUL,ISTAT)
145
C ... Now create the table.
147
CALL TBTINI(NAMEOUT,F_TRANS,17,NCOLOUT,NROW,TID,ISTAT)
151
WRITE (LABEL2(1:5),100) I+10000
152
LABEL(4:5) = LABEL2(4:5)
153
CALL TBCINI(TID,DTYPE,1,FORM,UNIT,LABEL,NSORTC,ISTAT)
157
CALL TBCMAP(TID,1,IPTROUT,ISTAT)
159
C ... ALLOCATE STORAGE
161
CALL GETSTOR(NROW*NROW,IADD0)
162
CALL GETSTOR(NROW*NROW,IADD1)
163
CALL GETSTOR(NROW,IADD2)
164
CALL GETSTOR(NROW,IADD3)
168
CALL APPL(NROW,NCOL,NCOLOUT,MADRID(IPTR),MADRID(IPTROUT),
169
X MADRID(IADD0),MADRID(IADD1),MADRID(IADD2),MADRID(IADD3))
171
C ... WRITE DESCRIPTORS
173
CALL DSCROUT(NAMEOUT,NROW,MADRID(IADD2),TID,KUNIT)
178
CALL RELSTOR(NROW*NROW,IADD0)
179
CALL RELSTOR(NROW*NROW,IADD1)
180
CALL RELSTOR(NROW,IADD2)
181
CALL RELSTOR(NROW,IADD3)
183
CALL TBTCLO(TID1,ISTAT)
185
CALL TBIPUT(TID,NCOLOUT,NROW,ISTAT)
186
CALL TBSINI(TID,ISTAT)
187
CALL TBTCLO(TID,ISTAT)
192
C----------------------------------------------------------------------
193
SUBROUTINE APPL(NR,NC1,NC2,AIN,AOUT,ACREA,A,W1,W2)
194
INTEGER NR,NC1,NC2,IERR,IPRINT,I,J,ISTAT
195
REAL*4 AIN(NR,NC1), AOUT(NR,NC2), ACREA(NR,NR),A(NR,NR),
201
ACREA(I,J) = AIN(I,J)
207
X (' A symmetric distances matrix is expected.',ISTAT)
208
CALL STTPUT(' The input matrix is not symmetric !',ISTAT)
212
CALL CMDS(NR,ACREA,IPRINT,W1,W2,A,IERR)
215
CALL STTPUT(' IERR not 0 on return from CMDS.',ISTAT)
221
AOUT(I,J) = ACREA(I,J)
227
C-------------------------------------------------------------------------
228
SUBROUTINE CHSEL(MASK,NROW,NSEL)
229
C ... Count table rows which are SELECTed.
231
REAL*4 MASK(NROW),TBLSEL
232
DOUBLE PRECISION TDTRUE,TDFALS
233
CALL TBMCON(TBLSEL,TDTRUE,TDFALS)
236
IF (MASK(I).EQ.TBLSEL) NSEL = NSEL + 1
240
C-------------------------------------------------------------------------
241
SUBROUTINE CHNULL(X,NT,NULL)
242
C ... Check if null values are present.
246
DOUBLE PRECISION TDNULL
247
CALL TBMNUL(TINULL,TRNULL,TDNULL)
250
IF (X(I).EQ.TRNULL) NULL = NULL + 1
251
IF (NULL.GT.0) RETURN
255
C---------------------------------------------------------------------
256
SUBROUTINE GETSTOR(NVALS,IPTR)
257
C ... Allocate storage space for NVALS real values.
258
INTEGER NVALS,IPTR,ISTAT
259
CALL TDMGET(4*NVALS,IPTR,ISTAT)
262
C---------------------------------------------------------------------
263
SUBROUTINE RELSTOR(NVALS,IPTR)
264
C ... Release storage space of NVALS real values.
265
INTEGER NVALS,IPTR,ISTAT
266
CALL TDMFRE(4*NVALS,IPTR,ISTAT)
269
C---------------------------------------------------------------------
270
SUBROUTINE DSCROUT(TAB,N,VALS,TID,KUNIT)
271
C ... Output descriptors, with table.
272
INTEGER I,N,TID,KUNIT,INDX,ISTAT
282
INDX = INDEX(TAB//' ',' ')-1
283
TABNAME = TAB(1:INDX)//'.TBL'
284
CALL STDWRR(TID,'EIGENVALUES',VALS,1,N-1,KUNIT,ISTAT)