'**************************************************************************** 'Module LOGQUAD 'This module contains subroutines to create and fill the log, data, and 'plot files. ' 'Zachary Wolf '8/16/94 '**************************************************************************** SUB logcalc (logfile$) '**************************************************************************** 'This subroutine summarizes the calculations used in the program. ' 'Inputs: ' logfile$, the name of the log file ' 'Zachary Wolf '9/22/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Header PRINT #filenum%, PRINT #filenum%, " SUMMARY OF THE CALCULATIONS AND CONVENTIONS USED" 'Summarize the calculations used for GL vs I PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation of GL:" PRINT #filenum%, "Vn = Nturns * velocity * Bn * L" PRINT #filenum%, " = Nturns * Rcoil * 2pi * Freq * (BLn)" PRINT #filenum%, "BLn = Vn / (Nturns * Rcoil * 2pi * Freq)" PRINT #filenum%, "GL = BL2 / Rcoil = V2 / (Nturns * Rcoil^2 * 2pi * Freq)" 'Harmonics PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation of the harmonics:" PRINT #filenum%, "Field expansion of intz(Br): BLr(r,th) = Sum BLrn(r,th)" PRINT #filenum%, " BLrn(r,th) = bln * r^(n-1) * cos(n*(th - THspole))" PRINT #filenum%, "At the coil radius, BLrn(th) = BLn * cos(n*(th - THspole))" PRINT #filenum%, "The coil voltage Vn(th) = Nturns * velocity * BLrn(th)" PRINT #filenum%, " = Nturns * Rcoil * 2pi * Freq * BLn * cos(n*(th - THspole))" PRINT #filenum%, "The FFT gives Vn and PhiVn in the formula" PRINT #filenum%, "Vn(i) = Vn * cos(n*2pi*i/N + PhiVn), V(i) = Sum(Vn(i))" PRINT #filenum%, "Then, BLn = Vn / (Nturns * Rcoil * 2pi * Freq)" PRINT #filenum%, " THspole = -PhiVn/n" 'Magnetic center PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Calculation of the magnetic center:" PRINT #filenum%, "Xcenter = - (1/GL) * BL1 * sin(THspole1)" PRINT #filenum%, "Ycenter = - (1/GL) * BL1 * cos(THspole1)" 'Close the log file CLOSE filenum% END SUB SUB logfreq (logfile$, freq!) '**************************************************************************** 'This subroutine writes the coil rotation frequency to the log file. ' 'Input: ' logfile$, the name of the log file ' freq!, the measured coil rotation frequency ' 'Zachary Wolf '10/3/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, "Time "; TIME$ PRINT #filenum%, "Coil Rotation Frequency, Freq = "; freq!; " Hz" 'Close the log file CLOSE filenum% END SUB SUB loggl (logfile$, rcoil!, nturns%, nrot%, nmeas%, imag!, freq!, sfreq!, v2!, sv2!, gl!, sgl!, tf!, stf!) '**************************************************************************** 'This subroutine write a summary of a GL measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of coil rotations for average ' nmeas%, the number of measurements for the average and standard deviation ' imag!, the measured current ' freq!, the coil rotation frequency ' sfreq!, the standard deviation of freq ' v2!, the voltage at the second rotation harmonic ' sv2!, the standard deviation of V2 ' gl!, the integrated gradient at each current ' sgl!, the standard deviation of GL ' tf!, GL/I ' stf!, the standard deviation of TF ' 'Zachary Wolf '8/15/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, "Integrated Gradient:" PRINT #filenum%, "Time "; TIME$; "" PRINT #filenum%, "Magnet Current, Imag = "; imag!; " A" PRINT #filenum%, "Coil Rotation Frequency, Freq = "; freq!; " +- "; sfreq!; " 1/s" PRINT #filenum%, "Coil Radius, Rcoil = "; rcoil!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; nturns% PRINT #filenum%, "Average, # Rotations/Measurement = "; nrot%; ", # Measurements = "; nmeas% PRINT #filenum%, "Coil Voltage, V2 = "; v2!; " +- "; sv2!; " V" PRINT #filenum%, "Integrated Gradient, GL = "; gl!; " +- "; sgl!; " T" PRINT #filenum%, "Transfer Function, GL/I = "; tf!; " +- "; stf!; " T/A" PRINT #filenum%, 'Close the log file CLOSE filenum% END SUB SUB logglvsi (logfile$, rcoil!, nturns%, nrot%, nmeas%, ni%, imag!(), freq!(), v2!(), sv2!(), gl!(), sgl!(), tf!(), stf!()) '**************************************************************************** 'This subroutine write a summary of the GL vs I measurements. ' 'Input: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of rotations for average ' nmeas%, the number of measurements for average and standard deviation ' ni%, the number of currents ' imag!(1 to ni%), the measured currents ' freq!(1 to ni%), the coil rotation frequency ' v2!(1 to ni%), the voltage at the second rotation harmonic ' sv2!(1 to ni%), the standard deviation of V2 ' gl!(1 to ni%), the integrated gradient at each current ' sgl!(1 to ni%), the standard deviation of GL ' tf!(1 to ni%), GL/I ' stf!(1 to ni%), the standard deviation of TF ' 'Zachary Wolf '8/14/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write a header for the hysteresis loop PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " INTEGRATED GRADIENT VS CURRENT" PRINT #filenum%, PRINT #filenum%, "Coil Radius, Rcoil = "; rcoil!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; nturns% PRINT #filenum%, "Average: # Rotations/Measurement = "; nrot%; ", # Measurements = "; nmeas% PRINT #filenum%, PRINT #filenum%, " Imag Rot Freq V2 sigV2 GL sigGL GL/I sigGL/I " PRINT #filenum%, " (A) (Hz) (V) (V) (T) (T) (T/kA) (T/kA) " PRINT #filenum%, "-------- -------- --------+-------- --------+-------- --------+--------" 'Write the results FOR i% = 1 TO ni% PRINT #filenum%, USING "####.###"; imag!(i%); PRINT #filenum%, USING " ##.#####"; freq!(i%); PRINT #filenum%, USING " ##.#####"; v2!(i%); PRINT #filenum%, USING " ##.#####"; sv2!(i%); PRINT #filenum%, USING " ##.#####"; gl!(i%); PRINT #filenum%, USING " ##.#####"; sgl!(i%); PRINT #filenum%, USING " ###.####"; tf!(i%) * 1000!; PRINT #filenum%, USING " ###.####"; stf!(i%) * 1000! NEXT i% 'Close the log file CLOSE filenum% END SUB SUB loghar (logfile$, imag!, freq!, sfreq!, rcoil!, nturns%, nrot%, nmeas%, gl!, sgl!, nh%, vm!(), svm!(), vp!(), svp!(), bl!(), sbl!(), th!(), sth!(), r!(), sr!(), x!, sx!, y!, sy!) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' imag!, the magnet current ' freq!, coil rotation frequency ' sfreq!, standard deviation of freq ' rcoil!, coil radius ' nturns%, the number of turns on the coil ' nrot%, the number of rotations for average ' nmeas%, the number of measurements for average and standard deviation ' gl!, integrated gradient ' sgl!, standard deviation of gl! ' nh%, the number of harmonics to print out ' vm!(1 TO nh%), average voltage magnitudes ' svm!(1 TO nh%), standard deviation of voltage magnitudes ' vp!(1 TO nh%), average voltage phases in degrees ' svp!(1 TO nh%), standard deviation of voltage phases ' bl!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbl!(1 TO nh%), standard deviation of Bn ' th!(1 TO nh%), field angle in degrees ' sth!(1 TO nh%), standard deviation of THn ' r!(1 TO nh%), BLn/BL2 ' sr!(1 TO nh%), standard deviation of r ' x!, x position of the magnetic center wrt the coil axis ' sx!, error on x ' y!, y position of the magnetic center wrt the coil axis ' sy!, error on y ' 'Zachary Wolf '7/9/94, 8/14/94 '**************************************************************************** 'Keep track of the number of times called STATIC ncall% ncall% = ncall% + 1 'Simplify the notation pi! = 3.1415926# 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, PRINT #filenum%, "Magnet Current, Imag = "; imag!; " A" PRINT #filenum%, "Integrated Gradient, GL = "; gl!; " +- "; sgl!; " T" PRINT #filenum%, "Coil Rotation Frequency, Freq = "; freq!; " +- "; sfreq!; " Hz" PRINT #filenum%, "Coil Radius, Rcoil = "; rcoil!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; nturns% PRINT #filenum%, "Average, # Rotations/Measurement = "; nrot%; ", # Measurements = "; nmeas% PRINT #filenum%, PRINT #filenum%, " n Vn VnPhase THspole sigTHsp BLn sigBLn BLn/BL2 sig " PRINT #filenum%, " (V) (deg) (deg) (deg) (Tm) (Tm) (%) BLn/BL2" PRINT #filenum%, "--- ------- ------- -------+------- -------+------- -------+-------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.####"; vm!(j%); PRINT #filenum%, USING " ####.##"; vp!(j%); PRINT #filenum%, USING " ####.##"; th!(j%); PRINT #filenum%, USING " ####.##"; sth!(j%); PRINT #filenum%, USING " #.#####"; bl!(j%); PRINT #filenum%, USING " #.#####"; sbl!(j%); PRINT #filenum%, USING " ###.###"; r!(j%) * 100!; PRINT #filenum%, USING " ###.###"; sr!(j%) * 100! NEXT j% 'Print the magnetic center to the log file PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "The magnetic center is at" PRINT #filenum%, "X = "; PRINT #filenum%, USING "#####.#"; x! * 1000000!; PRINT #filenum%, " +- "; PRINT #filenum%, USING "#####.#"; sx! * 1000000!; PRINT #filenum%, " microns" PRINT #filenum%, "Y = "; PRINT #filenum%, USING "#####.#"; y! * 1000000!; PRINT #filenum%, " +- "; PRINT #filenum%, USING "#####.#"; sy! * 1000000!; PRINT #filenum%, " microns" PRINT #filenum%, PRINT #filenum%, "The magnetic center is measured relative to the coil axis" PRINT #filenum%, "effectively at the longitudinal center of the magnet." PRINT #filenum%, "Pitch and yaw are not seen by the coil." 'After the first call, print the following diagram '(The diagram won't fit on the first page of the dat file.) IF ncall% = 1 THEN GOTO done: PRINT #filenum%, PRINT #filenum%, "View from the non-lead end of the magnet:" PRINT #filenum%, IF th!(2) > 0 THEN PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " N S " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " S N " ELSE PRINT #filenum%, " y " PRINT #filenum%, " ^ " PRINT #filenum%, " | " PRINT #filenum%, " S N " PRINT #filenum%, PRINT #filenum%, " --> x " PRINT #filenum%, PRINT #filenum%, " N S " END IF 'Close the log file done: CLOSE filenum% END SUB SUB logimag (logfile$, imag!) '**************************************************************************** 'This subroutine writes the magnet current to the log file. ' 'Input: ' logfile$, the name of the log file ' imag!, the measured current ' 'Zachary Wolf '9/22/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, "Time "; TIME$ PRINT #filenum%, "Magnet Current, Imag = "; imag!; " A" 'Close the log file CLOSE filenum% END SUB SUB lognewpage (logfile$) '**************************************************************************** 'This subroutine writes a page break character to the log file. ' 'Inputs: ' logfile$, the name of the log file ' 'Zachary Wolf '8/20/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write a page break character PRINT #filenum%, CHR$(12) 'Close the log file CLOSE filenum% END SUB SUB logpltglvsi (logfile$, magname$, run$, ni%, imag!(), gl!(), sgl!(), tf!(), stf!()) '**************************************************************************** 'This subroutine write a summary of the GL vs I measurements for plotting. ' 'Input: ' logfile$, the name of the log file ' magname$, the magnet name ' run$, the run number ' ni%, the number of currents ' imag!(1 to ni%), the measured currents ' gl!(1 to ni%), the integrated gradient at each current ' sgl!(1 to ni%), the standard deviation of gl ' tf!(1 to ni%), the transfer function at each current ' stf!(1 to ni%), the standard deviation of tf ' 'Zachary Wolf '7/16/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%, ";i gl sgl tf stf" 'Write the values FOR i% = 1 TO ni% PRINT #filenum%, USING "####.#"; imag!(i%); PRINT #filenum%, USING " ##.#####"; gl!(i%); PRINT #filenum%, USING " ##.#####"; sgl!(i%); PRINT #filenum%, USING " ###.#####"; tf!(i%); PRINT #filenum%, USING " ###.#####"; stf!(i%) NEXT i% 'Close the log file CLOSE filenum% END SUB SUB logpltharvsi (logfile$, magname$, run$, nh%, ni%, inom!(), rvsi!(), srvsi!()) '**************************************************************************** 'This subroutine write a summary of the GL vs I measurements for plotting. ' 'Input: ' logfile$, the name of the log file ' magname$, the magnet name ' run$, the run number ' nh%, the number of harmonics to record ' ni%, the number of currents ' inom!(1 to ni%), the nominal currents the harmonics are measured at ' rvsi!(1 to nh%, 1 to ni%), BLn/BL2 vs n and I ' srvsi!(1 to nh%, 1 to ni%), standard deviation of rvsi! ' 'Zachary Wolf '8/16/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%, ";n r sr r sr ... for different currents" 'Write the legends for the curves FOR i% = 1 TO ni% PRINT #filenum%, "/sa l 'I = "; PRINT #filenum%, USING "###"; inom!(i%); PRINT #filenum%, " A' " + STR$(2 * i%) NEXT i% 'Write the values FOR i% = 1 TO nh% PRINT #filenum%, USING "###"; i%; FOR j% = 1 TO ni% PRINT #filenum%, USING " ##.#####"; rvsi!(i%, j%); PRINT #filenum%, USING " ##.#####"; srvsi!(i%, j%); NEXT j% PRINT #filenum%, NEXT i% 'Close the log file CLOSE filenum% END SUB SUB logrt (logfile$, nrt%, tim$(), imag!(), vmag!(), rmag!(), twin!(), twout!(), tiron!(), tcoil!(), tamb!()) '**************************************************************************** 'This subroutine writes the resistance and temperature measurements 'to the log file. ' 'Inputs: ' logfile$, the name of the log file ' nrt%, the number of resistance and temperature measurements ' tim$(1 to nrt%), the times the measurements were taken ' imag!(1 to nrt%), the magnet current ' vmag!(1 to nrt%), the magnet voltage ' rmag!(1 to nrt%), the magnet resistance ' twin!(1 to nrt%), water input temperature in deg C ' twout!(1 to nrt%), water output temperature in deg C ' tiron!(1 to nrt%), magnet iron temperature in deg C ' tcoil!(1 to nrt%), magnet coil temperature in deg C ' tamb!(1 to nrt%), ambient temperature in deg C ' 'Zachary Wolf '9/6/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the header PRINT #filenum%, PRINT #filenum%, " Resistance and Temperature Measurements " PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, " Time Ipipe Vpipe Rpipe T1 T2 T3 T4 Ambient" PRINT #filenum%, " (A) (V) (mohm) (deg C) (deg C) (deg C) (deg C) (deg C)" PRINT #filenum%, "-------- ------- ------- ------- ------- ------- ------- ------- -------" FOR i% = 1 TO nrt% PRINT #filenum%, USING "&"; tim$(i%); PRINT #filenum%, USING " ####.##"; imag!(i%); PRINT #filenum%, USING " ###.###"; vmag!(i%); PRINT #filenum%, USING " ###.###"; rmag!(i%) * 1000!; PRINT #filenum%, USING " ####.##"; twin!(i%); PRINT #filenum%, USING " ####.##"; twout!(i%); PRINT #filenum%, USING " ####.##"; tiron!(i%); PRINT #filenum%, USING " ####.##"; tcoil!(i%); PRINT #filenum%, USING " ####.##"; tamb!(i%) NEXT i% 'Close the log file CLOSE filenum% END SUB SUB logv (logfile$, ns%, v!(), vm!(), vp!()) '**************************************************************************** 'This subroutine writes voltage samples to the log file. ' 'Inputs: ' logfile$, the name of the log file ' ns%, the number of voltage samples ' v!(0 to ns%-1), the voltage samples ' vm!(0 to ns%/2), magnitudes of the harmonics ' vp!(0 to ns%/2), phases of the harmonics in degrees ' 'Zachary Wolf '7/16/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the samples to the log file FOR k% = 0 TO ns% - 1 PRINT #filenum%, USING "###"; k%; PRINT #filenum%, USING " ###.####"; v!(k%); IF k% <= ns% / 2 THEN PRINT #filenum%, USING " ##.#####"; vm!(k%); PRINT #filenum%, USING " ####.###"; vp!(k%); ELSE PRINT #filenum%, USING " ##.#####"; 0!; PRINT #filenum%, USING " ##.#####"; 0!; END IF PRINT #filenum%, NEXT k% 'Close the log file CLOSE filenum% END SUB SUB logvsumm (logfile$, ns%, v!(), sv!(), a!, b!, c!, phi!, s!) '**************************************************************************** 'This subroutine logs the voltage samples from the rotating coil. ' 'Input: ' logfile$, the name of the log file ' ns%, the number of samples per coil revolution ' v!(0 to ns%-1), the coil voltage at each sample point (average value over several rotations) ' sv!(0 to ns%-1), the standard deviation of v! at each sample point ' a!, the coeffecient of the sin term from the fit ' b!, " cos " ' c!, the fitted amplitude ' phi!, the fitted phase in degrees ' s!, the rms of the residuals ' 'Zachary Wolf '8/15/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the fit parameters PRINT #filenum%, PRINT #filenum%, TIME$; " Coil Voltage Measurement: " PRINT #filenum%, "Vfit(i) = "; PRINT #filenum%, USING "##.#####"; c!; PRINT #filenum%, " * cos(2*2pi*i/n + "; PRINT #filenum%, USING "####.##"; phi!; PRINT #filenum%, " deg)" PRINT #filenum%, " = "; PRINT #filenum%, USING "##.#####"; a!; PRINT #filenum%, " * sin(2*2pi*i/n) + "; PRINT #filenum%, USING "##.#####"; b!; PRINT #filenum%, " * cos(2*2pi*i/n)" PRINT #filenum%, "RMS of the residuals = "; PRINT #filenum%, USING "##.#####"; s! 'Write the values 'FOR i% = 0 TO ns% - 1 STEP 9 'FOR j% = 0 TO 8 ' IF i% + j% > ns% - 1 THEN EXIT FOR ' IF j% = 0 THEN PRINT #filenum%, USING "###.###"; sv!(i% + j%); ' IF j% > 0 THEN PRINT #filenum%, USING " ###.###"; sv!(i% + j%); 'NEXT j% ' PRINT #filenum%, 'NEXT i% 'Close the log file CLOSE filenum% END SUB