DECLARE SUB harloghar (logfile$, nmain%, nh%, bln!(), sbln!(), r!(), sr!()) '**************************************************************************** 'Module HARMONIC.BAS ' 'These subroutines output the field harmonics from the BL(n) measurements. ' 'Zachary Wolf '5/3/95 '**************************************************************************** 'Open the parameter file REM $INCLUDE: 'param.inc' 'The required parameters are in 'FILE 'GETPARAM 'COIL 'BLN ' 'The required parameters are 'logfileP$ 'magnameP$ 'runP$ 'coilradiusmP! 'coilnturnsP% 'coilnrotaveP% 'blnnmeasaveP% SUB harcalcratio (nh%, bln!(), sbln!(), nmain%, rn!(), srn!()) '**************************************************************************** 'This subroutine calculates the ratio of each harmonic strength to the 'strength of the main component at the coil radius. ' 'Input: ' nh%, the number of field harmonics recorded ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' sbln!(1 to nh%), the rms variation of bln ' 'Output: ' nmain%, the number of the main harmonic (1 = dipole, 2 = quad, etc.) ' rn!(1 to nh%), the ratio bl(n)/bl(nmain%) at the coil radius ' srn!(1 to nh%), the rms variation of rn ' 'Zachary Wolf '5/3/95 '**************************************************************************** 'Find the strongest field harmonic nmain% = 1 FOR i% = 1 TO nh% IF bln!(i%) > bln!(nmain%) THEN nmain% = i% NEXT i% 'Compute the field strength ratios at the coil radius FOR i% = 1 TO nh% rn!(i%) = bln!(i%) / bln!(nmain%) NEXT i% 'Compute the rms variation of the rn FOR i% = 1 TO nh% srn!(i%) = rn!(i%) * SQR((sbln!(i%) / bln!(i%)) ^ 2 + (sbln!(nmain%) / bln!(nmain%)) ^ 2) NEXT i% 'Print the results to the screen PRINT PRINT " FIELD HARMONIC STRENGTH RATIOS" PRINT "Nmain = "; nmain% PRINT PRINT " N BLn sigBLn BLn/BLN sBLn/BLN" PRINT " (Tm) (Tm) (%) (%) " PRINT "--- --------+-------- --------+--------" FOR j% = 1 TO nh% PRINT USING "###"; j%; PRINT USING " ##.#####"; bln!(j%); PRINT USING " ##.#####"; sbln!(j%); PRINT USING " ###.####"; rn!(j%) * 100!; PRINT USING " ###.####"; srn!(j%) * 100! NEXT j% 'Log the result CALL harloghar(logfileP$, nmain%, nh%, bln!(), sbln!(), rn!(), srn!()) END SUB SUB hardathar (datfile$, imag!, simag!, nmain%, nh%, bln!(), sbln!(), thn!(), sthn!(), r!(), sr!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the data file. ' 'Inputs: ' datfile$, the name of the data file ' imag!, the magnet current ' simag!, rms variation of imag measurements ' nmain%, the number of the main harmonic ' nh%, the number of harmonics to print out ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbln!(1 TO nh%), standard deviation of Bn ' thn!(1 TO nh%), field angle in degrees ' sthn!(1 TO nh%), standard deviation of THn ' r!(1 TO nh%), BLn/BLNmain ' sr!(1 TO nh%), standard deviation of r ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95, 5/7/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN datfile$ FOR APPEND AS filenum% 'Keep track of # times called STATIC ncall% ncall% = ncall% + 1 'On the first call, write a title on the cover sheet IF ncall% = 1 THEN PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " Harmonics Measurements" END IF 'Start each measurement on a new page 'Write a page break character PRINT #filenum%, CHR$(12) 'Print a header PRINT #filenum%, "Date: "; DATE$ PRINT #filenum%, "Time: "; TIME$ PRINT #filenum%, "Magnet Name: "; magnameP$ PRINT #filenum%, "Run Number: "; runP$ 'Print the results PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, IF imag! >= 0! THEN PRINT #filenum%, "Magnet Current, Imag = "; imag!; " +- "; simag!; " A" END IF PRINT #filenum%, "Coil Radius, Rcoil = "; coilradiusmP!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; coilnturnsP% PRINT #filenum%, "Average, # Rotations/Measurement = "; coilnrotaveP%; ", # Measurements = "; blnnmeasaveP% PRINT #filenum%, "Nmain = "; nmain% PRINT #filenum%, PRINT #filenum%, " N BLn sigBLn THspole sigTH BLn/BLN sBLn/BLN" PRINT #filenum%, " (Tm) (Tm) (deg) (deg) (%) (%) " PRINT #filenum%, "--- --------+-------- --------+-------- --------+--------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.#####"; bln!(j%); PRINT #filenum%, USING " ##.#####"; sbln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%); PRINT #filenum%, USING " ####.##"; sthn!(j%); PRINT #filenum%, USING " ###.####"; r!(j%) * 100!; PRINT #filenum%, USING " ###.####"; sr!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB harlogcalc (logfile$) '**************************************************************************** 'This subroutine summarizes the calculations used in the program. ' 'Inputs: ' logfile$, the name of the log file ' 'Zachary Wolf '5/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Harmonics PRINT #filenum%, PRINT #filenum%, "Harmonic Strength Ratios:" PRINT #filenum%, "The main field, denoted by capital N, is the field harmonic" PRINT #filenum%, "with the largest strength at the coil radius." PRINT #filenum%, "The field strength ratio is defined by" PRINT #filenum%, " Rn = BLn / BLN" PRINT #filenum%, "It gives the ratio of each harmonic field strength to the" PRINT #filenum%, "main field strength at the coil radius." 'Close the log file CLOSE filenum% END SUB SUB harloghar (logfile$, nmain%, nh%, bln!(), sbln!(), rn!(), srn!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' nmain%, the number of the main harmonic ' nh%, the number of harmonics to print out ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbln!(1 TO nh%), standard deviation of Bn ' r!(1 TO nh%), BLn/BLNmain ' sr!(1 TO nh%), standard deviation of r ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, PRINT #filenum%, TIME$; " FIELD HARMONIC STRENGTH RATIOS" PRINT #filenum%, "Nmain = "; nmain% PRINT #filenum%, PRINT #filenum%, " N BLn sigBLn BLn/BLN sBLn/BLN" PRINT #filenum%, " (Tm) (Tm) (%) (%) " PRINT #filenum%, "--- --------+-------- --------+--------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.#####"; bln!(j%); PRINT #filenum%, USING " ##.#####"; sbln!(j%); PRINT #filenum%, USING " ###.####"; rn!(j%) * 100!; PRINT #filenum%, USING " ###.####"; srn!(j%) * 100! NEXT j% 'Close the log file CLOSE filenum% END SUB SUB harplthar (pltfile$, legend$, nh%, rn!(), srn!()) '**************************************************************************** 'This subroutine writes a summary of the field ratio measurements for plotting. ' 'Input: ' pltfile$, the name of the plot file ' legend$, the legend for the rn data ' nh%, the number of harmonics to record ' rn!(1 to nh%), BLn/BLNmain ' srn!(1 to nh%), standard deviation of rn! ' 'Zachary Wolf '8/16/94, 5/6/95 '**************************************************************************** 'Keep track of Ncall for handling the output STATIC ncall% ncall% = ncall% + 1 'Open the plot file pltnum% = FREEFILE OPEN pltfile$ FOR INPUT AS pltnum% 'Open the temp file tempnum% = FREEFILE OPEN "hartemp.dat" FOR OUTPUT AS tempnum% 'On the first call, write the entire file IF ncall% = 1 THEN 'Header PRINT #tempnum%, "/et g '" + magnameP$ + ", Run " + runP$ + "'" PRINT #tempnum%, ";n r sr r sr ... for different currents" 'Legend for the first curve PRINT #tempnum%, "/sa l '" + legend$ + "' 2" 'Write the values FOR i% = 1 TO nh% PRINT #tempnum%, USING "###"; i%; PRINT #tempnum%, USING " ##.#####"; rn!(i%); PRINT #tempnum%, USING " ##.#####"; srn!(i%) NEXT i% END IF 'On calls after the first, append the data IF ncall% > 1 THEN 'Find the harmonics lines, copy lines before the harmonics harmonic$ = "" DO UNTIL harmonic$ = " 1" LINE INPUT #pltnum%, pltline$ harmonic$ = LEFT$(pltline$, 3) IF harmonic$ <> " 1" THEN PRINT #tempnum%, pltline$ LOOP 'Legend for the new curve PRINT #tempnum%, "/sa l '" + legend$ + "' " + LTRIM$(STR$(2 * ncall%)) 'Write the values PRINT #tempnum%, pltline$; PRINT #tempnum%, USING " ##.#####"; rn!(1); PRINT #tempnum%, USING " ##.#####"; srn!(1) FOR i% = 2 TO nh% LINE INPUT #pltnum%, pltline$ PRINT #tempnum%, pltline$; PRINT #tempnum%, USING " ##.#####"; rn!(i%); PRINT #tempnum%, USING " ##.#####"; srn!(i%) NEXT i% END IF 'Close the plot file CLOSE pltnum% 'Close the temp file CLOSE tempnum% 'Replace the plot file with the temp file SHELL "copy hartemp.dat " + pltfile$ 'Delete the temp file SHELL "del hartemp.dat" END SUB