\documentstyle{report}

\pagestyle{myheadings}
\def\headlineaux{\sc Math 220/317: Programming II/Data Structures
\hrulefill
}
\markboth{\headlineaux}{\headlineaux}

\setlength{\textwidth}{6.25in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

\newcommand{\outdate}{7 September, 1993}

\begin{document}
\begin{titlepage}\begin{centerline}{\Huge \framebox{Burt Rosenberg}}
\end{centerline}\end{titlepage}
  
\section*{Files in Pascal \hfill{\parbox{3in}
  {\small\sc\begin{flushright}\outdate\end{flushright}}}}

The discussion in {\em Oh! Pascal!} shows how to use the
Turbo Pascal 6.0 {\em assign} statement to open a
named file for input or output as well as the use of
input/output redirection.
Here we will discuss how these things are done in the VMS and
Ultrix versions of Pascal.
Here is a simple program which will open named files for input
and output. Uncomment the section that applies:
\begin{verbatim}
program testfiles( input, output ) ;
{ Rewrites backwards the file named sin to
  the file named sout. }

{>>>>>>> Common code }

var
  fin, fout : text ;
  sin, sout : packed array [1..125] of char ;

procedure writeBackwards ;
var
  s : array[1..255] of char ;
  i, j : integer ;
begin
  while (not eof(fin)) do begin
    i := 1 ;
    while (not eoln(fin)) do begin
      read( fin, s[i] ) ;
      i := i + 1 ;
    end ;
    for j := i-1 downto 1 do
      write( fout, s[j] ) ;
    readln( fin ) ;
    writeln( fout ) ;
  end ;
end ;


begin {Start of main program.}

  write('Name of input file: ' ) ;
  readln( sin ) ;
  write('Name of output file: ' ) ;
  readln( sout ) ;
  
{>>>>>>> if on VAX/VMS 
  open( fin, sin, history:=old ) ;
  reset( fin ) ;
  open( fout, sout, history:=unknown ) ;
  rewrite( fout ) ;
}

{>>>>>>> if on RISC/Ultrix
  reset( fin, sin ) ;
  rewrite( fout, sout ) ;
}

{>>>>>>> on both
}
  writeBackwards ;

  close( fin ) ;
  close( fout ) ;

end.
\end{verbatim}

The other option is to write your code as if input was
from the keyboard and output was to the screen and then
{\em redirect} input and output at run time.
To redirect on VMS type,
\begin{verbatim}
$ define /user_mode sys$input infile.txt
$ define /user_mode sys$output outfile.txt
$ run aPascalProgram
\end{verbatim}
Only the {\em very next command} will be run in redirected mode.
The {\em /user\_mode} option in the define command instructs
VMS to reset the mode after the next command.
If you forget the /user\_mode option your {\em dir} commands
will also pipe into the redirect output file.
In these cases,  use {\em deassign} to ``unset'' the connection:
\begin{verbatim}
$ deassign sys$input
$ deassign sys$output
\end{verbatim}
To redirect input and output on Ultrix,
\begin{verbatim}
impala> aPascalProgram < inFile.txt > outFile.txt
\end{verbatim}
If you would rather that the output from aPascalProgram be
added onto the end of outFile.txt, use,
\begin{verbatim}
impala> aPascalProgram < inFile.txt >> outFile.txt
\end{verbatim}

\end{document}

