integer*4 function get_csrbunch(rt, rb, rs, rp) ! ! initialize the functions csr_bunchdelay and lin_bunchdelay using the ! node TIM CSRBUNCH as input. get_csrbunch returns 1 if TIM CSRBUNCH ! contains new data from LDINIT, 0 if it contains old data, and -1 if it ! contains invalid data. rt, rb, and rs are the numbers of trains, ! bunches, and 14 ns spaces between bunches. np is the number of ! injection patterns. ! All bucket delays are computed from the train number and bunch number ! by the function csr_bkt_dly, using the parameters in TIM CSRBUNCH 1-5. ! This function defines the train structure of cesr, and is used ! implicitly by LDINIT and all other programs which depend on train ! structure. Any redefinition of train structure should be done by ! changing csr_bkt_dly. ! csrbunch(1) is the offset of the delay table within array csrbunch. ! csrbunch(2) is number of trains. ! csrbunch(3) is the number of bunches per train. ! csrbunch(4) is the bunch spacing in 14 ns. ! csrbunch(5) is the train multiple as defined by LDINIT ! csrbunch(6) is bit-coded train enable ! csrbunch(7) is bit-coded phase enable (+2 ns per phase) ! csrbunch(8-14) are bit-coded bunch enables for each phase ! csrbunch(csrbunch(1) - 1) is the new data flag. ! csrbunch(15) is the number of injection patterns ! csrbunch(16) is the bit-coded pattern enable ! note that this file contains several entry points: ! ! entry clr_csrbunch ! Clear the new data flag in TIM CSRBUNCH. ! ! entry csr_bunchdelay(it, ib) ! Bucket delay of bunch in cesr. More documentation below. ! ! entry lin_bunchdelay(it, ib, ip) ! Bucket delay of bunch in linac. More documentation below. ! ! entry lin_cesr_delay(ib, ip) ! Bucket delay of cesr bunch in linac. More documentation below. ! ! integer*4 function csr_bkt_dly(t_ind, b_ind, param()) ! Basic train definition function. More documentation below. ! implicit none integer*4 rt, rb, rs, rp, it, ib, ip integer*4 nt, nb, ns, np, tm, csr_bkt_dly integer*4 cbshft, cb_ind, cb_off, csrbunch(200)/200*0/ integer*4 clr_csrbunch, csr_bunchdelay, lin_bunchdelay, lin_cesr_delay ! call vmgetn( 'TIM CSRBUNCH', 1, 200, csrbunch) get_csrbunch = -1 if (csrbunch(1) < 7) return if (csrbunch(2) <= 0) return if (csrbunch(3) <= 0) return if (csrbunch(4) <= 0) return if (csrbunch(5) <= 0) return nt = csrbunch(2) nb = csrbunch(3) ns = csrbunch(4) tm = csrbunch(5) np = csrbunch(15) rt = nt rb = nb rs = ns rp = np get_csrbunch = 0 if (csrbunch(csrbunch(1) - 1) < 0) get_csrbunch = 1 return entry clr_csrbunch ! ! reset new data flag clr_csrbunch = 1 !satisfy compiler and assert success call vmputn( 'TIM CSRBUNCH', csrbunch(1) - 1, csrbunch(1) - 1, 0) return entry csr_bunchdelay(it, ib) ! ! it and ib are the train number and bunch number referenced to 1. ! csr_bunchdelay is the location of the bunch in cesr in 14 ns units. ! note that csr_bunchdelay(1, 1) = 0 by definition. ! nonexistant bunch will return -1 csr_bunchdelay = -1 if (it <= 0) return if (ib <= 0) return csr_bunchdelay = csr_bkt_dly(it - 1, ib - 1, csrbunch) return entry lin_bunchdelay(it, ib, ip) ! ! it, ib, and ip are the train and bunch number in the linac, and cesr ! pattern number, all referenced to 1. ! lin_bunchdelay is the location of the bunch in the linac in 14 ns units, ! referenced to 0. note that lin_bunchdelay(1, 1, ip) = 0, 1, or 2 ! nonexistant bunch or pattern will return -1 lin_bunchdelay = -1 if (ip > np .or. ip <= 0) return if (it > nt .or. it <= 0) return if (ib > nb .or. ib <= 0) return cb_ind = it + ip - 2 !train index in cesr, 0 org cb_off = csr_bkt_dly(cb_ind, ib - 1, csrbunch) cbshft = csr_bkt_dly(ip - 1, 0, csrbunch)/3 lin_bunchdelay = mod(cb_off - 3*cbshft + 183, 183) return entry lin_cesr_delay(ib, ip) ! ! ib, and ip are the bunch number in the cesr, and injection pattern ! number, all referenced to 1. ! lin_cesr_delay is the location of the bunch in the linac in 14 ns units, ! referenced to 0. cbshft = csr_bkt_dly(ip - 1, 0, csrbunch)/3 lin_cesr_delay = mod(ib - 1 - 3*cbshft + 183, 183) return end integer*4 function csr_bkt_dly(t_ind, b_ind, param) ! ! This is the function that defines the cesr bunch structure. It gives ! the delay of bunch b_ind in train t_ind relative to bunch 1 in cesr. ! t_ind and b_ind are zero referenced, so that t_ind = 0 and b_ind = 0 ! represent the first bunch of the first train. This function is called ! by LDINIT and also the functions csr_bunchdelay and lin_bunchdelay ! below, and hence implicitly determines all of the bunch patterning ! except for patterns explicitly defined in timing .ctl files. ! tm, nt, nb, and ns are the train multiple, number of trains, number of ! bunches per train, and number of spaces between bunches. These four ! parameters are set by LDINIT when a configuration is restored. The ! train multiple tm determines the train spacing: If tm = N*nt, then the ! trains will be equally spaced, with any discrepancy after the last ! train. If tm = 183, then the trains will be quasi-unformly spaced, with ! any spacing discrepancy uniformly distributed among the train gaps. Any ! values of tm, nt, and nb are allowed, so in principal trains may wrap ! around the ring for special purposes. ! implicit none integer*4 param(20), t_ind, b_ind, tm, nt, nb, ns, np nt = param(2) ! number of trains nb = param(3) ! number of bunches per train ns = param(4) ! number of 14 ns buckets per bunch tm = param(5) ! train multiple np = param(15) ! number of injection patterns csr_bkt_dly = mod((tm*t_ind)/np + ns*b_ind, 183) return end !