DECLARE SUB vcoilgetf (f!) DECLARE SUB vcoilgetv1 (coilid%, v1!) DECLARE SUB blcalcratio (nh%, bln!(), sbln!(), nmain%, rn!(), srn!()) DECLARE SUB bldatblhar (datfile$, imag!, simag!, nmain%, nh%, bln!(), sbln!(), thn!(), sthn!(), r!(), sr!()) DECLARE SUB bldatview (logfile$, nmain%, thsp!, viewdir$) DECLARE SUB blgetblnav (nh%, bln!(), sbln!(), thn!(), sthn!()) DECLARE SUB blpltblhar (pltfile$, legend$, nh%, rn!(), srn!()) DECLARE SUB dpolcheckpar (ok$) DECLARE SUB dpoldatblvsi (datfile$, imag!, simag!, bl!, sbl!, tf!, stf!) DECLARE SUB dpolgetbl (bl!) DECLARE SUB dpolgetblav (bl!, sbl!) DECLARE SUB dpollogbl (logfile$, coilconst!, f!, v1!, bl!) DECLARE SUB dpollogblav (logfile$, bl!, sbl!) DECLARE SUB dpollogcalc (logfile$) DECLARE SUB dpollogstrmeas (logfile$) DECLARE SUB dpolpltblvsi (pltfile$, imag!, bl!, sbl!, tf!, stf!) DECLARE SUB imaggetiav (imag!, simag!) DECLARE SUB imagramp (inom!) DECLARE SUB filenewpage (filename$) '**************************************************************************** 'Module DPOL.BAS ' 'These subroutines perform calculations related to dipole magnet 'measurements. ' 'Zachary Wolf '11/25/95 '**************************************************************************** 'Put the required parameters for this module in a common block COMMON SHARED /dpol/ logfileP$, strdatfileP$, strpltfileP$, hardatfileP$, harpltfileP$, magnameP$, runP$, strcoilidP%, strdpolcoilconstP!, harcoilradiusmP!, blnmeasaveP%, nimagtestP%, imagtestP!(), imagharflagP!(), nhardisplayP%, viewdirP$ SUB dpolcheckpar (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$ = "" OR strdatfileP$ = "" OR strpltfileP$ = "" OR hardatfileP$ = "" OR harpltfileP$ = "" THEN PRINT "DPOL: required file not defined" EXIT SUB END IF 'Runinfo IF magnameP$ = "" OR runP$ = "" THEN PRINT "DPOL: required run parameter not defined" EXIT SUB END IF 'Coil IF strcoilidP% <= 0 OR strdpolcoilconstP! <= 0 OR harcoilradiusmP! <= 0 THEN PRINT "DPOL: required coil parameter not defined" EXIT SUB END IF 'Measurement parameters IF blnmeasaveP% <= 0 OR nhardisplayP% <= 0 OR nimagtestP% <= 0 THEN PRINT "DPOL: required measurement parameter not defined" EXIT SUB END IF 'Main harmonic picture IF viewdirP$ <> "LEADEND" AND viewdirP$ <> "NONLEADEND" THEN PRINT "DPOL: unknown view direction" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB dpoldatblvsi (datfile$, imag!, simag!, bl!, sbl!, tf!, stf!) '**************************************************************************** 'This subroutine writes a BL measurement at Imag to the data file. ' 'Input: ' datfile$, the name of the data file ' imag!, the measured current ' simag!, the standard deviation of imag ' bl!, the integrated field strength at the measured current ' sbl!, the standard deviation of BL ' tf!, BL/I ' stf!, the standard deviation of TF ' 'Zachary Wolf '11/19/95 '**************************************************************************** 'Keep track of Ncall so a header can be written on the first call STATIC ncall% ncall% = ncall% + 1 'Open the log file filenum% = FREEFILE OPEN datfile$ FOR APPEND AS filenum% 'On the first call, write a header for the hysteresis loop IF ncall% = 1 THEN PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " INTEGRATED FIELD STRENGTH VS CURRENT" PRINT #filenum%, PRINT #filenum%, " Imag sigImag BL sigBL BL/I sigBL/I " PRINT #filenum%, " (A) (A) (Tm) (Tm) (Tm/kA) (Tm/kA) " PRINT #filenum%, "--------+-------- --------+-------- --------+--------" END IF 'Write the result PRINT #filenum%, USING "####.###"; imag!; PRINT #filenum%, USING " ####.###"; simag!; PRINT #filenum%, USING " ##.#####"; bl!; PRINT #filenum%, USING " ##.#####"; sbl!; PRINT #filenum%, USING " ###.####"; tf! * 1000!; PRINT #filenum%, USING " ###.####"; stf! * 1000! 'Close the log file CLOSE filenum% END SUB SUB dpolgetbl (bl!) '**************************************************************************** 'This subroutine calculates the integrated dipole strength from the 'measured coil voltage at the first harmonic. ' 'Output: ' v1!, coil voltage at the first harmonic (V) ' bl!, the integrated field strength (Tm) ' 'Zachary Wolf '11/19/95 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL dpolcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Calculation Of BL: 'V1 = Nturns * velocity * B * L ' = Nturns * Rcoil * ang_freq * BL 'BL = V1 / (Nturns * Rcoil * ang_freq) 'For a double coil, 'V1 = [(Nturns * Rcoil)1 + (Nturns * Rcoil)2] * ang_freq * BL 'BL = V1 / ([(Nturns * Rcoil)1 + (Nturns * Rcoil)2] * ang_freq) 'Let CoilConst = [(Nturns * Rcoil)1 + (Nturns * Rcoil)2]^(-1) 'BL = CoilConst * V1 / ang_freq 'Simplify the notation pi! = 3.1415926# 'Measure the coil rotation frequency CALL vcoilgetf(f1!) SLEEP 1 CALL vcoilgetf(f2!) 'Get the coil voltage at the first harmonic CALL vcoilgetv1(strcoilidP%, v1!) 'Measure the coil rotation frequency again after the coil voltage CALL vcoilgetf(f3!) 'Compute the average of the coil rotation frequency measurements f! = (f1! + f2! + f3!) / 3! 'Compute BL bl! = strdpolcoilconstP! * v1! / (2 * pi! * f!) 'Log the result CALL dpollogbl(logfileP$, strdpolcoilconstP!, f!, v1!, bl!) END SUB SUB dpolgetblav (bl!, sbl!) '**************************************************************************** 'This subroutine has BL measured several times, then it computes the 'average and rms variation. ' 'Output: ' bl!, average of the BL measurements ' sbl!, rms variation of the BL measurements ' 'Zachary Wolf '11/21/95 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL dpolcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Log that a strength measurement is being made CALL dpollogstrmeas(logfileP$) 'Simplify the notation nm% = blnmeasaveP% 'Initialize data arrays DIM blmeas!(1 TO nm%) 'Message about the measurement number PRINT PRINT "Performing BL measurement #"; 'Loop over the measurements FOR i% = 1 TO nm% 'Message about the measurement number PRINT USING " #"; i%; 'Measure BL CALL dpolgetbl(bl!) 'Store the results blmeas!(i%) = bl! 'End the loop over the measurements NEXT i% 'End message info PRINT 'Compute averages bl! = 0! FOR i% = 1 TO nm% bl! = bl! + blmeas!(i%) NEXT i% bl! = bl! / nm% 'Compute rms deviations sbl! = 0! FOR i% = 1 TO nm% sbl! = sbl! + (blmeas!(i%) - bl!) ^ 2 NEXT i% sbl! = SQR(sbl! / nm%) 'Print the result to the screen PRINT "Integrated Field Strength BL = "; bl!; " +- "; sbl!; " Tm" 'Log the result CALL dpollogblav(logfileP$, bl!, sbl!) END SUB SUB dpollogbl (logfile$, coilconst!, f!, v1!, bl!) '**************************************************************************** 'This subroutine writes a summary of an average BL measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' coilconst!, coil constant ' f!, coil rotation frequency ' v1!, coil voltage at the first harmonic ' bl!, integrated field strength ' 'Zachary Wolf '11/19/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, TIME$; " Integrated Field Strength Measurement:" PRINT #filenum%, " CoilConst = "; coilconst!; " 1/m, Fcoil = "; f!; " Hz, V1 = "; v1!; " V" PRINT #filenum%, " BL = "; bl!; " Tm" 'Close the log file CLOSE filenum% END SUB SUB dpollogblav (logfile$, bl!, sbl!) '**************************************************************************** 'This subroutine writes a summary of an average BL measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' bl!, the average of the integrated field strength measurements ' sbl!, the rms variation of bl ' 'Zachary Wolf '11/19/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, TIME$; " Average Integrated Field Strength:" PRINT #filenum%, " BL = "; bl!; " +- "; sbl!; " Tm" 'Close the log file CLOSE filenum% END SUB SUB dpollogcalc (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, 6/3/97 '**************************************************************************** '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 BL vs I PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation Of BL:" PRINT #filenum%, "V1 = Nturns * velocity * B * L" PRINT #filenum%, " = Nturns * Rcoil * ang_freq * BL" PRINT #filenum%, "BL = V1 / (Nturns * Rcoil * ang_freq)" PRINT #filenum%, "For a double coil (for coil bowing correction)," PRINT #filenum%, "V1 = [(Nturns * Rcoil)1 + (Nturns * Rcoil)2] * ang_freq * BL" PRINT #filenum%, "BL = V1 / ([(Nturns * Rcoil)1 + (Nturns * Rcoil)2] * ang_freq)" PRINT #filenum%, "Let CoilConst = [(Nturns * Rcoil)1 + (Nturns * Rcoil)2]^(-1)" PRINT #filenum%, "BL = CoilConst * V1 / 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 / BL1 = Vn / V1" 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" 'Close the log file CLOSE filenum% END SUB SUB dpollogstrmeas (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$; " Magnet Strength Measurement..." 'Close the log file CLOSE filenum% END SUB SUB dpolmain '**************************************************************************** 'This subroutine controls the magnetic measurements of a dipole at 'various currents. ' 'Zachary Wolf '1/4/95, 5/6/95 '**************************************************************************** 'Make sure all parameters have been defined with acceptable values CALL dpolcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Message PRINT PRINT "Beginning the dipole field measurement cycle..." 'Simplify the notation ni% = nimagtestP% nh% = nhardisplayP% 'Initialize data arrays DIM bln!(1 TO nh%) 'field strength at Rcoil of the n'th harmonic DIM sbln!(1 TO nh%) 'standard deviation of Bn DIM thn!(1 TO nh%) 'field angle DIM sthn!(1 TO nh%) 'standard deviation of THn DIM rn!(1 TO nh%) 'BLn/BL1 DIM srn!(1 TO nh%) 'standard deviation of rn 'Loop over test currents FOR i% = 1 TO ni% 'Ramp to the desired current CALL imagramp(imagtestP!(i%)) 'Measure the current CALL imaggetiav(imag!, simag!) 'Get the integrated field strength CALL dpolgetblav(bl!, sbl!) 'Compute the transfer function IF imag! <> 0! THEN tf! = bl! / imag! stf! = tf! * SQR((sbl! / bl!) ^ 2 + (simag! / imag!) ^ 2) ELSE tf! = 0! stf! = 0! END IF 'Write the strength measurement to the data file CALL dpoldatblvsi(strdatfileP$, imag!, simag!, bl!, sbl!, tf!, stf!) 'Write the strength measurement to the plot file CALL dpolpltblvsi(strpltfileP$, imag!, bl!, sbl!, tf!, stf!) 'Do the following only if the harmonics are desired IF imagharflagP!(i%) > 0 THEN 'Get the field harmonics at the coil radius CALL blgetblnav(nh%, bln!(), sbln!(), thn!(), sthn!()) 'Compute the strength ratios of the harmonics CALL blcalcratio(nh%, bln!(), sbln!(), nmain%, rn!(), srn!()) 'Write the harmonics to the data file CALL bldatblhar(hardatfileP$, imag!, simag!, nmain%, nh%, bln!(), sbln!(), thn!(), sthn!(), rn!(), srn!()) 'Write a picture of the main harmonic under the table of harmonics CALL bldatview(hardatfileP$, nmain%, thn!(nmain%), viewdirP$) 'Write the harmonics to the plot file legend$ = "I = " + STR$(imagtestP!(i%)) + " A" CALL blpltblhar(harpltfileP$, legend$, nh%, rn!(), srn!()) 'End harmonics check END IF 'End loop over currents NEXT i% 'Write a summary of the calculations to the BL data file CALL filenewpage(strdatfileP$) CALL dpollogcalc(strdatfileP$) 'Write a summary of the calculations to the harmonics data file CALL filenewpage(hardatfileP$) CALL dpollogcalc(hardatfileP$) END SUB SUB dpolpltblvsi (pltfile$, imag!, bl!, sbl!, tf!, stf!) '**************************************************************************** 'This subroutine write a summary of the BL vs I measurements for plotting. ' 'Input: ' pltfile$, the name of the plot file ' imag!, the measured current ' bl!, the integrated field strength at the measured current ' sbl!, the standard deviation of bl ' tf!, the transfer function at the measured current ' stf!, the standard deviation of tf ' 'Zachary Wolf '11/19/95 '**************************************************************************** 'Keep track of Ncall for the header STATIC ncall% ncall% = ncall% + 1 'Open the plot file filenum% = FREEFILE OPEN pltfile$ FOR APPEND AS filenum% 'Write the title for plotting on the first call IF ncall% = 1 THEN PRINT #filenum%, "/et g '" + magnameP$ + ", Run " + runP$ + "'" PRINT #filenum%, ";i bl sbl tf stf" END IF 'Write the values PRINT #filenum%, USING "####.#"; imag!; PRINT #filenum%, USING " ##.#####"; bl!; PRINT #filenum%, USING " ##.#####"; sbl!; PRINT #filenum%, USING " ###.#####"; tf!; PRINT #filenum%, USING " ###.#####"; stf! 'Close the log file CLOSE filenum% END SUB SUB dpolsetpar (logfile$, strdatfile$, strpltfile$, hardatfile$, harpltfile$, magname$, run$, strcoilid%, strdpolcoilconst!, harcoilradiusm!, blnmeasave%, nimagtest%, imagtest!(), imagharflag!(), nhardisplay%, viewdir$) '**************************************************************************** 'This subroutine sets the parameters required by this module. ' 'Input: ' logfile$, path and name of the log file ' strdatfile$, magnet strength data file ' strpltfile$, magnet strength plot file ' hardatfile$, harmonics data file ' harpltfile$, harmonics plot file ' magname$, magnet name ' run$, run number ' strcoilid%, strength coil ID number ' strdpolcoilconst!, strength coil dipole coil constant ' harcoilradiusm!, harmonics coil radius (m) ' blnmeasave%, number of measurements for averaging ' nimagtest%, number of test currents ' imagtest!(), test currents ' imagharflag!(), flag for harmonics measurement ' nhardisplay%, number of harmonics to record ' viewdir$, view direction for picture of main harmonic ' 'Zachary Wolf '11/20/95 '**************************************************************************** 'Set the parameters logfileP$ = logfile$ strdatfileP$ = strdatfile$ strpltfileP$ = strpltfile$ hardatfileP$ = hardatfile$ harpltfileP$ = harpltfile$ magnameP$ = magname$ runP$ = run$ strcoilidP% = strcoilid% strdpolcoilconstP! = strdpolcoilconst! harcoilradiusmP! = harcoilradiusm! blnmeasaveP% = blnmeasave% nimagtestP% = nimagtest% DIM imagtestP!(1 TO nimagtestP%) DIM imagharflagP!(1 TO nimagtestP%) FOR i% = 1 TO nimagtestP% imagtestP!(i%) = imagtest!(i%) imagharflagP!(i%) = imagharflag!(i%) NEXT i% nhardisplayP% = nhardisplay% viewdirP$ = viewdir$ END SUB