DECLARE SUB summcheckdata (mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my1!, smy1!, my2!, smy2!, mz!, smz!, ok$) 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!, my1!, smy1!, my2!, smy2!, mz!, smz!) DECLARE SUB summgetline (n%, array$(), target$, index%, position%) '**************************************************************************** 'Program SUMMARY 'This program makes a summary of the Helmholtz coil measurements. 'It appends the latest block's data to the summary file. ' 'Zachary Wolf '3/13/97 '**************************************************************************** 'Print a message about the program 'CLS PRINT PRINT "************************Program SUMMONE*************************" PRINT "This program makes summaries of the Helmholtz coil measurements." 'Open the file to append the summary information to summfilenum% = FREEFILE summfilename$ = "summ.dat" OPEN summfilename$ FOR APPEND 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, save the last one DO UNTIL EOF(listfilenum%) LINE INPUT #listfilenum%, datfile$ LOOP 'Close the file containing the list of files to summarize CLOSE listfilenum% 'Make sure we have a reasonable file name IF MID$(datfile$, 1, 3) <> "c:\" THEN PRINT "SUMMONE: Bad file name. Exiting..." STOP END IF 'Get the information from the data file CALL summgetdata(datfile$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my1!, smy1!, my2!, smy2!, mz!, smz!) 'Check the measurement quality before writing to the summary file CALL summcheckdata(mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my1!, smy1!, my2!, smy2!, mz!, smz!, ok$) 'Only append the data if it looks ok IF ok$ <> "y" THEN PRINT PRINT PRINT "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" PRINT "The data is noisy." PRINT "Please rerun the program." PRINT "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" PRINT PRINT GOTO noisy END IF 'Write the data to the summary file CALL summdatdata(summfilename$, measdate$, blname$, runnum%, temp!, mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my1!, smy1!, mz!, smz!) 'Close the summary file CLOSE summfilenum% 'Message PRINT PRINT "The summary is complete." 'Done noisy: END SUB summcheckdata (mxy!, smxy!, thxy!, sthxy!, mx!, smx!, my1!, smy1!, my2!, smy2!, mz!, smz!, ok$) '**************************************************************************** 'This subroutine checks the quality of the measurement before data is written 'to the summary file. ' 'Input: ' 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! ' my1!, y component of the magnetic moment (Tm^3), first measurement ' smy1!, rms variation of my!, first measurement ' my2!, y component of the magnetic moment (Tm^3), second measurement ' smy2!, rms variation of my!, second measurement ' mz!, z component of the magnetic moment (Tm^3) ' smz!, rms variation of mz! ' 'Output: ' ok$, "y" if data looks ok, "n" otherwise ' 'Zachary Wolf '7/23/96, 3/13/97 '**************************************************************************** 'Default ok$ = "n" 'Check mxy IF ABS(smxy! / mxy!) > .001 THEN EXIT SUB 'Check thxy IF ABS(sthxy!) > .1 THEN EXIT SUB 'Check my1 and my2 IF ABS((my1! - my2!) / my1!) > .02 THEN EXIT SUB 'Check mz 'IF ABS(mz! / mxy!) > .01 THEN EXIT SUB 'If we made it to here, things are ok ok$ = "y" END SUB 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*10^4 " ' 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! * 10000!; '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!, my1!, smy1!, my2!, smy2!, 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! ' my1!, y component of the magnetic moment (Tm^3), first measurement ' smy1!, rms variation of my!, first measurement ' my2!, y component of the magnetic moment (Tm^3), second measurement ' smy2!, rms variation of my!, second measurement ' mz!, z component of the magnetic moment (Tm^3) ' smz!, rms variation of mz! ' 'Zachary Wolf '7/23/96, 3/13/97 '**************************************************************************** '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, 8) '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 the first My measurement 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") my1! = VAL(MID$(filecontents$(index%), pos1% + 4, (pos2% - 1) - (pos1% + 4))) smy1! = VAL(MID$(filecontents$(index%), pos2% + 2, (pos3% - 1) - (pos2% + 2))) filecontents$(index%) = " " 'so the second My can be found END IF 'Get the second My measurement 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") my2! = VAL(MID$(filecontents$(index%), pos1% + 4, (pos2% - 1) - (pos1% + 4))) smy2! = 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