DECLARE SUB filemkdir (DestDir$) DECLARE SUB fileopenout (file$, ok$) DECLARE SUB fileplot (file$) DECLARE SUB fileprnt (file$) DECLARE SUB fileprot (file$) DECLARE SUB fileexist (file$, yn$) '**************************************************************************** 'Module FILE 'This module contains file management utility subroutines. ' 'Zachary Wolf '6/3/94 '**************************************************************************** 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$, mn$, op$, ts$, dv$, rn$, cm$) '**************************************************************************** 'This subroutine writes the header of a log file. ' 'Input: ' logfile$, name, including the path, of the log file ' mn$, magnet name ' op$, operator name ' ts$, the name of the test stand which is being used ' dv$, the name of the measurement device ' rn$, the run number ' cm$, a comment about the test ' 'Zachary Wolf '6/4/94 '**************************************************************************** '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: "; mn$ PRINT #filenum%, "Test Operator: "; op$ PRINT #filenum%, "Test Stand: "; ts$ PRINT #filenum%, "Apparatus: "; dv$ PRINT #filenum%, "Run Number: "; rn$ PRINT #filenum%, "Comment: "; cm$ 'Close the log file CLOSE filenum% END SUB SUB fileheaderii (logfile$, mn$, op$, ts$, dv$, rn$, cm$, n1%, i1!(), n2%, i2!()) '**************************************************************************** 'This subroutine writes the header of a log file. ' 'Input: ' logfile$, name, including the path, of the log file ' mn$, magnet name ' op$, operator name ' ts$, the name of the test stand which is being used ' dv$, the name of the measurement device ' rn$, the run number ' cm$, a comment about the test ' n1%, the number of standardization ramps ' i1!(1 to n1%), the standardization currents ' n2%, the number of currents measurements are made at ' i2!(1 to n2%), the measurement currents ' 'Zachary Wolf '4/16/94, 6/3/94 '**************************************************************************** '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: "; mn$ PRINT #filenum%, "Test Operator: "; op$ PRINT #filenum%, "Test Stand: "; ts$ PRINT #filenum%, "Apparatus: "; dv$ PRINT #filenum%, "Run Number: "; rn$ PRINT #filenum%, "Comment: "; cm$ 'Write the standardization currents to the log file PRINT #filenum%, PRINT #filenum%, "Magnet Standardization Currents (Amps): " FOR i% = 1 TO n1% STEP 6 FOR j% = 0 TO 5 IF i% + j% > n1% THEN EXIT FOR PRINT #filenum%, USING " #####.#"; i1!(i% + j%); NEXT j% PRINT #filenum%, NEXT i% 'Write the test currents to the log file PRINT #filenum%, PRINT #filenum%, "Measurement Currents (Amps): " FOR i% = 1 TO n2% STEP 6 FOR j% = 0 TO 5 IF i% + j% > n2% THEN EXIT FOR PRINT #filenum%, USING " #####.#"; i2!(i% + j%); NEXT j% PRINT #filenum%, NEXT i% 'Close the log file CLOSE filenum% END SUB SUB fileinitl (test$, run$, logfile$, ok$) '**************************************************************************** 'This subroutine opens a log file in the current directory. It then 'writes a batch file for printing it and a batch file for write protecting 'it. ' 'Input: ' test$, the name of the test, used as the base name of the file ' run$, the run number ' 'Output: ' logfile$, the log file ' ok$, "y" if ok, "n" otherwise ' 'Zachary Wolf '6/6/94 '**************************************************************************** 'Initialize ok$ = "n" 'Form the file extension r% = VAL(run$) IF r% < 10 THEN ext$ = "ru" + run$ IF r% >= 10 THEN ext$ = "r" + run$ 'Name the log file logfile$ = test$ + "log." + ext$ 'Open the log file CALL fileopenout(logfile$, ok$) IF ok$ = "n" THEN EXIT SUB PRINT logfile$; " created" 'Write a .bat file to print the log file CALL fileprnt(logfile$) 'Write a .bat file to write protect the log file CALL fileprot(logfile$) 'If we made it here, things went ok ok$ = "y" END SUB SUB fileinitldp (magname$, run$, test$, logfile$, datfile$, pltfile$, ok$) '**************************************************************************** 'This subroutine creates the directory for the data files (if necessary), 'names the data files and opens them, then writes several batch files 'for printing the data and plotting it. ' 'Input: ' magname$, the magnet name ' run$, the run number ' test$, the name of the test, used as the base name of the files ' 'Output: ' logfile$, the log file ' datfile$, the data summary file ' pltfile$, the data file for plots ' ok$, "y" if ok, "n" otherwise ' 'Zachary Wolf '6/4/94 '**************************************************************************** 'Initialize ok$ = "n" 'Create the \magdata subdirectory to store the data and log files subdir$ = "c:\magdata\" + magname$ CALL filemkdir(subdir$) 'Form the common file extension r% = VAL(run$) IF r% < 10 THEN ext$ = "ru" + run$ IF r% >= 10 THEN ext$ = "r" + run$ 'Name the log file logfile$ = subdir$ + "\" + test$ + "log." + ext$ 'Open the log file CALL fileopenout(logfile$, ok$) IF ok$ = "n" THEN EXIT SUB PRINT logfile$; " created" 'Name the data file datfile$ = subdir$ + "\" + test$ + "dat." + ext$ 'Open the data file CALL fileopenout(datfile$, ok$) IF ok$ = "n" THEN EXIT SUB PRINT datfile$; " created" 'Name the plot file pltfile$ = subdir$ + "\" + test$ + "plt." + ext$ 'Open the plot data file CALL fileopenout(pltfile$, ok$) IF ok$ = "n" THEN EXIT SUB PRINT pltfile$; " created" 'Write a .bat file to print the data and log files CALL fileprnt(datfile$) CALL fileprnt(logfile$) 'Write a .bat file to plot the data CALL fileplot(pltfile$) 'Write a .bat file to write protect the data files CALL fileprot(logfile$) CALL fileprot(datfile$) CALL fileprot(pltfile$) 'If we made it here, things went ok ok$ = "y" 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 fileopenout (file$, ok$) '**************************************************************************** 'This subroutine is used to open files for output. It checks to see 'if file$ exists. If it does, the subroutine returns with ok$="n". 'If the file does not exist, the subroutine opens the file, closes it, 'sets ok$="y", and returns. Other routines can then append information 'to the file. ' 'Input: ' file$, path and name of the file to open ' 'Output: ' ok$, "y" if ok, "n" otherwise ' 'Zachary Wolf '4/14/94, 6/3/94 '**************************************************************************** 'Initialize ok$ = "n" 'Check to see if file$ already exists CALL fileexist(file$, yn$) 'If file$ already exists return IF yn$ = "y" THEN EXIT SUB 'Open the file filenum% = FREEFILE OPEN file$ FOR OUTPUT AS filenum% 'Close the file CLOSE filenum% 'ok ok$ = "y" END SUB SUB fileplot (file$) '**************************************************************************** '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 ' 'Zachary Wolf '5/14/94, 6/4/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 epbatch.dat" '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.bat" FOR OUTPUT AS filenum% ELSE OPEN "fileprnt.bat" FOR APPEND AS filenum% END IF 'Print the input file PRINT #filenum%, "call lprint "; 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