Debian Codegraph @

applic/statist/src/tkstest.for

raw
1 C @(#)tkstest.for 19.1 (ESO-DMD) 02/25/03 13:21:26
2 C===========================================================================
3 C Copyright (C) 1995 European Southern Observatory (ESO)
4 C
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.
9 C
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.
14 C
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 Massachusetts Ave, Cambridge,
18 C MA 02139, USA.
19 C
20 C Correspondence concerning ESO-MIDAS should be addressed as follows:
21 C Internet e-mail: [email protected]
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
26 C GERMANY
27 C===========================================================================
28 C
29 C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 C.COPYRIGHT: Copyright (c) 1987 European Southern Observatory,
31 C all rights reserved
32 C
33 C.VERSION: 1.0 ESO-FORTRAN Conversion, AA 1 JUL 1989
34 C
35 C.LANGUAGE: F77+ESOext
36 C
37 C.AUTHOR: M.PERON
38 C
39 C.IDENTIFICATION
40 C
41 C Program TKSTEST
42 C
43 C.KEYWORDS
44 C
45 C KOLMOGOROV TEST
46 C
47 C.PURPOSE
48 C
49 C Comparaison of one data set to a known distribution using Kolmogorov TEST
50 C
51 C The distribution available are :
52 C --Uniform Distribution (UNI)
53 C --Gaussian Distribution (GAUS)
54 C --
55 C
56 C
57 C The application calculates the KS statistic D as well as the probability
58 C of exceeding D under the Null hypothesis which is :
59 C Data follow the selectedn distribution
60 C References: Numerical Recipes p 472
61 C
62 C.VERSION
63 C
64 C 010621 last modif
65 C
66 C-----------------------------------------------------------
67 C
68 PROGRAM TKSTEST
69 C
70 IMPLICIT NONE
71 C
72 REAL*4 D,PROB,PARA(2)
73 C
74 INTEGER*8 ADDRIN(1)
75 C
76 INTEGER MADRID,IACT,KUN,KNUL,STAT,NSC,NBYTES
77 INTEGER PARVAL,NPAR,ISTAT,TID,NCOL,NROW,NACOL,NAROW,COL
78 INTEGER NREAL
79 C
80 CHARACTER*80 INTAB
81 CHARACTER*1 DISTRI
82 CHARACTER*17 COLIND
83 CHARACTER*80 OUTPUT1,OUTPUT2,OUT,OUTPUT0,OUTPUT3
84 C
85 INCLUDE 'MID_INCLUDE:TABLES.INC'
86 COMMON/VMR/MADRID(1)
87 C
88 INCLUDE 'MID_INCLUDE:TABLED.INC'
89 DATA PARVAL/8/, TID /-1/
90 DATA OUTPUT0
91 1 /' Null Hypothesis : Data follow the given distribution'/
92 DATA OUTPUT1
93 1 /'Kolmogorov-Smirnov D Statistic '/
94 DATA OUTPUT2
95 2 /'----------------------------------------------------- '/
96 DATA OUTPUT3
97 3 /'Probability of exceeding D under Null Hypothesis'/
98 C
99 C get into MIDAS
100 CALL STSPRO('TKSTEST')
101
102 C read parameters of the command
103 CALL TDPGET(PARVAL,NPAR,ISTAT)
104 IF (ISTAT.NE.0) GOTO 80
105 INTAB = TPARBF(1)
106 COLIND = TPARBF(2)
107
108 c read name of the distribution used
109
110 CALL STKRDC('INPUTC',1,1,1,IACT,DISTRI,KUN,KNUL,STAT)
111 CALL UPCAS(DISTRI,DISTRI)
112 C
113 c read parameters of this distribution
114 CALL STKRDR('INPUTR',1,2,IACT,PARA,KUN,KNUL,STAT)
115
116 c open the input table
117
118 CALL TBTOPN(INTAB,F_I_MODE,TID,ISTAT)
119 IF(ISTAT.NE.0) GOTO 80
120 CALL TBIGET(TID,NCOL,NROW,NSC,NACOL,NAROW,ISTAT)
121 CALL TBCSER(TID,COLIND,COL,ISTAT)
122 IF (COL.LT.0) THEN
123 CALL STTPUT('Column not found...',ISTAT)
124 GOTO 80
125 ENDIF
126
127
128 c prepare work space
129
130 NBYTES = 4*NROW
131 CALL TDMGET(NBYTES,ADDRIN(1),ISTAT)
132 CALL TMAP(TID,NROW,COL,MADRID(ADDRIN(1)),NREAL)
133 CALL SORT (MADRID(ADDRIN(1)),NREAL)
134
135 c calculate the KS Statistic
136
137 CALL KOLM1D(MADRID(ADDRIN(1)),NREAL,DISTRI,PARA,D,PROB)
138 CALL STTPUT(OUTPUT0,ISTAT)
139 CALL STTPUT(OUTPUT2,ISTAT)
140 CALL STTPUT(OUTPUT1,ISTAT)
141 WRITE(OUT,100)D
142 CALL STTPUT(OUT,ISTAT)
143 CALL STTPUT(OUTPUT2,ISTAT)
144 CALL STTPUT(OUTPUT3,ISTAT)
145 WRITE(OUT,100)PROB
146 CALL STTPUT(OUT,ISTAT)
147 CALL STTPUT(OUTPUT2,ISTAT)
148 CALL STKWRR('OUTPUTR',D,1,1,KUN,STAT)
149 CALL STKWRR('OUTPUTR',PROB,2,1,KUN,ISTAT)
150 CALL TBTCLO(TID,ISTAT)
151
152 C that's folks
153
154 CALL STSEPI
155 80 CONTINUE
156 100 FORMAT(1X,G15.6,15X,G15.6)
157 END
158