DECLARE SUB quadcalcgl (nh%, fcoil!, vm!(), vp!(), v2!, gl!) DECLARE SUB quadcalchar (nh%, fcoil!, vm!(), vp!(), bl!(), th!(), r!()) DECLARE SUB quadcalcxy (nh%, bl!(), sbl!(), th!(), sth!(), x!, sx!, y!, sy!) DECLARE SUB quadimagloop () DECLARE SUB quadlogcalc (logfile$) DECLARE SUB quadloggl (logfile$, rcoil!, nturns%, nrot%, f!, v2!, gl!) DECLARE SUB quadlogglav (logfile$, rcoil!, nturns%, nrotave%, nmeasave%, gl!, sgl!) DECLARE SUB quadlogglvsi (logfile$, rcoil!, nturns%, nrot%, nmeas%, ni%, imag!(), simag!(), gl!(), sgl!(), tf!(), stf!()) DECLARE SUB quadloghar (logfile$, rcoil!, nturns%, nh%, fcoil!, vm!(), vp!(), bl!(), th!(), r!()) DECLARE SUB quadlogharav (logfile$, rcoil!, nturns%, nrot%, nmeas%, nh%, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) DECLARE SUB quadlogharvsi (logfile$, rcoil!, nturns%, nrot%, nmeas%, nh%, imag!, simag!, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) DECLARE SUB quadlognewpage (logfile$) DECLARE SUB quadlogxy (logfile$, th!(), x!, sx!, y!, sy!) DECLARE SUB quadmeasgl (gl!) DECLARE SUB quadmeasglav (gl!, sgl!) DECLARE SUB quadmeashar (nh%, bl!(), th!(), r!()) DECLARE SUB quadmeasharav (nh%, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) DECLARE SUB quadpltglvsi (logfile$, magname$, run$, ni%, imag!(), gl!(), sgl!(), tf!(), stf!()) DECLARE SUB quadpltharvsi (logfile$, magname$, run$, nh%, ni%, inom!(), rvsi!(), srvsi!()) DECLARE SUB coilmeas (nh%, f!, vm!(), vp!()) DECLARE SUB imagmeas (imag!, simag!) DECLARE SUB imagramp (inom!) '**************************************************************************** 'Module QUAD.BAS ' 'These subroutines perform calculations related to quadrupole magnet 'measurements. ' 'Zachary Wolf '1/2/95 '**************************************************************************** 'Open the parameter file REM $INCLUDE: 'param.inc' SUB quad '**************************************************************************** 'This subroutine controls the quadrupole magnetic measurements. ' 'Zachary Wolf '1/4/95 '**************************************************************************** 'Loop over test currents, measure gl and the harmonics CALL quadimagloop END SUB SUB quadcalcgl (nh%, fcoil!, vm!(), vp!(), v2!, gl!) '**************************************************************************** 'This subroutine calculates the integrated gradient. ' 'Input: ' nh%, the number of voltage harmonics recorded ' fcoil!, the coil rotation frequency (1/s) ' vm!(1 to nh%), the voltage magnitudes (V) ' vp!(1 to nh%), the voltage phases (deg) ' 'Output: ' v2!, the value of vm!(2), the voltage at the second harmonic ' gl!, the integrated gradient (T) ' 'Zachary Wolf '1/2/94 '**************************************************************************** 'Some Math 'v2 = Nturns * velocity * B2 * L ' = Nturns * Rcoil * ang_freq * gl * Rcoil ' = Nturns * Rcoil^2 * ang_freq * gl 'gl = v2 / (Nturns * Rcoil^2 * ang_freq) 'Simplify the notation pi! = 3.1415926# 'Coil parameters nturns% = nturnscoilP% rcoil! = rcoilP! 'Get V2 v2! = vm!(2) 'Compute GL gl! = v2! / (nturns% * rcoil! ^ 2 * 2! * pi! * fcoil!) END SUB SUB quadcalchar (nh%, fcoil!, vm!(), vp!(), bl!(), th!(), r!()) '**************************************************************************** 'This subroutine calculates the integrated field strength of each harmonic 'and the ratio of each harmonic strength to the quadrupole strength at the 'coil radius. It also calculates the angle of the first south pole of 'each harmonic field. ' 'Input: ' nh%, the number of voltage harmonics recorded ' fcoil!, the coil rotation frequency (1/s) ' vm!(1 to nh%), the voltage magnitudes (V) ' vp!(1 to nh%), the voltage phases (deg) ' 'Output: ' bl!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' th!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' r!(1 to nh%), the ratio bl(n)/bl(2) at rcoil ' 'Zachary Wolf '1/2/94 '**************************************************************************** 'Some Math 'Vn = Nturns * velocity * Bn * L ' = Nturns * Rcoil * ang_freq * (BLn) 'BLn = Vn / (Nturns * Rcoil * ang_freq) 'Rn = BLn / BL2 = Vn / V2 'TH 'Field expansion of intz(Br): BLr(r,th) = Sum BLrn(r,th) ' BLrn(r,th) = bln * r^(n-1) * cos(n*(th - THspole)) 'At the coil radius, BLrn(th) = BLn * cos(n*(th - THspole)) 'The coil voltage Vn(th) = Nturns * velocity * BLrn(th) ' = Nturns * Rcoil * 2pi * Freq * BLn * cos(n*(th - THspole)) 'The FFT gives Vn and PhiVn in the formula 'Vn(i) = Vn * cos(n*2pi*i/N + PhiVn), V(i) = Sum(Vn(i)) 'So, Nturns * Rcoil * 2pi * Freq * BLn = Vn ' -n * THspole = PhiVn 'Then, BLn = Vn / (Nturns * Rcoil * 2pi * Freq) ' THspole = -PhiVn / n 'Simplify the notation pi! = 3.1415926# 'Coil parameters nturns% = nturnscoilP% rcoil! = rcoilP! 'Compute the strength of each field harmonic at the coil radius FOR i% = 1 TO nh% bl!(i%) = vm!(i%) / (nturns% * rcoil! * 2! * pi! * fcoil!) NEXT i% 'Compute the angle of the first south pole wrt horizontal for each harmonic FOR i% = 1 TO nh% th!(i%) = -vp!(i%) / i% NEXT i% 'Compute the field strength ratios at the coil radius FOR i% = 1 TO nh% r!(i%) = vm!(i%) / vm!(2) NEXT i% END SUB SUB quadcalcxy (nh%, bl!(), sbl!(), th!(), sth!(), x!, sx!, y!, sy!) '**************************************************************************** 'This subroutine calculates the (x, y) position of the quadrupole magnetic 'center relative to the coil axis. X is horizontal to the right (viewed 'from the encoder end) and Y is up. ' 'Input: ' nh%, the number of voltage harmonics recorded ' bl!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' sbl!(1 to nh%), rms variation of bl ' th!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' sth!(1 to nh%), rms variation of th ' 'Output: ' x!, x coordinate of the magnetic center wrt the coil axis (m) ' sx!, calculated error for x ' y!, y coordinate of the magnetic center wrt the coil axis (m) ' sy!, calculated error for y ' 'Zachary Wolf '1/2/94 '**************************************************************************** 'Some Math 'Simplify the notation pi! = 3.1415926# 'Coil parameters rcoil! = rcoilP! 'Compute gl from bl(2) gl! = bl!(2) / rcoil! sgl! = sbl!(2) / rcoil! 'Compute the magnetic center relative to the coil 'For a normal quad (th(2) = 45 deg): x! = -(1! / gl!) * bl!(1) * SIN(th!(1) * pi! / 180!) y! = -(1! / gl!) * bl!(1) * COS(th!(1) * pi! / 180!) 'With the leads reversed, the signs change IF th!(2) < 0 THEN x! = -x! y! = -y! END IF 'Compute the error on the magnetic center sx! = ABS(x!) * SQR((sgl! / gl!) ^ 2 + (sbl!(1) / bl!(1)) ^ 2 + (COS(th!(1) * pi! / 180!) / (SIN(th!(1) * pi! / 180!) + .000001)) ^ 2 * (sth!(1) * pi! / 180!) ^ 2) sy! = ABS(y!) * SQR((sgl! / gl!) ^ 2 + (sbl!(1) / bl!(1)) ^ 2 + (SIN(th!(1) * pi! / 180!) / (COS(th!(1) * pi! / 180!) + .000001)) ^ 2 * (sth!(1) * pi! / 180!) ^ 2) END SUB SUB quadimagloop '**************************************************************************** 'This subroutine controls the magnetic measurements at various currents. ' 'Zachary Wolf '1/4/95 '**************************************************************************** 'Message PRINT PRINT "Beginning the magnetic field measurement cycle..." 'Simplify the notation ni% = nimagtestP% nh% = nhardisplayP% nih% = nimagharP% 'Initialize data arrays and counters ih% = 0 DIM imagvsi!(1 TO ni%) 'measured magnet current DIM simagvsi!(1 TO ni%) 'standard deviation of imag DIM glvsi!(1 TO ni%) 'integrated gradient at each current DIM sglvsi!(1 TO ni%) 'standard deviation of gl DIM tfvsi!(1 TO ni%) 'transfer function DIM stfvsi!(1 TO ni%) 'standard deviation of tf DIM bl!(1 TO nh%) 'field strength at Rcoil of the n'th harmonic DIM sbl!(1 TO nh%) 'standard deviation of Bn DIM th!(1 TO nh%) 'field angle DIM sth!(1 TO nh%) 'standard deviation of THn DIM r!(1 TO nh%) 'BLn/BL2 DIM sr!(1 TO nh%) 'standard deviation of r DIM rvsi!(1 TO nh%, 1 TO ni%) 'BLn/BL2 vs I DIM srvsi!(1 TO nh%, 1 TO ni%) 'standard deviation of BLn/BL2 vs I DIM inomhar!(1 TO ni%) 'nominal harmonics currents 'Loop over test currents FOR i% = 1 TO ni% 'Message PRINT PRINT "Ramping to "; imagtestP!(i%); " Amps..." 'Ramp to the desired current CALL imagramp(imagtestP!(i%)) 'Measure the current CALL imagmeas(imag!, simag!) 'GL 'Measure the integrated gradient CALL quadmeasglav(gl!, sgl!) 'Compute the transfer function tf! = gl! / imag! stf! = tf! * SQR((sgl! / gl!) ^ 2 + (simag! / imag!) ^ 2) 'Save the results for summaries and plots imagvsi!(i%) = imag! simagvsi!(i%) = simag! glvsi(i%) = gl! sglvsi(i%) = sgl! tfvsi!(i%) = tf! stfvsi!(i%) = stf! 'HARMONICS 'See if the harmonics are desired at this current har% = 0 FOR j% = 1 TO nih% IF imagharP!(j%) = imagtestP!(i%) THEN har% = 1 NEXT j% IF har% = 0 THEN GOTO skiphar 'not a harmonics current IF ih% >= nih% THEN GOTO skiphar 'measure only on upramp ih% = ih% + 1 'Measure the harmonics CALL quadmeasharav(nh%, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) 'Write the results to the harmonics dat file CALL quadlogharvsi(hardatP$, rcoilP!, nturnscoilP%, nrotaveP%, nmeasaveP%, nh%, imag!, simag!, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) 'Save the ratios for plotting inomhar!(ih%) = imagtestP!(i%) FOR j% = 1 TO nh% rvsi!(j%, ih%) = r!(j%) srvsi!(j%, ih%) = sr!(j%) NEXT j% 'Compute the location of the magnetic center CALL quadcalcxy(nh%, bl!(), sbl!(), th!(), sth!(), x!, sx!, y!, sy!) 'Record the magnetic center CALL quadlogxy(hardatP$, th!(), x!, sx!, y!, sy!) 'Come here to skip the harmonics measurement skiphar: 'End loop over currents NEXT i% 'GL data and plot files 'Write a summary of the results to the dat file and log file CALL quadlogglvsi(gldatP$, rcoilP!, nturnscoilP%, nrotaveP%, nmeasaveP%, ni%, imagvsi!(), simagvsi!(), glvsi!(), sglvsi!(), tfvsi!(), stfvsi!()) CALL quadlogglvsi(logfileP$, rcoilP!, nturnscoilP%, nrotaveP%, nmeasaveP%, ni%, imagvsi!(), simagvsi!(), glvsi!(), sglvsi!(), tfvsi!(), stfvsi!()) 'Write the results to the plotting file CALL quadpltglvsi(glpltP$, magnameP$, runP$, ni%, imagvsi!(), glvsi!(), sglvsi!(), tfvsi!(), stfvsi!()) 'Write a summary of the calculations to the dat file CALL quadlognewpage(gldatP$) CALL quadlogcalc(gldatP$) 'Harmonics data and plot files 'Plot the results CALL quadpltharvsi(harpltP$, magnameP$, runP$, nh%, ih%, inomhar!(), rvsi!(), srvsi!()) 'Write a summary of the calculations to the dat file CALL quadlognewpage(hardatP$) CALL quadlogcalc(hardatP$) 'Log file 'Write a summary of the calculations to the log file CALL quadlognewpage(logfileP$) CALL quadlogcalc(logfileP$) END SUB SUB quadlogcalc (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 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Header PRINT #filenum%, PRINT #filenum%, " SUMMARY OF THE CALCULATIONS AND CONVENTIONS USED" 'Summarize the calculations used for GL vs I PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation Of GL:" PRINT #filenum%, "V2 = Nturns * velocity * B2 * L" PRINT #filenum%, " = Nturns * Rcoil * ang_freq * GL * Rcoil" PRINT #filenum%, " = Nturns * Rcoil^2 * ang_freq * GL" PRINT #filenum%, "GL = V2 / (Nturns * Rcoil^2 * ang_freq)" 'Harmonics PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation Of The Harmonics:" PRINT #filenum%, "Magnitude, harmonic n:" PRINT #filenum%, "Vn = Nturns * velocity * Bn * L" PRINT #filenum%, " = Nturns * Rcoil * ang_freq * (BLn)" PRINT #filenum%, "BLn = Vn / (Nturns * Rcoil * ang_freq)" PRINT #filenum%, "Rn = BLn / BL2 = Vn / V2" PRINT #filenum%, PRINT #filenum%, "Phase, harmonic n:" PRINT #filenum%, "At the coil radius, the radial field as a function of angle is," PRINT #filenum%, "BLn(th) = BLn * cos(n*(th - THspole))" PRINT #filenum%, "The coil voltage Vn(th) = Nturns * velocity * BLn(th)" PRINT #filenum%, "Vn(th)= Nturns * Rcoil * ang_freq * BLn * cos(n*(th - THspole))" PRINT #filenum%, "The FFT gives Vn and PhiVn in the formula" PRINT #filenum%, "Vn(i) = Vn * cos(n*2pi*i/N + PhiVn)" PRINT #filenum%, "So, Nturns * Rcoil * ang_freq * BLn = Vn" PRINT #filenum%, " -n * THspole = PhiVn" PRINT #filenum%, "Or, BLn = Vn / (Nturns * Rcoil * ang_freq)" PRINT #filenum%, " THspole = -PhiVn / n" 'Magnetic center PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation Of The Magnetic Center:" PRINT #filenum%, "In the quadrupole's frame, Bx' = G * y', By' = G * x'." PRINT #filenum%, "In the coil's frame (unprimed frame) the magnetic center is at (x0, y0)." PRINT #filenum%, "In the coil's frame," PRINT #filenum%, " Bx = G * (y - y0), By = G * (x - x0)." PRINT #filenum%, "This gives the magnetic center in terms of the measured" PRINT #filenum%, "dipole field." PRINT #filenum%, " x0 = - By / G, y0 = - Bx / G" PRINT #filenum%, "In terms of the measured integrated strengths," PRINT #filenum%, " Xcenter = - (1/GL) * BL1 * sin(THspole1)" PRINT #filenum%, " Ycenter = - (1/GL) * BL1 * cos(THspole1)" 'Close the log file CLOSE filenum% END SUB SUB quadloggl (logfile$, rcoil!, nturns%, nrot%, f!, v2!, gl!) '**************************************************************************** 'This subroutine write a summary of a GL measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of coil rotations for average ' f!, the coil rotation frequency ' v2!, the voltage at the second rotation harmonic ' gl!, the integrated gradient at each current ' 'Zachary Wolf '8/15/94, 1/5/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, TIME$; " Integrated Gradient:" PRINT #filenum%, "Coil: Radius = "; rcoil!; " m,"; " # Turns = "; nturns% PRINT #filenum%, "Average, # Rotations/Measurement = "; nrot% PRINT #filenum%, "Coil Rotation Frequency, Fcoil = "; f!; " 1/s" PRINT #filenum%, "Coil Voltage, V2 = "; v2!; " V" PRINT #filenum%, "Integrated Gradient, GL = "; gl!; " T" 'Close the log file CLOSE filenum% END SUB SUB quadlogglav (logfile$, rcoil!, nturns%, nrotave%, nmeasave%, gl!, sgl!) '**************************************************************************** 'This subroutine write a summary of an average GL measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of turns on the coil ' nrotave%, the number of coil rotations for average ' nmeasave%, the number of measurements for the average and standard deviation ' gl!, the average of the integrated gradient measurements ' sgl!, the rms variation of GL ' 'Zachary Wolf '8/15/94, 1/3/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, TIME$; " Integrated Gradient Measurement:" PRINT #filenum%, "Coil: Radius = "; rcoil!; " m,"; " # Turns = "; nturns% PRINT #filenum%, "Average, # Rotations/Measurement = "; nrotave%; ", # Measurements = "; nmeasave% PRINT #filenum%, "Integrated Gradient, GL = "; gl!; " +- "; sgl!; " T" 'Close the log file CLOSE filenum% END SUB SUB quadlogglvsi (logfile$, rcoil!, nturns%, nrot%, nmeas%, ni%, imag!(), simag!(), gl!(), sgl!(), tf!(), stf!()) '**************************************************************************** 'This subroutine write a summary of the GL vs I measurements. ' 'Input: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of rotations for average ' nmeas%, the number of measurements for average and standard deviation ' ni%, the number of currents ' imag!(1 to ni%), the measured currents ' simag!(1 to ni%), the standard deviation of imag ' gl!(1 to ni%), the integrated gradient at each current ' sgl!(1 to ni%), the standard deviation of GL ' tf!(1 to ni%), GL/I ' stf!(1 to ni%), the standard deviation of TF ' 'Zachary Wolf '8/14/94, 1/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write a header for the hysteresis loop PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " INTEGRATED GRADIENT VS CURRENT" PRINT #filenum%, PRINT #filenum%, "Coil: Radius = "; rcoil!; " m,"; " # Turns = "; nturns% PRINT #filenum%, "Average: # Rotations/Measurement = "; nrot%; ", # Measurements = "; nmeas% PRINT #filenum%, PRINT #filenum%, " Imag sigImag GL sigGL GL/I sigGL/I " PRINT #filenum%, " (A) (A) (T) (T) (T/kA) (T/kA) " PRINT #filenum%, "--------+-------- --------+-------- --------+--------" 'Write the results FOR i% = 1 TO ni% PRINT #filenum%, USING "####.###"; imag!(i%); PRINT #filenum%, USING " ####.###"; simag!(i%); PRINT #filenum%, USING " ##.#####"; gl!(i%); PRINT #filenum%, USING " ##.#####"; sgl!(i%); PRINT #filenum%, USING " ###.####"; tf!(i%) * 1000!; PRINT #filenum%, USING " ###.####"; stf!(i%) * 1000! NEXT i% 'Close the log file CLOSE filenum% END SUB SUB quadloghar (logfile$, rcoil!, nturns%, nh%, fcoil!, vm!(), vp!(), bl!(), th!(), r!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rcoil!, coil radius ' nturns%, the number of turns on the coil ' nh%, the number of harmonics to print out ' fcoil!, the coil rotation frequency ' vm!(1 to nh%), voltage magnitudes ' vp!(1 to nh%), voltage phases ' bl!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' th!(1 TO nh%), field angle in degrees ' r!(1 TO nh%), BLn/BL2 ' 'Zachary Wolf '1/5/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, PRINT #filenum%, "Coil Radius, Rcoil = "; rcoil!; " m, # Turns, Nturns = "; nturns% PRINT #filenum%, "Coil Rotation Frequency, Fcoil = "; fcoil! PRINT #filenum%, PRINT #filenum%, " N Vm Vp BLn THspole BLn/BL2" PRINT #filenum%, " (V) (deg) (Tm) (deg) (%) " PRINT #filenum%, "--- ------- ------- ------- ------- -------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.####"; vm!(j%); PRINT #filenum%, USING " ####.##"; vp!(j%); PRINT #filenum%, USING " ##.####"; bl!(j%); PRINT #filenum%, USING " ####.##"; th!(j%); PRINT #filenum%, USING " ###.###"; r!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB quadlogharav (logfile$, rcoil!, nturns%, nrot%, nmeas%, nh%, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rcoil!, coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of rotations for average ' nmeas%, the number of measurements for average and standard deviation ' nh%, the number of harmonics to print out ' bl!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbl!(1 TO nh%), standard deviation of Bn ' th!(1 TO nh%), field angle in degrees ' sth!(1 TO nh%), standard deviation of THn ' r!(1 TO nh%), BLn/BL2 ' sr!(1 TO nh%), standard deviation of r ' '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%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, PRINT #filenum%, "Coil Radius, Rcoil = "; rcoil!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; nturns% PRINT #filenum%, "Average, # Rotations/Measurement = "; nrot%; ", # Measurements = "; nmeas% PRINT #filenum%, PRINT #filenum%, " N BLn sigBLn THspole sigTH BLn/BL2 sBLn/BL2" PRINT #filenum%, " (Tm) (Tm) (deg) (deg) (%) (%) " PRINT #filenum%, "--- --------+-------- --------+-------- --------+--------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.#####"; bl!(j%); PRINT #filenum%, USING " ##.#####"; sbl!(j%); PRINT #filenum%, USING " ####.##"; th!(j%); PRINT #filenum%, USING " ####.##"; sth!(j%); PRINT #filenum%, USING " ###.####"; r!(j%) * 100!; PRINT #filenum%, USING " ###.####"; sr!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB quadlogharvsi (logfile$, rcoil!, nturns%, nrot%, nmeas%, nh%, imag!, simag!, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rcoil!, coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of rotations for average ' nmeas%, the number of measurements for average and standard deviation ' nh%, the number of harmonics to print out ' imag!, the magnet current ' simag!, rms variation of imag measurements ' bl!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbl!(1 TO nh%), standard deviation of Bn ' th!(1 TO nh%), field angle in degrees ' sth!(1 TO nh%), standard deviation of THn ' r!(1 TO nh%), BLn/BL2 ' sr!(1 TO nh%), standard deviation of r ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Keep track of # times called STATIC ncall% ncall% = ncall% + 1 'On first call write title 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%, "Coil Radius, Rcoil = "; rcoil!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; nturns% PRINT #filenum%, "Average, # Rotations/Measurement = "; nrot%; ", # Measurements = "; nmeas% PRINT #filenum%, PRINT #filenum%, " N BLn sigBLn THspole sigTH BLn/BL2 sBLn/BL2" PRINT #filenum%, " (Tm) (Tm) (deg) (deg) (%) (%) " PRINT #filenum%, "--- --------+-------- --------+-------- --------+--------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.#####"; bl!(j%); PRINT #filenum%, USING " ##.#####"; sbl!(j%); PRINT #filenum%, USING " ####.##"; th!(j%); PRINT #filenum%, USING " ####.##"; sth!(j%); PRINT #filenum%, USING " ###.####"; r!(j%) * 100!; PRINT #filenum%, USING " ###.####"; sr!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB quadlognewpage (logfile$) '**************************************************************************** 'This subroutine writes a page break character to the log file. ' 'Inputs: ' logfile$, the name of the log file ' 'Zachary Wolf '8/20/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write a page break character PRINT #filenum%, CHR$(12) 'Close the log file CLOSE filenum% END SUB SUB quadlogxy (logfile$, th!(), x!, sx!, y!, sy!) '**************************************************************************** 'This subroutine writes the (x, y) location of the magnetic center 'relative to the coil to the log file. ' 'Input: ' logfile$, file to print results ' th!(1 to nh%), gives the orientation of the quadrupole field ' x!, x position of the magnetic center wrt the coil axis ' sx!, error on x ' y!, y position of the magnetic center wrt the coil axis ' sy!, error on y ' 'Zachary Wolf '1/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the magnetic center to the log file PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "The magnetic center is at" PRINT #filenum%, "X = "; PRINT #filenum%, USING "#####.#"; x! * 1000000!; PRINT #filenum%, " +- "; PRINT #filenum%, USING "#####.#"; sx! * 1000000!; PRINT #filenum%, " microns" PRINT #filenum%, "Y = "; PRINT #filenum%, USING "#####.#"; y! * 1000000!; PRINT #filenum%, " +- "; PRINT #filenum%, USING "#####.#"; sy! * 1000000!; PRINT #filenum%, " microns" PRINT #filenum%, PRINT #filenum%, "The magnetic center is measured relative to the coil axis" PRINT #filenum%, "effectively at the longitudinal center of the magnet." PRINT #filenum%, "Pitch and yaw are not seen by the coil." 'Print the following diagram PRINT #filenum%, PRINT #filenum%, "View from the non-lead end of the magnet:" PRINT #filenum%, IF th!(2) > 0 THEN PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N S " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " S N " ELSE PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S N " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " N S " END IF 'Close the log file CLOSE filenum% END SUB SUB quadmeasgl (gl!) '**************************************************************************** 'This subroutine performs one measurement of the integrated gradient. ' 'Output: ' gl!, the integrated gradient ' 'Zachary Wolf '1/4/95 '**************************************************************************** 'Simplify the notation nh% = nhardisplayP% 'Initialize data arrays DIM vm!(1 TO nh%) DIM vp!(1 TO nh%) 'Measure the coil voltage CALL coilmeas(nh%, fcoil!, vm!(), vp!()) 'Compute the integrated gradient CALL quadcalcgl(nh%, fcoil!, vm!(), vp!(), v2!, gl!) 'Log the result CALL quadloggl(logfileP$, rcoilP!, nturnscoilP%, nrotaveP%, fcoil!, v2!, gl!) END SUB SUB quadmeasglav (gl!, sgl!) '**************************************************************************** 'This subroutine performs multiple measurements and returns average values 'and rms variations. ' 'Output: ' gl!, the average integrated gradient ' sgl!, rms variation of gl ' 'Zachary Wolf '1/3/95 '**************************************************************************** 'Simplify the notation nm% = nmeasaveP% 'Initialize data arrays DIM glmeas!(1 TO nm%) 'Loop over the measurements FOR i% = 1 TO nm% 'Measure the integrated gradient CALL quadmeasgl(glmeas!(i%)) 'End the loop over the measurements NEXT i% 'Compute averages gl! = 0! FOR i% = 1 TO nm% gl! = gl! + glmeas!(i%) NEXT i% gl! = gl! / nm% 'Compute rms deviations sgl! = 0! FOR i% = 1 TO nm% sgl! = sgl! + (glmeas!(i%) - gl!) ^ 2 NEXT i% sgl! = SQR(sgl! / nm%) 'Print the results to the screen PRINT PRINT "Integrated Gradient:" PRINT "GL = "; gl!; " +- "; sgl!; " T" 'Write these results to the log file CALL quadlogglav(logfileP$, rcoilP!, nturnscoilP%, nrotaveP%, nmeasaveP%, gl!, sgl!) END SUB SUB quadmeashar (nh%, bl!(), th!(), r!()) '**************************************************************************** 'This subroutine performs one harmonics measurement. ' 'Input: ' nh%, the number of harmonics to record ' 'Output: ' bl!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' th!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' r!(1 to nh%), the ratio bl(n)/bl(2) at rcoil ' 'Zachary Wolf '1/4/95 '**************************************************************************** 'Initialize data arrays DIM vm!(1 TO nh%) DIM vp!(1 TO nh%) 'Measure the coil voltage CALL coilmeas(nh%, fcoil!, vm!(), vp!()) 'Compute the harmonics CALL quadcalchar(nh%, fcoil!, vm!(), vp!(), bl!(), th!(), r!()) 'Log the results CALL quadloghar(logfileP$, rcoilP!, nturnscoilP%, nh%, fcoil!, vm!(), vp!(), bl!(), th!(), r!()) END SUB SUB quadmeasharav (nh%, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) '**************************************************************************** 'This subroutine performs averave and rms harmonics measurements. ' 'Input: ' nh%, the number of harmonics to record ' 'Output: ' bl!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' sbl!(1 to nh%), rms variation of bl ' th!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' sth!(1 to nh%), rms variation of th ' r!(1 to nh%), the ratio bl(n)/bl(2) at rcoil ' sr!(1 to nh%), rms variation of r ' 'Zachary Wolf '1/4/95 '**************************************************************************** 'Simplify the notation nm% = nmeasaveP% 'Initialize data arrays DIM bl1!(1 TO nh%) DIM th1!(1 TO nh%) DIM r1!(1 TO nh%) DIM blmeas!(1 TO nh%, 1 TO nm%) DIM thmeas!(1 TO nh%, 1 TO nm%) DIM rmeas!(1 TO nh%, 1 TO nm%) 'Loop over the measurements FOR i% = 1 TO nm% 'Measure the harmonics CALL quadmeashar(nh%, bl1!(), th1!(), r1!()) 'Store the results FOR j% = 1 TO nh% blmeas!(j%, i%) = bl1!(j%) thmeas!(j%, i%) = th1!(j%) rmeas!(j%, i%) = r1!(j%) NEXT j% 'End the loop over the measurements NEXT i% 'Compute averages FOR j% = 1 TO nh% bl!(j%) = 0! th!(j%) = 0! r!(j%) = 0! FOR i% = 1 TO nm% bl!(j%) = bl!(j%) + blmeas!(j%, i%) th!(j%) = th!(j%) + thmeas!(j%, i%) r!(j%) = r!(j%) + rmeas!(j%, i%) NEXT i% bl!(j%) = bl!(j%) / nm% th!(j%) = th!(j%) / nm% r!(j%) = r!(j%) / nm% NEXT j% 'Compute rms deviations FOR j% = 1 TO nh% sbl!(j%) = 0! sth!(j%) = 0! sr!(j%) = 0! FOR i% = 1 TO nm% sbl!(j%) = sbl!(j%) + (blmeas!(j%, i%) - bl!(j%)) ^ 2 sth!(j%) = sth!(j%) + (thmeas!(j%, i%) - th!(j%)) ^ 2 sr!(j%) = sr!(j%) + (rmeas!(j%, i%) - r!(j%)) ^ 2 NEXT i% sbl!(j%) = SQR(sbl!(j%) / nm%) sth!(j%) = SQR(sth!(j%) / nm%) sr!(j%) = SQR(sr!(j%) / nm%) NEXT j% 'Print the results to the screen PRINT PRINT "Harmonics:" PRINT " N BLn sigBLn THspole sigTH BLn/BL2 sBLn/BL2" PRINT " (Tm) (Tm) (deg) (deg) (%) (%) " PRINT "--- --------+-------- --------+-------- --------+--------" IF nh% > 10 THEN nprint% = 10 ELSE nprint% = nh% FOR j% = 1 TO nprint% PRINT USING "###"; j%; PRINT USING " ##.#####"; bl!(j%); PRINT USING " ##.#####"; sbl!(j%); PRINT USING " ####.##"; th!(j%); PRINT USING " ####.##"; sth!(j%); PRINT USING " ###.####"; r!(j%) * 100!; PRINT USING " ###.####"; sr!(j%) * 100! NEXT j% 'Write the results to the log file CALL quadlogharav(logfileP$, rcoilP!, nturnscoilP%, nrotaveP%, nmeasaveP%, nh%, bl!(), sbl!(), th!(), sth!(), r!(), sr!()) END SUB SUB quadpltglvsi (logfile$, magname$, run$, ni%, imag!(), gl!(), sgl!(), tf!(), stf!()) '**************************************************************************** 'This subroutine write a summary of the GL vs I measurements for plotting. ' 'Input: ' logfile$, the name of the log file ' magname$, the magnet name ' run$, the run number ' ni%, the number of currents ' imag!(1 to ni%), the measured currents ' gl!(1 to ni%), the integrated gradient at each current ' sgl!(1 to ni%), the standard deviation of gl ' tf!(1 to ni%), the transfer function at each current ' stf!(1 to ni%), the standard deviation of tf ' 'Zachary Wolf '7/16/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the title for plotting PRINT #filenum%, "/et g '" + magname$ + ", Run " + run$ + "'" PRINT #filenum%, ";i gl sgl tf stf" 'Write the values FOR i% = 1 TO ni% PRINT #filenum%, USING "####.#"; imag!(i%); PRINT #filenum%, USING " ##.#####"; gl!(i%); PRINT #filenum%, USING " ##.#####"; sgl!(i%); PRINT #filenum%, USING " ###.#####"; tf!(i%); PRINT #filenum%, USING " ###.#####"; stf!(i%) NEXT i% 'Close the log file CLOSE filenum% END SUB SUB quadpltharvsi (logfile$, magname$, run$, nh%, ni%, inom!(), rvsi!(), srvsi!()) '**************************************************************************** 'This subroutine write a summary of the GL vs I measurements for plotting. ' 'Input: ' logfile$, the name of the log file ' magname$, the magnet name ' run$, the run number ' nh%, the number of harmonics to record ' ni%, the number of currents ' inom!(1 to ni%), the nominal currents the harmonics are measured at ' rvsi!(1 to nh%, 1 to ni%), BLn/BL2 vs n and I ' srvsi!(1 to nh%, 1 to ni%), standard deviation of rvsi! ' 'Zachary Wolf '8/16/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the title for plotting PRINT #filenum%, "/et g '" + magname$ + ", Run " + run$ + "'" PRINT #filenum%, ";n r sr r sr ... for different currents" 'Write the legends for the curves FOR i% = 1 TO ni% PRINT #filenum%, "/sa l 'I = "; PRINT #filenum%, USING "###"; inom!(i%); PRINT #filenum%, " A' " + STR$(2 * i%) NEXT i% 'Write the values FOR i% = 1 TO nh% PRINT #filenum%, USING "###"; i%; FOR j% = 1 TO ni% PRINT #filenum%, USING " ##.#####"; rvsi!(i%, j%); PRINT #filenum%, USING " ##.#####"; srvsi!(i%, j%); NEXT j% PRINT #filenum%, NEXT i% 'Close the log file CLOSE filenum% END SUB