DECLARE SUB applycal (nz%, v1!(), v2!(), v3!(), v4!(), vincl!(), d1!(), d2!(), d3!(), d4!(), rincl!()) DECLARE SUB applycorr (nz%, d1!(), d2!(), d3!(), d4!(), rincl!(), d1c!(), d2c!(), d3c!(), d4c!(), rinclc!()) DECLARE SUB calcg (nz%, d1!(), d2!(), d3!(), d4!(), gout!(), goutave!, goutsig!, gin!(), ginave!, ginsig!, gm!(), gmave!, gmsig!, grad!(), gradave!, gradsig!) DECLARE SUB calchr (nz%, d1!(), d2!(), d3!(), d4!(), hout!(), houtave!, houtsig!, hin!(), hinave!, hinsig!, roll!(), rollave!, rollsig!) DECLARE SUB calchtar (nz%, z!(), hout!(), houtave!, roll!(), ht1w!, ht1a!, ht2w!, ht2a!) DECLARE SUB calcshim (nz%, z!(), hout!(), roll!(), mh!, bh!, mr!, br!, shimh1!, shimh2!, shimr1!, shimr2!) DECLARE SUB gettestparam () DECLARE SUB getv (v1!, v2!, v3!, v4!, vincl!) DECLARE SUB measure () DECLARE SUB logd (logfile$, nz%, z!(), d1!(), d2!(), d3!(), d4!(), rincl!(), d1c!(), d2c!(), d3c!(), d4c!()) DECLARE SUB logg (logfile$, nz%, z!(), gout!(), goutave!, goutsig!, gin!(), ginave!, ginsig!, gm!(), gmave!, gmsig!, grad!(), gradave!, gradsig!) DECLARE SUB loghr (logfile$, nz%, z!(), hout!(), houtave!, houtsig!, hin!(), hinave!, hinsig!, roll!(), rollave!, rollsig!) DECLARE SUB logplot (logfile$, magname$, run$, nz%, z!(), d1!(), d2!(), d3!(), d4!(), gout!(), gin!(), hout!(), hin!(), roll!()) DECLARE SUB logshim (logfile$, mr!, br!, mh!, bh!, shimr1!, shimr2!, shimh1!, shimh2!) DECLARE SUB logsumm (logfile$, goutave!, goutsig!, ginave!, ginsig!, gmave!, gmsig!, gradave!, gradsig!, houtave!, houtsig!, hinave!, hinsig!, ht1w!, ht1a!, ht2w!, ht2a!, rollave!, rollsig!) DECLARE SUB logv (logfile$, nz%, z!(), v1!(), v2!(), v3!(), v4!(), vincl!()) DECLARE SUB fileheader (logfile$, mn$, op$, ts$, dv$, rn$, cm$) DECLARE SUB fileinitldp (magname$, run$, test$, logfile$, datfile$, pltfile$, ok$) DECLARE SUB mathlinfit (n%, x!(), y!(), m!, b!) DECLARE SUB gpibinit () DECLARE SUB cm2100avdin (ain!, vin!, din!) DECLARE SUB cm2100gohome () DECLARE SUB cm2100init () DECLARE SUB hp3457cv (c%, v!) DECLARE SUB hp3457cvnoise (c%, v!) DECLARE SUB hp3457init () '**************************************************************************** 'Program HERDGAP.BAS 'This program is used for the gap measurements of the B Factory High 'Energy Ring dipoles. ' 'Zachary Wolf '5/2/94, 6/6/94, 6/25/94 '**************************************************************************** 'Include the constants used in the program REM $INCLUDE: 'param.inc' 'Prepare the screen CLS 'Initialize the GPIB CALL gpibinit 'Initialize the HP3457 CALL hp3457init 'Initialize the CM2100 CALL cm2100init 'Print a message about the program PRINT PRINT "Program HERDGAP" PRINT "This program measures the gap distances of the B-Factory" PRINT "HER dipoles. It is used to determine the elevation, pitch," PRINT "roll, and twist of the magnet. Shims are calculated to" PRINT "adjust all these quantities to zero." PRINT 'Get test parameters from the operator testparam: CALL gettestparam 'Open the output files CALL fileinitldp(magnameP$, runP$, "gap", logfileP$, datfileP$, pltfileP$, ok$) IF ok$ <> "y" THEN PRINT PRINT "Problem opening the data files. Please choose another run number." PRINT GOTO testparam: END IF 'Write headers CALL fileheader(logfileP$, magnameP$, operatorP$, "gap measurement stand", "gap sensors", runP$, commentP$) CALL fileheader(datfileP$, magnameP$, operatorP$, "gap measurement stand", "gap sensors", runP$, commentP$) 'Measure the gap as a function of position CALL measure 'Message PRINT PRINT "The test is complete." END SUB applycal (nz%, v1!(), v2!(), v3!(), v4!(), vincl!(), d1!(), d2!(), d3!(), d4!(), rincl!()) '**************************************************************************** 'This subroutine applies the calibrations to get from the sensor voltages 'to the measured quantities. ' 'Inputs: ' nz%, the number of z positions in the magnet ' v1!(0 to nz%+1), voltage from the upper outer sensor ' v2!(0 to nz%+1), voltage from the upper inner sensor ' v3!(0 to nz%+1), voltage from the lower inner sensor ' v4!(0 to nz%+1), voltage from the lower outer sensor ' vincl!(0 to nz%+1), voltage from the inclinometer ' 'Outputs: ' d1!(0 to nz%+1), distance from upper outer sensor to the pole ' d2!(0 to nz%+1), distance from upper inner sensor to the pole ' d3!(0 to nz%+1), distance from lower inner sensor to the pole ' d4!(0 to nz%+1), distance from lower outer sensor to the pole ' rincl!(0 to nz%+1), roll angle of the inclinometer ' 'Zachary Wolf '6/24/94 '**************************************************************************** 'Calculate the gaps in mils FOR i% = 0 TO nz% + 1 d1!(i%) = v1!(i%) / voltpermilP! d2!(i%) = v2!(i%) / voltpermilP! d3!(i%) = v3!(i%) / voltpermilP! d4!(i%) = v4!(i%) / voltpermilP! NEXT i% 'Calculate the roll of the inclinometer in mrad FOR i% = 0 TO nz% + 1 rincl!(i%) = vincl!(i%) / voltpermradP! NEXT i% END SUB SUB applycorr (nz%, d1!(), d2!(), d3!(), d4!(), rincl!(), d1c!(), d2c!(), d3c!(), d4c!(), rinclc!()) '**************************************************************************** 'This subroutine applies corrections to the measured gaps to account for the 'roll of the inclinometer. ' 'Inputs: ' nz%, the number of z positions in the magnet ' d1!(0 to nz%+1), distance from upper outer sensor to the pole ' d2!(0 to nz%+1), distance from upper inner sensor to the pole ' d3!(0 to nz%+1), distance from lower inner sensor to the pole ' d4!(0 to nz%+1), distance from lower outer sensor to the pole ' rincl!(0 to nz%+1), roll angle from the inclinometer ' 'Outputs: ' d1c!(0 to nz%+1), corrected distance from upper outer sensor to the pole ' d2c!(0 to nz%+1), corrected distance from upper inner sensor to the pole ' d3c!(0 to nz%+1), corrected distance from lower inner sensor to the pole ' d4c!(0 to nz%+1), corrected distance from lower outer sensor to the pole ' rinclc!(0 to nz%+1), corrected roll angle from the inclinometer ' 'Zachary Wolf '6/24/94 '**************************************************************************** 'The roll angle of the inclinometer in the initial home position is defined 'to be zero. This angle is subtracted from all other measurements to account 'for long term drifts, etc. FOR i% = 0 TO nz% + 1 rinclc!(i%) = rincl!(i%) - rincl!(0) NEXT i% 'The arm is defined to have a positive roll angle when it moves toward 'the upper pole of the magnet. The inclinometer is wired so that 'rincl-rincl0 is negative when the arm is moved toward the upper pole. 'This is fixed by a sigh reversal in software. FOR i% = 0 TO nz% + 1 rinclc!(i%) = -rinclc!(i%) NEXT i% 'Correct for the roll angle of the arm 'The correction is made to the readings one would get if the arm were level. 'A positive roll angle reduces the upper gaps and increases the lower gaps. 'For a positive roll angle, we then need to add to the upper gaps and 'and subtract from the lower gaps. 'A negative roll angle increases the upper gaps and decreases the lower gaps. 'larmoutinP! is in inches and rincl! is in mrad, so the correction is in mils FOR i% = 0 TO nz% + 1 d1c!(i%) = d1!(i%) + larmoutinP! * rinclc!(i%) d2c!(i%) = d2!(i%) + larmininP! * rinclc!(i%) d3c!(i%) = d3!(i%) - larmininP! * rinclc!(i%) d4c!(i%) = d4!(i%) - larmoutinP! * rinclc!(i%) NEXT i% 'Measure distances relative to the garage distances 'Adjust dnc!(i%) to be zero in the garage. Then suppose the garage 'surfaces were extended as two parallel planes down the magnet. 'All distances are then measured relative to these plane surfaces. d1c0! = d1c!(0) d2c0! = d2c!(0) d3c0! = d3c!(0) d4c0! = d4c!(0) FOR i% = 0 TO nz% + 1 d1c!(i%) = d1c!(i%) - d1c0! d2c!(i%) = d2c!(i%) - d2c0! d3c!(i%) = d3c!(i%) - d3c0! d4c!(i%) = d4c!(i%) - d4c0! NEXT i% END SUB SUB calcg (nz%, d1!(), d2!(), d3!(), d4!(), gout!(), goutave!, goutsig!, gin!(), ginave!, ginsig!, gm!(), gmave!, gmsig!, grad!(), gradave!, gradsig!) '**************************************************************************** 'This subroutine calculates the magnet gaps and related quantities 'at each point along the magnet. 'I use the notation of G. Fischer's Oct. 1977 note. ' 'Inputs: ' nz%, the number of z positions in the magnet ' d1!(0 to nz%+1), distance from the garage surface to the pole at the upper outer sensor ' d2!(0 to nz%+1), " upper inner " ' d3!(0 to nz%+1), " lower inner " ' d4!(0 to nz%+1), " lower outer " ' 'Outputs: ' gout!(0 to nz%+1), outer gap ' goutave!, average outer gap ' goutsig!, standard deviation of gout values ' gin!(0 to nz%+1), inner gap ' ginave!, average inner gap ' ginsig!, standard deviation of gin values ' gm!(0 to nz%+1), middle gap ' gmave!, average middle gap ' gmsig!, standard deviation of gm values ' grad!(0 to nz%+1), the fractional gradient of the gap ' gradave!, average fractional gradient ' gradsig!, standard deviation of grad values ' 'Zachary Wolf '6/24/94 '**************************************************************************** 'Calculate the total height of the magnet gap in mils 'Note that d=0 on extensions of the garage surface FOR i% = 0 TO nz% + 1 gout!(i%) = d1!(i%) + d4!(i%) + garagegapmilP! gin!(i%) = d2!(i%) + d3!(i%) + garagegapmilP! gm!(i%) = (gout!(i%) + gin!(i%)) / 2! + 2 * y0milP! NEXT i% 'Calculate the fractional gap gradient wmil! = winP! * 1000! FOR i% = 0 TO nz% + 1 grad!(i%) = (1! / gm!(i%)) * (gout!(i%) - gin!(i%)) / (wmil!) grad!(i%) = grad!(i%) * 1000! * (1! / .0254) 'convert to 1/meters NEXT i% 'Compute averages FOR i% = 1 TO nz% goutave! = goutave! + gout!(i%) ginave! = ginave! + gin!(i%) gmave! = gmave! + gm!(i%) gradave! = gradave! + grad!(i%) NEXT i% goutave! = goutave! / nz% ginave! = ginave! / nz% gmave! = gmave! / nz% gradave! = gradave! / nz% 'Compute standard deviations FOR i% = 1 TO nz% goutsig! = goutsig! + (gout!(i%) - goutave!) ^ 2 ginsig! = ginsig! + (gin!(i%) - ginave!) ^ 2 gmsig! = gmsig! + (gm!(i%) - gmave!) ^ 2 gradsig! = gradsig! + (grad!(i%) - gradave!) ^ 2 NEXT i% goutsig! = SQR(goutsig! / nz%) ginsig! = SQR(ginsig! / nz%) gmsig! = SQR(gmsig! / nz%) gradsig! = SQR(gradsig! / nz%) END SUB SUB calchr (nz%, d1!(), d2!(), d3!(), d4!(), hout!(), houtave!, houtsig!, hin!(), hinave!, hinsig!, roll!(), rollave!, rollsig!) '**************************************************************************** 'This subroutine computes the inner and outer gap midpoint elevations. 'It then uses these to compute the roll angles. 'I use the notation of G. Fischer's Oct. 1977 note. ' 'Inputs: ' nz%, the number of z positions in the magnet ' d1!(0 to nz%+1), distance from the garage surface to the pole at the upper outer sensor ' d2!(0 to nz%+1), distance from the garage surface to the pole at the upper inner sensor ' d3!(0 to nz%+1), distance from the garage surface to the pole at the lower inner sensor ' d4!(0 to nz%+1), distance from the garage surface to the pole at the lower outer sensor ' 'Outputs: ' hout!(0 to nz%+1), outer vertical height of gap center ' houtave!, average value of hout in the magnet ' houtsig!, standard deviation of hout values in the magnet ' hin!(0 to nz%+1), inner vertical height of gap center ' hinave!, average value of hin in the magnet ' hinsig!, standard deviation of hin values in the magnet ' roll!(0 to nz%+1), roll angle ' rollave!, average roll in the magnet ' rollsig!, standard deviation of roll values in the magnet ' 'Zachary Wolf '6/24/94 '**************************************************************************** 'Theory for elevation calculations 's=distance to sensor from ideal 0 elevation 'd=distance from sensor to pole in garage 'D=distance from sensor to pole in magnet 's+d or s+D=distance from ideal 0 elevation to pole 'home positon: s1+d1 = s4+d4, ie. the garage is precisely positioned 'in magnet: hm = midpoint height = (D4+s4+s1+D1)/2 above bottom pole 'h0 = 0 elevation height = D4+s4 above bottom pole 'h = magnet elevation = hm-h0 = (s1+D1-s4-D4)/2 's1 = s4+d4-d1 from above 'h = (s4+d4-d1+D1-s4-D4)/2 = ((D1-d1)-(D4-d4))/2 'The garage distances have already been subtracted in the d's used below. 'similar equations for sensors 2 and 3 'Calculate the vertical height of the gap center FOR i% = 0 TO nz% + 1 hout!(i%) = (d1!(i%) - d4!(i%)) / 2! hin!(i%) = (d2!(i%) - d3!(i%)) / 2! NEXT i% 'Calculate the roll wmil! = winP! * 1000! FOR i% = 0 TO nz% + 1 roll!(i%) = (hin!(i%) - hout!(i%)) / wmil! roll!(i%) = roll!(i%) * 1000! 'mrad NEXT i% 'Compute averages FOR i% = 1 TO nz% houtave! = houtave! + hout!(i%) hinave! = hinave! + hin!(i%) rollave! = rollave! + roll!(i%) NEXT i% houtave! = houtave! / nz% hinave! = hinave! / nz% rollave! = rollave! / nz% 'Compute standard deviations FOR i% = 1 TO nz% houtsig! = houtsig! + (hout!(i%) - houtave!) ^ 2 hinsig! = hinsig! + (hin!(i%) - hinave!) ^ 2 rollsig! = rollsig! + (roll!(i%) - rollave!) ^ 2 NEXT i% houtsig! = SQR(houtsig! / nz%) hinsig! = SQR(hinsig! / nz%) rollsig! = SQR(rollsig! / nz%) END SUB SUB calchtar (nz%, z!(), hout!(), houtave!, roll!(), ht1w!, ht1a!, ht2w!, ht2a!) '**************************************************************************** 'This subroutine calculates the alignment target elevations used by 'precision alignment to set the magnets. ' 'Input: ' nz%, the number of z positions ' z!(0 to nz%+1), the z positions ' hout!(0 to nz%+1), the elevation of the middle of the gap on the outside ' houtave!, the average height of the outer gap ' roll!(0 to nz%+1), the magnet roll angle in mrad ' 'Output: ' ht1w!, the elevation of the target on the wall side at foot 1 in mils ' ht1a!, the elevation of the target on the aisle side at foot 1 in mils ' ht2w!, the elevation of the target on the wall side at foot 2 in mils ' ht2w!, the elevation of the target on the aisle side at foot 2 in mils ' 'Zachary Wolf '8/10/94, 8/20/94 '**************************************************************************** 'Find the z positions of the magnet feet z1! = (lmaginP! / 2) - (dbtwnfeetinP! / 2) z2! = (lmaginP! / 2) + (dbtwnfeetinP! / 2) 'Loop over z positions, find foot 1, calcuate ht1! FOR i% = 1 TO nz% IF z!(i%) >= z1! THEN j% = i% IF z1! - z!(i% - 1) < z!(i%) - z1! THEN j% = i% - 1 ht1w! = hout!(j%) + dgtargetwinP! * roll!(j%) ht1a! = hout!(j%) + dgtargetainP! * roll!(j%) EXIT FOR END IF NEXT i% 'Loop over z positions, find foot 2, calcuate ht2! FOR i% = 1 TO nz% IF z!(i%) >= z2! THEN j% = i% IF z2! - z!(i% - 1) < z!(i%) - z2! THEN j% = i% - 1 ht2w! = hout!(j%) + dgtargetwinP! * roll!(j%) ht2a! = hout!(j%) + dgtargetainP! * roll!(j%) EXIT FOR END IF NEXT i% 'Correct for the average height of the magnet if it is not zero ht1w! = ht1w! - houtave! ht1a! = ht1a! - houtave! ht2w! = ht2w! - houtave! ht2a! = ht2a! - houtave! END SUB SUB calcshim (nz%, z!(), hout!(), roll!(), mh!, bh!, mr!, br!, shimh1!, shimh2!, shimr1!, shimr2!) '**************************************************************************** 'This subroutine does linear fits to hout vs z and roll vs z. 'Shims are calculated to give the fitted lines zero slope and zero value. 'I use the notation of G. Fischer's Oct. 1977 note. ' 'Inputs: ' nz%, the number of z positions in the magnet ' z!(0 to nz%+1), z positions ' hout!(0 to nz%+1), outer vertical height of gap center ' roll!(0 to nz%+1), roll angle ' 'Outputs: ' mh!, slope of the fitted line to hout vs z ' bh!, intercept ' mr!, slope of the fitted line to roll vs z ' br!, intercept ' shimh1!, height-pitch shim for foot 1 ' shimh2!, foot 2 ' shimr1!, roll-twist shim for foot 1 ' shimr2!, foot 2 ' 'Zachary Wolf '6/26/94 '**************************************************************************** 'Do least squares linear fits of height vs z and roll vs z in the magnet DIM zmag!(1 TO nz%) DIM houtmag!(1 TO nz%) DIM rollmag!(1 TO nz%) FOR i% = 1 TO nz% zmag!(i%) = z!(i%) houtmag!(i%) = hout!(i%) rollmag!(i%) = roll!(i%) NEXT i% CALL mathlinfit(nz%, zmag!(), houtmag!(), mh!, bh!) CALL mathlinfit(nz%, zmag!(), rollmag!(), mr!, br!) 'Find the fitted height at the feet h1! = mh! * (lmaginP! - dbtwnfeetinP!) / 2! + bh! h2! = mh! * (lmaginP! + dbtwnfeetinP!) / 2! + bh! 'Compute shims to take out the elevation and pitch shimh1! = -h1! shimh2! = -h2! 'Find the fitted roll at the feet r1! = mr! * (lmaginP! - dbtwnfeetinP!) / 2! + br! r2! = mr! * (lmaginP! + dbtwnfeetinP!) / 2! + br! 'Compute shims to take out the roll and twist shimr1! = -r1! * dbtwnballsinP! 'mils shimr2! = -r2! * dbtwnballsinP! 'mils 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 ' runP$, run number ' commentP$, comment about the test ' 'Zachary Wolf '4/16/94 '**************************************************************************** begin: 'Get the magnet name PRINT "What is the magnet name (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$; "]"; INPUT operator$ IF operator$ <> "" THEN operatorP$ = operator$ '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 getv (v1!, v2!, v3!, v4!, vincl!) '**************************************************************************** 'This subroutine measures the voltages from the four gap sensors and the 'inclinometer. ' 'Outputs: ' v1!, voltage from the upper outer sensor ' v2!, voltage from the upper inner sensor ' v3!, voltage from the lower inner sensor ' v4!, voltage from the lower outer sensor ' vincl!, the voltage from the inclinometer ' 'Zachary Wolf '6/25/94 '**************************************************************************** 'Measure the gap voltages CALL hp3457cv(uochanP%, v1!) CALL hp3457cv(uichanP%, v2!) CALL hp3457cv(lichanP%, v3!) CALL hp3457cv(lochanP%, v4!) 'Measure the voltage from the inclinometer CALL hp3457cvnoise(inclchanP%, vincl!) END SUB SUB measure '**************************************************************************** 'This subroutine controls the gap measurements along the magnet. 'It calls the same subroutine used to make the measurements in the garage 'to protect against errors. 'I use the notation of G. Fischer's Oct. 1977 note. ' 'Zachary Wolf '4/16/94, 6/25/94 '**************************************************************************** 'Message PRINT PRINT "Beginning the measurements..." 'Get the required parameters nz% = nzposP% 'Initialize 'Positions 0 and nz%+1 are in the home position, the rest are in the magnet DIM z!(0 TO nz% + 1) 'z positions DIM v1!(0 TO nz% + 1) 'voltage from the upper outer sensor DIM v2!(0 TO nz% + 1) 'voltage from the upper inner sensor DIM v3!(0 TO nz% + 1) 'voltage from the lower inner sensor DIM v4!(0 TO nz% + 1) 'voltage from the lower outer sensor DIM vincl!(0 TO nz% + 1) 'voltage from the inclinometer DIM d1!(0 TO nz% + 1) 'distance from the upper outer sensor to the pole DIM d2!(0 TO nz% + 1) 'distance from the upper inner sensor to the pole DIM d3!(0 TO nz% + 1) 'distance from the lower inner sensor to the pole DIM d4!(0 TO nz% + 1) 'distance from the lower outer sensor to the pole DIM rincl!(0 TO nz% + 1) 'roll angle of the inclinometer in mrad DIM d1c!(0 TO nz% + 1) 'corrected distance from the upper outer sensor to the pole DIM d2c!(0 TO nz% + 1) 'corrected distance from the upper inner sensor to the pole DIM d3c!(0 TO nz% + 1) 'corrected distance from the lower inner sensor to the pole DIM d4c!(0 TO nz% + 1) 'corrected distance from the lower outer sensor to the pole DIM rinclc!(0 TO nz% + 1) 'corrected roll angle of the inclinometer in mrad DIM gout!(0 TO nz% + 1) 'outer gap DIM gin!(0 TO nz% + 1) 'inner gap DIM gm!(0 TO nz% + 1) 'middle gap DIM grad!(0 TO nz% + 1) '(1/G)(dG/dx) = -(1/B)(dB/dx) DIM hout!(0 TO nz% + 1) 'outer vertical height of gap center DIM hin!(0 TO nz% + 1) 'inner vertical height of gap center DIM roll!(0 TO nz% + 1) 'roll angle of the median plane in mrad 'Make an initial measurement in the home position PRINT PRINT "Making a measurement in the home position..." z!(0) = 0 CALL getv(v1!(0), v2!(0), v3!(0), v4!(0), vincl!(0)) 'Move the measuring probe into the magnet PRINT PRINT "Moving the measuring probe into the magnet..." CALL cm2100avdin(ainP!, vinP!, z0inP!) 'Loop over z positions in the magnet FOR i% = 1 TO nz% 'Allow the run to stop if there is a problem IF INKEY$ = CHR$(27) THEN STOP 'Step the linear motor IF i% > 1 THEN PRINT "Moving the motor." CALL cm2100avdin(ainP!, vinP!, dinP!) END IF 'Message PRINT "Measuring at point # "; i%; "." 'Compute the z position in inches z!(i%) = (i% - 1) * dinP! + zmag0inP! 'Perform the measurement CALL getv(v1!(i%), v2!(i%), v3!(i%), v4!(i%), vincl!(i%)) 'End loop over z positions NEXT i% 'Move the measuring probe back to the home position PRINT PRINT "Moving back to the home position..." CALL cm2100gohome 'Make a final measurement in the home position after the test to close the loop PRINT PRINT "Making a measurement in the home position..." z!(nz% + 1) = 0! CALL getv(v1!(nz% + 1), v2!(nz% + 1), v3!(nz% + 1), v4!(nz% + 1), vincl!(nz% + 1)) 'Done with the measurements 'Log the voltages CALL logv(logfileP$, nz%, z!(), v1!(), v2!(), v3!(), v4!(), vincl!()) 'Apply the sensor calibrations to get from measured voltages to the sensed parameter CALL applycal(nz%, v1!(), v2!(), v3!(), v4!(), vincl!(), d1!(), d2!(), d3!(), d4!(), rincl!()) 'Apply corrections to the measured gaps to account for the roll angle of the arm, etc. CALL applycorr(nz%, d1!(), d2!(), d3!(), d4!(), rincl!(), d1c!(), d2c!(), d3c!(), d4c!(), rinclc!()) 'Log the distances CALL logd(logfileP$, nz%, z!(), d1!(), d2!(), d3!(), d4!(), rinclc!(), d1c!(), d2c!(), d3c!(), d4c!()) 'Calculate and log the magnet gap and related quantities CALL calcg(nz%, d1c!(), d2c!(), d3c!(), d4c!(), gout!(), goutave!, goutsig!, gin!(), ginave!, ginsig!, gm!(), gmave!, gmsig!, grad!(), gradave!, gradsig!) CALL logg(logfileP$, nz%, z!(), gout!(), goutave!, goutsig!, gin!(), ginave!, ginsig!, gm!(), gmave!, gmsig!, grad!(), gradave!, gradsig!) 'Calculate and log the elavation and roll values CALL calchr(nz%, d1c!(), d2c!(), d3c!(), d4c!(), hout!(), houtave!, houtsig!, hin!(), hinave!, hinsig!, roll!(), rollave!, rollsig!) CALL loghr(logfileP$, nz%, z!(), hout!(), houtave!, houtsig!, hin!(), hinave!, hinsig!, roll!(), rollave!, rollsig!) 'Calculate alignment target heights CALL calchtar(nz%, z!(), hout!(), houtave!, roll!(), ht1w!, ht1a!, ht2w!, ht2a!) 'Calculate and log the magnet shims to take out height, pitch, roll, and twist CALL calcshim(nz%, z!(), hout!(), roll!(), mh!, bh!, mr!, br!, shimh1!, shimh2!, shimr1!, shimr2!) CALL logshim(logfileP$, mr!, br!, mh!, bh!, shimr1!, shimr2!, shimh1!, shimh2!) 'Write a summary to the "dat" file CALL logsumm(datfileP$, goutave!, goutsig!, ginave!, ginsig!, gmave!, gmsig!, gradave!, gradsig!, houtave!, houtsig!, hinave!, hinsig!, ht1w!, ht1a!, ht2w!, ht2a!, rollave!, rollsig!) CALL logshim(datfileP$, mr!, br!, mh!, bh!, shimr1!, shimr2!, shimh1!, shimh2!) 'Write the results to the "plt" file for plotting CALL logplot(pltfileP$, magnameP$, runP$, nz%, z!(), d1c!(), d2c!(), d3c!(), d4c!(), gout!(), gin!(), hout!(), hin!(), roll!()) END SUB