program read implicit none #include "partap.inc" #include "dVersion.inc" #include "dgPOS.inc" #include "dgDETINFO.inc" #include "dgVOLU.inc" integer i, i1, i2, iok, ind, n, igaf, idfl logical ok character*80 cline !===================================================================== ! INITIALIZE ADAMO and OPEN THE GAF !===================================================================== call INITAP cline = 'NAME=hmcdg.ie,DRIVER=IE' call OPEGAF (igaf,cline,iok) if (iok.ne.0) stop 'OPEGAF failed.' call NEXGAF (igaf, dVersion, iok) idfl = gettdf(dVersion_cType) call FETGAF (igaf, dVersion, idfl, iok) !===================================================================== ! GOAL 1: Find the name of the detector from dgDETINFO which is ! furthest downstream. !===================================================================== ! Create an index on the pZ column of dgDETINFO, thereby sorting the ! table in ascending order of z position. The last entry in the ! index will correspond to the position furthest downstream (highest z). ind = GETIND (dgDETINFO,'pZ') n = COUTAB (dgDETINFO) call FETTAB (dgDETINFO, ind, n) write(6,'(1x, 3a,f8.2,a)') '>>> Detector ', dgDETINFO_cName, + ' is furthest downstream, at z = ', dgDETINFO_pZ, ' cm' !===================================================================== ! GOAL 2: Find the mother volume of detector V1U4 !===================================================================== ! Use SELTAB to locate the row of dgDETINFO corresponding to V1U4. ! Note the example error checking. SELTAB should find exactly one row, ! and will therefore automatically load the row into the WIN of dgDETINFO. ind = GETIND (dgDETINFO,'cName') dgDETINFO_cName = 'V1U4' call SELTAB (dgDETINFO, ind, i1, i2) if (i1.gt.i2) then stop 'ERROR: SELTAB could not find V1U4.' else if (i1.ne.i2) then stop 'ERROR: SELTAB found more than one V1U4 !?!' endif ! Now navigate from dgDETINFO to dgVOLU via the generalized ! relationship Volume using NATGEN. NATGEN loads the dgVOLU row to the WIN. if (dgDETINFO_Volume.ne.'dgVOLU') then stop 'ERROR: V1U4 is not linked to dgVOLU !?!' endif call NATGEN (dgDETINFO, dgDETINFO_Volume, dgVOLU, ok) if (.not.ok) stop 'NATGEN from dgDETINFO to dgVOLU failed.' ! Next, we navigate BACKWARDS against the relationship dgPOS_dgVOLU ! to find the corresponding row in dgPOS. Again, exactly one row should ! be found, and loaded automatically to the WIN. ind = GETIND (dgPOS, 'dgVOLU') call NAFREL (dgVOLU, dgPOS_dgVOLU, dgPOS, ind, i1, i2) if (i1.gt.i2) then stop 'ERROR: NAFREL could not find row in dgPOS.' else if (i1.ne.i2) then stop 'ERROR: NAFREL found more than one row in dgPOS !?!' endif ! Finally, navigate from dgPOS TO the mother volume in dgVOLU via ! the generalized relationship Mother. if (dgPOS_Mother.ne.'dgVOLU') then stop 'ERROR: The mother volume is not in dgVOLU !?!' endif call NATGEN (dgPOS, dgPOS_Mother, dgVOLU, ok) if (.not.ok) stop 'NATGEN from dgPOS to dgVOLU failed.' ! We're done. The mother volume is now in the WIN of dgVOLU. print *, '>>> The mother volume of V1U4 is called ', + dgVOLU_cName print * call CLOGAF (igaf,iok) end