#include #include "partap.h" #include "cfortran.h" #include "dVersion.h" #include "dgPOS.h" #include "dgDETINFO.h" #include "dgVOLU.h" int i, i1, i2, iok, ind, n, igaf, idfl; int ok; /* use as logical, 0=F 1=T */ char cline[81], dummystring[81]; /* Start of program */ void main() { /* =================================================================== */ /* INITIALIZE ADAMO and OPEN THE GAF */ /* =================================================================== */ INITAP(); sprintf(cline,"NAME=hmcdg.ie,DRIVER=IE"); OPEGAF (igaf,cline,iok); if (iok != 0) { printf("\n OPEGAF failed."); exit(0); } NEXGAF (igaf, dVersion, iok); FCB2CSTR(dVersion.cType, dummystring, 0); idfl = GETTDF(dummystring); 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); FETTAB (dgDETINFO, ind, n); FCB2CSTR(dgDETINFO.cName, dummystring, 0); printf("\n >>> Detector %s is furthest downstream,", dummystring); printf(" at z = %f cm", dgDETINFO.pZ); /* =================================================================== */ /* 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"); C2FCBSTR("V1U4", dgDETINFO.cName, 0); SELTAB (dgDETINFO, ind, i1, i2); if (i1 > i2) { printf("\n ERROR: SELTAB could not find V1U4 \n"); exit(0); } else if (i1 != i2) { printf("\n ERROR: SELTAB found more than one V1U4 !?! \n"); exit(0); } /* Now navigate from dgDETINFO to dgVOLU via the generalized relationship Volume using NATGEN. NATGEN loads the dgVOLU row to the WIN. */ FCB2CSTR(dgDETINFO.Volume, dummystring, 0); if (strcmp(dummystring,"dgVOLU") != 0) { printf("\n ERROR: V1U4 is not linked to dgVOLU !?! \n"); exit(0); } NATGEN (dgDETINFO, dgDETINFO.Volume, dgVOLU, ok); if (!ok) { printf("\n NATGEN from dgDETINFO to dgVOLU failed \n"); exit(0); } /* 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"); NAFREL (dgVOLU, dgPOS.dgVOLU, dgPOS, ind, i1, i2); if (i1 > i2) { printf("\n ERROR: NAFREL could not find row in dgPOS \n"); exit(0); } else if (i1 != i2) { printf("\n ERROR: NAFREL found more than one row in dgPOS !?! \n"); exit(0); } /* Finally, navigate from dgPOS TO the mother volume in dgVOLU via the generalized relationship Mother. */ FCB2CSTR(dgPOS.Mother, dummystring, 0); if (strcmp(dummystring, "dgVOLU") != 0) { printf("\n ERROR: The mother volume is not in dgVOLU !?! \n"); exit(0); } NATGEN (dgPOS, dgPOS.Mother, dgVOLU, ok); if (!ok) { printf("\n NATGEN from dgPOS to dgVOLU failed \n"); exit(0); } /* We're done. The mother volume is now in the WIN of dgVOLU. */ FCB2CSTR(dgVOLU.cName, dummystring, 0); printf("\n >>> The mother volume of V1U4 is called %s", dummystring); CLOGAF (igaf,iok); printf("\n\n"); /* End of program */ }