DECLARE SUB fileheader () DECLARE SUB fileopen (m%, path$, run$) DECLARE SUB fileprot () DECLARE SUB gettestparam () DECLARE SUB measure () DECLARE SUB standardize () DECLARE SUB fileprint () DECLARE SUB fileplot () DECLARE SUB logbl (logfile$, m%, nx%, imag!(), vt!(), svt!(), bl!(), sbl!(), r!(), sr!()) DECLARE SUB logheader (logfile$, mn$, op$, ts$, dv$, rn$, cm$, n1%, i1!(), n2%, i2!()) DECLARE SUB logopen (logfile$) DECLARE SUB logplot (logfile$, magname$, run$, nx%, ni%, imag!(), r!(), sr!()) DECLARE SUB logstand (logfile$, m%, ni%, imag!(), bl!(), sbl!()) DECLARE SUB logvt (logfile$, X%, m%, i1!, i2!, nave%, vtp!(), vtn!()) DECLARE SUB imagmeas (c%, vperi!, imag!) DECLARE SUB imagramp (rr!, iperv!, ifin!) DECLARE SUB vcoilcntvt (c%, n%, t!, nave%, vtp!(), vtn!(), vt!, sigvt!) DECLARE SUB dac488hrinit () DECLARE SUB dac488hrsetupv () DECLARE SUB hp3457init () DECLARE SUB gpibinit () '**************************************************************************** 'Program HERDHAR 'This program is used to measure the integrated harmonics in the 'B-Factory HER dipoles. It samples the voltage from the rotating coil. 'It then numerically integrates the coil voltage as a function of time 'over a half period. This gives the change of flux in the coil as it is 'flipped. The integrated dipole field strength is then determined. 'This is done at several x-locations to determine the harmonics. ' 'Zachary Wolf '5/14/94 '**************************************************************************** 'Include the constants used in the program REM $INCLUDE: 'param.inc' 'Prepare the screen CLS 'Initialize the GPIB CALL gpibinit 'Initialize the DAC CALL dac488hrinit CALL dac488hrsetupv 'Initialize the HP3457 CALL hp3457init 'Print a message about the program PRINT PRINT "Program HERDHAR" PRINT "This program measures the integrated field strengths of all three" PRINT "B-Factory HER dipoles on the test stands as a function of current" PRINT "and as a function of x-position across the gap. In this way" PRINT "the field quality in the magnet can be determined." PRINT "To begin, make sure all coils are centered in the magnets." PRINT 'Get test parameters from the operator CALL gettestparam 'Create the subdirectories to store the data and log files pass% = 0 ON ERROR GOTO direxists path1$ = "c:\magdata\" + magname1P$ MKDIR path1$ PRINT : PRINT "Directory "; path1$; " created" dirdone: IF pass% >= 2 THEN GOTO dir2done path2$ = "c:\magdata\" + magname2P$ MKDIR path2$ PRINT : PRINT "Directory "; path2$; " created" dir2done: 'Open the log and data files and write headers CALL fileopen(1, path1$, runP$) CALL fileopen(2, path2$, runP$) CALL fileheader 'Write a .bat file to print the log and data files CALL fileprint 'Write a .bat file to plot the data CALL fileplot 'Write a .bat file to write protect the data files CALL fileprot 'Standardize the magnet CALL standardize 'Measure the integrated field strength as a function of current CALL measure 'Message PRINT PRINT "Ramping to 0 Amps." 'Ramp to 0 amps CALL imagramp(imagramprateP!, imagpervdacP!, 0!) 'Message PRINT "The test is complete." END direxists: IF ERR = 75 THEN PRINT : PRINT "Directory "; path$; " already exists." pass% = pass% + 1 IF pass% >= 3 THEN CLS PRINT "Problem creating the data files." PRINT "Check that the run number has not already been used." PRINT "The program will be stopped to avoid overwriting any files." PRINT "Terminate the batch job by typing CTRL C." PRINT "Start over by typing HARMONICS." STOP END IF RESUME dirdone END IF ON ERROR GOTO 0 END SUB fileheader '**************************************************************************** 'This subroutine writes the headers of the files. ' 'Input from the /testparam/ common block: ' magname1P$, magnet name for magnet 1 ' magname2P$, magnet name for magnet 2 ' operatorP$, operator name ' runP$, the run number ' commentP$, a comment about the test ' 'Input from the /filenames/ common block: ' logfile1P$, the log file for magnet 1 ' datfile1P$, the data file for magnet 1 ' pltfile1P$, the plot file for magnet 1 ' logfile2P$, the log file for magnet 2 ' datfile2P$, the data file for magnet 2 ' pltfile2P$, the plot file for magnet 2 ' 'Zachary Wolf '4/16/94 '**************************************************************************** 'Magnet 1 'Write the header of the log file CALL logheader(logfile1P$, magname1P$, operatorP$, "D1", "Coil 1", runP$, commentP$, imagnstandP%, imagstandP!(), imagntestP%, imagtestP!()) 'Write the header of the data file CALL logheader(datfile1P$, magname1P$, operatorP$, "D1", "Coil 1", runP$, commentP$, imagnstandP%, imagstandP!(), imagntestP%, imagtestP!()) 'Magnet 2 'Write the header of the log file CALL logheader(logfile2P$, magname2P$, operatorP$, "D2", "Coil 2", runP$, commentP$, imagnstandP%, imagstandP!(), imagntestP%, imagtestP!()) 'Write the header of the data file CALL logheader(datfile2P$, magname2P$, operatorP$, "D2", "Coil 2", runP$, commentP$, imagnstandP%, imagstandP!(), imagntestP%, imagtestP!()) END SUB SUB fileopen (m%, path$, run$) '**************************************************************************** 'This subroutine opens the files that the program uses. ' 'Input: ' m%, test magnet number ' path$, subdirectory where the files are to be created ' run$, run number, used to distinguish files ' 'Output placed in the /filenames/ common block: ' logfileP1$, name, including the path, of the log file ' datfileP1$, name, including the path, of the data file ' pltfileP1$, name, including the path, of the plot data file ' logfileP2$, name, including the path, of the log file ' datfileP2$, name, including the path, of the data file ' pltfileP2$, name, including the path, of the plot data file ' 'Zachary Wolf '4/16/94 '**************************************************************************** 'Make the file extension r% = VAL(run$) IF r% < 10 THEN ext$ = "ru" + run$ IF r% >= 10 THEN ext$ = "r" + run$ 'Open the log file logfile$ = path$ + "\" + "harlog." + ext$ CALL logopen(logfile$) PRINT logfile$; " created" 'Open the data file datfile$ = path$ + "\" + "hardat." + ext$ CALL logopen(datfile$) PRINT datfile$; " created" 'Open the plot data file pltfile$ = path$ + "\" + "harplt." + ext$ CALL logopen(pltfile$) PRINT pltfile$; " created" 'Store the file names IF m% = 1 THEN logfile1P$ = logfile$ datfile1P$ = datfile$ pltfile1P$ = pltfile$ ELSEIF m% = 2 THEN logfile2P$ = logfile$ datfile2P$ = datfile$ pltfile2P$ = pltfile$ END IF END SUB SUB fileplot '**************************************************************************** 'This subroutine makes a .bat file which is used to plot the data. ' 'Inputs from param.inc: ' pltfile1P$, path and name of the plot file for magnet 1 ' pltfile2P$, path and name of the plot file for magnet 2 ' 'Zachary Wolf '5/14/94 '**************************************************************************** 'Create the .bat file filenum% = FREEFILE OPEN "harplot.bat" FOR OUTPUT AS filenum% 'Copy the plot file for magnet 1 PRINT #filenum%, "copy "; pltfile1P$; " harplot.dat" 'Run the plotting program PRINT #filenum%, "c:\easyplot\ep harep.bat" 'Delete the tempory plotting file PRINT #filenum%, "del harplot.dat" 'Copy the plot file for magnet 2 PRINT #filenum%, "copy "; pltfile2P$; " harplot.dat" 'Run the plotting program PRINT #filenum%, "c:\easyplot\ep harep.bat" 'Delete the tempory plotting file PRINT #filenum%, "del harplot.dat" 'Close the log file CLOSE filenum% END SUB SUB fileprint '**************************************************************************** 'This subroutine makes a .bat file which is used to print the data files. ' 'Inputs from param.inc: ' logfile1P$, path and name of the log file for magnet 1 ' datfile1P$, path and name of the data file for magnet 1 ' logfile2P$, path and name of the log file for magnet 2 ' datfile2P$, path and name of the data file for magnet 2 ' 'Zachary Wolf '5/14/94 '**************************************************************************** 'Create the .bat file filenum% = FREEFILE OPEN "harprint.bat" FOR OUTPUT AS filenum% 'Print the data file for magnet 1 PRINT #filenum%, "print "; datfile1P$ 'Print the log file for magnet 1 PRINT #filenum%, "print "; logfile1P$ 'Print the data file for magnet 2 PRINT #filenum%, "print "; datfile2P$ 'Print the log file for magnet 2 PRINT #filenum%, "print "; logfile2P$ 'Close the log file CLOSE filenum% END SUB SUB fileprot '**************************************************************************** 'This subroutine makes a .bat file which is used to set the attributes 'of the data files so they can not be written over. ' 'Inputs from param.inc: ' logfile1P$, path and name of the log file for magnet 1 ' datfile1P$, path and name of the data file for magnet 1 ' pltfile1P$, path and name of the plot file for magnet 1 ' logfile1P$, path and name of the log file for magnet 2 ' datfile2P$, path and name of the data file for magnet 2 ' pltfile2P$, path and name of the data file for magnet 2 ' 'Zachary Wolf '5/14/94 '**************************************************************************** 'Create the .bat file filenum% = FREEFILE OPEN "harprot.bat" FOR OUTPUT AS filenum% 'Make the data files for magnet 1 read only PRINT #filenum%, "attrib +r "; logfile1P$ PRINT #filenum%, "attrib +r "; datfile1P$ PRINT #filenum%, "attrib +r "; pltfile1P$ 'Make the data files for magnet 2 read only PRINT #filenum%, "attrib +r "; logfile2P$ PRINT #filenum%, "attrib +r "; datfile2P$ PRINT #filenum%, "attrib +r "; pltfile2P$ 'Close the bat file CLOSE filenum% 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: ' magname1P$, name of magnet 1 ' magname2P$, name of magnet 2 ' operatorP$, name of the operator doing the test ' runP$, run number ' commentP$, comment about the test ' 'Zachary Wolf '4/16/94 '**************************************************************************** begin: 'Get the name of the magnet on test stand 1 PRINT "What is the name of the magnet on test stand D1?" PRINT "(8 characters or less): ["; magname1P$; "]"; INPUT magname1$ magname1$ = UCASE$(magname1$) IF magname1$ <> "" THEN magname1P$ = magname1$ 'Get the name of the magnet on test stand 2 PRINT "What is the name of the magnet on test stand D2?" PRINT "(8 characters or less): ["; magname2P$; "]"; INPUT magname2$ magname2$ = UCASE$(magname2$) IF magname2$ <> "" THEN magname2P$ = magname2$ '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$; "]"; 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 'as a function of current for the B-Factory high energy ring dipoles. 'Constants come from param.inc. ' 'Zachary Wolf '4/16/94 '**************************************************************************** 'Message PRINT PRINT "Beginning the measurement cycle..." 'Simplify the notation nx% = nxpositionsP% ni% = imagntestP% n% = vcoilnptsP% t! = vcoildeltatP! nave% = vcoilnaveP% 'Initialize data arrays DIM i0!(1 TO nx%) 'reference magnet DIM vt0!(1 TO nx%) DIM sigvt0!(1 TO nx%) DIM bl0!(1 TO nx%) DIM sigbl0!(1 TO nx%) DIM i1!(1 TO nx%) 'test magnet 1 DIM vt1!(1 TO nx%) DIM sigvt1!(1 TO nx%) DIM bl1!(1 TO nx%) DIM sigbl1!(1 TO nx%) DIM r1!(1 TO nx%) DIM sigr1!(1 TO nx%) DIM i2!(1 TO nx%) 'test magnet 2 DIM vt2!(1 TO nx%) DIM sigvt2!(1 TO nx%) DIM bl2!(1 TO nx%) DIM sigbl2!(1 TO nx%) DIM r2!(1 TO nx%) DIM sigr2!(1 TO nx%) DIM vtp!(1 TO nave%) 'holds +vt values during averaging DIM vtn!(1 TO nave%) 'holds -vt values during averaging DIM one!(1 TO nx%) FOR X% = 1 TO nx% one!(X%) = 1! NEXT X% DIM rxi1!(1 TO nx%, 1 TO ni%) DIM srxi1!(1 TO nx%, 1 TO ni%) DIM rxi2!(1 TO nx%, 1 TO ni%) DIM srxi2!(1 TO nx%, 1 TO ni%) 'Loop over currents FOR i% = 1 TO ni% 'Message PRINT PRINT "Ramping to "; imagtestP!(i%); " Amps." 'Ramp to the desired current CALL imagramp(imagramprateP!, imagpervdacP!, imagtestP!(i%)) 'Loop over x-positions FOR X% = 1 TO nx% 'Message to move coils PRINT PRINT "Please move coils 1 and 2 to position "; X% PRINT "The reference coil does not move." INPUT "Press ENTER when ready.", a$ 'Loop over reference and magnets under test FOR m% = 0 TO 2 'Get the parameters for the magnet being measured IF m% = 0 THEN c% = coil0chanP% coilconst! = coil0constP! ELSEIF m% = 1 THEN c% = coil1chanP% coilconst! = coil1constP! ELSEIF m% = 2 THEN c% = coil2chanP% coilconst! = coil2constP! END IF 'Message IF m% = 0 THEN PRINT "Measuring the integrated field strength of the reference magnet." ELSE PRINT "Measuring the integrated field strength of magnet "; m%; "." END IF 'Measure the current before the coil measurement CALL imagmeas(imagchanP%, vtransperimagP!, ibef!) 'Measure the voltage integral CALL vcoilcntvt(c%, n%, t!, nave%, vtp!(), vtn!(), vt!, sigvt!) 'Measure the current after the coil measurement CALL imagmeas(imagchanP%, vtransperimagP!, iaft!) 'Write the voltage integrals to the log file IF m% = 0 THEN CALL logvt(logfile1P$, X%, m%, ibef!, iaft!, nave%, vtp!(), vtn!()) CALL logvt(logfile2P$, X%, m%, ibef!, iaft!, nave%, vtp!(), vtn!()) ELSEIF m% = 1 THEN CALL logvt(logfile1P$, X%, m%, ibef!, iaft!, nave%, vtp!(), vtn!()) ELSEIF m% = 2 THEN CALL logvt(logfile2P$, X%, m%, ibef!, iaft!, nave%, vtp!(), vtn!()) END IF 'Apply the coil constant to get bl from vt bl! = vt! * coilconst! sigbl! = sigvt! * coilconst! 'Message PRINT "The integrated voltage is "; vt!; " +- "; sigvt!; " Vs" PRINT "The integrated field strength is "; bl!; " +- "; sigbl!; " Tm." 'Place the results in a data array IF m% = 0 THEN i0!(X%) = (ibef! + iaft!) / 2 vt0!(X%) = vt! sigvt0!(X%) = sigvt! bl0!(X%) = bl! sigbl0!(X%) = sigbl! ELSEIF m% = 1 THEN i1!(X%) = (ibef! + iaft!) / 2 vt1!(X%) = vt! sigvt1!(X%) = sigvt! bl1!(X%) = bl! sigbl1!(X%) = sigbl! ELSEIF m% = 2 THEN i2!(X%) = (ibef! + iaft!) / 2 vt2!(X%) = vt! sigvt2!(X%) = sigvt! bl2!(X%) = bl! sigbl2!(X%) = sigbl! END IF 'End loop over magnets NEXT m% 'End loop over x-positions NEXT X% 'Find the ratio of the test magnet strength to the reference strength FOR X% = 1 TO nx% bl0c! = bl0!(X%) * i1!(X%) / i0!(X%) r1!(X%) = bl1!(X%) / bl0c! sigr1!(X%) = r1!(X%) * SQR((sigbl1!(X%) / bl1!(X%)) ^ 2 + (sigbl0!(X%) / bl0!(X%)) ^ 2) bl0c! = bl0!(X%) * i2!(X%) / i0!(X%) r2!(X%) = bl2!(X%) / bl0c! sigr2!(X%) = r2!(X%) * SQR((sigbl2!(X%) / bl2!(X%)) ^ 2 + (sigbl0!(X%) / bl0!(X%)) ^ 2) rxi1!(X%, i%) = r1!(X%) srxi1!(X%, i%) = sigr1!(X%) rxi2!(X%, i%) = r2!(X%) srxi2!(X%, i%) = sigr2!(X%) NEXT X% 'Write the results to the log file and data file 'Magnet 1 CALL logbl(logfile1P$, 0, nx%, i0!(), vt0!(), sigvt0!(), bl0!(), sigbl0!(), one!(), one!()) CALL logbl(datfile1P$, 0, nx%, i0!(), vt0!(), sigvt0!(), bl0!(), sigbl0!(), one!(), one!()) CALL logbl(logfile1P$, 1, nx%, i1!(), vt1!(), sigvt1!(), bl1!(), sigbl1!(), r1!(), sigr1!()) CALL logbl(datfile1P$, 1, nx%, i1!(), vt1!(), sigvt1!(), bl1!(), sigbl1!(), r1!(), sigr1!()) 'Magnet 2 CALL logbl(logfile2P$, 0, nx%, i0!(), vt0!(), sigvt0!(), bl0!(), sigbl0!(), one!(), one!()) CALL logbl(datfile2P$, 0, nx%, i0!(), vt0!(), sigvt0!(), bl0!(), sigbl0!(), one!(), one!()) CALL logbl(logfile2P$, 2, nx%, i2!(), vt2!(), sigvt2!(), bl2!(), sigbl2!(), r2!(), sigr2!()) CALL logbl(datfile2P$, 2, nx%, i2!(), vt2!(), sigvt2!(), bl2!(), sigbl2!(), r2!(), sigr2!()) 'End loop over currents NEXT i% 'Write the results to the plotting file 'Magnet 1 CALL logplot(pltfile1P$, magname1P$, runP$, nx%, ni%, imagtestP!(), rxi1!(), srxi1!()) 'Magnet 2 CALL logplot(pltfile2P$, magname2P$, runP$, nx%, ni%, imagtestP!(), rxi2!(), srxi2!()) END SUB SUB standardize '**************************************************************************** 'This procedure controls the standardization of the magnet. Measurements 'of the integrated field strength are made after each part of the ramp. '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% n% = vcoilnptsP% t! = vcoildeltatP! nave% = vcoilnaveP% 'Initialize data arrays DIM i0!(1 TO ni%) 'reference magnet DIM bl0!(1 TO ni%) DIM sigbl0!(1 TO ni%) DIM i1!(1 TO ni%) 'test magnet 1 DIM bl1!(1 TO ni%) DIM sigbl1!(1 TO ni%) DIM i2!(1 TO ni%) 'test magnet 2 DIM bl2!(1 TO ni%) DIM sigbl2!(1 TO ni%) DIM vtp!(1 TO nave%) 'holds +vt values used for averaging DIM vtn!(1 TO nave%) 'holds -vt values used for averaging 'Loop over currents FOR i% = 1 TO ni% 'Message PRINT PRINT "Ramping to "; imagstandP!(i%); " Amps." 'Ramp to the desired current CALL imagramp(imagramprateP!, imagpervdacP!, imagstandP!(i%)) 'Loop over reference and magnets under test FOR m% = 0 TO 2 'Get the parameters for the magnet being measured IF m% = 0 THEN c% = coil0chanP% coilconst! = coil0constP! ELSEIF m% = 1 THEN c% = coil1chanP% coilconst! = coil1constP! ELSEIF m% = 2 THEN c% = coil2chanP% coilconst! = coil2constP! END IF 'Message IF m% = 0 THEN PRINT "Measuring the integrated field strength of the reference magnet." ELSE PRINT "Measuring the integrated field strength of magnet "; m%; "." END IF 'Measure the current before the coil measurement CALL imagmeas(imagchanP%, vtransperimagP!, ibef!) 'Measure the voltage integral CALL vcoilcntvt(c%, n%, t!, nave%, vtp!(), vtn!(), vt!, sigvt!) 'Measure the current after the coil measurement CALL imagmeas(imagchanP%, vtransperimagP!, iaft!) 'Apply the coil constant to get bl from vt bl! = vt! * coilconst! sigbl! = sigvt! * coilconst! 'Message PRINT "The integrated voltage is "; vt!; " +- "; sigvt!; " Vs" PRINT "The integrated field strength is "; bl!; " +- "; sigbl!; " Tm." 'Place the results in a data array IF m% = 0 THEN i0!(i%) = (ibef! + iaft!) / 2 bl0!(i%) = bl! sigbl0!(i%) = sigbl! ELSEIF m% = 1 THEN i1!(i%) = (ibef! + iaft!) / 2 bl1!(i%) = bl! sigbl1!(i%) = sigbl! ELSEIF m% = 2 THEN i2!(i%) = (ibef! + iaft!) / 2 bl2!(i%) = bl! sigbl2!(i%) = sigbl! END IF 'End loop over magnets NEXT m% 'End loop over currents NEXT i% 'Write the results to the log file and data file 'Magnet 1 CALL logstand(logfile1P$, 0, ni%, i0!(), bl0!(), sigbl0!()) CALL logstand(logfile1P$, 1, ni%, i1!(), bl1!(), sigbl1!()) 'Magnet 2 CALL logstand(logfile2P$, 0, ni%, i0!(), bl0!(), sigbl0!()) CALL logstand(logfile2P$, 2, ni%, i2!(), bl2!(), sigbl2!()) END SUB