DECLARE SUB vtautogain () DECLARE SUB mmdatmuxyz (logfile$, proj%, mux!, smux!, muy!, smuy!, muz!, smuz!) DECLARE SUB mmcalcxyz (projection%, mu!, smu!, th!, sth!, mux!, smux!, muy!, smuy!, muz!, smuz!) DECLARE SUB mmdatparam (datfile$) DECLARE SUB mmcheckpar (ok$) DECLARE SUB mmdatmuav (logfile$, proj%, mu!, smu!, th!, sth!) DECLARE SUB mmgetmu (mu!, th!) DECLARE SUB mmgetmuav (mu!, smu!, th!, sth!) DECLARE SUB mmlogmu (logfile$, rotdir$, vtmag!, vtphase!, mu!, th!) DECLARE SUB mmlogmuav (logfile$, mu!, smu!, th!, sth!) DECLARE SUB mmmeas (projection%) DECLARE SUB mmdatcalib (logfile$, icoil!, calcoilarea!, mucalc!) DECLARE SUB vtgetvthar1 (rotdir$, vtmag!, vtphase!) DECLARE SUB pmtdattemp (logfile$, temp!) DECLARE SUB pmtgettblock (temp!) DECLARE SUB hp3457cv (c%, v!) '**************************************************************************** 'Module MAGMOM.BAS ' 'These subroutines find the magnetic moment of a permenent magnet block. ' 'Zachary Wolf '9/16/95 '**************************************************************************** 'Common block containing parameters for this module COMMON SHARED /magmom/ logfileP$, datfileP$, hhcoilradiusP!, hhGP!, hhnturnsP%, nmeasaveP%, calcurhpchanP%, calvtransperimagP!, calcoilareaP! 'Constants used in this module CONST mu0P! = 1.256637E-06 'mu0, 4*pi*10^-7, Tm/A SUB mmcalcxyz (projection%, mu!, smu!, th!, sth!, mux!, smux!, muy!, smuy!, muz!, smuz!) '**************************************************************************** 'This subroutine calculates the components of the magnetic moment. ' 'Input: ' projection%, gives the projection of mu being measured ' 1 = projection of mu in x-y plane ' 2 = projection of mu in y-z plane ' 3 = projection of mu in z-x plane ' mu!, magnitude of the magnetic moment (Tm^3) ' smu!, rms variation of mu in repeated measurements ' th!, angle of the magnetic moment (deg), + = CCW, - = CW ' sth!, rms variation of th ' 'Output: ' mux!, calculated x component of the magnetic moment ' smux!, calculated rms variation of the x component ' muy!, calculated y component of the magnetic moment ' smuy!, calculated rms variation of the y component ' muz!, calculated z component of the magnetic moment ' smuz!, calculated rms variation of the z component ' 'Zachary Wolf '6/14/96 '**************************************************************************** 'Default mux! = 0! smux! = 0! muy! = 0! smuy! = 0! muz! = 0! smuz! = 0! 'Convert angles to radians thrad! = th! * 3.1415927# / 180! sthrad! = sth! * 3.1415927# / 180! 'Consider each projection separately 'Projection 1, x-y plane ' |z ' | /y +th ' |/______x IF projection% = 1 THEN mux! = mu! * COS(thrad!) muy! = mu! * SIN(thrad!) muz! = 0! smux! = mux! * SQR((smu! / mu!) ^ 2 + (SIN(thrad!) * sthrad! / (COS(thrad!) + .00001)) ^ 2) smux! = ABS(smux!) smuy! = muy! * SQR((smu! / mu!) ^ 2 + (COS(thrad!) * sthrad! / (SIN(thrad!) + .00001)) ^ 2) smuy! = ABS(smuy!) smuz! = 0! END IF 'Projection 2, y-z plane ' |x ' | +th ' |______z ' / ' /y IF projection% = 2 THEN muz! = mu! * COS(thrad!) muy! = mu! * SIN(-thrad!) mux! = 0! smuz! = muz! * SQR((smu! / mu!) ^ 2 + (SIN(thrad!) * sthrad! / (COS(thrad!) + .00001)) ^ 2) smuz! = ABS(smuz!) smuy! = muy! * SQR((smu! / mu!) ^ 2 + (COS(thrad!) * sthrad! / (SIN(thrad!) + .00001)) ^ 2) smuy! = ABS(smuy!) smux! = 0! END IF 'Projection 3, z-x plane ' |y ' | /x +th ' |/______z IF projection% = 3 THEN muz! = mu! * COS(thrad!) mux! = mu! * SIN(thrad!) muy! = 0! smuz! = muz! * SQR((smu! / mu!) ^ 2 + (SIN(thrad!) * sthrad! / (COS(thrad!) + .00001)) ^ 2) smuz! = ABS(smuz!) smux! = mux! * SQR((smu! / mu!) ^ 2 + (COS(thrad!) * sthrad! / (SIN(thrad!) + .00001)) ^ 2) smux! = ABS(smux!) smuy! = 0! END IF END SUB SUB mmcalibrate '**************************************************************************** 'This subroutine measures the magnetic moment of a current loop of known 'area. It outputs the measured and expected magnetic moments to the log 'file. ' 'Zachary Wolf '6/11/96 '**************************************************************************** 'Make sure all required parameters are defined CALL mmcheckpar(ok$) IF ok$ <> "y" THEN EXIT SUB END IF 'Make an initial measurement of the calibration coil current CALL hp3457cv(calcurhpchanP%, vtrans!) iinit! = vtrans! / calvtransperimagP! 'Perform a magnetic moment measurement 'Write the results to the data file CALL mmmeas(1) 'Make a final measurement of the calibration coil current CALL hp3457cv(calcurhpchanP%, vtrans!) ifinal! = vtrans! / calvtransperimagP! 'Average the two current measurements icoil! = (iinit! + ifinal!) / 2! 'Calculate the expected magnetic moment mucalc! = mu0P! * icoil! * calcoilareaP! 'Write the result of the calculation to the log and data files CALL mmdatcalib(logfileP$, icoil!, calcoilareaP!, mucalc!) CALL mmdatcalib(datfileP$, icoil!, calcoilareaP!, mucalc!) END SUB SUB mmcheckpar (ok$) '**************************************************************************** 'This subroutine checks that all required MM parameters have been assigned 'values. ' 'Output: ' ok$, "y" if parameter assignments are ok, "n" otherwise ' 'Zachary Wolf '9/18/95 '**************************************************************************** 'Default value ok$ = "n" IF logfileP$ = "" THEN PRINT "MM: Log file not defined" EXIT SUB END IF IF datfileP$ = "" THEN PRINT "MM: Data file not defined" EXIT SUB END IF IF hhcoilradiusP! <= 0 OR hhcoilradiusP! > 2 THEN PRINT "MM: coil radius problem: "; hhcoilradiusP! EXIT SUB END IF IF hhGP! <= 1.39 OR hhGP! > 1.4 THEN PRINT "MM: G problem: "; hhGP! EXIT SUB END IF IF hhnturnsP% <= 0 OR hhnturnsP% > 10000 THEN PRINT "MM: Nturns problem: "; hhnturnsP% EXIT SUB END IF IF nmeasaveP% <= 0 OR nmeasaveP% > 50 THEN PRINT "MM: nmeasaveP% problem: "; nmeasaveP% EXIT SUB END IF IF calcurhpchanP% < 0 OR calcurhpchanP% > 9 THEN PRINT "MM: calcurhpchanP% problem: "; calcurhpchanP% EXIT SUB END IF IF calvtransperimagP! <= 0 THEN PRINT "MM: calvtransperimagP! problem: "; calvtransperimagP! EXIT SUB END IF IF calcoilareaP! <= 0 OR calcoilareaP! > 1! THEN PRINT "MM: calcoilareaP! problem: "; calcoilareaP! EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB mmdatcalib (logfile$, icoil!, calcoilarea!, mucalc!) '**************************************************************************** 'This subroutine writes the calculated calibration coil magnetic moment 'to the data file. ' 'Inputs: ' logfile$, the name of the log file ' icoil!, calibration coil current (A) ' calcoilarea!, calibration coil area (m^2) ' mucalc!, calibration coil magnetic moment (Tm^3) ' 'Zachary Wolf '6/11/96 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the data file PRINT #filenum%, PRINT #filenum%, "Calibration Coil Calculated Magnetic Moment:" PRINT #filenum%, "Calibration coil current, I = "; icoil!; " A" PRINT #filenum%, "Calibration coil area, A = "; calcoilarea!; " m^2" PRINT #filenum%, "Calculated magnetic moment, M = "; mucalc!; " Tm^3" 'Close the log file CLOSE filenum% END SUB SUB mmdatmuav (logfile$, proj%, mu!, smu!, th!, sth!) '**************************************************************************** 'This subroutine writes the average and rms magnetic moment measurements 'to the log file. ' 'Inputs: ' logfile$, the name of the log file ' proj%, projection plane the measurement is made in ' mu!, the magnetic moment ' smu!, rms variation of mu ' th!, magnetic moment direction ' sth!, rms variation of th ' 'Zachary Wolf '9/15/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Define projection planes DIM planes$(1 TO 3) planes$(1) = "X-Y" planes$(2) = "Y-Z" planes$(3) = "Z-X" 'Print the results to the log file PRINT #filenum%, PRINT #filenum%, "Magnetic Moment Measurement:" PRINT #filenum%, "Projection plane: "; proj%; " ("; planes$(proj%); ")" PRINT #filenum%, "Magnetic moment strength, M = "; mu!; " +- "; smu!; " Tm^3" PRINT #filenum%, "Magnetic moment direction CCW, Theta = "; th!; " +- "; sth!; " deg" 'Close the log file CLOSE filenum% END SUB SUB mmdatmuxyz (logfile$, proj%, mux!, smux!, muy!, smuy!, muz!, smuz!) '**************************************************************************** 'This subroutine writes the xyz components of the magnetic moment 'to the log file. ' 'Inputs: ' logfile$, the name of the log file ' proj%, projection plane the measurement is made in ' mux!, the x component of the magnetic moment ' smux!, rms variation of mux ' muy!, the y component of the magnetic moment ' smuy!, rms variation of muy ' muz!, the z component of the magnetic moment ' smuz!, rms variation of muz ' 'Zachary Wolf '6/14/96 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Projection 1, x-y IF proj% = 1 THEN PRINT #filenum%, " |\ " PRINT #filenum%, " Y^ | \ Mx = "; mux!; " +- "; smux!; " Tm^3" PRINT #filenum%, " | | | My = "; muy!; " +- "; smuy!; " Tm^3" PRINT #filenum%, " | | =>| +th " PRINT #filenum%, " Z. | | --->X " PRINT #filenum%, " | / " PRINT #filenum%, " |/ " PRINT #filenum%, " View From Above " END IF 'Projection 2, y-z IF proj% = 2 THEN PRINT #filenum%, " +th " PRINT #filenum%, " X. |-------------| --->Z" PRINT #filenum%, " | |-------------| " PRINT #filenum%, " | | |<= My = "; muy!; " +- "; smuy!; " Tm^3" PRINT #filenum%, " | |-------------| Mz = "; muz!; " +- "; smuz!; " Tm^3" PRINT #filenum%, " Yv |-------------| " PRINT #filenum%, " View From Above " END IF 'Projection 3, z-x IF proj% = 3 THEN PRINT #filenum%, " X^ |-------------| " PRINT #filenum%, " | | | ^^" PRINT #filenum%, " | | | || Mx = "; mux!; " +- "; smux!; " Tm^3" PRINT #filenum%, " | | | +th Mz = "; muz!; " +- "; smuz!; " Tm^3" PRINT #filenum%, " Y. |-------------| --->Z" PRINT #filenum%, " View From Above " END IF 'Close the log file CLOSE filenum% END SUB SUB mmdatparam (logfile$) '**************************************************************************** 'This subroutine writes parameter values to the data file. ' 'Inputs: ' logfile$, the name of the data file ' 'Zachary Wolf '9/15/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the values PRINT #filenum%, PRINT #filenum%, "Helmholtz Coil Parameters:" PRINT #filenum%, "Coil radius, R = "; hhcoilradiusP!; " m" PRINT #filenum%, "Number of turns, N = "; hhnturnsP% PRINT #filenum%, "Geometry factor, G = "; hhGP! PRINT #filenum%, "Number of measurements for averaging = "; nmeasaveP% 'Close the log file CLOSE filenum% END SUB SUB mmgetmu (mu!, th!) '**************************************************************************** 'This subroutine gets the magnetic moment of a permanent magnet block. 'It also returns dipole direction with respect to the reference direction 'defined by the encoder index pulse. ' 'Output: ' mu!, the magnetic moment of the block (Tm^3) ' th!, the dipole direction wrt the reference (degrees), + = CCW, - = CW ' 'Zachary Wolf '9/14/95 '**************************************************************************** 'Make sure all required parameters are defined CALL mmcheckpar(ok$) IF ok$ <> "y" THEN mu! = 0! th! = 0! EXIT SUB END IF 'CW Rotation 'Get the integrated voltage harmonic at the fundamental frequency for CW rotation CALL vtgetvthar1("+", vtmagcw!, vtphasecw!) 'Compute the magnetic moment and direction mucw! = vtmagcw! * hhcoilradiusP! * hhGP! / hhnturnsP% thcw! = -vtphasecw! '- sign, FFT convention is cos(th + phase) 'Log the results CALL mmlogmu(logfileP$, "+", vtmagcw!, vtphasecw!, mucw!, thcw!) 'CCW Rotation 'Get the integrated voltage harmonic at the fundamental frequency for CCW rotation CALL vtgetvthar1("-", vtmagccw!, vtphaseccw!) 'Compute the magnetic moment and direction muccw! = vtmagccw! * hhcoilradiusP! * hhGP! / hhnturnsP% thccw! = -vtphaseccw! '- sign, FFT convention is cos(th + phase) 'Log the results CALL mmlogmu(logfileP$, "-", vtmagccw!, vtphaseccw!, muccw!, thccw!) 'Average the CW and CCW measurements and return the average values mu! = (mucw! + muccw!) / 2! th! = (thcw! + thccw!) / 2! END SUB SUB mmgetmuav (mu!, smu!, th!, sth!) '**************************************************************************** 'This subroutine measures the magnetic moment several times and returns 'the average and rms variation. ' 'Output: ' mu!, average of the magnetic moment measurements ' smu!, rms variation of mu ' th!, average of the direction measurements ' sth!, rms variation of th ' 'Zachary Wolf '9/15/95 '**************************************************************************** 'Simplify the notation nm% = nmeasaveP% 'Initialize data arrays DIM mumeas!(1 TO nm%) DIM thmeas!(1 TO nm%) 'Message PRINT PRINT "Measuring mu average..." 'Loop over the measurements FOR i% = 1 TO nm% 'Message PRINT " " + LTRIM$(STR$(i%)); 'Measure the magnetic moment CALL mmgetmu(mumeas!(i%), thmeas!(i%)) 'End the loop over the measurements NEXT i% 'Finish loop messages PRINT 'Compute averages mu! = 0! th! = 0! FOR i% = 1 TO nm% mu! = mu! + mumeas!(i%) th! = th! + thmeas!(i%) NEXT i% mu! = mu! / nm% th! = th! / nm% 'Compute rms deviations smu! = 0! sth! = 0! FOR i% = 1 TO nm% smu! = smu! + (mumeas!(i%) - mu!) ^ 2 sth! = sth! + (thmeas!(i%) - th!) ^ 2 NEXT i% smu! = SQR(smu! / nm%) sth! = SQR(sth! / nm%) 'Write the results to the log file CALL mmlogmuav(logfileP$, mu!, smu!, th!, sth!) 'Print the results to the screen PRINT PRINT "Magnetic Moment Measurement:" PRINT "Magnetic moment strength mu = "; mu!; " +- "; smu!; " Tm^3" PRINT "Magnetic moment direction th = "; th!; " +- "; sth!; " deg" END SUB SUB mmlogmu (logfile$, rotdir$, vtmag!, vtphase!, mu!, th!) '**************************************************************************** 'This subroutine writes a magnetic moment measurement to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rotdir$, rotation direction, "+" = CW, "-" = CCW ' vtmag!, magnitude of the integrated voltage at the fundamental frequency ' vtphase!, phase of the integrated voltage ' mu!, the magnetic moment ' th!, magnetic moment direction ' 'Zachary Wolf '9/15/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, TIME$; " Magnetic Moment Calculation:" PRINT #filenum%, " Rotation direction: "; rotdir$ PRINT #filenum%, " Integrated voltage vtmag = "; vtmag!; " Vs" PRINT #filenum%, " Integrated voltage vtphase = "; vtphase!; " deg" PRINT #filenum%, " Magnetic moment strength mu = "; mu!; " Tm^3" PRINT #filenum%, " Magnetic moment direction th = "; th!; " deg" 'Close the log file CLOSE filenum% END SUB SUB mmlogmuav (logfile$, mu!, smu!, th!, sth!) '**************************************************************************** 'This subroutine writes the average and rms magnetic moment measurements 'to the log file. ' 'Inputs: ' logfile$, the name of the log file ' mu!, the magnetic moment ' smu!, rms variation of mu ' th!, magnetic moment direction ' sth!, rms variation of th ' 'Zachary Wolf '9/15/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, TIME$; " Average Magnetic Moment:" PRINT #filenum%, " Magnetic moment strength mu = "; mu!; " +- "; smu!; " Tm^3" PRINT #filenum%, " Magnetic moment direction th = "; th!; " +- "; sth!; " deg" 'Close the log file CLOSE filenum% END SUB SUB mmmeas (projection%) '**************************************************************************** 'This subroutine performs a magnetic moment measurement. ' 'Input: ' projection%, gives the projection of mu being measured ' 1 = projection of mu in x-y plane ' 2 = projection of mu in y-z plane ' 3 = projection of mu in z-x plane ' 'Zachary Wolf '6/11/96 '**************************************************************************** 'Check projection% IF projection% < 1 OR projection% > 3 THEN PRINT "MMMEAS: unknown projection requested" EXIT SUB END IF 'Place the magnet BEEP PRINT PRINT "Please place the magnet in position "; LTRIM$(STR$(projection%)); "." INPUT "Press ENTER when ready.", a$ 'Set the gain of the integrator IF projection% = 1 THEN CALL vtautogain 'Get the block temperature before the measurement CALL pmtgettblock(temp1!) 'Perform the measurement CALL mmgetmuav(mu!, smu!, th!, sth!) 'Get the block temperature after the measurement CALL pmtgettblock(temp2!) 'Calculate the average temperature during the measurement temp! = (temp1! + temp2!) / 2! 'Calculate the xyz components of the magnetic moment CALL mmcalcxyz(projection%, mu!, smu!, th!, sth!, mux!, smux!, muy!, smuy!, muz!, smuz!) 'Store the result in the data file CALL mmdatmuav(datfileP$, projection%, mu!, smu!, th!, sth!) CALL pmtdattemp(datfileP$, temp!) CALL mmdatmuxyz(datfileP$, projection%, mux!, smux!, muy!, smuy!, muz!, smuz!) 'Store the result in the log file CALL mmdatmuav(logfileP$, projection%, mu!, smu!, th!, sth!) CALL pmtdattemp(logfileP$, temp!) CALL mmdatmuxyz(logfileP$, projection%, mux!, smux!, muy!, smuy!, muz!, smuz!) END SUB SUB mmsetpar (logfile$, datfile$, hhcoilradius!, hhG!, hhnturns%, nmeasave%, calcurhpchan%, calvtransperimag!, calcoilarea!) '**************************************************************************** 'This subroutine sets all required parameters for a Helmholtz coil 'measurement of a magnetic moment. ' 'Input: ' logfile$, path and name of the log file ' datfile$, path and name of the data file ' hhcoilradius!, Helmholtz coil radius in m ' hhG!, geometry factor ' hhnturns%, number of turns on each Helmholtz coil ' nmeasave%, # measurements of mu for averaging ' calcurhpchan%, HP channel to measure calibration coil current ' calvtransperimag!, transductor voltage per calibration coil amp ' calcoilarea!, calibration coil total area ' 'Zachary Wolf '9/12/95 '**************************************************************************** 'Put the parameters in the common area logfileP$ = logfile$ datfileP$ = datfile$ hhcoilradiusP! = hhcoilradius! hhGP! = hhG! hhnturnsP% = hhnturns% nmeasaveP% = nmeasave% calcurhpchanP% = calcurhpchan% calvtransperimagP! = calvtransperimag! calcoilareaP! = calcoilarea! 'Print the values 'PRINT 'PRINT "The MAGMOM parameters are" 'PRINT "logfileP$ = "; logfileP$ 'PRINT "hhcoilradiusP! = "; hhcoilradiusP! 'PRINT "hhGP! = "; hhGP! 'PRINT "hhnturnsP% = "; hhnturnsP% 'PRINT "nmeasaveP% = "; nmeasaveP% 'INPUT "Press ENTER to continue.", a$ END SUB