DECLARE SUB standardize () DECLARE SUB calccorr (ns%, bhall!(), bnmr!(), bcorr!()) DECLARE SUB gettestparam () DECLARE SUB measure () DECLARE SUB trapint (ns%, x!(), y!(), iydx!) DECLARE SUB logbl (logfile$, imagave!, bl!) DECLARE SUB logbnmrh (logfile$, ns%, z!(), imag!(), bhall!(), bnmr!(), bcorr!()) DECLARE SUB logplot (logfile$, magname$, run$, ns%, z!(), imag!(), bhall!(), bnmr!(), bcorr!()) DECLARE SUB fileheader (logfile$, mn$, op$, ts$, dv$, rn$, cm$) DECLARE SUB fileinitldp (magname$, run$, test$, logfile$, datfile$, pltfile$, ok$) DECLARE SUB imagmeas (imag!) DECLARE SUB imagramp (rr!, ifin!) DECLARE SUB gpibinit () DECLARE SUB gp3getb (b!) DECLARE SUB gp3init () DECLARE SUB gp3setrange (r%) DECLARE SUB gp3zero () DECLARE SUB pt2025getb (b!) DECLARE SUB pt2025init () DECLARE SUB pt2025search () DECLARE SUB dac488doutoff (d%) DECLARE SUB dac488douton (d%) DECLARE SUB dac488init () DECLARE SUB dac488hrinit () DECLARE SUB dac488hrsetupv () DECLARE SUB hp3457init () '**************************************************************************** 'Program HERDNMRH 'This program is used to get an absolute calibration for one of 'the B-Factory high energy ring dipole coils. This calibration, 'together with the cross calibration, provides an absolute calibration 'of all three coils. ' 'Zachary Wolf '6/12/94 '**************************************************************************** 'Include the constants used in the program REM $INCLUDE: 'partest.inc' 'Prepare the screen CLS 'Initialize the GPIB CALL gpibinit 'Initialize the NMR CALL pt2025init 'Initialize the Hall probe CALL gp3init CALL gp3setrange(0) 'Initialize the DAC for moving the stage CALL dac488init 'Initialize the DAC for ramping the current 'CALL dac488hrinit 'CALL dac488hrsetupv 'Initialize the HP3457 CALL hp3457init 'Print a message about the program PRINT PRINT "Program HERDNMRH" PRINT "This program uses the NMR probe and Hall probe to provide an" PRINT "absolute calibration of one of the HER dipole coils. The cross" PRINT "calibrations then provide the absolute calibrations of the other" PRINT "coils." PRINT 'Get test parameters from the operator testparam: CALL gettestparam 'Open the log file CALL fileinitldp(magnameP$, runP$, "nmrh", logfileP$, datfileP$, pltfileP$, ok$) IF ok$ <> "y" THEN PRINT : PRINT "Problem opening the log file. Try a different run number.": PRINT GOTO testparam: END IF 'Write a header to the log and data files CALL fileheader(logfileP$, magnameP$, operatorP$, teststandP$, "NMR and Hall probes", runP$, commentP$) CALL fileheader(datfileP$, magnameP$, operatorP$, teststandP$, "NMR and Hall probes", runP$, commentP$) 'Standardize the magnet 'CALL standardize 'Get the test current from the operator 'PRINT 'current: 'INPUT "What current do you wish to perform the measurement at? (Amps) ", inom! 'IF inom! < 0 OR inom! > 1000! THEN ' PRINT "The current must be in the range 0 < I < 1000 A" ' GOTO current: 'END IF 'Message 'PRINT 'PRINT "Ramping to "; inom!; " Amps..." 'Ramp to the desired current 'CALL imagramp(imagramprateP!, inom!) 'Zero the Hall probe PRINT PRINT "Hall Probe Zero" PRINT "Please place the Hall probe into a 0 Gauss chamber." INPUT "Press ENTER when ready. ", a$ CALL gp3zero PRINT "The Hall probe is zeroed." 'Do an NMR search until it locks on the field, freeze the DAC setting PRINT PRINT "NMR Coarse Adjust" PRINT "Please place the NMR probe into the middle of the magnet." INPUT "Press ENTER when ready. ", a$ CALL pt2025search PRINT "NMR coarse adjust finished." 'Get ready for the measurements PRINT PRINT "Measurements" PRINT "Now reassemble the NMR-Hall probe in preparation for the measurements." INPUT "Press ENTER when ready to start the measurements. ", a$ 'Measure the integrated field strength CALL measure 'Message 'PRINT 'PRINT "Ramping to 0 Amps." 'Ramp to 0 amps 'CALL imagramp(imagramprateP!, 0!) 'Message PRINT "The measurement is complete." END SUB calccorr (ns%, bhall!(), bnmr!(), bcorr!()) '**************************************************************************** 'This subroutine calculates corrected field values at each z position. 'If there is an NMR reading, that is bcorr. Otherwise, bcorr is the Hall 'probe reading corrected by the NMR readings. ' 'Input: ' ns%, the number of steps through the magnet ' bhall!(0 to ns%), the Hall probe measurements ' bnmr!(0 to ns%), the NMR measurements ' 'Outputs: ' bcorr!(0 to ns%), the corrected field values ' 'Zachary Wolf '6/30/94 '**************************************************************************** 'Find the average ratio of Bnmr/Bhall nb% = 0 corr! = 0 FOR i% = 0 TO ns% IF bnmr!(i%) > 0! THEN nb% = nb% + 1 corr! = corr! + bnmr!(i%) / bhall!(i%) END IF NEXT i% corr! = corr! / nb% 'Fill the bcorr array using either bnmr or bhall*corr FOR i% = 0 TO ns% IF bnmr!(i%) > 0 THEN bcorr!(i%) = bnmr!(i%) ELSE bcorr!(i%) = bhall!(i%) * corr! END IF NEXT i% END SUB SUB gettestparam '**************************************************************************** 'This subroutine prompts the operator for the magnet name and other 'parameters of the test. ' 'Outputs put in the /testparam/ common block: ' magnameP$, name of the magnet ' operatorP$, name of the operator doing the test ' teststandP$, the teststand being used ' runP$, run number ' commentP$, comment about the test ' 'Zachary Wolf '4/16/94 '**************************************************************************** begin: 'Get the name of the magnet PRINT "What is the name of the magnet being used for this measurement?" PRINT "(8 characters or less): ["; magnameP$; "]"; INPUT magname$ magname$ = UCASE$(magname$) IF magname$ <> "" THEN magnameP$ = magname$ 'Get the operator's name(s) PRINT "Enter the operator(s) name(s): ["; operatorP$; "]"; LINE INPUT operator$ IF operator$ <> "" THEN operatorP$ = operator$ 'Get the name of the test stand stand: PRINT "Enter which test stand is being used (D0, D1, or D2): ["; teststandP$; "]"; INPUT teststand$ teststand$ = UCASE$(teststand$) IF teststand$ <> "" THEN teststandP$ = teststand$ IF teststand$ <> "" AND teststand$ <> "D0" AND teststand$ <> "D1" AND teststand$ <> "D2" THEN GOTO stand IF teststandP$ = "" GOTO stand 'Get the name of the measurement coil 'meascoil: 'PRINT "Enter the name of the measurement coil (COIL0, COIL1, or COIL2): ["; coilP$; "]"; 'INPUT coil$ 'coil$ = UCASE$(coil$) 'IF coil$ <> "" THEN coilP$ = coil$ 'IF coil$ <> "" AND coil$ <> "COIL0" AND coil$ <> "COIL1" AND coil$ <> "COIL2" THEN GOTO meascoil 'IF coilP$ = "" GOTO meascoil 'Get the run number PRINT "What is the run number (1, 2, 3, ...): ["; runP$; "]"; INPUT run$ IF run$ <> "" THEN runP$ = run$ 'Get a comment PRINT "Enter any comment about the run: ["; commentP$; "]"; LINE INPUT comment$ IF comment$ <> "" THEN commentP$ = comment$ 'See if everything was entered correctly PRINT INPUT "Do you wish to make any changes to the values entered (Y or N): ", yn$ IF yn$ = "Y" OR yn$ = "y" THEN GOTO begin END SUB SUB measure '**************************************************************************** 'This subroutine controls the measurement of the integrated field strength 'for a B-Factory high energy ring dipole. 'Constants come from param.inc. ' 'Zachary Wolf '6/22/94 '**************************************************************************** 'Simplify the notation ns% = nzstepsP% 'Initialize DIM z!(0 TO ns%) 'the z position DIM imag!(0 TO ns%) 'the magnet current DIM bhall!(0 TO ns%) 'the Hall probe readings DIM bnmr!(0 TO ns%) 'the NMR readings DIM bcorr!(0 TO ns%) 'corrected field values 'Have the number of stepping motor steps per slide step set by the user ndial% = nmotorstepstotP& / ns% PRINT PRINT "Please turn the dials to "; ndial%; " on the stepping motor controller." INPUT "Press ENTER when ready. ", a$ 'Loop over z positions FOR i% = 0 TO ns% 'Allow run to end if there is a problem IF INKEY$ = CHR$(27) THEN EXIT SUB 'Take a step, except for the first position IF i% > 0 THEN PRINT PRINT "Moving the NMR and Hall probes." CALL dac488douton(2) CALL dac488doutoff(2) 'send a pulse SLEEP tmotorstepP% 'wait until the lead screw is done turning END IF 'Message PRINT "Measuring at point "; i%; " out of "; ns%; "." 'Calculate the z position z!(i%) = (i% * lleadscrewP! * ndial%) / nmotorstepstotP& 'Measure the current CALL imagmeas(imag!(i%)) 'Measure the field strength using the Hall probe CALL gp3getb(bhall!(i%)) 'Measure the field strength using the NMR probe CALL pt2025getb(bnmr!(i%)) 'Message PRINT "The current is "; imag!(i%); " amps." PRINT "The field from the Hall probe is "; bhall!(i%); " T." PRINT "The field from the NMR probe is "; bnmr!(i%); " T." 'End loop over z positions NEXT i% 'Calculate the corrected field at each point CALL calccorr(ns%, bhall!(), bnmr!(), bcorr!()) 'Integrate the corrected field strengths CALL trapint(ns%, z!(), bcorr!(), bl!) 'Find the average current imagave! = 0 FOR i% = 0 TO ns% imagave! = imagave! + imag!(i%) NEXT i% imagave! = imagave! / (ns% + 1) 'Write the field values to the log file CALL logbnmrh(logfileP$, ns%, z!(), imag!(), bhall!(), bnmr!(), bcorr!()) 'Write the field integral to the data and log files CALL logbl(datfileP$, imagave!, bl!) CALL logbl(logfileP$, imagave!, bl!) 'Write the measurements to the plot file CALL logplot(pltfileP$, magnameP$, runP$, ns%, z!(), imag!(), bhall!(), bnmr!(), bcorr!()) END SUB SUB standardize '**************************************************************************** 'This procedure controls the standardization of the magnet. 'Parameters come from param.inc. ' 'Zachary Wolf '4/23/94 '**************************************************************************** 'Let the operator know what is happening PRINT PRINT "Standardizing the magnet..." 'Simplify the notation ni% = imagnstandP% 'Loop over currents FOR i% = 1 TO ni% 'Message PRINT PRINT "Ramping to "; imagstandP!(i%); " Amps." 'Ramp to the desired current CALL imagramp(imagramprateP!, imagstandP!(i%)) 'End loop over currents NEXT i% END SUB SUB trapint (ns%, x!(), y!(), iydx!) '**************************************************************************** 'This subroutine uses the trapezoidal rule to perform a numerical 'integration. ' 'Input: ' ns%, the number of steps for the integration ' x!(0 to ns%), the x values ' y!(0 to ns%), the y values ' 'Output: ' iydx!, the value of the integral ' 'Zachary Wolf '7/7/94 '**************************************************************************** 'Initialize iydx! = 0 'Sum the areas of the trapezoids to get the integral FOR i% = 1 TO ns% iydx! = iydx! + .5 * (y!(i%) + y!(i% - 1)) * (x!(i%) - x!(i% - 1)) NEXT i% END SUB