DECLARE SUB vtgetvthar (rotdir$, nh%, harm!(), harp!()) DECLARE SUB blcalcbln (coilconfig$, nh%, vtm!(), vtp!(), bln!(), thn!()) DECLARE SUB blcheckpar (ok$) DECLARE SUB blgetbln (coilconfig$, nh%, bln!(), thn!()) DECLARE SUB bllogbln (logfile$, rotdir$) DECLARE SUB bllogblnav (logfile$, nh%, bln!(), sbln!(), thn!(), sthn!()) DECLARE SUB bllogcalcbln (logfile$, coilconfig$, rcoil!, nturns%, nh%, vtm!(), vtp!(), bf!(), bln!(), thn!()) DECLARE SUB bllogharmeas (logfile$) '**************************************************************************** 'Module HARMONIC.BAS ' 'These subroutines output the field harmonics from the BL(n) measurements. ' 'Zachary Wolf '5/3/95 '**************************************************************************** 'Put the module's parameters in a common block COMMON SHARED /blhar/ logfileP$, magnameP$, runP$, harcoilradiusmP!, harcoilnturnsP%, blnmeasaveP% SUB blcalcbln (coilconfig$, nh%, vtm!(), vtp!(), bln!(), thn!()) '**************************************************************************** 'This subroutine calculates the field harmonics from the integrated 'voltage harmonics. ' 'Input: ' coilconfig$, coil configuration, used for the bucking factors ' nh%, the number of harmonics to record ' vtm!(1 to nh%), integrated voltage harmonic magnitudes ' vtp!(1 to nh%), integrated voltage harmonic phases ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (Tm) ' thn!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' 'Zachary Wolf '9/2/96 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL blcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Some Math ' 'Field expansion (Bryant, CERN 92-05, p. 55) 'Br = Sum Bref (r / rref)^n-1 [-an cos(n th) + bn sin(n th)] 'Bt = Sum Bref (r / rref)^n-1 [ an sin(n th) + bn cos(n th)] 'For flux calculations, we re-express Bt 'Bt = - Sum Brefn (r / rref)^n-1 sin[n (th - THspole)] ' 'Flux from the origin to a wire bundle of N turns at R 'Flux = Int_0^R Bt L N dr ' = - Sum Brefn L N rref (1 / n) (R / rref)^n sin[n (th - THspole)] 'Fluxn = - Brefn L N rref (1 / n) (R / rref)^n sin[n (th - THspole)] ' 'Integrator output 'The integrated coil voltage VT is sampled and Fourier analyzed 'The FFT gives VTn and PhiVTn in the formula 'VTn(i) = VTn cos(n 2pi i / N + PhiVTn), VT(i) = Sum(VTn(i)) ' 'Equating the flux to the integrator output gives 'Brefn L N rref (1 / n) (R / rref)^n = VTn 'BLn |_rref = n VTn (rref / R)^n / (N rref) <<<--- ' '-sin[n (th - THspole)] = cos(n 2pi i / N + PhiVTn) ' = -sin(n th + PhiVTn - pi / 2) '- n THspole = PhiVTn - pi / 2 'THspole = - (PhiVTn - pi / 2) / n <<<--- 'For our planar bucking coil, we have: 'N turns at Rcoil (main winding) '2N turns at Rcoil/2 and -Rcoil/2 (quadrupole bucking) 'N turns at Rcoil/2 and -Rcoil/2 (dipole bucking) 'various return windings at R = 0 'The sin[n (th - THspole)] dependence must be included. 'At -R, sin[n (th + pi - THspole)] = cos(n pi) sin[n (th - THspole)] '= (-1)^n sin[n (th - THspole)]. 'VTn = BLn |_rref (rref / n) { N (Rcoil / rref)^n ' - 2N (Rcoil / 2 rref)^n - 2N (-Rcoil / 2 rref)^n ' - N (Rcoil / 2 rref)^n + N (-Rcoil / 2 rref)^n } 'Set rref = Rcoil 'VTn = BLn |_Rcoil (Rcoil / n) { N ' - 2N (1 / 2)^n - 2N (-1 / 2)^n ' - N (1 / 2)^n + N (-1 / 2)^n } 'VTn = BLn |_Rcoil (N Rcoil / n) { 1 ' - 2 (1 / 2)^n - 2 (-1 / 2)^n ' - (1 / 2)^n + (-1 / 2)^n } 'BLn |_Rcoil = VTn (n / N Rcoil) { 1 ' - 2 (1 / 2)^n - 2 (-1 / 2)^n ' - (1 / 2)^n + (-1 / 2)^n }^(-1) 'THspole = - (PhiVTn - pi / 2) / n 'Declare variables DIM bf!(1 TO nh%) 'Simplify the notation rcoil! = harcoilradiusmP! nturns% = harcoilnturnsP% 'Compute the strength of each field harmonic at the coil radius 'BLn |_Rcoil = VTn (n / N Rcoil) { 1 ' - 2 (1 / 2)^n - 2 (-1 / 2)^n ' - (1 / 2)^n + (-1 / 2)^n }^(-1) 'Compute the bucking factors FOR n% = 1 TO nh% bf!(n%) = 1! 'default IF coilconfig$ = "main" THEN bf!(n%) = 1! IF coilconfig$ = "dbuck" THEN bf!(n%) = 1! - (1! / 2!) ^ n% + (-1! / 2!) ^ n% IF coilconfig$ = "qbuck" THEN bf!(n%) = 1! - 2! * (1! / 2!) ^ n% - 2! * (-1! / 2!) ^ n% IF coilconfig$ = "dqbuck" THEN bf!(n%) = 1! - 2! * (1! / 2!) ^ n% - 2! * (-1! / 2!) ^ n% - (1! / 2!) ^ n% + (-1! / 2!) ^ n% NEXT n% FOR n% = 1 TO nh% IF bf!(n%) <> 0 THEN bln!(n%) = vtm!(n%) * n% / (nturns% * rcoil! * bf!(n%)) ELSE bln!(n%) = 0! END IF NEXT n% 'Compute the angle of the first south pole wrt horizontal for each harmonic 'THspole = - (PhiVTn - pi / 2) / n FOR n% = 1 TO nh% IF vtp!(n%) < 0! THEN vtp!(n%) = 360! + vtp!(n%) '(-180, 180) -> (0, 360) bphase! = vtp!(n%) - 90! IF bphase! > 180! THEN bphase! = -(360! - bphase!) 'undo (0, 360) conversion thn!(n%) = -bphase! / n% IF bf!(n%) = 0 THEN thn!(n%) = 0! NEXT n% 'Log the results CALL bllogcalcbln(logfileP$, coilconfig$, rcoil!, nturns%, nh%, vtm!(), vtp!(), bf!(), bln!(), thn!()) END SUB SUB blcalcratio (nh%, bln!(), sbln!(), nmain%, rn!(), srn!()) '**************************************************************************** 'This subroutine calculates the ratio of each harmonic strength to the 'strength of the main component at the coil radius. ' 'Input: ' nh%, the number of field harmonics recorded ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' sbln!(1 to nh%), the rms variation of bln ' 'Output: ' nmain%, the number of the main harmonic (1 = dipole, 2 = quad, etc.) ' rn!(1 to nh%), the ratio bl(n)/bl(nmain%) at the coil radius ' srn!(1 to nh%), the rms variation of rn ' 'Zachary Wolf '5/3/95 '**************************************************************************** 'Find the strongest field harmonic nmain% = 1 FOR i% = 1 TO nh% IF bln!(i%) > bln!(nmain%) THEN nmain% = i% NEXT i% 'Compute the field strength ratios at the coil radius FOR i% = 1 TO nh% rn!(i%) = bln!(i%) / bln!(nmain%) NEXT i% 'Compute the rms variation of the rn FOR i% = 1 TO nh% IF (bln!(i%) > 0) THEN srn!(i%) = rn!(i%) * SQR((sbln!(i%) / bln!(i%)) ^ 2 + (sbln!(nmain%) / bln!(nmain%)) ^ 2) ELSE srn!(i%) = 0! END IF NEXT i% 'Print the results to the screen PRINT PRINT " FIELD HARMONIC STRENGTH RATIOS" PRINT "Nmain = "; nmain% PRINT " n BLn sigBLn BLn/BLN sBLn/BLN" PRINT " (Tm) (Tm) (%) (%) " PRINT "--- ------------+------------ --------+--------" IF nh% > 10 THEN nprint% = 10 ELSE nprint% = nh% END IF FOR j% = 1 TO nprint% PRINT USING "###"; j%; PRINT USING " #.######^^^^"; bln!(j%); PRINT USING " #.######^^^^"; sbln!(j%); PRINT USING " ###.####"; rn!(j%) * 100!; PRINT USING " ###.####"; srn!(j%) * 100! NEXT j% END SUB SUB blcheckpar (ok$) '**************************************************************************** 'This subroutine checks that all required parameters have been assigned 'values. ' 'Output: ' ok$, "y" if parameter assignments are ok, "n" otherwise ' 'Zachary Wolf '9/18/95 '**************************************************************************** 'Default value ok$ = "n" 'Files IF logfileP$ = "" THEN PRINT "BLHAR: required file not defined" EXIT SUB END IF 'Runinfo IF magnameP$ = "" OR runP$ = "" THEN PRINT "BLHAR: required run parameter not defined" EXIT SUB END IF 'Coil IF harcoilradiusmP! <= 0 OR harcoilnturnsP% <= 0 THEN PRINT "BLHAR: required coil parameter not defined" EXIT SUB END IF 'Measurement parameters IF blnmeasaveP% <= 0 THEN PRINT "BLHAR: required measurement parameter not defined" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB bldatblhar (datfile$, nmain%, nh%, bln!(), sbln!(), thn!(), sthn!(), r!(), sr!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the data file. ' 'Inputs: ' datfile$, the name of the data file ' nmain%, the number of the main harmonic ' nh%, the number of harmonics to print out ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbln!(1 TO nh%), standard deviation of Bn ' thn!(1 TO nh%), field angle in degrees ' sthn!(1 TO nh%), standard deviation of THn ' r!(1 TO nh%), BLn/BLNmain ' sr!(1 TO nh%), standard deviation of r ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95, 5/7/95, 8/18/96 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN datfile$ FOR APPEND AS filenum% 'Keep track of # times called STATIC ncall% ncall% = ncall% + 1 'On the first call, write a title on the cover sheet IF ncall% = 1 THEN PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " Harmonics Measurements" END IF 'Start each measurement on a new page 'Write a page break character PRINT #filenum%, CHR$(12) 'Print a header PRINT #filenum%, "Date: "; DATE$ PRINT #filenum%, "Time: "; TIME$ PRINT #filenum%, "Magnet Name: "; magnameP$ PRINT #filenum%, "Run Number: "; runP$ 'Print the results PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, PRINT #filenum%, "Harmonics at Rcoil = "; harcoilradiusmP!; " m" PRINT #filenum%, "Nmain = "; nmain% PRINT #filenum%, PRINT #filenum%, " n BLn sigBLn THspole sigTH BLn/BLN sBLn/BLN " PRINT #filenum%, " (Tm) (Tm) (deg) (deg) (%) (%) " PRINT #filenum%, "--- ------------+------------ --------+-------- ---------+---------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " #.######^^^^"; bln!(j%); PRINT #filenum%, USING " #.######^^^^"; sbln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%); PRINT #filenum%, USING " ####.##"; sthn!(j%); PRINT #filenum%, USING " ###.#####"; r!(j%) * 100!; PRINT #filenum%, USING " ###.#####"; sr!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB bldatblvsihar (datfile$, imag!, simag!, nmain%, nh%, bln!(), sbln!(), thn!(), sthn!(), r!(), sr!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the data file. ' 'Inputs: ' datfile$, the name of the data file ' imag!, the magnet current ' simag!, rms variation of imag measurements ' nmain%, the number of the main harmonic ' nh%, the number of harmonics to print out ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbln!(1 TO nh%), standard deviation of Bn ' thn!(1 TO nh%), field angle in degrees ' sthn!(1 TO nh%), standard deviation of THn ' r!(1 TO nh%), BLn/BLNmain ' sr!(1 TO nh%), standard deviation of r ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95, 5/7/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN datfile$ FOR APPEND AS filenum% 'Keep track of # times called STATIC ncall% ncall% = ncall% + 1 'On the first call, write a title on the cover sheet IF ncall% = 1 THEN PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " Harmonics Measurements" END IF 'Start each measurement on a new page 'Write a page break character PRINT #filenum%, CHR$(12) 'Print a header PRINT #filenum%, "Date: "; DATE$ PRINT #filenum%, "Time: "; TIME$ PRINT #filenum%, "Magnet Name: "; magnameP$ PRINT #filenum%, "Run Number: "; runP$ 'Print the results PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, PRINT #filenum%, "Magnet Current, Imag = "; imag!; " +- "; simag!; " A" PRINT #filenum%, PRINT #filenum%, "Harmonics at Rcoil = "; harcoilradiusmP!; " m" PRINT #filenum%, "Nmain = "; nmain% PRINT #filenum%, PRINT #filenum%, " n BLn sigBLn THspole sigTH BLn/BLN sBLn/BLN " PRINT #filenum%, " (Tm) (Tm) (deg) (deg) (%) (%) " PRINT #filenum%, "--- ------------+------------ --------+-------- ---------+---------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " #.######^^^^"; bln!(j%); PRINT #filenum%, USING " #.######^^^^"; sbln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%); PRINT #filenum%, USING " ####.##"; sthn!(j%); PRINT #filenum%, USING " ###.#####"; r!(j%) * 100!; PRINT #filenum%, USING " ###.#####"; sr!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB blgetbln (coilconfig$, nh%, bln!(), thn!()) '**************************************************************************** 'This subroutine performs a measurement of the field harmonics in a magnet. ' 'Input: ' coilconfig$, coil configuration, used for bucking ' nh%, the number of harmonics to record ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (Tm) ' thn!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' 'Zachary Wolf '1/4/95, 5/3/95, 8/23/96 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL blcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Initialize data arrays DIM vtm!(1 TO nh%) DIM vtp!(1 TO nh%) DIM blnpos!(1 TO nh%) DIM thnpos!(1 TO nh%) DIM blnmin!(1 TO nh%) DIM thnmin!(1 TO nh%) 'Perform a measurement using + coil rotation rotdir$ = "+" 'Log the measurement CALL bllogbln(logfileP$, rotdir$) 'Measure the integrated voltage from the coil for + rotation CALL vtgetvthar(rotdir$, nh%, vtm!(), vtp!()) 'Calculate and log the field harmonics CALL blcalcbln(coilconfig$, nh%, vtm!(), vtp!(), blnpos!(), thnpos!()) 'Perform a measurement using - coil rotation rotdir$ = "-" 'Log the measurement CALL bllogbln(logfileP$, rotdir$) 'Measure the integrated voltage from the coil for - rotation CALL vtgetvthar(rotdir$, nh%, vtm!(), vtp!()) 'Calculate and log the field harmonics CALL blcalcbln(coilconfig$, nh%, vtm!(), vtp!(), blnmin!(), thnmin!()) 'Average the + and - rotation results FOR i% = 1 TO nh% bln!(i%) = (blnpos!(i%) + blnmin!(i%)) / 2! thn!(i%) = (thnpos!(i%) + thnmin!(i%)) / 2! NEXT i% END SUB SUB blgetblnav (coilconfig$, nh%, bln!(), sbln!(), thn!(), sthn!()) '**************************************************************************** 'This subroutine measures BLn several times and returns the average 'and rms variation. ' 'Input: ' coilconfig$, coil configuration, used for bucking factors ' nh%, the number of harmonics to record ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' sbln!(1 to nh%), rms variation of bl ' thn!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' sthn!(1 to nh%), rms variation of th ' 'Zachary Wolf '1/4/95, 5/5/95 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL blcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Log the measurement CALL bllogharmeas(logfileP$) 'Simplify the notation nm% = blnmeasaveP% 'Initialize data arrays DIM bln1!(1 TO nh%) DIM thn1!(1 TO nh%) DIM bln2!(1 TO nh%, 1 TO nm%) DIM thn2!(1 TO nh%, 1 TO nm%) 'Message about the measurement number PRINT PRINT "Performing harmonics measurement #"; 'Loop over the measurements FOR i% = 1 TO nm% 'Message about the measurement number PRINT USING " #"; i%; 'Measure BLn CALL blgetbln(coilconfig$, nh%, bln1!(), thn1!()) 'Store the results FOR j% = 1 TO nh% bln2!(j%, i%) = bln1!(j%) thn2!(j%, i%) = thn1!(j%) NEXT j% 'End the loop over the measurements NEXT i% 'End message info PRINT 'Compute averages FOR j% = 1 TO nh% bln!(j%) = 0! thn!(j%) = 0! FOR i% = 1 TO nm% bln!(j%) = bln!(j%) + bln2!(j%, i%) thn!(j%) = thn!(j%) + thn2!(j%, i%) NEXT i% bln!(j%) = bln!(j%) / nm% thn!(j%) = thn!(j%) / nm% NEXT j% 'Compute rms deviations FOR j% = 1 TO nh% sbln!(j%) = 0! sthn!(j%) = 0! FOR i% = 1 TO nm% sbln!(j%) = sbln!(j%) + (bln2!(j%, i%) - bln!(j%)) ^ 2 sthn!(j%) = sthn!(j%) + (thn2!(j%, i%) - thn!(j%)) ^ 2 NEXT i% sbln!(j%) = SQR(sbln!(j%) / nm%) sthn!(j%) = SQR(sthn!(j%) / nm%) NEXT j% 'Write the results to the log file CALL bllogblnav(logfileP$, nh%, bln!(), sbln!(), thn!(), sthn!()) END SUB SUB bllogbln (logfile$, rotdir$) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rotdir$, rotation direction ' 'Zachary Wolf '1/5/95, 5/3/95, 9/1/96 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, TIME$; " FIELD HARMONICS MEASUREMENT **********" PRINT #filenum%, " Rotation Direction = "; rotdir$ 'Close the log file CLOSE filenum% END SUB SUB bllogblnav (logfile$, nh%, bln!(), sbln!(), thn!(), sthn!()) '**************************************************************************** 'This subroutine writes the average and rms BLn measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' nh%, the number of harmonics to print out ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbln!(1 TO nh%), standard deviation of Bn ' thn!(1 TO nh%), field angle in degrees ' sthn!(1 TO nh%), standard deviation of THn ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, TIME$; " AVERAGE FIELD HARMONICS" PRINT #filenum%, " Harmonics at Rcoil = "; harcoilradiusmP!; " m" PRINT #filenum%, " n BLn sigBLn THspole sigTH " PRINT #filenum%, " (Tm) (Tm) (deg) (deg) " PRINT #filenum%, " --- ------------+------------ --------+--------" FOR j% = 1 TO nh% PRINT #filenum%, USING " ###"; j%; PRINT #filenum%, USING " #.######^^^^"; bln!(j%); PRINT #filenum%, USING " #.######^^^^"; sbln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%); PRINT #filenum%, USING " ####.##"; sthn!(j%) NEXT j% 'Close the log file CLOSE filenum% END SUB SUB bllogcalc (logfile$) '**************************************************************************** 'This subroutine summarizes the calculations used in the program. ' 'Inputs: ' logfile$, the name of the log file ' 'Zachary Wolf '9/22/94, 12/3/94, 5/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Summarize the calculations on a new page 'Write a page break character PRINT #filenum%, CHR$(12) 'Header PRINT #filenum%, PRINT #filenum%, " SUMMARY OF THE CALCULATIONS AND CONVENTIONS USED" 'Field expansion PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Field expansion (Bryant, CERN 92-05, p. 55)" PRINT #filenum%, "Br = Sum Bref (r / rref)^n-1 [-an cos(n th) + bn sin(n th)]" PRINT #filenum%, "Bt = Sum Bref (r / rref)^n-1 [ an sin(n th) + bn cos(n th)]" PRINT #filenum%, "For flux calculations, we re-express Bt" PRINT #filenum%, "Bt = - Sum Brefn (r / rref)^n-1 sin[n (th - THspole)]" PRINT #filenum%, PRINT #filenum%, "Flux from the origin to a wire bundle of N turns at R" PRINT #filenum%, "Flux = Int_0^R Bt L N dr" PRINT #filenum%, " = - Sum Brefn L N rref (1 / n) (R / rref)^n sin[n (th - THspole)]" PRINT #filenum%, "Fluxn = - Brefn L N rref (1 / n) (R / rref)^n sin[n (th - THspole)]" PRINT #filenum%, PRINT #filenum%, "Integrator output" PRINT #filenum%, "The integrated coil voltage VT is sampled and Fourier analyzed" PRINT #filenum%, "The FFT gives VTn and PhiVTn in the formula" PRINT #filenum%, "VTn(i) = VTn cos(n 2pi i / N + PhiVTn), VT(i) = Sum(VTn(i))" PRINT #filenum%, PRINT #filenum%, "Equating the flux to the integrator output gives" PRINT #filenum%, "Brefn L N rref (1 / n) (R / rref)^n = VTn" PRINT #filenum%, "BLn |_rref = n VTn (rref / R)^n / (N rref) <<<---" PRINT #filenum%, PRINT #filenum%, "-sin[n (th - THspole)] = cos(n 2pi i / N + PhiVTn)" PRINT #filenum%, " = -sin(n th + PhiVTn - pi / 2)" PRINT #filenum%, "- n THspole = PhiVTn - pi / 2" PRINT #filenum%, "THspole = - (PhiVTn - pi / 2) / n <<<---" PRINT #filenum%, PRINT #filenum%, "For our planar bucking coil, we have:" PRINT #filenum%, "N turns at Rcoil (main winding)" PRINT #filenum%, "2N turns at Rcoil/2 and -Rcoil/2 (quadrupole bucking)" PRINT #filenum%, "N turns at Rcoil/2 and -Rcoil/2 (dipole bucking)" PRINT #filenum%, "various return windings at R = 0" PRINT #filenum%, "The sin[n (th - THspole)] dependence must be included." PRINT #filenum%, "At -R, sin[n (th + pi - THspole)] = cos(n pi) sin[n (th - THspole)]" PRINT #filenum%, "= (-1)^n sin[n (th - THspole)]." PRINT #filenum%, "VTn = BLn |_rref (rref / n) { N (Rcoil / rref)^n" PRINT #filenum%, " - 2N (Rcoil / 2 rref)^n - 2N (-Rcoil / 2 rref)^n" PRINT #filenum%, " - N (Rcoil / 2 rref)^n + N (-Rcoil / 2 rref)^n }" PRINT #filenum%, "Set rref = Rcoil" PRINT #filenum%, "VTn = BLn |_Rcoil (Rcoil / n) { N" PRINT #filenum%, " - 2N (1 / 2)^n - 2N (-1 / 2)^n" PRINT #filenum%, " - N (1 / 2)^n + N (-1 / 2)^n }" PRINT #filenum%, "VTn = BLn |_Rcoil (N Rcoil / n) { 1" PRINT #filenum%, " - 2 (1 / 2)^n - 2 (-1 / 2)^n" PRINT #filenum%, " - (1 / 2)^n + (-1 / 2)^n }" PRINT #filenum%, "BLn |_Rcoil = VTn (n / N Rcoil) { 1" PRINT #filenum%, " - 2 (1 / 2)^n - 2 (-1 / 2)^n" PRINT #filenum%, " - (1 / 2)^n + (-1 / 2)^n }^(-1)" PRINT #filenum%, "THspole = - (PhiVTn - pi / 2) / n" 'Harminic strength ratios PRINT #filenum%, PRINT #filenum%, "Harmonic Strength Ratios:" PRINT #filenum%, "The main field, denoted by capital N, is the field harmonic" PRINT #filenum%, "with the largest strength at the coil radius." PRINT #filenum%, "The field strength ratio is defined by" PRINT #filenum%, " Rn = BLn / BLN" PRINT #filenum%, "It gives the ratio of each harmonic field strength to the" PRINT #filenum%, "main field strength at the coil radius." 'Close the log file CLOSE filenum% END SUB SUB bllogcalcbln (logfile$, coilconfig$, rcoil!, nturns%, nh%, vtm!(), vtp!(), bf!(), bln!(), thn!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' coilconfig$, coil configuration ' rcoil!, the coil radius ' nturns%, the number of coil turns ' nh%, the number of harmonics to print out ' vtm!(1 to nh%), integrated voltage magnitudes ' vtp!(1 to nh%), integrated voltage phases ' bf!(1 to nh%), bucking factors ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' thn!(1 TO nh%), field angle in degrees ' 'Zachary Wolf '1/5/95, 5/3/95, 9/1/96 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, TIME$; " FIELD HARMONICS CALCULATION" PRINT #filenum%, " Coil Radius, Rcoil = "; rcoil!; " m" PRINT #filenum%, " # Turns, Nturns = "; nturns% PRINT #filenum%, " Coil Configuration: "; coilconfig$ PRINT #filenum%, " n VTm VTp Bucking BLn THspole" PRINT #filenum%, " (Vs) (deg) Factor (Tm) (deg) " PRINT #filenum%, " --- ------------ ------- --------- ------------ -------" FOR j% = 1 TO nh% PRINT #filenum%, USING " ###"; j%; PRINT #filenum%, USING " #.######^^^^"; vtm!(j%); PRINT #filenum%, USING " ####.##"; vtp!(j%); PRINT #filenum%, USING " #.#######"; bf!(j%); PRINT #filenum%, USING " #.######^^^^"; bln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%) NEXT j% 'Close the log file CLOSE filenum% END SUB SUB bllogharmeas (logfile$) '**************************************************************************** 'This subroutine records a measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' 'Zachary Wolf '11/25/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, TIME$; " Harmonics Measurement..." 'Close the log file CLOSE filenum% END SUB SUB blngetcoilradius (rcoil!) '**************************************************************************** 'This subroutine returns the coil radius. ' 'Output: ' rcoil!, coil radius in meters ' 'Zachary Wolf '10/28/96 '**************************************************************************** 'Return the coil radius rcoil! = harcoilradiusmP! END SUB SUB blpltblhar (pltfile$, nh%, rn!(), srn!()) '**************************************************************************** 'This subroutine writes a summary of the field ratio measurements for plotting. ' 'Input: ' pltfile$, the name of the plot file ' nh%, the number of harmonics to record ' rn!(1 to nh%), BLn/BLNmain ' srn!(1 to nh%), standard deviation of rn! ' 'Zachary Wolf '8/16/94, 5/6/95, 8/18/96 '**************************************************************************** 'Keep track of Ncall for handling the output STATIC ncall% ncall% = ncall% + 1 'Open the plot file pltnum% = FREEFILE OPEN pltfile$ FOR INPUT AS pltnum% 'Open the temp file tempnum% = FREEFILE OPEN "hartemp.dat" FOR OUTPUT AS tempnum% 'On the first call, write the entire file IF ncall% = 1 THEN 'Header PRINT #tempnum%, "/et g '" + magnameP$ + ", Run " + runP$ + "'" PRINT #tempnum%, ";n r sr r sr ..." 'Write the values FOR i% = 1 TO nh% PRINT #tempnum%, USING "###"; i%; PRINT #tempnum%, USING " ##.########"; rn!(i%); PRINT #tempnum%, USING " ##.########"; srn!(i%) NEXT i% END IF 'On calls after the first, append the data IF ncall% > 1 THEN 'Find the harmonics lines, copy lines before the harmonics harmonic$ = "" DO UNTIL harmonic$ = " 1" LINE INPUT #pltnum%, pltline$ harmonic$ = LEFT$(pltline$, 3) IF harmonic$ <> " 1" THEN PRINT #tempnum%, pltline$ LOOP 'Write the values PRINT #tempnum%, pltline$; PRINT #tempnum%, USING " ##.########"; rn!(1); PRINT #tempnum%, USING " ##.########"; srn!(1) FOR i% = 2 TO nh% LINE INPUT #pltnum%, pltline$ PRINT #tempnum%, pltline$; PRINT #tempnum%, USING " ##.########"; rn!(i%); PRINT #tempnum%, USING " ##.########"; srn!(i%) NEXT i% END IF 'Close the plot file CLOSE pltnum% 'Close the temp file CLOSE tempnum% 'Replace the plot file with the temp file SHELL "copy hartemp.dat " + pltfile$ 'Delete the temp file SHELL "del hartemp.dat" END SUB SUB blpltblvsihar (pltfile$, legend$, nh%, rn!(), srn!()) '**************************************************************************** 'This subroutine writes a summary of the field ratio measurements for plotting. ' 'Input: ' pltfile$, the name of the plot file ' legend$, the legend for the rn data ' nh%, the number of harmonics to record ' rn!(1 to nh%), BLn/BLNmain ' srn!(1 to nh%), standard deviation of rn! ' 'Zachary Wolf '8/16/94, 5/6/95 '**************************************************************************** 'Keep track of Ncall for handling the output STATIC ncall% ncall% = ncall% + 1 'Open the plot file pltnum% = FREEFILE OPEN pltfile$ FOR INPUT AS pltnum% 'Open the temp file tempnum% = FREEFILE OPEN "hartemp.dat" FOR OUTPUT AS tempnum% 'On the first call, write the entire file IF ncall% = 1 THEN 'Header PRINT #tempnum%, "/et g '" + magnameP$ + ", Run " + runP$ + "'" PRINT #tempnum%, ";n r sr r sr ... for different currents" 'Legend for the first curve PRINT #tempnum%, "/sa l '" + legend$ + "' 2" 'Write the values FOR i% = 1 TO nh% PRINT #tempnum%, USING "###"; i%; PRINT #tempnum%, USING " ##.#####"; rn!(i%); PRINT #tempnum%, USING " ##.#####"; srn!(i%) NEXT i% END IF 'On calls after the first, append the data IF ncall% > 1 THEN 'Find the harmonics lines, copy lines before the harmonics harmonic$ = "" DO UNTIL harmonic$ = " 1" LINE INPUT #pltnum%, pltline$ harmonic$ = LEFT$(pltline$, 3) IF harmonic$ <> " 1" THEN PRINT #tempnum%, pltline$ LOOP 'Legend for the new curve PRINT #tempnum%, "/sa l '" + legend$ + "' " + LTRIM$(STR$(2 * ncall%)) 'Write the values PRINT #tempnum%, pltline$; PRINT #tempnum%, USING " ##.#####"; rn!(1); PRINT #tempnum%, USING " ##.#####"; srn!(1) FOR i% = 2 TO nh% LINE INPUT #pltnum%, pltline$ PRINT #tempnum%, pltline$; PRINT #tempnum%, USING " ##.#####"; rn!(i%); PRINT #tempnum%, USING " ##.#####"; srn!(i%) NEXT i% END IF 'Close the plot file CLOSE pltnum% 'Close the temp file CLOSE tempnum% 'Replace the plot file with the temp file SHELL "copy hartemp.dat " + pltfile$ 'Delete the temp file SHELL "del hartemp.dat" END SUB SUB blsetpar (logfile$, magname$, run$, harcoilradiusm!, harcoilnturns%, blnmeasave%) '**************************************************************************** 'This subroutine sets the parameters required by this module. ' 'Input: ' logfile$, path and name of the log file ' magname$, magnet name ' run$, run number ' harcoilradiusm!, coil radius in meters ' harcoilnturns%, coil number of turns ' blnmeasave%, number of BLn measurements for averaging ' 'Zachary Wolf '11/20/95 '**************************************************************************** 'Assign values to the parameters logfileP$ = logfile$ magnameP$ = magname$ runP$ = run$ harcoilradiusmP! = harcoilradiusm! harcoilnturnsP% = harcoilnturns% blnmeasaveP% = blnmeasave% END SUB