Debian Codegraph @

applic/general/libsrc/aini.for

raw
1 C @(#)aini.for 19.1 (ES0-DMD) 02/25/03 13:18:59
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 Massachusetss Ave, Cambridge,
18 C MA 02139, USA.
19 C
20 C Corresponding 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 SUBROUTINE aini(NX,NY,MT,IN,H0,HG,HL,EG,EL,SG,SL,YMT)
30 C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 C initializes the algorithm:
32 C EG,SG,EL,SL: exspectation value and standard deviation
33 C of gradients and Laplace-terms resp. by noise (out)
34 C other parameters as in afido
35 C
36 C------------------------------------------------------------------------
37 IMPLICIT NONE
38 C
39 LOGICALL
40 CHARACTER*1 YMT
41 INTEGER NX,NY,I1,J1,N1X,N1Y,I,J,T
42 REAL IN(NX,NY),H0(NX,NY),HG(NX,NY),HL(NX,NY),
43 > EG,EL,SG,SL,A,C,B,D,HX,HY,H,QG,QL,NP,NPP,
44 > MT(NX,NY)
45 C
46 C *** 1.order:smoothing
47 DO J=1,NY-1
48 J1=J+1
49 DO I=1,NX-1
50 I1=I+1
51 H0(I1,J1)=(IN(I,J)+IN(I1,J)+IN(I,J1)+IN(I1,J1))/4.
52 ENDDO
53 ENDDO
54 C
55 C *** set edge lines: up and left and upper left corner pixel
56 H0(1,1)=H0(2,2) ! corner
57 C
58 DO I=2,NX
59 H0(I,1)=H0(I,2) ! 1.row
60 ENDDO
61 C
62 DO J=2,NY
63 H0(1,J)=H0(2,J) ! 1.column
64 ENDDO
65 C
66 L=.FALSE.
67 NP=0.
68 EL=NP
69 EG=NP
70 QL=NP
71 QG=NP
72 C
73 C *** 2.order: centering
74 DO J=1,NY-1
75 J1=J+1
76 DO I=1,NX-1
77 I1=I+1
78 A=H0(I,J)
79 B=H0(I1,J)
80 C=H0(I,J1)
81 D=H0(I1,J1)
82 H=(A+B+C+D)/4.
83 H0(I,J)=H ! smooth
84 H=IN(I,J)-H
85 HL(I,J)=H ! Laplace
86 IF (YMT.EQ.'N') GOTO 15 ! no mask for statistics
87 T=MT(I,J)
88 IF (T.NE.0) L=.TRUE.
89 IF (L) GOTO 16 ! pixel not used for statistics
90 15 NPP=NP
91 NP=NP+1
92 NPP=NPP/NP
93 H=H-EL
94 EL=EL+H/NP ! estimate statistics
95 QL=QL+H*H*NPP ! for Laplace
96 16 HX=(A-B+C-D)/4.
97 HY=(A+B-C-D)/4.
98 H=SQRT(HX*HX+HY*HY)
99 HG(I,J)=H ! gradient
100 IF (YMT.EQ.'N') GOTO 17 ! no mask for statistics
101 IF (L) GOTO 20 ! pixel not used for statistics
102 17 H=H-EG
103 EG=EG+H/NP ! estimate statistics
104 QG=QG+H*H*NPP ! for gradient
105 20 L=.FALSE.
106 ENDDO
107 ENDDO
108
109 C correct statistics
110 NP=NP-1
111 SL=SQRT(QL/NP)
112 SG=SQRT(QG/NP)
113 C
114 C *** set edge lines down and right and lower right corner pixel
115 N1X=NX-1
116 N1Y=NY-1
117 H0(NX,NY)=H0(N1X,N1Y) ! corner
118 HG(NX,NY)=HG(N1X,N1Y)
119 HL(NX,NY)=HL(N1X,N1Y)
120
121 DO I=1,N1X ! last row
122 H0(I,NY)=H0(I,N1Y)
123 HG(I,NY)=HG(I,N1Y)
124 HL(I,NY)=HL(I,N1Y)
125 ENDDO
126
127 DO J=1,N1Y ! last column
128 H0(NX,J)=H0(N1X,J)
129 HG(NX,J)=HG(N1X,J)
130 HL(NX,J)=HL(N1X,J)
131 ENDDO
132 C
133 RETURN
134 END