DECLARE SUB bllogharmeas (logfile$) DECLARE SUB vcoilgetf (f!) DECLARE SUB vcoilgetvhar (coilid%, nh%, harm!(), harp!()) DECLARE SUB blgetbln (nh%, bln!(), thn!()) DECLARE SUB bllogbln (logfile$, rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) DECLARE SUB bllogblnav (logfile$, nh%, bln!(), sbln!(), thn!(), sthn!()) DECLARE SUB blcheckpar (ok$) '**************************************************************************** '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$, harcoilidP%, harcoilradiusmP!, harcoilnturnsP%, blnmeasaveP% 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% srn!(i%) = rn!(i%) * SQR((sbln!(i%) / bln!(i%)) ^ 2 + (sbln!(nmain%) / bln!(nmain%)) ^ 2) 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 harcoilidP% <= 0 OR 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$, 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%, IF imag! >= 0! THEN PRINT #filenum%, "Magnet Current, Imag = "; imag!; " +- "; simag!; " A" END IF 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 bldatview (logfile$, nmain%, thsp!, viewdir$) '**************************************************************************** 'This subroutine makes a picture of the main multipole field configuration 'as viewed from the lead or non-lead end of the magnet. ' 'Input: ' logfile$, file to print results ' nmain%, main harmonic number ' thsp!, angle of the first south pole (deg) ' viewdir$, view direction ' 'Zachary Wolf '9/25/97 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Explanation of picture PRINT #filenum%, IF viewdir$ = "LEADEND" THEN PRINT #filenum%, "View from the lead end of the magnet:" ELSEIF viewdir$ = "NONLEADEND" THEN PRINT #filenum%, "View from the non-lead end of the magnet:" ELSE PRINT PRINT "BLDATVIEW: unknown view direction, exiting..." EXIT SUB END IF 'Dipoles 'Skew dipole at 180 deg IF nmain% = 1 AND (thsp! > 135! OR thsp! < -135!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S N " PRINT #filenum%, PRINT #filenum%, " S N --> x " PRINT #filenum%, PRINT #filenum%, " S N " 'Normal dipole at 90 deg ELSEIF nmain% = 1 AND (thsp! <= 135! AND thsp! >= 45!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S S S " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " N N N " 'Skew dipole at 0 deg ELSEIF nmain% = 1 AND (thsp! < 45! AND thsp! > -45!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N S " PRINT #filenum%, PRINT #filenum%, " N S --> x " PRINT #filenum%, PRINT #filenum%, " N S " 'Normal dipole at -90 deg ELSEIF nmain% = 1 AND (thsp! <= -45! AND thsp! >= -135!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N N N " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " S S S " 'Quadrupoles 'Skew quadrupole at 90 deg ELSEIF nmain% = 2 AND (thsp! > 60! OR thsp! < -60!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S " PRINT #filenum%, PRINT #filenum%, " N N --> x " PRINT #filenum%, PRINT #filenum%, " S " 'Normal quadrupole at 45 deg ELSEIF nmain% = 2 AND (thsp! <= 60! AND thsp! >= 20!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N S " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " S N " 'Skew quadrupole at 0 deg ELSEIF nmain% = 2 AND (thsp! < 20 AND thsp! > -20!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N " PRINT #filenum%, PRINT #filenum%, " S S --> x " PRINT #filenum%, PRINT #filenum%, " N " 'Normal quadrupole at -45 deg ELSEIF nmain% = 2 AND (thsp! >= -60 AND thsp! <= -20!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S N " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " N S " 'Sextupoles 'Skew sextupole at 60 deg ELSEIF nmain% = 3 AND (thsp! > 50! OR thsp! < -50!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N S " PRINT #filenum%, " " PRINT #filenum%, " S N --> x " PRINT #filenum%, " " PRINT #filenum%, " N S " 'Normal sextupole at 30 deg ELSEIF nmain% = 3 AND (thsp! <= 50! AND thsp! >= 10!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N " PRINT #filenum%, " S S " PRINT #filenum%, " --> x " PRINT #filenum%, " N N " PRINT #filenum%, " S " 'Skew sextupole at 0 deg ELSEIF nmain% = 3 AND (thsp! < 10! AND thsp! > -10!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S N " PRINT #filenum%, " " PRINT #filenum%, " N S --> x " PRINT #filenum%, " " PRINT #filenum%, " S N " 'Normal sextupole at -60 deg ELSEIF nmain% = 3 AND (thsp! <= -10! AND thsp! >= -50!) THEN PRINT #filenum%, PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S " PRINT #filenum%, " N N " PRINT #filenum%, " --> x " PRINT #filenum%, " S S " PRINT #filenum%, " N " 'Unknown pole configuration ELSE 'Don't print anything END IF 'Close the log file CLOSE filenum% END SUB SUB blgetbln (nh%, bln!(), thn!()) '**************************************************************************** 'This subroutine performs a measurement of the field harmonics in a magnet. ' 'Input: ' nh%, the number of harmonics to record ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' 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 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL blcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Some Math, single coil, no bucking 'BL 'Vn = Nturns * velocity * Bn * L ' = Nturns * Rcoil * ang_freq * (BLn) 'BLn = Vn / (Nturns * Rcoil * ang_freq) '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 coilid% = harcoilidP% rcoil! = harcoilradiusmP! nturns% = harcoilnturnsP% pi! = 3.1415926# 'Initialize data arrays DIM vm!(1 TO nh%) DIM vp!(1 TO nh%) 'Measure the coil rotation frequency CALL vcoilgetf(f1!) SLEEP 1 CALL vcoilgetf(f2!) 'Measure the coil voltage CALL vcoilgetvhar(coilid%, nh%, vm!(), vp!()) 'Measure the coil rotation frequency again after the coil voltage CALL vcoilgetf(f3!) 'Compute the average of the coil rotation frequency measurements fcoil! = (f1! + f2! + f3!) / 3! 'Compute the strength of each field harmonic at the coil radius FOR i% = 1 TO nh% bln!(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% thn!(i%) = -vp!(i%) / i% NEXT i% 'Log the results CALL bllogbln(logfileP$, rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) END SUB SUB blgetblnav (nh%, bln!(), sbln!(), thn!(), sthn!()) '**************************************************************************** 'This subroutine measures BLn several times and returns the average 'and rms variation. ' 'Input: ' 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(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$, rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of coil turns ' fcoil!, the coil rotation frequency ' nh%, the number of harmonics to print out ' vm!(1 to nh%), voltage magnitudes ' vp!(1 to nh%), voltage phases ' 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 '**************************************************************************** '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 Rotation Frequency, Fcoil = "; fcoil!; " Hz" PRINT #filenum%, " n Vm Vp BLn THspole" 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 " ##.########"; bln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%) NEXT j% '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% 'Header PRINT #filenum%, PRINT #filenum%, " SUMMARY OF THE CALCULATIONS AND CONVENTIONS USED" 'Field expansion PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Field Expansion:" PRINT #filenum%, "The expansion of the radial and azimuthal field in polar" PRINT #filenum%, "coordinates is" PRINT #filenum%, " Br(r,th) = Sum Bn (r/rref)^(n-1) cos(n(th-thspole))" PRINT #filenum%, " Bth(r,th) = -Sum Bn (r/rref)^(n-1) sin(n(th-thspole))" PRINT #filenum%, "Our convention is to set rref = Rcoil." PRINT #filenum%, "Thspole is the angle of the first magnetic south pole" PRINT #filenum%, "with respect to the horizontal, measured ccw by a shaft" PRINT #filenum%, "encoder in the system." PRINT #filenum%, PRINT #filenum%, "Coil Voltage:" PRINT #filenum%, "The coil voltage from each field harmonic is" PRINT #filenum%, " Vn(th) = Nturns * velocity * Brn(Rcoil,th) * L" PRINT #filenum%, "L is the magnet effective length, or BLn is the integrated" PRINT #filenum%, "field strength of the n'th harmonic." PRINT #filenum%, "At the coil radius, the radial field as a function of angle is," PRINT #filenum%, " Brn(Rcoil,th) * L = BLn * cos(n*(th - thspole))" PRINT #filenum%, "The coil voltage is" PRINT #filenum%, " Vn(th) = Nturns * velocity * BLn * cos(n*(th - thspole))" PRINT #filenum%, " = Nturns * Rcoil * ang_freq * BLn * cos(n*(th - THspole))" PRINT #filenum%, "An FFT of the coil voltage gives Vn and PhiVn according to the formula" PRINT #filenum%, " Vn(i) = Vn * cos(n*2pi*i/N + PhiVn)" PRINT #filenum%, PRINT #filenum%, "Multipole Field Calculations:" PRINT #filenum%, "To find the multipole field magnitudes and phases," PRINT #filenum%, "the measured voltage harmonics are related to their values" PRINT #filenum%, "calculated from the field harmonics:" PRINT #filenum%, " Nturns * Rcoil * ang_freq * BLn = Vn" PRINT #filenum%, " -n * thspole = PhiVn" PRINT #filenum%, "Or," PRINT #filenum%, " BLn = Vn / (Nturns * Rcoil * ang_freq)" PRINT #filenum%, " thspole = -PhiVn / n" 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 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 blpltblhar (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$, harcoilid%, 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 ' harcoilid%, ID number of the harmonics coil ' 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$ harcoilidP% = harcoilid% harcoilradiusmP! = harcoilradiusm! harcoilnturnsP% = harcoilnturns% blnmeasaveP% = blnmeasave% END SUB