DECLARE SUB PolyCurveFit (indvar!(), depvar!(), numobs%, order%, coef!(), yest!(), resid!(), see!, coefsig!(), rsq!, r!, cferror%) DECLARE SUB swcalcsl (nx%, x0!(), dx!, vtvsx!(), svtvsx!(), sl!, ssl!) DECLARE SUB swlogcalcsl (logfile$, sl!, ssl!) DECLARE SUB sw2fit (n%, x!(), y!(), c2!, sc2!) DECLARE SUB swlogcalcgl (logfile$, gl!, sgl!) DECLARE SUB swcalcgl (nx%, x0!(), dx!, vtvsx!(), svtvsx!(), gl!, sgl!) DECLARE SUB swlinfit (n%, x!(), y!(), m!, sm!, b!, sb!) DECLARE SUB swlogsw (logfile$, nmeas%, nx%, imag!, x0!(), dx!, vt!(), svt!(), gl!, sgl!) DECLARE SUB swlogvtvsx (logfile$, nx%, x0!(), dx!, vt!(), svt!()) DECLARE SUB swmeasvtvsx (nx%, x0!(), dx!, vtvsx!(), svtvsx!()) DECLARE SUB swpltvtvsx (logfile$, magname$, run$, nx%, x!(), vt!(), svt!()) DECLARE SUB wiregetvtav (x0!, dx!, vt!, svt!) DECLARE SUB wiremoveabs (x!) DECLARE SUB imaggeti (imag!) DECLARE SUB imagmeas (imag!, simag!) '**************************************************************************** 'Module SW.BAS ' 'These subroutines perform calculations related to quadrupole magnet 'stretched wire measurements. ' 'Zachary Wolf '1/14/95 '**************************************************************************** 'Open the parameter file REM $INCLUDE: 'param.inc' SUB sw '**************************************************************************** 'This subroutine supervises the wire measurements and integrated sextupole 'calculation. ' 'Zachary Wolf '10/31/94 '**************************************************************************** 'Simplify the notation nx% = nx0P% dx! = dxcmP! DIM x0!(1 TO nx%) FOR i% = 1 TO nx% x0!(i%) = x0P!(i%) NEXT i% nmeas% = nmeasaveP% 'Initialize data arrays DIM vtvsx!(1 TO nx%) 'average voltage integral at each position DIM svtvsx!(1 TO nx%) 'standard deviation of the voltage integral measurements 'Message PRINT PRINT "Beginning the stretched wire measurement cycle..." 'Measure the magnet current CALL imagmeas(imag!, simag!) 'Measure the voltage integral at points across the magnet aperture CALL swmeasvtvsx(nx%, x0!(), dx!, vtvsx!(), svtvsx!()) 'Calculate the integrated strength of the sextupole CALL swcalcsl(nx%, x0!(), dx!, vtvsx!(), svtvsx!(), sl!, ssl!) 'Write the result to the dat file CALL swlogsw(datfileP$, nmeas%, nx%, imag!, x0!(), dx!, vtvsx!(), svtvsx!(), sl!, ssl!) 'Message PRINT PRINT "Moving back to the home position..." 'Move the wire back to the home position CALL wiremoveabs(0!) END SUB SUB sw2fit (n%, x!(), y!(), c2!, sc2!) '**************************************************************************** ' 'Input: ' n%, the number of (x,y) points ' x!(1 to n%), the x values ' y!(1 to n%), the y values ' 'Output: ' c2!, the fitted second order coefficient ' sc2!, error estimate for c2 ' 'Zachary Wolf '6/7/95 '**************************************************************************** 'Use the same variable names as the QBTOOLS routines numobs% = n% DIM indvarary!(0 TO numobs% - 1) DIM depvarary!(0 TO numobs% - 1) order% = 2 DIM polycoef!(0 TO order%) DIM yest!(0 TO numobs% - 1) DIM resid!(0 TO numobs% - 1) DIM coefsig!(0 TO order%) 'Fill the variable arrays FOR i% = 0 TO numobs% - 1 indvarary!(i%) = x!(i% + 1) depvarary!(i%) = y!(i% + 1) NEXT i% 'Do the fit CALL PolyCurveFit(indvarary!(), depvarary!(), numobs%, order%, polycoef!(), yest!(), resid!(), see!, coefsig!(), rsqval!, r!, cferror%) 'Return the second order term c2! = polycoef!(2) sc2! = coefsig!(2) END SUB SUB swcalcsl (nx%, x0!(), dx!, vtvsx!(), svtvsx!(), sl!, ssl!) '**************************************************************************** 'This subroutine calculates the integrated gradient from the measurements 'of the integrated voltage as a function of x. ' 'Input: ' nx%, the number of x positions ' x0!(1 to nx%), the position of the center of each wire motion ' dx!, the distance the wire moves for each motion ' vtvsx!(1 to nx%), the integrated voltage measurements ' svtvsx!(1 to nx%), the standard deviation on each vt ' 'Output: ' sl!, the integrated gradient of the magnet ' ssl!, the standard deviation on sl ' 'Zachary Wolf '1/14/95 '**************************************************************************** 'Fit the vt vs x data points with a line CALL sw2fit(nx%, x0!(), vtvsx!(), c2!, sc2!) 'm=dVT/dX0 (Vs/cm) 'Compute the integrated gradient 'sl = (1/delX)*(2 * C2) c2! = ABS(c2!) c2! = c2! * 100! * 100! '(Vs/m^2) sl! = 2! * c2! / (dx! * .01) 'Error sc2! = sc2! * 100! * 100! '(Vs/m^2) ssl! = 2! * sc2! / (dx! * .01) 'Log the result CALL swlogcalcsl(logfileP$, sl!, ssl!) END SUB SUB swlogcalcsl (logfile$, sl!, ssl!) '**************************************************************************** 'This subroutine writes the calculated integrated sextupole strength of the magnet. ' 'Input: ' logfile$, the name of the log file ' sl!, the integrated sextupole strength of the magnet ' ssl!, the standard deviation of sl ' 'Zachary Wolf '1/14/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Calculated Results PRINT #filenum%, PRINT #filenum%, "The integrated sextupole strength is "; sl!; " +- "; ssl!; " T/m" 'Close the log file CLOSE filenum% END SUB SUB swlogsw (logfile$, nmeas%, nx%, imag!, x0!(), dx!, vt!(), svt!(), gl!, sgl!) '**************************************************************************** 'This subroutine writes a summary of the VT vs X measurements. ' 'Input: ' logfile$, the name of the log file ' nmeas%, the number of measurements for average and standard deviation ' nx%, the number of x-positions ' imag!, the magnet current ' x0!(1 to nx%), the x-position of the center of each wire motion ' dx!, the distance the wire is moved for each measurement ' vt!(1 to nx%), the voltage integral for the wire motion ' svt!(1 to ni%), the standard deviation of VT ' gl!, the integrated gradient of the magnet ' sgl!, the standard deviation of GL ' 'Zachary Wolf '11/25/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write a header PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " STRETCHED WIRE" PRINT #filenum%, " INTEGRATED VOLTAGE VS X" PRINT #filenum%, PRINT #filenum%, "# Measurements For Average, Nmeas = "; nmeas% PRINT #filenum%, "# x-positions, Nx = "; nx% PRINT #filenum%, "Distance wire moved, Delta X = "; dx!; " cm" PRINT #filenum%, PRINT #filenum%, "Magnet Current, Imag = "; imag!; " A" PRINT #filenum%, PRINT #filenum%, " X0 VT sigVT " PRINT #filenum%, " (cm) (VS) (VS) " PRINT #filenum%, " -------- ----------+----------" 'Write the results of the measurements FOR i% = 1 TO nx% PRINT #filenum%, USING " ##.#####"; x0!(i%); PRINT #filenum%, USING " ##.#######"; vt!(i%); PRINT #filenum%, USING " ##.#######"; svt!(i%) NEXT i% 'Calculated Results PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "The integrated sextupole strength is" PRINT #filenum%, USING "###.######"; gl!; PRINT #filenum%, " +- "; PRINT #filenum%, USING " ###.######"; sgl!; PRINT #filenum%, " T/m" 'Close the log file CLOSE filenum% END SUB SUB swlogvtvsx (logfile$, nx%, x0!(), dx!, vt!(), svt!()) '**************************************************************************** 'This subroutine writes a summary of the VT vs X measurements. ' 'Input: ' logfile$, the name of the log file ' nx%, the number of x-positions ' x0!(1 to nx%), the x-position of the center of each wire motion ' dx!, the distance the wire is moved for each measurement ' vt!(1 to nx%), the voltage integral for the wire motion ' svt!(1 to ni%), the standard deviation of VT ' 'Zachary Wolf '11/25/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write a header PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "STRETCHED WIRE MEASUREMENT SUMMARY" PRINT #filenum%, PRINT #filenum%, "Distance wire moved, Delta X = "; dx!; " cm" PRINT #filenum%, "X0 = center position of the wire motion" PRINT #filenum%, "VT = integrated voltage" PRINT #filenum%, PRINT #filenum%, " X0 VT sigVT " PRINT #filenum%, " (cm) (VS) (VS) " PRINT #filenum%, " -------- ----------+----------" 'Write the results of the measurements FOR i% = 1 TO nx% PRINT #filenum%, USING " ##.#####"; x0!(i%); PRINT #filenum%, USING " ##.#######"; vt!(i%); PRINT #filenum%, USING " ##.#######"; svt!(i%) NEXT i% 'Close the log file CLOSE filenum% END SUB SUB swmeasvtvsx (nx%, x0!(), dx!, vtvsx!(), svtvsx!()) '**************************************************************************** 'This subroutine measures the integrated voltage as a function of position 'across the magnet aperture. ' 'Input: ' nx%, the number of x positions ' x0!(1 to nx%), the center position of each wire motion ' dx!, the distance the wire moves ' 'Output: ' vtvsx!(1 to nx%), the integrated voltage at each x positions ' svtvsx!(1 to nx%), the standard deviation of each vt measurement ' 'Zachary Wolf '1/14/95 '**************************************************************************** 'Loop over x positions FOR i% = 1 TO nx% 'Measure the magnet current 'The value is recorded in the log file CALL imaggeti(imag!) 'Message PRINT PRINT "Measuring at X0 = "; x0!(i%); " cm..." 'Get the voltage integral at this position CALL wiregetvtav(x0!(i%), dx!, vt!, svt!) 'Save the results vtvsx!(i%) = vt! svtvsx!(i%) = svt! 'End loop over x positions NEXT i% 'Write the results to the log file CALL swlogvtvsx(logfileP$, nx%, x0!(), dx!, vtvsx!(), svtvsx!()) 'Plot VT vs X CALL swpltvtvsx(pltfileP$, magnameP$, runP$, nx%, x0!(), vtvsx!(), svtvsx!()) END SUB SUB swpltvtvsx (logfile$, magname$, run$, nx%, x!(), vt!(), svt!()) '**************************************************************************** 'This subroutine write a summary of the VT vs X measurements for plotting. ' 'Input: ' logfile$, the name of the log file ' magname$, the magnet name ' run$, the run number ' nx%, the number of x positions ' x!(1 to nx%), the x positions ' vt!(1 to nx%), the integrated voltage at each x position ' svt!(1 to nx%), the standard deviation of vt ' 'Zachary Wolf '12/27/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%, ";x vt svt" 'Write the values FOR i% = 1 TO nx% PRINT #filenum%, USING "##.####"; x!(i%); PRINT #filenum%, USING " ###.#######"; vt!(i%); PRINT #filenum%, USING " ###.#######"; svt!(i%) NEXT i% 'Close the log file CLOSE filenum% END SUB