5 * Revision 1.1.1.1 1995/10/24 10:21:45 cernlib
9 #include "geant321/pilot.h"
10 #if defined(CERNLIB_OLD)
11 *CMZ : 3.21/02 29/03/94 15.41.24 by S.Giani
13 SUBROUTINE GINVOL (X, ISAME)
15 C. ******************************************************************
17 C. * SUBR. GINVOL (X, ISAME*) *
19 C. * Checks if particle at point X has left current volume/medium *
20 C. * If so, returns ISAME = 0 and prepares information useful to *
21 C. * identify the new volume entered. *
22 C. * Otherwise, returns ISAME = 1 *
24 C. * Note : INGOTO is set by GTNEXT, to transmit the information *
25 C. * on the one volume which has limited the step SNEXT, *
26 C. * >0 : INth content *
27 C. * =0 : current volume *
28 C. * <0 : -NLONLY, with NLONLY defined as the first 'ONLY' *
29 C. * level up in the tree for the 'NOT-ONLY' volume *
30 C. * where the point X is found to be. *
32 C. * Called by : GNEXT, GTELEC, GTHADR, GTMUON, GTNEXT *
33 C. * Authors : S.Banerjee, R.Brun, F.Bruyant *
35 C. ******************************************************************
37 #include "geant321/gcbank.inc"
38 #include "geant321/gcvolu.inc"
39 #include "geant321/gctrak.inc"
40 #if defined(CERNLIB_USRJMP)
41 #include "geant321/gcjump.inc"
48 C. ------------------------------------------------------------------
50 * SECTION I: The /GCVOLU/ table contains the presumed location of X in the
51 * geometry tree, at level NLEVEL. The suggestion is that INGOTO
52 * is the index of a content at NLEVEL which may also contain X.
53 * If this is so, ISAME=0 and return. INGOTO is left unchanged.
54 * If this is not so, have we left the volume at NLEVEL altogether?
55 * If so, ISAME=0 and INGOTO=0, return. Otherwise, this is the
56 * starting position for a search. Reset search record variables
57 * and proceed to section II.
59 * *** Check if point is in current volume
62 C***** Code Expanded From Routine: GTRNSF
64 100 IF (GRMAT(10,NLEVEL) .EQ. 0.) THEN
65 XC(1) = X(1) - GTRAN(1,NLEVEL)
66 XC(2) = X(2) - GTRAN(2,NLEVEL)
67 XC(3) = X(3) - GTRAN(3,NLEVEL)
70 XL1 = X(1) - GTRAN(1,NLEVEL)
71 XL2 = X(2) - GTRAN(2,NLEVEL)
72 XL3 = X(3) - GTRAN(3,NLEVEL)
73 XC(1) = XL1*GRMAT(1,NLEVEL) + XL2*GRMAT(2,NLEVEL) + XL3*
75 XC(2) = XL1*GRMAT(4,NLEVEL) + XL2*GRMAT(5,NLEVEL) + XL3*
77 XC(3) = XL1*GRMAT(7,NLEVEL) + XL2*GRMAT(8,NLEVEL) + XL3*
81 C***** End of Code Expanded From Routine: GTRNSF
83 JVO = LQ(JVOLUM-LVOLUM(NLEVEL))
85 * Note: At entry the variable INGOTO may contain the index of a volume
86 * contained within the current one at NLEVEL. If so, begin by checking
87 * if X lies inside. This improves the search speed over that of GMEDIA.
90 IF ((INGOTO.LE.0).OR.(INGOTO.GT.NIN)) THEN
94 * *** Entrance in content INGOTO predicted by GTNEXT
98 JVOT = LQ(JVOLUM-IVOT)
99 JPAR = LQ(JGPAR-NLEVEL-1)
102 C***** Code Expanded From Routine: GITRAN
104 C. ------------------------------------------------------------------
106 IF (IROTT .EQ. 0) THEN
107 XT(1) = XC(1) - Q(5+JIN)
108 XT(2) = XC(2) - Q(6+JIN)
109 XT(3) = XC(3) - Q(7+JIN)
112 XL1 = XC(1) - Q(5+JIN)
113 XL2 = XC(2) - Q(6+JIN)
114 XL3 = XC(3) - Q(7+JIN)
116 XT(1) = XL1*Q(JR+1) + XL2*Q(JR+2) + XL3*Q(JR+3)
117 XT(2) = XL1*Q(JR+4) + XL2*Q(JR+5) + XL3*Q(JR+6)
118 XT(3) = XL1*Q(JR+7) + XL2*Q(JR+8) + XL3*Q(JR+9)
121 C***** End of Code Expanded From Routine: GITRAN
123 * * Check if point is in content
125 CALL GINME (XT, Q(JVOT+2), Q(JPAR+1), IYES)
128 * If so, prepare information for volume retrieval, and return
131 LVOLUM(NLEVIN) = IVOT
132 NAMES(NLEVIN) = IQ(JVOLUM+IVOT)
133 NUMBER(NLEVIN) = Q(JIN+3)
134 LINDEX(NLEVIN) = INGOTO
135 LINMX(NLEVIN) = Q(JVO+3)
136 GONLY(NLEVIN) = Q(JIN+8)
137 IF (LQ(LQ(JVOLUM-IVOT)).EQ.0) THEN
138 NLDEV(NLEVIN) = NLDEV(NLEVEL)
140 NLDEV(NLEVIN) = NLEVIN
142 CALL GTRMUL (GTRAN(1,NLEVEL), GRMAT(1,NLEVEL), Q(JIN+5),
143 + IROTT, GTRAN(1,NLEVIN), GRMAT(1,NLEVIN))
149 * End of INGOTO processing
151 JPAR = LQ(JGPAR-NLEVEL)
152 CALL GINME (XC, Q(JVO+2), Q(JPAR+1), IYES)
159 * ** Point is in current volume
163 IF ((INFROM.LE.0).OR.(INFROM.GT.NIN)) THEN
168 IF (INGOTO.GT.0) THEN
171 IQ(JIN) = IBSET(IQ(JIN),4)
174 * SECTION II: X is found inside current node at NLEVEL in /GCVOLU/.
175 * Search all contents for any containing X. Take the
176 * first one found, incrementing NLEVEL and extending the
177 * /GCVOLU/ tables. Otherwise if the list of contents is
178 * exhausted without finding X inside, proceed to Section III.
179 * Note: Since Section II is re-entered from Section III, a blocking word
180 * is used to mark those contents already checked. Upon exit from Section
181 * II, these blocking words are cleared at NLEVEL, but may remain set in
182 * levels between NLEVEL-1 and NLMIN, if any. They must be cleared at exit.
184 * ** Check contents, if any
186 200 JVO = LQ(JVOLUM-LVOLUM(NLEVEL))
189 * * Case with no contents
194 * * Case with contents defined by division
196 ELSEIF (NIN.LT.0) THEN
197 CALL GMEDIV (JVO, IN, XC, 1)
199 IF ((GONLY(NLEVEL).EQ.0).AND.
200 + (NLEVEL.LE.NLEVIN)) THEN
209 * * Case with contents positioned
212 JCONT = LQ(JVO-NIN-1)+1
215 IF (ISEARC.LT.0) THEN
217 * Prepare access to contents, when ordered by GSORD
219 JSB = LQ(LQ(JVO-NIN-1))
223 IDIV = LOCATF (Q(JSB+3), NSB, XC(IAX))
225 CALL GFCOOR (XC, IAX, CX)
226 IDIV = LOCATF (Q(JSB+3), NSB, CX)
228 IF (IDIV.LT.0) IDIV = -IDIV
230 IF (IAX.NE.6) GO TO 260
232 ELSEIF (IDIV.EQ.NSB) THEN
233 IF (IAX.NE.6) GO TO 260
236 NCONT = IQ(JSC0+IDIV)
237 JCONT = LQ(JSC0-IDIV)
240 * otherwise, scan contents (possibly a user selection of them)
242 JNEAR = LQ(JVO-NIN-1)
243 IF (ISEARC.GT.0) THEN
244 #if !defined(CERNLIB_USRJMP)
245 CALL GUNEAR (ISEARC, 1, XC, JNEAR)
247 #if defined(CERNLIB_USRJMP)
248 CALL JUMPT4(JUNEAR,ISEARC, 1, XC, JNEAR)
250 ELSEIF (INFR.GT.0) THEN
251 JNUP = LQ(LQ(JVO-INFR)-1)
260 * For each selected content in turn, check if point is inside
266 * If the value IQ(JCONT+ICONT)=0 then we are back in the mother.
267 * So jump to 260, the search is finished. Clean-up should be done
268 * only up to ICONT-1, so we set:
274 IF (.NOT.BTEST(IQ(JIN),4)) THEN
275 CALL GMEPOS (JVO, IN, XC, 1)
277 IF ((GONLY(NLEVEL).EQ.0).AND.
278 + (NLEVEL.LE.NLEVIN)) THEN
286 IQ(JIN) = IBSET(IQ(JIN),4)
292 260 IF(NCONT.EQ.NIN) THEN
295 IQ(JIN) = IBCLR(IQ(JIN),4)
301 IQ(JIN) = IBCLR(IQ(JIN),4)
305 IQ(JIN) = IBCLR(IQ(JIN),4)
309 IQ(JIN) = IBCLR(IQ(JIN),4)
315 * SECTION III: X is found at current node (NLEVEL in /GCVOLU/) but not in
316 * any of its contents, if any. If this is a MANY volume,
317 * save it as a candidate best-choice, and continue the search
318 * by backing up the tree one node and proceed to Section II.
319 * If this is an ONLY volume, proceed to Section IV.
321 * *** Point is in current volume/medium, and not in any content
323 300 IF (GONLY(NLEVEL).EQ.0.) THEN
325 * ** Lowest level is 'NOT ONLY'
327 IF (NLMANY.EQ.0) THEN
332 * * Go up the tree up to a volume with positioned contents
334 310 INFR = LINDEX(NLEVEL)
336 JVO = LQ(JVOLUM-LVOLUM(NLEVEL))
338 IF (NIN.LT.0) GO TO 310
340 C***** Code Expanded From Routine: GTRNSF
342 IF (GRMAT(10,NLEVEL) .EQ. 0.) THEN
343 XC(1) = X(1) - GTRAN(1,NLEVEL)
344 XC(2) = X(2) - GTRAN(2,NLEVEL)
345 XC(3) = X(3) - GTRAN(3,NLEVEL)
348 XL1 = X(1) - GTRAN(1,NLEVEL)
349 XL2 = X(2) - GTRAN(2,NLEVEL)
350 XL3 = X(3) - GTRAN(3,NLEVEL)
351 XC(1) = XL1*GRMAT(1,NLEVEL) + XL2*GRMAT(2,NLEVEL) +
352 + XL3* GRMAT(3,NLEVEL)
353 XC(2) = XL1*GRMAT(4,NLEVEL) + XL2*GRMAT(5,NLEVEL) +
354 + XL3* GRMAT(6,NLEVEL)
355 XC(3) = XL1*GRMAT(7,NLEVEL) + XL2*GRMAT(8,NLEVEL) +
356 + XL3* GRMAT(9,NLEVEL)
359 C***** End of Code Expanded From Routine: GTRNSF
362 IQ(JIN) = IBSET(IQ(JIN),4)
363 NLMIN = MIN(NLEVEL,NLMIN)
367 * SECTION IV: This is the end of the search.
368 * (1) Entry at 400: ISAME = 1 The current node (NLEVEL
369 * in /GCVOLU/) is an ONLY volume and there were no contents
370 * in the tree below it which could claim X.
371 * (2) Entry at 450: ISAME = 0 Section II has just found
372 * another volume which has more claim to X than the current
373 * one: either another ONLY or a deeper MANY was found.
374 * Note: A valid structure is assumed, in which no ONLY volumes overlap.
375 * If this rule is violated, or if a daughter is not entirely contained
376 * within the mother volume, the results are unpredictable.
383 480 DO 489 NL=NLMIN,NLEVEL-1
384 JVO = LQ(JVOLUM-LVOLUM(NL))
388 IQ(JIN) = IBCLR(IQ(JIN),4)
392 IF (NLMANY.GT.0) THEN
395 ELSEIF (NLEVEL.GT.NLEVIN) THEN
396 INGOTO = LINDEX(NLEVEL)
402 999 IF(JGSTAT.NE.0) CALL GFSTAT(ISAME)