DECLARE SUB fileexist (file$, yn$) '**************************************************************************** 'Module FILE 'This module contains file management utility subroutines. ' 'Zachary Wolf '6/3/94 '**************************************************************************** 'Open the parameter file REM $INCLUDE: 'param.inc' 'The required parameters are 'magnameP$ 'barcodeP$ 'projectP$ 'teststandP$ 'coilnameP$ 'operatorP$ 'runP$ 'commentP$ ' 'The required parameters are in 'GETPARAM ' 'Sample FILE parameters 'FILE 'COMMON SHARED /file/ logfileP$, rawfileP$, rtdatP$, sldatP$, slpltP$, hardatP$, harpltP$ SUB fileexist (file$, yn$) '**************************************************************************** 'This subroutine checks to see if a given file exists. ' 'Input: ' file$, the file we are checking on ' 'Output: ' yn$, "y" if the file exists, "n" if it doesn't ' 'Zachary Wolf '5/28/94 '**************************************************************************** 'See if file$ exists check$ = DIR$(file$) 'Return "y" or "n" yn$ = "y" IF check$ = "" THEN yn$ = "n" END SUB SUB fileheader (logfile$) '**************************************************************************** 'This subroutine writes the header of a log file. ' 'Input: ' logfile$, name, including the path, of the log file ' 'Zachary Wolf '6/4/94, 1/19/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print a general header PRINT #filenum%, "SLAC Magnetic Measurements" PRINT #filenum%, "Date: "; DATE$ PRINT #filenum%, "Time: "; TIME$ PRINT #filenum%, 'Print the magnet test parameters to the log file PRINT #filenum%, "Magnet Name (Serial #): "; magnameP$ PRINT #filenum%, "Bar Code Number: "; barcodeP$ PRINT #filenum%, "Project: "; projectP$ PRINT #filenum%, "Test Stand: "; teststandP$; posbarP$ PRINT #filenum%, "Measurement Coil: "; coilnameP$ PRINT #filenum%, "Operator: "; operatorP$ PRINT #filenum%, "Run Number: "; runP$ PRINT #filenum%, "Comment: "; commentP$ 'Close the log file CLOSE filenum% END SUB SUB fileihead (logfile$, iname$, n%, imag!()) '**************************************************************************** 'This subroutine writes the test currents to the header of a log file. ' 'Input: ' logfile$, name, including the path, of the log file ' iname$, description of the currents ' n%, number of currents ' imag!(1 to n%), the magnet currents ' 'Zachary Wolf '4/16/94, 6/3/94, 8/14/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the currents to the log file PRINT #filenum%, PRINT #filenum%, iname$ FOR i% = 1 TO n% STEP 7 FOR j% = 0 TO 6 IF i% + j% > n% THEN EXIT FOR PRINT #filenum%, USING " #####.#"; imag!(i% + j%); NEXT j% PRINT #filenum%, NEXT i% 'Close the log file CLOSE filenum% END SUB SUB filemkdir (destdir$) '**************************************************************************** 'This subroutine comes from the examples in HELP under MKDIR. It checks 'to see if the directory already exists. If it doesn't, it creates the 'directory. ' 'Input: ' DestDir$, the name, including the path, of the new directory you wish to make ' 'Zachary Wolf '6/4/94 '**************************************************************************** ON LOCAL ERROR GOTO errhandler 'Set up the local error handler. CurDirName$ = CURDIR$ 'Preserve the name of the current directory. CHDIR destdir$ 'Change to DestDir$ - Error 76 if not exist. PRINT : PRINT "Directory "; destdir$; " already exists." madedir: CHDIR CurDirName$ 'Change back to original directory. EXIT SUB errhandler: IF ERR = 76 THEN MKDIR destdir$ 'Make the directory. PRINT : PRINT "Directory "; destdir$; " created." RESUME madedir: END IF RESUME NEXT END SUB SUB filenewpage (filename$) '**************************************************************************** 'This subroutine writes a page break character to a file. ' 'Inputs: ' filename$, the name of the file ' 'Zachary Wolf '8/20/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN filename$ FOR APPEND AS filenum% 'Write a page break character PRINT #filenum%, CHR$(12) 'Close the log file CLOSE filenum% END SUB SUB fileopenout (destdir$, basename$, ext$, filename$, ok$) '**************************************************************************** 'This subroutine opens a file in the specified directory with the 'specified base name and extension. Any problems opening the file are 'flagged. ' 'Input: ' destdir$, destination directory ' basename$, base name of file ' ext$, file extension ' 'Output: ' filename$, the complete file name, including the path, of the created file ' ok$, "y" if ok, "n" otherwise ' 'Zachary Wolf '8/14/94 '**************************************************************************** 'Initialize ok$ = "n" 'Set up the local error handler ON LOCAL ERROR GOTO errhandle 'Name the file IF destdir$ = "" OR destdir$ = "." THEN filename$ = basename$ + "." + ext$ ELSE filename$ = destdir$ + "\" + basename$ + "." + ext$ END IF 'Check to see if filename$ already exists CALL fileexist(filename$, yn$) 'If filename$ already exists return IF yn$ = "y" THEN GOTO notok 'Open the file filenum% = FREEFILE OPEN filename$ FOR OUTPUT AS filenum% 'Close the file CLOSE filenum% 'Message PRINT "File " + filename$ + " created." 'If we made it here, things went ok ok$ = "y" notok: EXIT SUB errhandle: RESUME notok END SUB SUB fileplot (file$, epfile$) '**************************************************************************** 'This subroutine makes a .bat file which is used to plot the input file. ' 'Input: ' file$, the name of the file the .bat file will plot ' epfile$, the EasyPlot batch file name to format the plot ' 'Zachary Wolf '5/14/94, 6/4/94, 8/14/94 '**************************************************************************** 'Initialize STATIC ncall% ncall% = ncall% + 1 'Open the .bat file 'On the first call, overwrite any existing fileplot.bat filenum% = FREEFILE IF ncall% = 1 THEN OPEN "fileplot.bat" FOR OUTPUT AS filenum% ELSE OPEN "fileplot.bat" FOR APPEND AS filenum% END IF 'Copy the input file to the current directory and give it a standard name PRINT #filenum%, "copy "; file$; " plot.dat" 'Run the plotting program PRINT #filenum%, "c:\easyplot\ep "; epfile$ 'Delete the tempory plotting file PRINT #filenum%, "del plot.dat" 'Close the log file CLOSE filenum% END SUB SUB fileprnt (file$) '**************************************************************************** 'This subroutine makes a .bat file which is used to print input files. ' 'Input: ' file$, input file for the .bat file to print ' 'Zachary Wolf '5/14/94, 6/3/94 '**************************************************************************** 'Initialize STATIC ncall% ncall% = ncall% + 1 'Open the .bat file 'On the first call overwrite any existing fileprnt.bat filenum% = FREEFILE IF ncall% = 1 THEN OPEN "fileprnt.dat" FOR OUTPUT AS filenum% ELSE OPEN "fileprnt.dat" FOR APPEND AS filenum% END IF 'Print the input file 'PRINT #filenum%, "call lprint "; file$ PRINT #filenum%, file$ 'Close the .bat file CLOSE filenum% END SUB SUB fileprot (file$) '**************************************************************************** 'This subroutine makes a .bat file which is used to set the attributes 'of a file so it can not be written over. ' 'Input: ' file$, name of the file to make read only ' 'Zachary Wolf '5/14/94, 6/3/94 '**************************************************************************** 'Initialize STATIC ncall% ncall% = ncall% + 1 'Open the .bat file 'On the first call, overwrite an existing fileprot.bat filenum% = FREEFILE IF ncall% = 1 THEN OPEN "fileprot.bat" FOR OUTPUT AS filenum% ELSE OPEN "fileprot.bat" FOR APPEND AS filenum% END IF 'Make the input file read only PRINT #filenum%, "attrib +r "; file$ 'Close the .bat file CLOSE filenum% END SUB