OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
dmatch.f
Go to the documentation of this file.
1  SUBROUTINE dmatch (DANGTL, DMAGTL, IFXCLM, NUMCAT,
2  I IDNCAT, DATCAT, NUMSTR, KLMSTR,
3  I NUMCLM, LBLCLM, GCICLM, BRICLM, NOBCLM,
4  O MRKCLM, MRKSTR, IDFCLM, NRFCLM,
5  O MAPCLM, SKYCLM, IRCODE)
6 C-----------------------------------------------------------------------
7 C MODULE NAME: STDMATCH
8 C
9 C PURPOSE: TO PERFORM DIRECT MATCH ALGORITHM ON CLUMPS.
10 C
11 C
12 C ARGUMENT LIST:
13 C ARGUMENT I/O TYPE DIMENS DESCRIPTION
14 C -------- --- ---- ------ -----------
15 C DANGTL I R*8 MAX ANGULAR SEPARATION FOR MATCH (DEGREES)
16 C DMAGTL I R*8 MAX MAGNITUDE DIFFERENCE FOR MATCH
17 C IFXCLM I I*4 MAX NUMBER OF REF STAR MATCHES :ARRAY DIM
18 C NUMCAT I I*4 NUMBER OF REFERENCE STARS IN CATALOG
19 C IDNCAT I I*4 * SKYMAP REFERENCE STAR NUMBERS IN CATALOG
20 C DATCAT I R*4 7,* CATALOG DATA (1=X AXIS,2=Y AXIS,3=Z AXIS,
21 C 4=MAGNITUDE,5=MOTION,
22 C 6=QUALITY,7=COLOR)
23 C NUMSTR I I*4 NUMBER OF OBSERVATIONS
24 C KLMSTR I I*4 * CLUMP NUMBER FOR EACH OBSERVATION
25 C NUMCLM I I*4 NUMBER OF CLUMPS PER TRACKER
26 C LBLCLM I I*4 * CLUMP LABELS
27 C GCICLM I R*4 3,* AVERAGE POSITION VEC (GCI) FOR EACH CLUMP
28 C BRICLM I R*4 * AVERAGE MAGNITUDE FOR EACH CLUMP
29 C NOBCLM I I*4 * NUMBER OF OBSERVATIONS IN EACH CLUMP
30 C MRKCLM I O I*4 * STATUS FLAG FOR EACH CLUMP
31 C MRKSTR I O I*4 * STATUS FLAG FOR EACH OBSERVATION
32 C IDFCLM O I*4 * CLUMP IDENTIFICATION FLAG
33 C NRFCLM O I*4 * NUMBER OF REFERENCE STARS MATCHED TO CLUMP
34 C MAPCLM O I*4 10,* LIST OF REF STAR NUMBERS MATCHED TO CLUMP
35 C SKYCLM O R*4 10,3,* LIST OF CORRECTED REFERENCE STAR POSITIONS
36 C IRCODE O I*4 ERROR FLAG (0=NO ERROR, 1=ERROR)
37 C
38 C
39 C COMMON BLOCK VARIABLES USED:
40 C COMMON VAR I/O VAR I/O VAR I/O VAR I/O
41 C ------ --- --- --- --- --- --- --- ---
42 C CMDEBG LEVDBG I LUDBUG I
43 C CMSMSG IMSGNM I IVARLN I IDSTFG I IRC I
44 C C$VDAT I C$SBID I
45 C CMCONV DTR I
46 C
47 C ++INCLUDE STCMDEBG
48 C ++INCLUDE STCMSMSG
49 C ++INCLUDE AECMCONV
50  INTEGER*4 LEVDBG(8),LUDBUG
51  COMMON /CMDEBG/LEVDBG,LUDBUG
52  REAL*8 PI,RADEG,RE,REM,F,OMF2,OMEGAE
53  COMMON /GCONST/PI,RADEG,RE,REM,F,OMF2,OMEGAE
54 C
55 C EXTERNAL FILES REFERENCED: l
56 C FILENAME OPERATION FORTRAN UNIT ID
57 C -------- --------- ---------------
58 C NONE
59 C
60 C EXTERNAL REFERENCES:
61 C --------------------------------------------------------------------
62 C STDIRINI - INITIALIZE DIRECT MATCH ALGORITHM AND DATA
63 C UTDANGLE - FUNCTION TO COMPUTE ANGULAR SEPARATION BETWEEN 2 VECTORS
64 C UTMSG - OUTPUT AN ERROR MESSAGE
65 C
66 C
67 C SUBROUTINE CALLED FROM:
68 C --------------------------------------------------------------------
69 C STIDENTY - STAR MATCHING DRIVER
70 C
71 C
72 C CONSTRAINTS, RESTRICTIONS, MESSAGES, NOTES:
73 C --------------------------------------------------------------------
74 C NONE
75 C
76 C REQUIREMENTS REFERENCES:
77 C --------------------------------------------------------------------
78 C UARS FDSS SPECS PAGE 3.1.1.5-17 F3-1A TO F3-1B
79 C
80 C DEVELOPMENT HISTORY:
81 C DATE AUTHOR DESCRIPTION
82 C -------- ------ -----------
83 C 8/2/88 R.J. BURLEY DESIGN
84 C 5/8/89 R.J. BURLEY CODED
85 C 10/10/89 R.J. BURLEY ROUTINE NAME CHANGED FROM DIRECT TO
86 C DMATCH BECAUSE DIRECT IS A RESERVED
87 C NAME IN GESS.
88 C 10/12/89 R.J. BURLEY IMPROVE DEBUG
89 C 11/ 2/89 R.J. BURLEY CORRECT IDFCLM VALUES
90 C 11/ 6/89 R.J. BURLEY ADD LBLCLM GESS ARRAY
91 C-----------------------------------------------------------------------
92 C METHOD:
93 C CALL DIRINI TO INITIALIZE CLUMP AND OBSERVATION ID FIELDS
94 C
95 C! * MATCH CLUMPS WITH REFERENCE STARS
96 C DO FOR ALL CLUMPS
97 C IF (MRKCLM FLAG INDICATES THAT CLUMP IS GOOD) THEN
98 C DO FOR ALL REFERENCE STARS IN CATALOG (1 TO NUMCAT)
99 C USE DANGLE TO COMPUTE ANGULAR SEPARATION BETWEEN AVG CLUMP
100 C POSITION AND REFERENCE STAR POSITION
101 C COMPUTE ABSOLUTE VALUE OF MAGNITUDE DIFFERENCE BETWEEN CLUMP
102 C AND REFERENCE STAR
103 C IF ((ANGULAR SEPARATION < DANGTL).AND.
104 C (MAGNITUDE DIFFERENCE < DMAGTL)) THEN
105 C! WITHIN TOLERANCE, SAVE REF STAR NUMBER IN LIST OF MATCHES
106 C! FOR CURRENT CLUMP AS FOLLOWS:
107 C NRFCLM(CLUMP#) = NRFCLM(CLUMP#)+1
108 C IF (NRFCLM(CLUMP#) > IFXCLM) THEN
109 C IRCODE = 1 OVERFILL OF MATCH ARRAY SPACE
110 C ABORT TO ERROR_HANDLE
111 C ELSE
112 C MAPCLM(NRFCLM(CLUMP#),CLUMP#)=IDNCAT(REF STAR#)
113 C ENDIF
114 C ENDIF
115 C ENDDO FOR
116 C ENDIF
117 C ENDDO FOR
118 C
119 C DO FOR ALL CLUMPS (1 TO NUMCLM)
120 C IF (# OF REFERENCE STAR MATCHES FOR CLUMP = 0) THEN
121 C IDFCLM(CLUMP#) = 0 MARK CLUMP AS UNIDENTIFIED
122 C SET MRKCLM FLAG TO 14 TO INDICATE UNIDENTIFIED
123 C DO FOR ALL OBSERVATIONS
124 C IF (OBSERVATION IS IN CURRENT CLUMP AND THE OBSERVATION
125 C HAS NOT YET BEEN DROPPED) THEN
126 C SET FLAG IN MRKSTR ARRAY TO 16 INDICATING THE OBSERVATION
127 C HAS BEEN DROPPED DUE TO NON-IDENTIFICATION
128 C ENDIF
129 C ENDDO FOR
130 C ELSE IF (# OF REFERENCE STAR MATCHES FOR CLUMP = 1) THEN
131 C IDFCLM(CLUMP#) = 2 MARK CLUMP AS IDENTIFIED
132 C ELSE MORE THAN 1 REFERENCE STAR MATCH FOR CLUMP
133 C IDFCLM(CLUMP#) = 1 MARK CLUMP AS QUESTIONABLE MATCH
134 C COMPUTE BEST POSITION MATCH FROM CANDIDATE REF STARS AND
135 C PLACE THIS REF STAR AT BEGINNING OF REF STAR LIST FOR
136 C THIS CLUMP.
137 C ENDIF
138 C ENDDO FOR
139 C
140 C
141 C RETURN
142 C -------------
143 C ERROR_HANDLE:
144 C DO CASE OF ERROR CONDITION
145 C IRCODE = 1: CALL UTMSG TO OUTPUT ERROR MESSAGE
146 C ENDCASE
147 C RETURN
148 C-----------------------------------------------------------------------
149 C
150 C * DEFINE PARAMETER VARIABLES
151  real*8 dangtl , dmagtl
152 C
153  real*4 datcat(7,*) , gciclm(3,*), briclm(*), skyclm(10,3,*)
154 C
155  INTEGER*4 IFXCLM , NUMCAT , IDNCAT(*)
156  INTEGER*4 NUMSTR , KLMSTR(*) , MRKSTR(*)
157  INTEGER*4 NUMCLM , LBLCLM(*) , NOBCLM(*)
158  INTEGER*4 MRKCLM(*) , IDFCLM(*) , NRFCLM(*)
159  INTEGER*4 MAPCLM(10,*), IRCODE
160 C
161 C * DECLARE LOCAL VARIABLES
162  real*8 angsep , angdif , toler , dangle, besta
163  real*8 e2clm(3), e2ref(3) , ue2ref(3), rangtl, rmagdf, rmax
164  INTEGER*4 ICLM , ISTAR , IOBS , IBEST , ITEMP , IMATCH
165  INTEGER*4 I
166  DATA toler /0.99d0/
167  DATA rmax /999999.0d0/
168 C
169 C INITIALIZE ROUTINE
170  ircode = 0
171  IF (levdbg(7) .NE. 0) WRITE (ludbug,1000)
172 C
173 C INITIALIZE ALGORITHM
174  CALL dirini (numstr, numclm, ifxclm,
175  1 mrkclm, idfclm, nrfclm, mapclm, skyclm, mrkstr)
176 C
177 C
178 C CONVERT ANGULAR SEPARATION
179 C TOLERANCE TO RADIANS
180 C RANGTL = DANGTL * DTR
181  rangtl = dangtl / radeg
182  IF (levdbg(7) .GE. 1) WRITE (ludbug,4000) rangtl, dmagtl
183 C
184 C
185 C MATCH CLUMPS WITH REFERENCE STARS
186  DO 200 iclm = 1,numclm
187  IF (mrkclm(iclm) .EQ. 0) THEN
188 C
189 C INTERMEDIATE DEBUG
190  IF (levdbg(7) .GE. 4) THEN
191  WRITE (ludbug,4010) lblclm(iclm),(gciclm(i,iclm),i=1,3),
192  1 briclm(iclm)
193  ENDIF
194 C
195 C COMPARE CLUMP WITH ALL STARS
196  DO 100 istar = 1,numcat
197 C
198 C COMPUTE ANGLE BETWEEN VECTORS
199  e2clm(1) = dble(gciclm(1,iclm))
200  e2clm(2) = dble(gciclm(2,iclm))
201  e2clm(3) = dble(gciclm(3,iclm))
202  e2ref(1) = dble(datcat(1,istar))
203  e2ref(2) = dble(datcat(2,istar))
204  e2ref(3) = dble(datcat(3,istar))
205  angsep = dangle(e2clm, e2ref, toler, angdif)
206 C
207 C COMPUTE MAGNITUDE DIFFERENCE
208  rmagdf = dble(abs(briclm(iclm)-datcat(4,istar)))
209 C
210 C TEST FOR MATCH
211  IF ((angsep .LT. rangtl).AND.(rmagdf .LT. dmagtl)) THEN
212  nrfclm(iclm) = nrfclm(iclm) + 1
213 C
214 C INTERMEDIATE DEBUG
215  IF (levdbg(7) .GE. 4) THEN
216  WRITE (ludbug,4020) nrfclm(iclm), istar, idncat(istar),
217  1 angsep, rmagdf
218  ENDIF
219  IF (nrfclm(iclm) .GT. ifxclm) THEN
220  ircode = 1
221  GO TO 9999
222  ELSE
223  mapclm(nrfclm(iclm),iclm) = istar
224  ENDIF
225  ENDIF
226 100 CONTINUE
227  ENDIF
228 200 CONTINUE
229 C
230 C
231 C MATCH OBSERVATIONS WITH THE
232 C REFERENCE STARS FROM ABOVE
233  DO 500 iclm = 1,numclm
234  IF (nrfclm(iclm) .EQ. 0) THEN
235 C FLAG CLUMP AND ALL OBSERVATIONS
236 C IN CLUMP AS UNIDENTIFIED
237  idfclm(iclm) = 0
238  mrkclm(iclm) = 14
239  DO 300 iobs = 1,numstr
240  IF ((klmstr(iobs).EQ. iclm).AND.(mrkstr(iobs).EQ. 0)) THEN
241  mrkstr(iobs) = 16
242  ENDIF
243 300 CONTINUE
244  ELSE IF (nrfclm(iclm) .EQ. 1) THEN
245 C FLAG CLUMP AS IDENTIFIED
246  idfclm(iclm) = 2
247  ELSE
248 C FLAG CLUMP AS QUESTIONABLE MATCH
249 C AND INITIALIZE BEST MATCH LOOP
250  idfclm(iclm) = 1
251  e2clm(1) = dble(gciclm(1,iclm))
252  e2clm(2) = dble(gciclm(2,iclm))
253  e2clm(3) = dble(gciclm(3,iclm))
254  besta = rmax
255  ibest = 0
256 C
257 C COMPUTE BEST MATCH, BY POSITION
258 C OF CANDIDATE REFERENCE STARS
259  DO 400 imatch = 1,nrfclm(iclm)
260  istar = mapclm(imatch,iclm)
261  e2ref(1) = dble(datcat(1,istar))
262  e2ref(2) = dble(datcat(2,istar))
263  e2ref(3) = dble(datcat(3,istar))
264  angsep = dangle(e2clm, e2ref, toler, angdif)
265  IF (angsep .LT. besta) THEN
266  besta = angsep
267  ibest = imatch
268  ENDIF
269 400 CONTINUE
270 C
271 C MOVE BEST MATCH TO FRONT OF LIST
272  itemp = mapclm(1,iclm)
273  mapclm(1,iclm) = mapclm(ibest,iclm)
274  mapclm(ibest,iclm) = itemp
275  ENDIF
276 500 CONTINUE
277 C
278 C
279 C NORMAL TERMINATION
280  IF (levdbg(7) .NE. 0) WRITE (ludbug,2000)
281  RETURN
282 C
283 C ERROR HANDLING
284 9999 CONTINUE
285  IF (levdbg(7) .NE. 0) WRITE (ludbug,3000)
286  IF (ircode .EQ. 1) THEN
287 c IMSGNM = 60
288 c IVARLN = 0
289 c CALL UTMSG (C$SBID, IMSGNM, IVARLN, C$VDAT, IDSTFG, IRC)
290  IF (levdbg(7) .GE. 4) WRITE (ludbug,6000) iclm
291  ENDIF
292  RETURN
293 C
294 C FORMAT SECTION
295 1000 FORMAT(' *** ENTER DMATCH ***')
296 2000 FORMAT(' *** EXIT DMATCH ***')
297 3000 FORMAT(' *** ABEND DMATCH ***')
298 4000 FORMAT(' DIRECT MATCH MAX ANGSEP=',d14.6,' RADIANS AND',
299  1 ' MAGDIF MAX=',d14.6)
300 4010 FORMAT(' WORKING ON CLUMP ',i6,' GCI=',3(f14.6,1x),' MAG=',f14.6)
301 4020 FORMAT(' MATCH ',i4,' STARINDEX=',i6,' SKYMAP#=',i10,
302  1 ' ANGSEP=',d14.6,' MAGDIF=',d14.6)
303 6000 FORMAT(' DIRECT: MATCH TABLE OVERFILL WHILE MATCHING CLUMP ',i6)
304  END
#define real
Definition: DbAlgOcean.cpp:26
subroutine dirini(NUMSTR, NUMCLM, IFXCLM, MRKCLM, IDFCLM, NRFCLM, MAPCLM, SKYCLM, MRKSTR)
Definition: dirini.f:4
subroutine dmatch(DANGTL, DMAGTL, IFXCLM, NUMCAT, IDNCAT, DATCAT, NUMSTR, KLMSTR, NUMCLM, LBLCLM, GCICLM, BRICLM, NOBCLM, MRKCLM, MRKSTR, IDFCLM, NRFCLM, MAPCLM, SKYCLM, IRCODE)
Definition: dmatch.f:6
#define abs(a)
Definition: misc.h:90
real *8 function dangle(A, B, TOLER, ANG)
Definition: dangle.f:62