DECLARE SUB sw2fit (n%, x!(), y!(), c2!, sc2!) DECLARE SUB swcalcsl (nx%, x0!(), dx!, vtvsx!(), svtvsx!(), sl!, ssl!) DECLARE SUB swcheckpar (ok$) DECLARE SUB swdatslvsi (logfile$, imag!, simag!, sl!, ssl!) DECLARE SUB swgetsl (sl!, ssl!) DECLARE SUB swlogsl (logfile$, sl!, ssl!) DECLARE SUB swpltslvsi (logfile$, imag!, simag!, sl!, ssl!) DECLARE SUB vtwgetvtvsx (nx%, x0!(), dx!, vtvsx!(), svtvsx!()) DECLARE SUB vtwmoveabs (x!) DECLARE SUB PolyCurveFit (indvar!(), depvar!(), numobs%, order%, coef!(), yest!(), resid!(), see!, coefsig!(), rsq!, r!, cferror%) DECLARE SUB imaggetiav (imag!, simag!) DECLARE SUB imagramp (inom!) '**************************************************************************** 'Module SWIRE.BAS ' 'These subroutines perform calculations related to sextupole magnet 'stretched wire measurements. ' 'Zachary Wolf '1/14/95 '**************************************************************************** 'Common area for shared parameters COMMON SHARED /swire/ logfileP$, datfileP$, pltfileP$, magnameP$, runP$, dxcmP!, nx0P%, x0P!(), nturnsP%, nimagtestP%, imagtestP!() 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!) 'Compute the integrated gradient 'sl = (1/delX)*(2 * C2) c2! = ABS(c2!) c2! = c2! * 100! * 100! '(Vs/m^2) c2! = c2! / nturnsP% 'take out Nturns, VT now flux change in magnet sl! = 2! * c2! / (dx! * .01) 'Error sc2! = sc2! * 100! * 100! '(Vs/m^2) sc2! = sc2! / nturnsP% 'take out Nturns, VT now flux change in magnet ssl! = 2! * sc2! / (dx! * .01) END SUB SUB swcheckpar (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" 'logfileP$ IF logfileP$ = "" THEN PRINT "SWIRE: log file not defined" EXIT SUB END IF 'datfileP$ IF logfileP$ = "" THEN PRINT "SWIRE: dat file not defined" EXIT SUB END IF 'pltfileP$ IF logfileP$ = "" THEN PRINT "SWIRE: plt file not defined" EXIT SUB END IF 'magnameP$ IF magnameP$ = "" THEN PRINT "SWIRE: magnet name not defined" EXIT SUB END IF 'runP$ IF logfileP$ = "" THEN PRINT "SWIRE: run number not defined" EXIT SUB END IF 'dxcmP! IF dxcmP! <= 0! OR dxcmP! > 10! THEN PRINT "SWIRE: dxcm has improper value" EXIT SUB END IF 'nx0P% IF nx0P% <= 0 OR nx0P% > 50 THEN PRINT "SWIRE: nx0 has improper value" EXIT SUB END IF 'nturnsP% IF nturnsP% <= 0 OR nturnsP% > 200 THEN PRINT "SWIRE: nturns has improper value" EXIT SUB END IF 'nimagtestP% IF nimagtestP% <= 0 OR nimagtestP% > 50 THEN PRINT "SWIRE: nimagtest has improper value" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB swdatslvsi (logfile$, imag!, simag!, 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 '**************************************************************************** 'Keep track of Ncall for the header STATIC ncall% ncall% = ncall% + 1 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the header IF ncall% = 1 THEN PRINT #filenum%, PRINT #filenum%, " INTEGRATED SEXTUPOLE STRENGTH VS CURRENT" PRINT #filenum%, PRINT #filenum%, " Imag sImag SL sSL " PRINT #filenum%, " (A) (A) (T/m) (T/m)" PRINT #filenum%, "---------+---------- ---------+----------" END IF 'Calculated Results PRINT #filenum%, USING "#####.###"; imag!; PRINT #filenum%, USING " #####.###"; simag!; PRINT #filenum%, USING " ##.######"; sl!; PRINT #filenum%, USING " ##.######"; ssl! 'Close the log file CLOSE filenum% END SUB SUB swgetsl (sl!, ssl!) '**************************************************************************** 'This subroutine supervises the wire measurements and integrate sextupole 'strength calculation. ' 'Output: ' sl!, the integrated sextupole strength ' ssl!, the standard deviation of sl! ' 'Zachary Wolf '10/31/94 '**************************************************************************** 'Initialize data arrays DIM vtvsx!(1 TO nx0P%) 'average voltage integral at each position DIM svtvsx!(1 TO nx0P%) 'standard deviation of the voltage integral measurements 'Message PRINT PRINT "Beginning the stretched wire measurement cycle..." 'Measure the voltage integral at points across the magnet aperture CALL vtwgetvtvsx(nx0P%, x0P!(), dxcmP!, vtvsx!(), svtvsx!()) 'Plot VT vs X 'CALL swpltvtvsx(pltfileP$, magnameP$, runP$, nx0P%, x0P!(), vtvsx!(), svtvsx!()) 'Calculate the integrated strength of the sextupole CALL swcalcsl(nx0P%, x0P!(), dxcmP!, vtvsx!(), svtvsx!(), sl!, ssl!) 'Message PRINT PRINT "The integrated sextupole strength is SL = "; sl!; " +- "; ssl!; " T/m" 'Write the result to the log file CALL swlogsl(logfileP$, sl!, ssl!) 'Message PRINT PRINT "Moving back to the home position..." 'Move the wire back to the home position CALL vtwmoveabs(0!) END SUB SUB swlogsl (logfile$, sl!, ssl!) '**************************************************************************** 'This subroutine writes a summary of the VT vs X measurements. ' 'Input: ' logfile$, the name of the log file ' sl!, the integrated sextupole strength of the magnet ' ssl!, the standard deviation of SL ' 'Zachary Wolf '11/25/94, 12/18/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the result PRINT #filenum%, TIME$; " The integrated sextupole strength is SL = "; sl!; " +- "; ssl!; " T/m" 'Close the log file CLOSE filenum% END SUB SUB swpltslvsi (logfile$, imag!, simag!, 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 '**************************************************************************** 'Keep track of Ncall for the header STATIC ncall% ncall% = ncall% + 1 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the header IF ncall% = 1 THEN PRINT #filenum%, ";I sI SL sSL" END IF 'Calculated Results PRINT #filenum%, USING "#####.###"; imag!; PRINT #filenum%, USING " #####.###"; simag!; PRINT #filenum%, USING " ##.######"; sl!; PRINT #filenum%, USING " ##.######"; ssl! 'Close the log file CLOSE filenum% 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 SUB swsetpar (logfile$, datfile$, pltfile$, magname$, run$, dxcm!, nx0%, x0!(), nturns%, nimagtest%, imagtest!()) '**************************************************************************** 'This subroutine sets parameters used in this module. ' 'Input: ' logfile$, name of the log file ' datfile$, name of the data file ' pltfile$, name of the plot file ' magname$, magnet name ' run$, run number ' dxcm!, distance to move the wire in a scan ' nx0%, number of x-positions at which to do wire scans ' x0!(1 to nx0%), array of x-postions ' nturnsP%, number of turns in the wire bundle ' nimagtest%, number of test currents ' imagtest!(1 to nimagtest%), test currents ' 'Zachary Wolf '9/21/95 '**************************************************************************** 'Save the parameters in the local common block for future use logfileP$ = logfile$ datfileP$ = datfile$ pltfileP$ = pltfile$ magnameP$ = magname$ runP$ = run$ dxcmP! = dxcm! nx0P% = nx0% DIM x0P!(1 TO nx0P%) FOR i% = 1 TO nx0P% x0P!(i%) = x0!(i%) NEXT i% nturnsP% = nturns% nimagtestP% = nimagtest% DIM imagtestP!(1 TO nimagtestP%) FOR i% = 1 TO nimagtestP% imagtestP!(i%) = imagtest!(i%) NEXT i% END SUB SUB swslvsi '**************************************************************************** 'This subroutine supervises the wire measurements and integrated sextupole 'calculation. ' 'Zachary Wolf '10/31/94 '**************************************************************************** 'Make sure all parameters have been initialized CALL swcheckpar(ok$) IF ok$ <> "y" THEN PRINT "SW: the parameters in swblvsi have a problem" EXIT SUB END IF 'Loop over currents FOR i% = 1 TO nimagtestP% 'Ramp to the desired current CALL imagramp(imagtestP!(i%)) 'Measure the current CALL imaggetiav(imag!, simag!) 'Perform the stretched wire measurement CALL swgetsl(sl!, ssl!) 'Record the result in the data file CALL swdatslvsi(datfileP$, imag!, simag!, sl!, ssl!) 'Plot the results CALL swpltslvsi(pltfileP$, imag!, simag!, sl!, ssl!) 'End current loop NEXT i% END SUB