DECLARE SUB summdatdata (summfile$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my!, smy!, mz!, smz!) DECLARE SUB summgetdata (datfile$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my!, smy!, mz!, smz!) DECLARE SUB summgetline (n%, array$(), target$, index%, position%) '**************************************************************************** 'Program SUMMARY 'This program makes a summary of the Helmholtz coil measurements. ' 'Zachary Wolf '7/17/96 '**************************************************************************** 'Print a message about the program CLS PRINT PRINT "************************Program SUMMARY*************************" PRINT "This program makes summaries of the Helmholtz coil measurements." 'Create a file to write the summary information to summfilenum% = FREEFILE summfilename$ = "summary.dat" OPEN summfilename$ FOR OUTPUT AS summfilenum% CLOSE summfilenum% 'Open the file containing the list of data files to summarize listfilenum% = FREEFILE listfilename$ = "filelist.dat" OPEN listfilename$ FOR INPUT AS listfilenum% 'Loop over data files from the list DO UNTIL EOF(listfilenum%) LINE INPUT #listfilenum%, datfile$ 'Skip comments IF MID$(datfile$, 1, 3) <> "c:\" THEN GOTO skipline 'Skip calibration runs IF INSTR(datfile$, "CALIB") <> 0 THEN GOTO skipline 'Get the information from the data file CALL summgetdata(datfile$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my!, smy!, mz!, smz!) 'Summarize blocks of a certain type (if desired) type$ = MID$(blname$, LEN(blname$), 1) IF type$ <> "C" THEN GOTO skipline 'Write the data to the summary file CALL summdatdata(summfilename$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my!, smy!, mz!, smz!) 'End loop over files from the list skipline: LOOP 'Close the file containing the list of files to summarize CLOSE listfilenum% 'Message PRINT PRINT "The summary is complete." END SUB summdatdata (summfile$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my!, smy!, mz!, smz!) '**************************************************************************** 'This subroutine writes data to a summary file. ' 'Input: ' summfile$, name of the summary file to write the data to ' measdate$, measurement date ' blname$, block name ' runnum%, run number ' temp!, block temperature (C) ' mxy!, magnitude of the magnetic moment in the xy plane (Tm^3) ' smxy!, rms variation of mxy! ' thxy!, direction of the magnetic moment in the xy plane (Tm^3) ' sthxy!, rms variation of thxy! ' mx!, x component of the magnetic moment (Tm^3) ' smx!, rms variation of mx ' my!, y component of the magnetic moment (Tm^3) ' smy!, rms variation of my ' mz!, z component of the magnetic moment (Tm^3) ' smz!, rms variation of mz ' 'Zachary Wolf '7/23/96 '**************************************************************************** 'Keep track of the number of times called STATIC ncall% ncall% = ncall% + 1 'Open the summary file filenum% = FREEFILE OPEN summfile$ FOR APPEND AS filenum% 'Print a header on the first call IF ncall% = 1 THEN PRINT #filenum%, PRINT #filenum%, "SLAC Magnetic Measurements" PRINT #filenum%, "Date: "; DATE$ PRINT #filenum%, "Time: "; TIME$ PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, ' PRINT #filenum%, " Helmholtz Coil Measurement Summary " ' PRINT #filenum%, ' PRINT #filenum%, " Date Block Temp Mx My Mz sigMxy/" ' PRINT #filenum%, " Name (C) (Tm^3) (Tm^3) (Tm^3) Mxy " ' PRINT #filenum%, "---------- ----- ----- ----------- ----------- ----------- --------" PRINT #filenum%, " Helmholtz Coil Measurement Summary " PRINT #filenum%, PRINT #filenum%, " Date Block Run Temp Mxy sMxy THxy sTHxy Mz " PRINT #filenum%, " Name # (C) *10^-4 (Tm^3) (deg) (Tm^3) " PRINT #filenum%, "---------- ----- --- ----- --------+-------- --------+------ -----------" END IF 'Print the measurement data to the summary file PRINT #filenum%, USING "\ \"; measdate$; PRINT #filenum%, USING " \ \"; blname$; PRINT #filenum%, USING " ###"; runnum%; PRINT #filenum%, USING " ##.##"; temp!; PRINT #filenum%, USING " ##.#####"; mxy! * 10000!; PRINT #filenum%, USING " ##.#####"; smxy! * 10000!; PRINT #filenum%, USING " ####.###"; thxy!; PRINT #filenum%, USING " ##.###"; sthxy!; 'PRINT #filenum%, USING " ##.####^^^^"; mx!; 'PRINT #filenum%, USING " ##.####^^^^"; smx!; 'PRINT #filenum%, USING " ##.####^^^^"; my!; 'PRINT #filenum%, USING " ##.####^^^^"; smy!; PRINT #filenum%, USING " ##.####^^^^"; mz!; 'PRINT #filenum%, USING " ##.####^^^^"; smz!; 'PRINT #filenum%, USING " #.##^^^^"; smxy! / mxy!; PRINT #filenum%, 'Close the summary file CLOSE filenum% END SUB SUB summgetdata (datfile$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my!, smy!, mz!, smz!) '**************************************************************************** 'This subroutine extracts summary information from a data file. ' 'Input: ' datfile$, name of the data file to get the information from ' 'Output: ' measdate$, measurement date ' blname$, block name ' runnum%, run number ' temp!, block temperature (C) ' mxy!, magnitude of the magnetic moment in the xy plane (Tm^3) ' smxy!, rms variation of mxy! ' thxy!, direction of the magnetic moment in the xy plane (Tm^3) ' sthxy!, rms variation of thxy! ' mx!, x component of the magnetic moment (Tm^3) ' smx!, rms variation of mx! ' my!, y component of the magnetic moment (Tm^3) ' smy!, rms variation of my! ' mz!, z component of the magnetic moment (Tm^3) ' smz!, rms variation of mz! ' 'Zachary Wolf '7/23/96 '**************************************************************************** 'Dimension a string array to store the file contents DIM filecontents$(1 TO 300) 'Open the data file filenum% = FREEFILE OPEN datfile$ FOR INPUT AS #filenum% 'Read the file contents into the storage array nlines% = 0 DO UNTIL EOF(filenum%) nlines% = nlines% + 1 LINE INPUT #filenum%, filecontents$(nlines%) LOOP 'Close the data file CLOSE filenum% 'Get the date CALL summgetline(nlines%, filecontents$(), "Date: ", index%, position%) IF index% > 0 THEN measdate$ = MID$(filecontents$(index%), 7, 10) 'Get the block name CALL summgetline(nlines%, filecontents$(), "Magnet Name ", index%, position%) IF index% > 0 THEN blname$ = MID$(filecontents$(index%), 25, 5) 'Get the run number CALL summgetline(nlines%, filecontents$(), "Run Number: ", index%, position%) IF index% > 0 THEN runnum% = VAL(MID$(filecontents$(index%), position% + 11, 3)) 'Get the temperature CALL summgetline(nlines%, filecontents$(), "T = ", index%, position%) IF index% > 0 THEN temp! = VAL(MID$(filecontents$(index%), position% + 4, 8)) 'Get Mxy CALL summgetline(nlines%, filecontents$(), "M = ", index%, position%) IF index% > 0 THEN pos1% = INSTR(filecontents$(index%), "M = ") pos2% = INSTR(filecontents$(index%), "+-") pos3% = INSTR(filecontents$(index%), "Tm^3") mxy! = VAL(MID$(filecontents$(index%), pos1% + 3, (pos2% - 1) - (pos1% + 3))) smxy! = VAL(MID$(filecontents$(index%), pos2% + 2, (pos3% - 1) - (pos2% + 2))) END IF 'Get Theta CALL summgetline(nlines%, filecontents$(), "Theta = ", index%, position%) IF index% > 0 THEN pos1% = INSTR(filecontents$(index%), "Theta = ") pos2% = INSTR(filecontents$(index%), "+-") pos3% = INSTR(filecontents$(index%), "deg") thxy! = VAL(MID$(filecontents$(index%), pos1% + 7, (pos2% - 1) - (pos1% + 7))) sthxy! = VAL(MID$(filecontents$(index%), pos2% + 2, (pos3% - 1) - (pos2% + 2))) END IF 'Get Mx CALL summgetline(nlines%, filecontents$(), "Mx = ", index%, position%) IF index% > 0 THEN pos1% = INSTR(filecontents$(index%), "Mx = ") pos2% = INSTR(filecontents$(index%), "+-") pos3% = INSTR(filecontents$(index%), "Tm^3") mx! = VAL(MID$(filecontents$(index%), pos1% + 4, (pos2% - 1) - (pos1% + 4))) smx! = VAL(MID$(filecontents$(index%), pos2% + 2, (pos3% - 1) - (pos2% + 2))) END IF 'Get My CALL summgetline(nlines%, filecontents$(), "My = ", index%, position%) IF index% > 0 THEN pos1% = INSTR(filecontents$(index%), "My = ") pos2% = INSTR(filecontents$(index%), "+-") pos3% = INSTR(filecontents$(index%), "Tm^3") my! = VAL(MID$(filecontents$(index%), pos1% + 4, (pos2% - 1) - (pos1% + 4))) smy! = VAL(MID$(filecontents$(index%), pos2% + 2, (pos3% - 1) - (pos2% + 2))) END IF 'Get Mz CALL summgetline(nlines%, filecontents$(), "Mz = ", index%, position%) IF index% > 0 THEN pos1% = INSTR(filecontents$(index%), "Mz = ") pos2% = INSTR(filecontents$(index%), "+-") pos3% = INSTR(filecontents$(index%), "Tm^3") mz! = VAL(MID$(filecontents$(index%), pos1% + 4, (pos2% - 1) - (pos1% + 4))) smz! = VAL(MID$(filecontents$(index%), pos2% + 2, (pos3% - 1) - (pos2% + 2))) END IF END SUB SUB summgetline (n%, array$(), target$, index%, position%) '**************************************************************************** 'This subroutine searches an array of strings for the first occurence 'of a target string. It returns the index of the array string which 'contains the target string. ' 'Input: ' n%, the number of elements in the array ' array$(1 to n%), array of strings ' target$, (sub)string we are searching for ' 'Output: ' index%, gives first array element which contains target$ ' position%, gives the position of target$ in the array element ' 'Zachary Wolf '7/25/96 '**************************************************************************** 'Initialize index% = 0 position% = 0 'Loop over array elements FOR i% = 1 TO n% 'See if the array element contains the target 'If it does, return the index and the position position% = INSTR(array$(i%), target$) IF position% <> 0 THEN index% = i% EXIT SUB END IF 'End loop over array elements NEXT i% END SUB