DECLARE SUB calcave (totmag%, gl!(), tf!(), r!(), agl!(), atf!(), ar!()) DECLARE SUB calcstd (totmag%, gl!(), tf!(), r!(), agl!(), atf!(), ar!(), sgl!(), stf!(), sr!()) DECLARE SUB displayresults () DECLARE SUB getdmr (dmr$()) DECLARE SUB getgl (gl!(), stdgl!(), totmag%, mag%(), bc%()) DECLARE SUB getr (r!()) DECLARE SUB getspa2 (spa2!()) DECLARE SUB gettf (tf!(), stdtf!()) DECLARE SUB printresults (totmag%, agl!(), atf!(), ar!(), sgl!(), stf!(), sr!()) DECLARE SUB printupdate (totmag%, dmr$(), mag%(), bc%(), spa2!(), gl!(), stdgl!(), tf!(), stdtf!(), r!()) DECLARE SUB sort (totmag%, mag%()) DIM dmr$(120), mag%(120), bc%(120) DIM spa2!(120, 9), gl!(120, 9), stdgl!(120, 9), tf!(120, 9), stdtf!(120, 9) DIM r!(4 TO 16, 80, 9), ar!(4 TO 16, 9), sr!(4 TO 16, 9) DIM agl!(9), atf!(9), sgl!(9), stf!(9) 'Get the Date, Magnet #, and Run #'s.... CALL getdmr(dmr$()) 'Get the integrated gradient for all magnets at all currents... CALL getgl(gl!(), stdgl!(), totmag%, mag%(), bc%()) 'Get the Transfer Function for all magnets at all currents... CALL gettf(tf!(), stdtf!()) 'Get the quadrupole angle for all magnets at all currents... CALL getspa2(spa2!()) 'Get the magnetic center data delta x and delta y... 'CALL getxy(x!(), y!()) 'Get the Ratios for all magnets at all harmonics and currents... 'CALL getr(r!()) 'Calculate the averages and standard deviations... CALL calcave(totmag%, gl!(), tf!(), r!(), agl!(), atf!(), ar!()) CALL calcstd(totmag%, gl!(), tf!(), r!(), agl!(), atf!(), ar!(), sgl!(), stf!(), sr!()) 'Print out the results CALL printupdate(totmag%, dmr$(), mag%(), bc%(), spa2!(), gl!(), stdgl!(), tf!(), stdtf!(), r!()) CALL printresults(totmag%, agl!(), atf!(), ar!(), sgl!(), stf!(), sr!()) CALL displayresults END SUB calcave (totmag%, gl!(), tf!(), r!(), agl!(), atf!(), ar!()) DIM nzero%(20) 'Number of currents for integrated gradient and transfer function... ncur% = 7 'Calculate the average integrated gradient at each current... FOR i% = 1 TO ncur% nzero%(i%) = 0 FOR m% = 1 TO totmag% IF gl(m%, i%) = 0 THEN nzero%(i%) = nzero%(i%) + 1 ELSE agl!(i%) = agl!(i%) + gl(m%, i%) END IF NEXT NEXT FOR i% = 1 TO ncur% agl!(i%) = agl!(i%) / (totmag% - nzero%(i%)) NEXT 'Calculate the average transfer function at each current... FOR i% = 1 TO ncur% nzero%(i%) = 0 FOR m% = 1 TO totmag% IF tf(m%, i%) = 0 THEN nzero%(i%) = nzero%(i%) + 1 ELSE atf!(i%) = atf!(i%) + tf(m%, i%) END IF NEXT NEXT FOR i% = 1 TO ncur% atf!(i%) = atf!(i%) / (totmag% - nzero%(i%)) NEXT GOTO extcalcave 'Calculate the average ratios for each harmonic at each current... ncur% = 5 FOR h% = 4 TO 16 FOR i% = 1 TO ncur% FOR m% = 1 TO totmag% ar!(h%, i%) = ar!(h%, i%) + r(h%, m%, i%) NEXT NEXT NEXT FOR h% = 4 TO 16 FOR i% = 1 TO ncur% ar!(h%, i%) = ar!(h%, i%) / totmag% NEXT 'PRINT ar!(h%, 1), ar!(h%, 2), ar!(h%, 3) NEXT 'Calculate the average magnetic center delta x and delta y at each current... 'FOR i% = 1 TO ncur% ' FOR m% = 1 TO totmag% ' ax!(i%) = ax!(i%) + x(m%, i%) ' ay!(i%) = ay!(i%) + y(m%, i%) ' NEXT 'NEXT 'FOR i% = 1 TO ncur% ' ax!(i%) = ax!(i%) / totmag% ' ay!(i%) = ay!(i%) / totmag% 'NEXT extcalcave: END SUB SUB calcstd (totmag%, gl!(), tf!(), r!(), agl!(), atf!(), ar!(), sgl!(), stf!(), sr!()) DIM nzero%(20) 'Calculate standard deviation 1/(N-n) where n = ... n% = 0 'Number of currents for integrated gradient and transfer function... ncur% = 7 'Calculate the standard deviation of integrated gradient at each current... FOR i% = 1 TO ncur% nzero%(i%) = 0 FOR m% = 1 TO totmag% IF gl(m%, i%) = 0 THEN nzero%(i%) = nzero%(i%) + 1 ELSE sgl!(i%) = sgl!(i%) + (gl(m%, i%) - agl!(i%)) ^ 2 END IF NEXT NEXT FOR i% = 1 TO ncur% sgl!(i%) = SQR(sgl!(i%) / (totmag% - n% - nzero%(i%))) 'PRINT agl!(i%), sgl!(i%) NEXT 'Calculate the standard deviation of transfer function at each current... FOR i% = 1 TO ncur% nzero%(i%) = 0 FOR m% = 1 TO totmag% IF tf(m%, i%) = 0 THEN nzero%(i%) = nzero%(i%) + 1 ELSE stf!(i%) = stf!(i%) + (tf(m%, i%) - atf!(i%)) ^ 2 END IF NEXT NEXT FOR i% = 1 TO ncur% stf!(i%) = SQR(stf!(i%) / (totmag% - n% - nzero%(i%))) 'PRINT atf!(i%), stf!(i%) NEXT GOTO extcalstd 'Calculate the standard deviation of ratios for each harmonic at each current... ncur% = 5 FOR h% = 4 TO 16 FOR i% = 1 TO ncur% FOR m% = 1 TO totmag% sr!(h%, i%) = sr!(h%, i%) + (r(h%, m%, i%) - ar!(h%, i%)) ^ 2 NEXT NEXT NEXT FOR h% = 4 TO 16 FOR i% = 1 TO ncur% sr!(h%, i%) = SQR(sr!(h%, i%) / (totmag% - n%)) NEXT 'PRINT ar!(h%, 2), sr!(h%, 2) NEXT extcalstd: END SUB SUB displayresults CLS SHELL ("type ..\summary\update.txt | more") SHELL ("pause") CLS SHELL ("type ..\summary\summary.txt | more") PRINT PRINT "Would you like a printout of the update? [n]: "; INPUT resp$ IF resp$ = "y" THEN SHELL ("print ..\summary\update.txt | more") SHELL ("print ..\summary\summary.txt | more") END IF END SUB SUB getdmr (dmr$()) infile% = FREEFILE filein$ = "..\summary\gldate.txt" OPEN filein$ FOR INPUT AS infile% j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 LINE INPUT #infile%, tmpstr$ dmr$(j%) = MID$(tmpstr$, 1, 34) WEND CLOSE infile% END SUB SUB getgl (gl!(), stdgl!(), totmag%, mag%(), bc%()) 'Number of measurements... ncur% = 7 infile% = FREEFILE filein$ = "..\summary\gldate.txt" OPEN filein$ FOR INPUT AS infile% j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 INPUT #infile%, t1!, t2!, mag%(j%), bc%(j%), t3! FOR i% = 1 TO ncur% INPUT #infile%, gl!(j%, i%), stdgl!(j%, i%) NEXT WEND totmag% = j% CLOSE infile% END SUB SUB getr (r!()) 'Number of measurement currents... ncur% = 5 FOR h% = 4 TO 16 infile% = FREEFILE filein$ = "..\summary\blth" + LTRIM$(STR$(h%)) + ".txt" OPEN filein$ FOR INPUT AS infile% j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 INPUT #infile%, t1!, t2!, mag%, n%, t3! FOR i% = 1 TO ncur% INPUT #infile%, r(h%, j%, i%), t4!, t5!, t6! NEXT WEND CLOSE infile% NEXT END SUB SUB getspa2 (spa2!()) 'Number of measurements... ncur% = 5 infile% = FREEFILE filein$ = "..\summary\blth3.txt" OPEN filein$ FOR INPUT AS infile% j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 INPUT #infile%, t1!, t2!, mag%, n%, t3! FOR i% = 1 TO ncur% INPUT #infile%, spa2!(j%, i%), t4! NEXT WEND totmag% = j% CLOSE infile% END SUB SUB gettf (tf!(), stdtf!()) 'Number of measurement currents... ncur% = 7 infile% = FREEFILE filein$ = "..\summary\tfdate.txt" OPEN filein$ FOR INPUT AS infile% j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 INPUT #infile%, t1!, t2!, mag%, n%, t3! FOR i% = 1 TO ncur% INPUT #infile%, tf!(j%, i%), stdtf!(j%, i%) NEXT WEND CLOSE infile% END SUB SUB getxy (x!(), y!()) 'Number of measurement currents... ncur% = 9 'Get the magnetic center data delta x infile% = FREEFILE filein$ = "c:\philr\bfact\sext\summary\dxdate.txt" OPEN filein$ FOR INPUT AS infile% FOR i = 1 TO 7 LINE INPUT #infile%, tmpstr$ NEXT j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 INPUT #infile%, t1!, t2!, mag%, t3! FOR i% = 1 TO ncur% INPUT #infile%, x(j%, i%), t4! NEXT 'PRINT x(j%, 1), x(j%, 2), x(j%, 3) WEND CLOSE infile% 'Get the magnetic center data delta y infile% = FREEFILE filein$ = "c:\philr\bfact\sext\summary\dydate.txt" OPEN filein$ FOR INPUT AS infile% 'FOR i = 1 TO 7 ' LINE INPUT #infile%, tmpstr$ 'NEXT j% = 0 WHILE NOT EOF(infile%) j% = j% + 1 INPUT #infile%, t1!, t2!, mag%, t3! FOR i% = 1 TO ncur% INPUT #infile%, y(j%, i%), t4! NEXT 'PRINT y(j%, 1), y(j%, 2), y(j%, 3) WEND CLOSE infile% END SUB SUB printresults (totmag%, agl!(), atf!(), ar!(), sgl!(), stf!(), sr!()) 'Number of current for integrated gradient and transfer function... ncur% = 7 'Currents measurements made at... DIM mcur%(10) mcur%(1) = 25 mcur%(2) = 50 mcur%(3) = 100 mcur%(4) = 125 mcur%(5) = 150 mcur%(6) = 175 mcur%(7) = 200 'Print out results of integrated gradient and transfer function... outfile% = FREEFILE fileout$ = "..\summary\summary.txt" OPEN fileout$ FOR OUTPUT AS outfile% PRINT #outfile%, " " PRINT #outfile%, " B-Factory HER Sextupole Magnetic Measurement Summary" PRINT #outfile%, "" PRINT #outfile%, " "; DATE$ PRINT #outfile%, "" PRINT #outfile%, USING " Magnets Tested to Date ###"; totmag% PRINT #outfile%, "" PRINT #outfile%, " " PRINT #outfile%, " " PRINT #outfile%, " Integrated Gradient & Transfer Function " PRINT #outfile%, " " PRINT #outfile%, " Cur SL sSL SL/I sSL/I sSL/SL" PRINT #outfile%, " (A) (T/m) (T/m) (T/m/kA) (T/m/kA) (%)" PRINT #outfile%, " --- ------- ------- ------- ------ ----" FOR i% = 1 TO ncur% PRINT #outfile%, USING " ### ##.##### #.#####"; mcur%(i%); agl!(i%); sgl!(i%); PRINT #outfile%, USING " ###.#### #.#### #.##"; atf!(i%); stf!(i%); (stf!(i%) / atf!(i%)) * 100! NEXT PRINT #outfile%, " " CLOSE outfile% GOTO ext 'Print out results of harmonics... outfile% = FREEFILE fileout$ = "..\summary\summary.txt" OPEN fileout$ FOR APPEND AS outfile% PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, " Harmonics R(n) = BL(n)/BL2" PRINT #outfile%, "" PRINT #outfile%, " Harm 50A 150A 200A" PRINT #outfile%, " # R(n) sR(n) R(n) sR(n) R(n) sR(n)" PRINT #outfile%, " ---- ------ ------ ------ ------ ------ ------" ncur% = 5 mcur%(1) = 25 mcur%(2) = 50 mcur%(3) = 100 mcur%(4) = 150 mcur%(5) = 200 FOR h% = 4 TO 16 PRINT #outfile%, USING " ## "; h%; FOR i% = 1 TO ncur% IF (mcur%(i%) = 50 OR mcur%(i%) = 150 OR mcur%(i%) = 200) THEN PRINT #outfile%, USING " #.#### #.#### "; ar!(h%, i%); sr!(h%, i%); END IF NEXT PRINT #outfile%, " " NEXT CLOSE outfile% ext: END SUB SUB printupdate (totmag%, dmr$(), mag%(), bc%(), spa2!(), gl!(), stdgl!(), tf!(), stdtf!(), r!()) 'Sort the magnets... CALL sort(totmag%, bc%()) 'Print an update of magnets tested.... outfile% = FREEFILE fileout$ = "..\summary\update.txt" OPEN fileout$ FOR OUTPUT AS outfile% PRINT #outfile%, "" PRINT #outfile%, " B-Factory HER Sextupole Measurement Update" PRINT #outfile%, "" PRINT #outfile%, " "; DATE$ PRINT #outfile%, "" PRINT #outfile%, USING " Magnets Tested to Date ###"; totmag% PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, " "; FOR i% = 1 TO totmag% PRINT #outfile%, USING "### "; bc%(i%); IF (i% MOD 10 = 0) THEN PRINT #outfile%, " " PRINT #outfile%, " "; END IF NEXT PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, " Magnets as Tested by Date" PRINT #outfile%, " All Measurements @ 150A" PRINT #outfile%, "" PRINT #outfile%, "" PRINT #outfile%, " Date Time Mag BC Run SPA3 SL sSL SL/I sSL/I" PRINT #outfile%, " # # # (deg) (T/m) (T/m) (T/m/kA) (T/m/kA)" PRINT #outfile%, " -------- ----- --- --- --- ------ ------- ------- ------- -------" FOR i% = 1 TO totmag% PRINT #outfile%, USING "& ###.## ##.##### #.##### ###.#### ##.####"; dmr$(i%); spa2!(i%, 4); gl!(i%, 5); stdgl!(i%, 5); tf!(i%, 5); stdtf!(i%, 5) NEXT CLOSE outfile% END SUB SUB sort (totmag%, mag%()) 'Sort magnet numbers: CONST FALSE = 0, TRUE = -1 Exchange = TRUE 'Force first pass through the array. WHILE Exchange 'Sort until no elements are exchanged. Exchange = FALSE 'Compare the array elements by pairs. When two are exchanged, 'force another pass by setting Exchange to TRUE. FOR i = 2 TO totmag% IF mag%(i - 1) > mag%(i) THEN Exchange = TRUE SWAP mag%(i - 1), mag%(i) END IF NEXT WEND END SUB