DECLARE SUB ibabgetiav (id%, imag!, simag!) DECLARE SUB ibablogmeas (logfile$) DECLARE SUB ibabloggetiav (logfile$, id%, imag!, simag!) DECLARE SUB ibabloggeti (logfile$, id%, vsensor!, imag!) DECLARE SUB ibabgeti (id%, imag!) DECLARE SUB hp3457cv (c%, v!) DECLARE SUB ibabcheckpar (ok$) '**************************************************************************** 'Module IBAB 'This module contains drivers to set and measure the magnet current manually. ' 'Zachary Wolf '1/22/98 '**************************************************************************** 'Common block for this module's parameters COMMON SHARED /ibab/ logfileP$, imag1hpchanP%, vtrans1perimagP!, imag2hpchanP%, vtrans2perimagP!, imag3hpchanP%, vtrans3perimagP!, nmeasaveP% SUB ibabcheckpar (ok$) '**************************************************************************** 'This subroutine checks that all required parameters have been assigned 'values. ' 'Output: ' ok$, "y" if parameter assignments are ok, "n" otherwise ' 'Zachary Wolf '1/22/98 '**************************************************************************** 'Default value ok$ = "n" 'logfileP$ IF logfileP$ = "" THEN PRINT "IBAB: log file undefined" EXIT SUB END IF 'imag1hpchanP% IF imag1hpchanP% < 0 OR imag1hpchanP% > 9 THEN PRINT "IBAB: imag1hpchan has improper value" EXIT SUB END IF 'vtrans1perimagP! IF vtrans1perimagP! <= 0 OR vtrans1perimagP! > 10 THEN PRINT "IBAB: vtrans1perimag has improper value" EXIT SUB END IF 'imag2hpchanP% IF imag2hpchanP% < 0 OR imag2hpchanP% > 9 THEN PRINT "IBAB: imag2hpchan has improper value" EXIT SUB END IF 'vtrans2perimagP! IF vtrans2perimagP! <= 0 OR vtrans2perimagP! > 10 THEN PRINT "IBAB: vtrans2perimag has improper value" EXIT SUB END IF 'imag3hpchanP% IF imag3hpchanP% < 0 OR imag3hpchanP% > 9 THEN PRINT "IBAB: imag3hpchan has improper value" EXIT SUB END IF 'vtrans3perimagP! IF vtrans3perimagP! <= 0 OR vtrans3perimagP! > 10 THEN PRINT "IBAB: vtrans3perimag has improper value" EXIT SUB END IF 'nmeasaveP% IF nmeasaveP% <= 0 THEN PRINT "IBAB: nmeasave has improper value" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB ibabgeti (id%, imag!) '**************************************************************************** 'This subroutine gets the transductor output voltage. It then applies 'the calibration constant to get the magnet current. ' 'Input: ' id%, magnet current sensor ID number ' 'Output: ' imag!, the measured magnet current ' 'Zachary Wolf '1/22/98 '**************************************************************************** 'Make sure all parameters have been set CALL ibabcheckpar(ok$) IF ok$ <> "y" THEN PRINT "IBAB: problem with parameters" imag! = 0! EXIT SUB END IF 'Measure the voltage from the transductor and apply the conversion factor IF id% = 1 THEN CALL hp3457cv(imag1hpchanP%, v!) imag! = v! / vtrans1perimagP! ELSEIF id% = 2 THEN CALL hp3457cv(imag2hpchanP%, v!) imag! = v! / vtrans2perimagP! ELSEIF id% = 3 THEN CALL hp3457cv(imag3hpchanP%, v!) imag! = v! / vtrans3perimagP! ELSE PRINT "IBAB: unknown ID number" v! = 0! imag! = 0! END IF 'Log the result CALL ibabloggeti(logfileP$, id%, v!, imag!) END SUB SUB ibabgetiav (id%, imag!, simag!) '**************************************************************************** 'This subroutine finds the average magnet current from repeated measurements. ' 'Input: ' id%, ID number of the current sensor desired ' 'Output: ' imag!, average current (A) ' simag!, standard deviation of imag! (A) ' 'Zachary Wolf '1/25/98 '**************************************************************************** 'Check module level parameters CALL ibabcheckpar(ok$) IF ok$ <> "y" THEN PRINT PRINT "!!! Problem in IBABGETIAV" imag! = 0! simag! = 0! EXIT SUB END IF 'Simplify the notation nm% = nmeasaveP% 'Initialize data arrays DIM imagmeas!(1 TO nm%) 'Log the measurement CALL ibablogmeas(logfileP$) 'Loop over measurements for averaging FOR j% = 1 TO nm% 'Get the current reading CALL ibabgeti(id%, imagmeas!(j%)) 'End averaging loop NEXT j% 'Compute the average of the measurements imag! = 0! FOR j% = 1 TO nm% imag! = imag! + imagmeas!(j%) NEXT j% imag! = imag! / nm% 'Compute the standard deviation of the measurements simag! = 0! FOR j% = 1 TO nm% simag! = simag! + (imagmeas!(j%) - imag!) ^ 2 NEXT j% simag! = SQR(simag! / nm%) 'Write the result to the log file CALL ibabloggetiav(logfileP$, id%, imag!, simag!) END SUB SUB ibabinit '**************************************************************************** 'This subroutine sets the parameters in the common blocks required 'to control the magnet current. ' 'Zachary Wolf '7/31/95 '**************************************************************************** 'Nothing needs to be done for manual ramping. END SUB SUB ibabloggeti (logfile$, id%, vsensor!, imag!) '**************************************************************************** 'This subroutine records the measured magnet current to the log file. ' 'Input: ' logfile$, the name of the log file ' id%, current sensor ID number ' vsensor!, voltage from the current sensor ' imag!, magnet current (A) ' 'Zachary Wolf '1/25/98 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the field strength PRINT #filenum%, TIME$; " Current Sensor ID = "; id%; ", V = "; PRINT #filenum%, USING " ###.######"; vsensor!; PRINT #filenum%, " V, Imag = "; PRINT #filenum%, USING " ######.###"; imag!; PRINT #filenum%, " A" 'Close the log file CLOSE filenum% END SUB SUB ibabloggetiav (logfile$, id%, imag!, simag!) '**************************************************************************** 'This subroutine records the measured magnet current to the log file. ' 'Input: ' logfile$, the name of the log file ' id%, current sensor ID number ' imag!, magnet current (A) ' simag!, rms variation of magnet current readings (A) ' 'Zachary Wolf '1/25/98 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the field strength PRINT #filenum%, TIME$; " Current Sensor ID = "; id%; ", Imag = "; PRINT #filenum%, USING " ######.###"; imag!; PRINT #filenum%, " +-"; PRINT #filenum%, USING " ######.###"; simag!; PRINT #filenum%, " A" 'Close the log file CLOSE filenum% END SUB SUB ibablogmeas (logfile$) '**************************************************************************** 'This subroutine records an average magnet current measurement to the log file. ' 'Input: ' logfile$, the name of the log file ' 'Zachary Wolf '1/19/98 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, TIME$; " Average Magnet Current Measurement..." 'Close the log file CLOSE filenum% END SUB SUB ibabsetpar (logfile$, imag1hpchan%, vtrans1perimag!, imag2hpchan%, vtrans2perimag!, imag3hpchan%, vtrans3perimag!, nmeasave%) '**************************************************************************** 'This subroutine sets parameters for Babar current operation. ' 'Input: ' logfile$, log file ' imag1hpchan%, HP3457 channel to read transductor voltage ' vtran1sperimag!, transductor voltage per amp in the magnet ' imag2hpchan%, HP3457 channel to read transductor voltage ' vtran2sperimag!, transductor voltage per amp in the magnet ' imag3hpchan%, HP3457 channel to read transductor voltage ' vtran3sperimag!, transductor voltage per amp in the magnet ' nmeasave%, the number of measurments for averaging ' 'Zachary Wolf '1/22/98 '**************************************************************************** 'Place the parameters in the common area logfileP$ = logfile$ imag1hpchanP% = imag1hpchan% vtrans1perimagP! = vtrans1perimag! imag2hpchanP% = imag2hpchan% vtrans2perimagP! = vtrans2perimag! imag3hpchanP% = imag3hpchan% vtrans3perimagP! = vtrans3perimag! nmeasaveP% = nmeasave% END SUB SUB ibabuser '**************************************************************************** 'This routine gives magnet current information from the transducer requested 'by the user. ' 'Zachary Wolf '4/15/98 '**************************************************************************** 'Get the transductor ID number from the user transductor: PRINT PRINT "ID = 1, solenoid current" PRINT "ID = 2, power supply current" PRINT "ID = 3, bucking coil current" INPUT "Enter the current transducer ID number to report on (0 to end): ", id$ IF id$ = "end" OR id$ = "END" OR id$ = "quit" OR id$ = "QUIT" OR id$ = "0" THEN EXIT SUB id% = VAL(id$) 'Check IF id% < 1 OR id% > 3 THEN PRINT "The current transducer ID number must be between 1 and 3." GOTO transductor END IF 'See what the user wants to do beginibab: PRINT PRINT "Type" PRINT " M to measure" PRINT " Q to quit" INPUT ">", cmd$ 'Message PRINT PRINT "Current transducer ID number:"; id% 'Do as the user requested IF cmd$ = "M" OR cmd$ = "m" THEN CALL ibabgetiav(id%, imag!, simag!) PRINT "Current reading: "; imag!; " +- "; simag!; " A" ELSEIF cmd$ = "Q" OR cmd$ = "q" THEN GOTO endibab ELSE PRINT "Unknown command." END IF GOTO beginibab 'Done endibab: 'Return to beginning of loop GOTO transductor END SUB