def CONTROLB(IDBG,NVAC):
	# IMPLICIT #real*8(A-H,O-Z)
	# IMPLICIT #integer*8(I-N)
	# CHARACTER*6 SCR(17),SCR1(17)
	#     COMMON/INPT2/KGAS,LGAS,DETEFF,EXCWGHT
	# COMMON/COMP/LCMP,LCFLG,LRAY,LRFLG,LPAP,LPFLG,LBRM,LBFLG,LPEFLG
	# COMMON/GENCAS/ELEV[17,79],NSDEG(17),AA[17],BB[17],SCR,SCR1
	# COMMON/MIXC/PRSH(6,3,17,17),ESH(6,3,17),AUG(6,3,17,17,17),RAD[6,3,17,17],PRSHBT(6,3,17),IZ[6,3],INIOCC(6,3,17),ISHLMX(6,3),AMZ[6,3]
	# COMMON/UPD/NOCC(6,3,17),AUGR(6,3,17,17,17),RADR(6,3,17,17)
	# COMMON/CALCASB/IONSUM(10),IFLSUM(10),ESTORE(10,28),EPHOTON(10,28),DRXE(10,28),DRYE(10,28),DRZE(10,28),DRX(10,28),DRY(10,28),DRZ[10,28]
	# COMMON/CALCAS1B/IONSUM1(10),IFLSUM1(10),ESTOR1(10,28),EPHOTG1(10,28),DRXE1(10,28),DRYE1(10,28),DRZE1(10,28),DRX1(10,28),DRY1(10,28),DRZ1(10,28)
	# COMMON/CALCAS2B/IONSUM2(10),IFLSUM2(10),ESTOR2(10,28),EPHOTG2(10,28),DRXE2(10,28),DRYE2(10,28),DRZE2(10,28),DRX2(10,28),DRY2(10,28),DRZ2(10,28)
	# COMMON/CALCAS3B/IONSUM3(10),IFLSUM3(10),ESTOR3(10,28),EPHOTG3(10,28),DRXE3(10,28),DRYE3(10,28),DRZE3(10,28),DRX3(10,28),DRY3(10,28),DRZ3(10,28)
	# COMMON/CALCAS4B/IONSUM4(10),IFLSUM4(10),ESTOR4(10,28),EPHOTG4(10,28),DRXE4(10,28),DRYE4(10,28),DRZE4(10,28),DRX4(10,28),DRY4(10,28),DRZ4(10,28)
	# COMMON/CALCAS5B/IONSUM5(10),IFLSUM5(10),ESTOR5(10,28),EPHOTG5(10,28),DRXE5(10,28),DRYE5(10,28),DRZE5(10,28),DRX5(10,28),DRY5(10,28),DRZ5(10,28)
	# COMMON/COUTE/ECMP(10),ECDRX(10),ECDRY(10),ECDRZ[10],XCPOS(10),YCPOS(10),ZCPOS(10),KCGAS(10),LCGAS(10),ICSHELL(10)
	#
	#COMMON/COMP/
	global LCMP,LCFLG,LRAY,LRFLG,LPAP,LPFLG,LBRM,LBFLG,LPEFLG
	#COMMON/GENCAS/
	global ELEV#(17,79)
	global NSDEG#(17)
	global AA#(17)
	global BB#(17)
	global SCR,SCR1
	#COMMON/MIXC/
	global PRSH#(6,3,17,17)
	global ESH#(6,3,17)
	global AUG#(6,3,17,17,17)
	global RAD#(6,3,17,17)
	global PRSHBT#(6,3,17)
	global IZ#(6,3)
	global INIOCC#(6,3,17)
	global ISHLMX#(6,3)
	global AMZ#(6,3)
	#COMMON/UPD/
	global NOCC#(6,3,17)
	global AUGR#(6,3,17,17,17)
	global RADR#(6,3,17,17)
	#COMMON/CALCASB/
	global IONSUM#(10)
	global IFLSUM#(10)
	global ESTORE#(10,28)
	global EPHOTON#(10,28)
	global DRXE#(10,28)
	global DRYE#(10,28)
	global DRZE#(10,28)
	global DRX#(10,28)
	global DRY#(10,28)
	global DRZ#(10,28)
	#COMMON/CALCAS1B/
	global IONSUM1#(10)
	global IFLSUM1#(10)
	global ESTOR1#(10,28)
	global EPHOTG1#(10,28)
	global DRXE1#(10,28)
	global DRYE1#(10,28)
	global DRZE1#(10,28)
	global DRX1#(10,28)
	global DRY1#(10,28)
	global DRZ1#(10,28)
	#COMMON/CALCAS2B/
	global IONSUM2#(10)
	global IFLSUM2#(10)
	global ESTOR2#(10,28)
	global EPHOTG2#(10,28)
	global DRXE2#(10,28)
	global DRYE2#(10,28)
	global DRZE2#(10,28)
	global DRX2#(10,28)
	global DRY2#(10,28)
	global DRZ2#(10,28)
	#COMMON/CALCAS3B/
	global IONSUM3#(10)
	global IFLSUM3#(10)
	global ESTOR3#(10,28)
	global EPHOTG3#(10,28)
	global DRXE3#(10,28)
	global DRYE3#(10,28)
	global DRZE3#(10,28)
	global DRX3#(10,28)
	global DRY3#(10,28)
	global DRZ3#(10,28)
	#COMMON/CALCAS4B/
	global IONSUM4#(10)
	global IFLSUM4#(10)
	global ESTOR4#(10,28)
	global EPHOTG4#(10,28)
	global DRXE4#(10,28)
	global DRYE4#(10,28)
	global DRZE4#(10,28)
	global DRX4#(10,28)
	global DRY4#(10,28)
	global DRZ4#(10,28)
	#COMMON/CALCAS5B/
	global IONSUM5#(10)
	global IFLSUM5#(10)
	global ESTOR5#(10,28)
	global EPHOTG5#(10,28)
	global DRXE5#(10,28)
	global DRYE5#(10,28)
	global DRZE5#(10,28)
	global DRX5#(10,28)
	global DRY5#(10,28)
	global DRZ5#(10,28)
	#COMMON/COUTE/
	global ECMP#(10)
	global ECDRX#(10)
	global ECDRY#(10)
	global ECDRZ#(10)
	global XCPOS#(10)
	global YCPOS#(10)
	global ZCPOS#(10)
	global KCGAS#(10)
	global LCGAS#(10)
	global ICSHELL#(10)

	#  CALCULATES AUGER AND FLUORESCENCE CASCADE FOR VACANCY IN ICSHELL
	#
	IFIRST=1
	ISECOND=2
	ICONPH=1
	X0=XCPOS[NVAC]
	Y0=YCPOS[NVAC]
	Z0=ZCPOS[NVAC]
	DRXE[NVAC][1]=ECDRX[NVAC]
	DRYE[NVAC][1]=ECDRY[NVAC]
	DRZE[NVAC][1]=ECDRZ[NVAC]
	KDUM=KCGAS[NVAC]
	LDUM=LCGAS[NVAC]
	EDUM=ECMP[NVAC]
	IDUM=ICSHELL[NVAC]
	# 
	# CALCULATE CASCADE EVENT
	CALCB(NVAC,KDUM,LDUM,EDUM,IDUM)
	#     IF(IDBG == 1) :
	#     DO 67 M1=1,NVAC
	#     WRITE(6,66) EDUM,M1,(ESTORE(M1,KK),KK=1,28)
	#  66 print(' IN CONTROLB EDUM=','%.4f' % ,' M1=',I3,/,' ESTORE(M1,K)=',
	#    /4(7'%.4f' % ,/))
	#  67 CONTINUE
	#     WRITE(6,68) (IFLSUM(KK),KK=1,10)
	#  68 print(' IFLSUM=',10I4)
	#     DO 70 M1=1,NVAC
	#     WRITE(6,69) (EPHOTON(M1,KK),KK=1,28)
	#  69 print(' EPHOTON=',4(7'%.4f' % ,/))
	#  70 CONTINUE   
	#C    # endIF
	# STORE EVENT 
	#     Z0=DIST
	CASSTOREB(NVAC,X0,Y0,Z0)
	# IF INCLUDE PHOTOABSORPTION OF FLUORESENCE : 
	if(ICONPH == 1):
		if(IFLSUM[NVAC]== 0):
			# ZERO COUNTER
			L1=0
			CSSTFB1(NVAC,L1,DIST1)
			pass
			# endif
			# LOOP AROUND FIRST GEN FLUORESCENCE
		else:			
			IFLLOW=0
			IFL1=IFLSUM[NVAC]
			for L1 in range(1,IFL1):
				EPH=EPHOTON[NVAC][L1]
				#
				# CALC ABSORPTION POSITION X1,Y1,Z1 FOR FLUORESENCE PHOTON OF ENERGY EPH
				# WITH ABSORPTION IN SHELL ISHELL1 IN GAS KGAS1 COMPONENT LGAS1 
				ABSO(ISECOND,EPH,ISHELL1,KGAS1,LGAS1,DIST1)
				#      IF(IDBG == 1) :
				#      WRITE(6,72) EPH,ISHELL1
				#  72  print('IN CONTROLB EPH=','%.4f' % ,' ISHELL1=',I4)
				#      # endIF
				# LOW ENERGY PHOTON
				if(ISHELL1 == -1):
					IFLSUM[NVAC]=IFLSUM[NVAC]-1
					pass
					# endif
					#
					# CALCULATE CASCADE IN GAS 
					#      IF(IDBG == 1) :
					#      WRITE(6,445) L1,ISHELL1,EPH
					# 445  print(' CALLING CALCB1 L1=',I3,' ISHELL1=',I3,' EPH=','%.4f' % )
					#      # endIF
				else:
					CALCB1(NVAC,KGAS1,LGAS1,EPH,ISHELL1,L1)
					# STORE EVENT
					CSSTFB1(NVAC,L1,DIST1) 
		# 
		# SECOND GENERATION FLUORESCENCE
		if(IFLSUM1[NVAC]== 0) :    
			# ZERO COUNTER
			L2=0
			CSSTFB2(NVAC,L2,DIST)
			pass
			# endif 
		else:
			# LOOP AROUND SECOND GEN FLUORESCENCE
			IFL2=IFLSUM1[NVAC]
			for L2 in range(1,IFL2):
				EPH=EPHOTG1(NVAC,L2)
				#
				# CALC ABSORPTION POSITION X2,Y2,Z2 FOR FLUORESENCE PHOTON OF ENERGY EPH
				# WITH ABSORPTION IN SHELL ISHELL2 IN GAS KGAS2 COMPONENT LGAS2
				ABSO(ISECOND,EPH,ISHELL2,KGAS2,LGAS2,DIST2)
				# LOW ENERGY PHOTON
				if(ISHELL2 == -1):
					pass
					#
					# CALCULATE CASCADE IN GAS 
				else:
					CALCB2(NVAC,KGAS2,LGAS2,EPH,ISHELL2,L2)
					# STORE EVENT
					CSSTFB2(NVAC,L2,DIST2)               
		# 
		# THIRD GENERATION FLUORESCENCE
		if(IFLSUM2[NVAC]== 0):     
			# ZERO COUNTER
			L3=0
			CSSTFB3(NVAC,L3,DIST) 
			pass
			# endif
			# LOOP AROUND THIRD GEN FLUORESCENCE
		else:
			IFL3=IFLSUM2[NVAC]
			for L3 in range(1,IFL3):
				EPH=EPHOTG2[NVAC][L3]
				#
				# CALC ABSORPTION POSITION X3,Y3,Z3 FOR FLUORESENCE PHOTON OF ENERGY EPH
				# WITH ABSORPTION IN SHELL ISHELL3 IN GAS KGAS3 COMPONENT LGAS3
				ABSO(ISECOND,EPH,ISHELL3,KGAS3,LGAS3,DIST3)
				# LOW ENERGY PHOTON
				if(ISHELL3 == -1):
					pass
					#
					# CALCULATE CASCADE IN GAS 
				else:
					CALCB3(NVAC,KGAS3,LGAS3,EPH,ISHELL3,L3)
					# STORE EVENT
					CSSTFB3(NVAC,L3,DIST3)               
		# 
		# FOURTH GENERATION FLUORESCENCE
		if(IFLSUM3[NVAC]== 0):    
			# ZERO COUNTER
			L4=0
			CSSTFB4(NVAC,L4,DIST)
			pass
			# endif
			# LOOP AROUND FOURTH GEN FLUORESCENCE
		else:
			IFL4=IFLSUM3[NVAC]
			for L4 in range(1,IFL4):
				EPH=EPHOTG3[NVAC][L4]
				#
				# CALC ABSORPTION POSITION X4,Y4,Z4 FOR FLUORESENCE PHOTON OF ENERGY EPH
				# WITH ABSORPTION IN SHELL ISHELL4 IN GAS KGAS4 COMPONENT LGAS4
				ABSO(ISECOND,EPH,ISHELL4,KGAS4,LGAS4,DIST4)
				# LOW ENERGY PHOTON
				if(ISHELL4 == -1):
					pass
				else:
					#
					# CALCULATE CASCADE IN GAS 
					CALCB4(NVAC,KGAS4,LGAS4,EPH,ISHELL4,L4)
					# STORE EVENT
					CSSTFB4(NVAC,L4,DIST4)                    
		# 
		# FIFTH GENERATION FLUORESCENCE
		if(IFLSUM4[NVAC]== 0):     
			# ZERO COUNTER
			L5=0
			CSSTFB5(NVAC,L5,DIST)
			pass
			# endif
			# LOOP AROUND FIFTH GEN FLUORESCENCE
		else:
			IFL5=IFLSUM5[NVAC]
			for L5 in range(1,IFL5):
				EPH=EPHOTG4[NVAC][L5]
				#
				# CALC ABSORPTION POSITION X5,Y5,Z5 FOR FLUORESENCE PHOTON OF ENERGY EPH
				# WITH ABSORPTION IN SHELL ISHELL5 IN GAS KGAS5 COMPONENT LGAS5
				ABSO(ISECOND,EPH,ISHELL5,KGAS5,LGAS5,DIST5)
				# LOW ENERGY PHOTON
				if(ISHELL5 == -1):
					pass
				else:
					#
					# CALCULATE CASCADE IN GAS 
					CALCB5(NVAC,KGAS5,LGAS5,EPH,ISHELL5,L5)
					# STORE EVENT
					CSSTFB5(NVAC,L5,DIST5)               
					if(IFLSUM5[NVAC]>= 1):
						print(' WARNING SIXTH GENERATION EXISTS IFLSUM5=',IFLSUM5)
	# endif
	# 10 CONTINUE
	#     IF(IDBG == 1) :
	#     DO 666 KKK=1,NVAC
	#     WRITE(6,777) (ESTORE(KKK,K),K=1,28)
	# 777 print(' ESTORE=',4(7'%.4f' % ,/))
	#     WRITE(6,778) (ESTOR1(KKK,K),K=1,28)
	# 778 print(' ESTOR1=',4(7'%.4f' % ,/))
	#     WRITE(6,779) IONSUM(KKK),IONSUM1(KKK),IONSUM2(KKK),IONSUM3(KKK),
	#    /IONSUM4(KKK),IONSUM5(KKK)
	# 779 print(' IONSUM 0-5=',6I4)
	#     WRITE(6,780) IFLSUM(KKK),IFLSUM1(KKK),IFLSUM2(KKK),IFLSUM3(KKK),
	#    /IFLSUM4(KKK),IFLSUM5(KKK)
	# 780 print(' IFLSUM 0-5=',6I4)
	# 666 CONTINUE
	#     # endIF
	return 
	# end