/* Program: IOUtils */ /* Created: 26th June 1991 by FJR from GalibFJR bits */ /* Completed: 26th June 1991 by FJR */ /* Last modified: */ /* 26 Jun 91 FJR Changed parameters for BlatScr */ /* 12 Sep 91 FJR Exported filenames from IndirGet */ /* 07 Feb 93 FJR Added ReadCtrl and FakeRead */ /* 27 Feb 93 FJR Corrected and improved FakeRead */ /* 14 Mar 93 FJR New version of Constant.GL - no True */ /* 17 Mar 93 FJR Used SEEKR in FakeRead - much faster! */ /* 18 Jun 95 FJR Added Exists */ /* 27 Jun 95 FJR Moved Exists to DataUtil.GL */ /* 17 Mar 96 FJR Used QryFile in ReadCtrl and IndirGet */ /* Commented out InDirGet - anyone use it? */ /* 20 Aug 96 FJR Added "RawFiles" - for the 2nd time!! */ /* 01 Apr 97 FJR Added ReadCtl2 for non-user input */ /* */ /* */ /* Various I/O utilities for the Gauss programs */ /* */ /* Exported: */ /* PROC (0) BlatScr (pixels, back, fore) */ /* PROC (2) OpenFile (name, warn); */ /* PROC (2) IndirGet (numFiles, prompt, quitText); */ /* PROC (4) ReadCtrl (numFiles, prompt, quitText); */ /* PROC (2) Extract (handle, dBlock, nLines); */ /* PROC (0) FakeRead (handle, nLines); */ /* location for data files */ #DEFINECS RawFiles "c:\\gauss\\dtiprogs\\" /* P r o c e d u r e D e f i n i t i o n s */ /* = = = = = = = = = = = = = = = = = = = = = */ PROC (0) = BlatScr (pixels, back, fore); /* Sets screen colours and then clears it */ /* In: */ /* pixels, back, fore Respective colours -1 = no chg */ LOCAL colours; colours = {0, 0, 0}; colours[1,1] = pixels; colours[2,1] = back; colours[3,1] = fore; colours = COLOR(colours); /* forget restoration */ CLS; ENDP; /* BlatScr */ PROC (2) = OpenFile (name, warn); /* Attempt to retrieve a file handle for reading */ /* In: */ /* name Name of target file (no extension) */ /* warn Tell user of the failure */ /* Out: */ /* found File exists and was opened */ /* handle Handle returned for the file */ LOCAL found; LOCAL handle; OPEN handle = ^name FOR READ VARINDXI; found = (handle /= -1); IF (NOT found) AND warn; PRINT $name $" could not be opened for input."; ENDIF; RETP (found, handle); ENDP; /* OpenFile */ PROC (2) = AskGFile (path, prompt, quitText); /* Prompt user for the name of a Gauss file. Repeat until */ /* the 'quitText' is entered or a valid file is found */ /* In: */ /* path Name of target file dir (with final \ ) */ /* prompt Prompt for user */ /* quitText Escape response for user (upper-case) */ /* Out: */ /* found File exists and was opened */ /* handle Handle returned for the file */ LOCAL handle; LOCAL name; LOCAL ok; LOCAL bored; ok = False; bored = False; handle = 0; DO WHILE NOT bored; PRINT $prompt;; name = CONS; PRINT; bored = UPPER(name) $== quitText; IF NOT bored; {ok, handle} = OpenFile (path$+name, NOT False); bored = ok; ENDIF; ENDO; RETP (ok, handle); ENDP; /* AskGFile */ PROC (4) = ReadCtrl (numFiles, prompt, quitText); /* Prompt user for name of file containing names of the */ /* data files. Got that? Good. Try opening them. If */ /* unsuccessful, loop until you get one or return "quit" */ /* In: */ /* numFiles Number of files expected to be opened */ /* prompt Prompt for file-containing-filenames name */ /* quitText Compare to test for abandonment */ /* Out: */ /* ctrlName Control file name */ /* ctrlInfo numFiles file names plus control counter */ /* handles numFiles file handles */ /* cont ==False if user wants to abandon it */ LOCAL ctrlInfo; /* [numFiles, 1] input file names */ LOCAL handles; /* ditto, file handles */ LOCAL exist; /* ditto, existence tests */ LOCAL ctrlName; /* file with names of ASCII files */ LOCAL cont, bored; /* various Boolean operators */ cont = NOT False; bored = False; handles = ZEROS (numFiles,1); ctrlInfo = handles | 0; exist = handles; quitText = UPPER (quitText); DO WHILE NOT bored; {ctrlName, cont} = QryFile(prompt, QuitText, ""); IF cont; /* check to see if files exist */ load ctrlInfo[] = ^ctrlName; IF ROWS(ctrlInfo) /= (numFiles+1); PRINT $"Incorrect number of names read; " numFiles $" expected"; ELSE; i = 1; bored = NOT False; DO WHILE (i <= numFiles) AND bored; {exist[i], handles[i]} = OpenFile (RawFiles$+ctrlInfo[i], NOT False); bored = exist[i]; i = i + 1; ENDO; ENDIF; ELSE; /* drop out of loop */ bored = NOT False; ENDIF; ENDO; RETP (ctrlName, ctrlInfo, handles, cont); ENDP; /* ReadCtrl */ PROC (2) = ReadCtl2 (numFiles, ctrlName); /* Open control and data files. Assume file exists */ /* In: */ /* numFiles Number of files expected to be opened */ /* ctrlName Name of control file */ /* Out: */ /* ctrlInfo numFiles file names plus control counter */ /* handles numFiles file handles */ LOCAL ctrlInfo; /* [numFiles, 1] input file names */ LOCAL handles; /* ditto, file handles */ LOCAL exist; /* ditto, existence tests */ LOCAL i; handles = ZEROS (numFiles,1); exist = ZEROS (numFiles,1); ctrlInfo = handles | 0; load ctrlInfo[] = ^ctrlName; IF ROWS(ctrlInfo) /= (numFiles+1); PRINT $"Incorrect number of names read; " numFiles $" expected"; ELSE; i = 1; DO WHILE (i <= numFiles); {exist[i], handles[i]} = OpenFile (RawFiles$+ctrlInfo[i], NOT False); i = i + 1; ENDO; ENDIF; RETP (ctrlInfo, handles); ENDP; /* ReadCtrl */ PROC (2) = Extract (handle, dBlock, nLines); /* Perform an EOF check and then, if possible read file */ /* In: */ /* handle Handle of file to read */ /* dBlock Variable to be used for data read */ /* nLines No. of lines to read */ /* Out: */ /* dBlock Filled in, if 'found', else unspecified */ /* found EOF not reached */ LOCAL found; found = NOT (EOF (handle)); IF found; dBlock = READR (handle, nLines); ENDIF; RETP (dBlock, found); ENDP; /* Extract */ PROC (0) = FakeRead (handle, nLines); /* Skip through a data file, without reading anything */ /* Prints a line of dots while it's doing so */ /* In: */ /* handle File handle */ /* nLines Number of lines to skip */ LOCAL currRow; currRow = SEEKR(handle, -1); currRow = SEEKR(handle, currRow+nLines); ENDP; /* FakeRead */