Matrix Comparison Facility
Manpage for Input File Format


mcf(5)                                                                  mcf(5)

Input File Format
-----------------

A matrix comparison file stores the contents of a single vector or matrix 
(i.e., rank one or rank two array), or a corresponding slice from an array 
of higher order.

Dense Format:

          []  {value}...

        The first line represents the dimensions of the matrix, expressed  as 
        ranges of index values.  Each range is either an integer, or a pair 
        using Fortran-90 notation (e.g., 1:10, -200:300).  A range is specified
        for each dimension of the matrix, so the second range is omitted if the
        file stores a vector.  All remaining values are treated as the contents
        of the matrix.  Note that ranges/values may be formatted one per line, 
        as pairs, as rows, or as densely packed numbers.  The following is an 
        example of a dense format file representing a matrix of two rows and 
        ten columns:

        2  -8:1
        0.0 -7.1 0.0 0.0 13.0 -4.0 0.0 0.0 12.781 0.0
        0.0 0.9 0.0 6.431 0.0 0.0 0.0 0.0 0.0 21.987

Sparse Format:

            {    value}...

        This format may be used to represent matrices with relatively few
        non-zero elements.  The first line of the file has the same
        significance as in the dense format.  All values following the
        index-ranges indicate the contents of non-zero elements of the matrix,
        ordered with the lowest index first (i.e., in ascending order by index).
        These are specified as an index pair followed by a value.  For example,

                1  10           7.392162

        indicates that the element 7.392162 is stored in the tenth column of
        the first row.  Elements not specified in the file are assumed to have
        a value of zero.  Note that index-pairs/values may be formatted  one
        per line, as pairs,  as  rows , or as densely packed numbers.  The
        following is a sparse-format representation of the dense file shown
        above :

        2  10
        1 1  -7.1 1 4 13.0 1 7 -4.0
        1 10 12.781 2 3 0.9 2 6 6.431
        2 9 21.987



Storing matrix values in an input file
---------------------------------------


In many cases, a matrix can be stored  using a single print statement such as :

        print *, nrows, ncols, matrix

If only  a 2-D slice of a large array is to be stored, or if a sparse-format
file is to be saved, the following utilitiesmay used  :

        FUNCTION PRINT_DENSE_MCF (NROWS,NCOLS,MATRIX,FILENAME)
        dimension real matrix[nrows, ncols]
        char *filename

        open (unit=12, file=filename)
        write (12,*) nrows, ncols
        write (12,*) (matrix(i,j), (i=1,(j=1,ncols)) )
        return
        end



        FUNCTION PRINT_SPARSE_MCF(NROWS,NCOLS,MATRIX,FILENAME)
        dimension real matrix[nrows, ncols]
        char *filename

        open (unit=12, file=filename)
        write (12,*) nrows, ncols
        do 25 i = 1,nrows
          do 20 j = 1,ncols
           if (rmatrix(i, j) .ne. 0.0) write (12,*) i, j, matrix(i, j)
20        continue
25      continue
        return
        end



User-Defined Comparison Operators
----------------------------------

User-defined comparison operators are executable programs identified by the
extension mcf.  A template for a user-defined program is given below.  The
program calculates the difference between the absolute values of each pair of
elements, and will be invoked by matcmp or xmatcmp for each pair of elements to
be compared.  The assignment to diff can be replaced as the user desires.  The
input pair and the result of the comparison, however, must be named in the I/O
statements, since the tool sets up a pipe to communicate with the program.  The
program must be compiled to produce an executable before naming it  on a matcmp
command line or selecting it within xmatcmp.

C       This program reads two elements,  and finds the difference
C       between their absolute values.
        PROGRAM USR_ABS
        real  element1, element2, diff

C       get pair of values from  pipe
        read *, element1, element2
C       calculate result
        diff = abs (element1) - abs(element2)
C       write result to pipe
        print *, diff
        end


COPYRIGHT

        The design and implementation of the Matrix Comparison Facility
        (MCF) are available for royalty-free adoption and use for
        non-commercial purposes, by any public or private organization.
        Copyright is retained by Oregon State University.
        Redistribution of any part of MCF or any derivative works must
        include this notice.

	MCF was developed by Bhanu Balasubramaniam, Department of Computer
	Science, Oregon State University, 1995.


Back to MCF home page