\documentstyle [11pt] {article}
\pagestyle{empty}
%
\topmargin=-0.75in
\hoffset=-0.75in
\textheight=10.0in \vsize\textheight
\textwidth=6.5in \hsize\textwidth
%
\begin {document}
{\Large
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Insert source immediately following \begin{verbatim}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{verbatim}
c===========================================================
c     Implements matrix-matrix multiply 
c
c     c = a b 
c
c     where a, b and c are n x n real*8 (square) matrices.
c===========================================================
      subroutine dmmmult(a,b,c,n)

         implicit         none

         integer          n
         real*8           a(n,n),    b(n,n),    c(n,n)

         integer          i,     j,     k

         do j = 1 , n
            do i = 1 , n 
               c(i,j) = 0.0d0
               do k = 1 , n
                  c(i,j) = c(i,j) + a(i,k) * b(k,j)
               end do
            end do
         end do

         return

      end
\end{verbatim}
\newpage
\begin{verbatim}
c===========================================================
c     Writes a double precision matrix (two dimensional
c     array) to file 'fname'.  If 'fname' is the
c     string '-', the matrix is written to standard input.
c
c     This routine is modelled on 'dvto' previously 
c     discussed in class: see ~phy329/ex3/dvto.f
c===========================================================

      subroutine dmto(fname,a,d1,d2)
c-----------------------------------------------------------
c     Arguments:
c
c        fname:  (I)    File name
c        a:      (I)    Return matrix
c        d1:     (I)    First dimension of a 
c        d2:     (I)    Second dimension of a
c-----------------------------------------------------------
         implicit         none

         integer          indlnb,      getu

         character*(*)    fname
         integer          d1,          d2
         real*8           a(d1,d2)

         integer          ustdout
         parameter      ( ustdout = 6 )

         integer          uto,         rc
\end{verbatim}
\newpage
\begin{verbatim}
c-----------------------------------------------------------
c        Parse fname: either "attach" 'uto' to stdout or 
c        get a unit number using 'getu', and open the 
c        file 'fname' for formatted I/O via 'uto'
c-----------------------------------------------------------
         if( fname .eq. '-' ) then
            uto = ustdout
         else
            uto = getu()
            open(uto,file=fname(1:indlnb(fname)),
     &           form='formatted',iostat=rc)
            if( rc .ne. 0 ) then
               write(0,*) 'dmto: Error opening ',
     &                    fname(1:indlnb(fname))
               return
            end if
         end if
c-----------------------------------------------------------
c        Write dimensions, then array elements
c-----------------------------------------------------------
         write(uto,*,iostat=rc) d1, d2
         if( rc .ne. 0 ) then
            write(0,*) 'dmto: Error writing dimensions'
         go to 500
         end if

         write(uto,*,iostat=rc) a

         if( rc .ne. 0 ) then
            write(0,*) 'dmto: Error reading matrix'
         end if
c-----------------------------------------------------------
c        Exit: Close file and return
c-----------------------------------------------------------
 500     continue
         close(uto)

         return
         end

c===========================================================
c     Returns a double precision matrix (two dimensional
c     array) read from file 'fname'.  If 'fname' is the
c     string '-', the matrix is read from standard input.
c
c     The dimensions of the matrix must precede the matrix 
c     elements themselves in the file.  Specifically, the 
c     file should have been created using the following 
c     list-directed, formatted READ statement 
c     (or equivalent):
c
c        integer      d1,    d2
c        real*8       a(d1,d2)
c        integer      uout
c 
c        write(uout,*) d1, d2
c        write(uout,*) a
c
c     This routine is modelled on 'dvfrom' previously 
c     discussed in class: see ~phy329/ex3/dvfrom.f
c
c     Note the use of helper routine 'dmfrom1' which 
c     reads actual array values once bounds have been 
c     extracted from file.
c===========================================================

      subroutine dmfrom(fname,a,d1,d2,asize)
c-----------------------------------------------------------
c     Arguments:
c
c        fname:  (I)    File name
c        a:      (O)    Return matrix
c        d1:     (O)    First dimension of a 
c        d2:     (O)    Second dimension of a
c        asize:  (I)    Maximum size (d1 * d2) of a 
c-----------------------------------------------------------
         implicit         none

         integer          indlnb,      getu
\end{verbatim}
\newpage
\begin{verbatim}
         character*(*)    fname
         integer          d1,          d2,        asize
         real*8           a(d1,d2)

         integer          ustdin
         parameter      ( ustdin = 5 )
         integer          ufrom,       rc,        i,       j
c-----------------------------------------------------------
c        Parse fname: either "attach" 'ufrom' to stdin or 
c        get a unit number using 'getu', and open the 
c        file 'fname' for formatted I/O via 'ufrom'
c-----------------------------------------------------------
         if( fname .eq. '-' ) then
            ufrom = ustdin
         else
            ufrom = getu()
            open(ufrom,file=fname(1:indlnb(fname)),
     &           form='formatted',iostat=rc,status='old')
            if( rc .ne. 0 ) then
               write(0,*) 'dmfrom: Error opening ',
     &                    fname(1:indlnb(fname))
               return
            end if
         end if
c-----------------------------------------------------------
c        Read dimensions and abort if there is insufficient
c        storage for the entire matrix.  Note the 'go to'
c        to the 'exit block' since we've opened a file now
c        and should close it, even if there's an error.
c        Also, set the dimensions to 0 in case of any 
c        error as a way of communicating failure to 
c        the calling routine.
c-----------------------------------------------------------
         read(ufrom,*,iostat=rc) d1, d2
         if( rc .ne. 0 ) then
            write(0,*) 'dmfrom: Error reading dimensions'
            d1 = 0
            d2 = 0
         go to 500
         end if
         if( (d1 * d2) .gt. asize ) then
            write(0,*) 'dmfrom: Insufficient storage'
            d1 = 0
            d2 = 0
         go to 500
         end if
c-----------------------------------------------------------
c        Now that dimensions have been determined call
c        helper routine to read values 
c-----------------------------------------------------------
         call dmfrom1(ufrom,a,d1,d2,rc)
         if( rc .ne. 0 ) then
            write(0,*) 'dmfrom1: Error reading matrix'
            d1 = 0
            d2 = 0
         end if
c-----------------------------------------------------------
c        Exit: Close file and return
c-----------------------------------------------------------
 500     continue
         close(ufrom)

         return

      end
c===========================================================
c     Helper routine for dmfrom: Reads array values, returns
c     I/O status to calling routine via 'rc'
c===========================================================
      subroutine dmfrom1(ufrom,a,d1,d2,rc)

         implicit      none

         integer       d1,       d2,     ufrom,     rc
         real*8        a(d1,d2)

         read(ufrom,*,iostat=rc) a

         return
      end
\end{verbatim}
\newpage
\begin{verbatim}
#############################################################
# Building 'tdm' and sample output
#############################################################

einstein% pwd; ls
/usr2/people/phy329/f77/ex7
Makefile       dmroutines.f   tdm.f

einstein% make
  f77 -g -c tdm.f
  f77 -g -c dmroutines.f
  f77 -g -L/usr/local/lib tdm.o dmroutines.o -lp329f -o tdm

einstein% tdm
 usage: tdm <file name> 

        Use 'tdm -' to read from standard input

einstein% tdm -
2 2 
1 2 3 4
            2           2
    7.000000000000000       10.00000000000000       
    15.00000000000000    22.00000000000000 

einstein% tdm -
2 3 
1 2 3 4 5 6
 tdm: Input array not square
\end{verbatim}
\newpage
\begin{verbatim}
#############################################################
# Illustration of general technique for porting Fortran
# code to Cray J90.  It is highly recommended that you port 
# only thoroughly tested codes to minimize the amount of 
# debugging etc. you need to do on the J90
#############################################################

#############################################################
# All class members should be able to 'rlogin' into 'charon'
# via
#
# % rlogin charon.cc.utexas.edu -l phas761
#
# from any of the course machines.  E-mail me if you can't.
# From your account on einstein, this can be abbreviated to
#
# % rlogin phas761@charon
#############################################################
charon% who am i
phas761    ttyp028      Sep 30 11:27  (newton.ph.utexas.edu)

charon% pwd
/hpcf/u0/ph/as/phas761

#############################################################
# When using this Cray account, work ONLY within your 
# own sub-directory
#############################################################
charon% ls
README    dfink/    jiwoh/    kurtm/    oleg/     phy329/
achiang/  eburns/   kurt/     lib/      oneko/    smartin/
\end{verbatim}
\newpage
\begin{verbatim}
#############################################################
# 'tdm' example 
#############################################################
charon% cd ~/phy329/f77/ex7

#############################################################
# Using a separate shell, 'rcp' the files from 'einstein'
# to the Cray account.  Be very careful so as not to clobber
# anyone else's files!!
#############################################################
einstein% cd ~phy329/f77/ex7

einstein% ls 
Makefile       dmroutines.f   tdm.f

einstein% rcp * phas761@charon:~/phy329/f77/ex7

#############################################################
% Back on Cray account ...
#############################################################
charon% pwd; ls
/hpcf/u0/ph/as/phas761/phy329/f77/ex7
Makefile       dmroutines.f   tdm.f

#############################################################
# Convert the Fortran source files to Cray-compatible form 
# using 'f77transcray' command (Instructor supplied script).
# WARNING: The script may fail if you violate any of the    
# conventions discussed in class; particularly those having
# to do with the specification of real*8 constants!
#############################################################
charon% f77transcray
usage: f77transcray <f77 source file> [<f77 source file> ...]

Converts 'canonical' double precision FORTRAN programs written 
for a 32-bit machine to equivalent Cray FORTRAN.  Source code 
is modified in place, but original source is always saved in 
'.O' files.
\end{verbatim}
\newpage
\begin{verbatim}
charon% f77transcray *.f
f77transcray: Translating dmroutines.f
f77transcray: Translating tdm.f

charon% ls
Makefile         dmroutines.f.O   tdm.f.O
dmroutines.f     tdm.f

#############################################################
# The environment variables needed in the Makefile are 
# set in '~/.cshrc' ...
#############################################################
charon% env | grep F77
F77=cf77
F77FLAGS=-g
F77CFLAGS=-c
F77LFLAGS=-L/hpcf/u0/ph/as/phas761/lib

#############################################################
# Build the application ... (note that the 'p329f' library
# lives in phas761's 'lib' directory)
#############################################################
charon% make
        cf77 -g -c tdm.f
        cf77 -g -c dmroutines.f
        cf77 -g -L/hpcf/u0/ph/as/phas761/lib tdm.o \
             dmroutines.o -lp329f -o tdm
\end{verbatim}
\newpage
\begin{verbatim}
#############################################################
# Test 'tdm' ...
#############################################################
charon% tdm
 usage: tdm <file name>
 
        Use 'tdm -' to read from standard input
 STOP executed at line 60 in Fortran routine 'TDM'
 CPU: 0.004s,  Wallclock: 0.011s,  6.8% of 5-CPU Machine
 Memory HWM: 383015, Stack HWM: 204161, Stack segment expansions: 0

charon% tdm -
 2*2
 7.,  10.,  15.,  22.
 STOP executed at line 52 in Fortran routine 'TDM'
 CPU: 0.005s,  Wallclock: 5.132s
 Memory HWM: 393256, Stack HWM: 204161, Stack segment expansions: 0
\end{verbatim}
}
%
\end {document}
