Beispiel #1
0
/*
   -----------------------------
   input a chevron in the matrix

   created -- 98jan28, cca
   -----------------------------
*/
void
InpMtx_inputChevron (
   InpMtx   *inpmtx,
   int       chv,
   int       chvsize,
   int       chvind[]
) {
/*
   --------------
   check the data
   --------------
*/
if (  inpmtx == NULL || chv < 0 || chvsize < 0 || chvind == NULL ) {
   fprintf(stderr, 
          "\n fatal error in InpMtx_inputChevron(%p,%d,%d,%p)"
          "\n bad input\n", inpmtx, chv, chvsize, chvind) ;
   spoolesFatal();
}
if ( ! INPMTX_IS_INDICES_ONLY(inpmtx) ) {
   fprintf(stderr, 
          "\n fatal error in InpMtx_inputChevron(%p,%d,%d,%p)"
          "\n inputMode must be INPMTX_INDICES_ONLY\n", 
           inpmtx, chv, chvsize, chvind) ;
   spoolesFatal();
}
inputChevron(inpmtx, chv, chvsize, chvind, NULL) ;

return ; }
Beispiel #2
0
/*
   ------------------------------
   input a real row in the matrix

   created -- 98jan28, cca
   ------------------------------
*/
void
InpMtx_inputRow (
   InpMtx   *inpmtx,
   int       row,
   int       rowsize,
   int       rowind[]
) {
/*
   --------------
   check the data
   --------------
*/
if (  inpmtx == NULL || row < 0 || rowsize < 0 || rowind == NULL ) {
   fprintf(stderr, 
           "\n fatal error in InpMtx_inputRow(%p,%d,%d,%p)"
           "\n bad input\n", inpmtx, row, rowsize, rowind) ;
   spoolesFatal();
}
if ( ! INPMTX_IS_INDICES_ONLY(inpmtx) ) {
   fprintf(stderr, 
           "\n fatal error in InpMtx_inputRow(%p,%d,%d,%p)"
           "\n inputMode is not INPMTX_INDICES_ONLY\n",
           inpmtx, row, rowsize, rowind) ;
   spoolesFatal();
}
inputRow(inpmtx, row, rowsize, rowind, NULL) ;

return ; }
Beispiel #3
0
/*
   -------------------------------------------------------------
   input a number of (row,column, entry) triples into the matrix

   created -- 98jan28, cca
   -------------------------------------------------------------
*/
void
InpMtx_inputTriples (
   InpMtx   *inpmtx,
   int       ntriples,
   int       rowids[],
   int       colids[]
) {
/*
   --------------
   check the data
   --------------
*/
if (  inpmtx == NULL || ntriples < 0 
   || rowids == NULL || colids == NULL ) {
   fprintf(stderr, 
          "\n fatal error in InpMtx_inputTriples(%p,%d,%p,%p)"
          "\n bad inputComplex\n", 
          inpmtx, ntriples, rowids, colids) ;
   spoolesFatal();
}
if ( ! INPMTX_IS_INDICES_ONLY(inpmtx) ) {
   fprintf(stderr, 
           "\n fatal error in InpMtx_inputEntry(%p,%d,%p,%p)"
           "\n coordType must be INPMTX_INDICES_ONLY\n",
           inpmtx, ntriples, rowids, colids) ;
   spoolesFatal();
}
inputTriples(inpmtx, ntriples, rowids, colids, NULL) ;

return ; }
Beispiel #4
0
/*
   ---------------------------------------
   given the data is in raw triples,
   sort and compress the data

   created  -- 98jan28, cca
   modified -- 98sep04, cca
      test to see if the sort is necessary 
   ---------------------------------------
*/
void
InpMtx_sortAndCompress (
   InpMtx   *inpmtx
) {
int      ient, nent, sortMustBeDone ;
int      *ivec1, *ivec2 ;
/*
   ---------------
   check the input
   ---------------
*/
if ( inpmtx == NULL ) {
   fprintf(stderr, "\n fatal error in InpMtx_sortAndCompress(%p)"
           "\n bad input\n", inpmtx) ;
   exit(-1) ;
}
if (  INPMTX_IS_SORTED(inpmtx) 
   || INPMTX_IS_BY_VECTORS(inpmtx) 
   || (nent = inpmtx->nent) == 0 ) {
   inpmtx->storageMode = INPMTX_SORTED ;
   return ;
}
ivec1 = InpMtx_ivec1(inpmtx) ;
ivec2 = InpMtx_ivec2(inpmtx) ;
sortMustBeDone = 0 ;
for ( ient = 1 ; ient < nent ; ient++ ) {
   if ( ivec1[ient-1] > ivec1[ient] 
      || (   ivec1[ient-1] == ivec1[ient] 
          && ivec2[ient-1] > ivec2[ient] ) ) {
      sortMustBeDone = 1 ;
      break ;
   }
}
if ( sortMustBeDone == 1 ) {
   if ( INPMTX_IS_INDICES_ONLY(inpmtx) ) {
      inpmtx->nent = IV2sortUpAndCompress(nent, ivec1, ivec2) ;
   } else if ( INPMTX_IS_REAL_ENTRIES(inpmtx) ) {
      double   *dvec = InpMtx_dvec(inpmtx) ;
      inpmtx->nent = IV2DVsortUpAndCompress(nent, ivec1, ivec2, dvec) ;
   } else if ( INPMTX_IS_COMPLEX_ENTRIES(inpmtx) ) {
      double   *dvec = InpMtx_dvec(inpmtx) ;
      inpmtx->nent = IV2ZVsortUpAndCompress(nent, ivec1, ivec2, dvec) ;
   }
}
inpmtx->storageMode = INPMTX_SORTED ;

return ; }
Beispiel #5
0
/*
   -----------------------
   input a matrix

   created -- 98jan28, cca
   -----------------------
*/
void
InpMtx_inputMatrix (
   InpMtx   *inpmtx,
   int       nrow,
   int       ncol,
   int       rowstride,
   int       colstride,
   int       rowind[],
   int       colind[]
) {
/*
   --------------
   check the data
   --------------
*/
if (  inpmtx == NULL || nrow < 0 || ncol < 0 
   || rowstride < 1  || colstride < 1
   || rowind == NULL || colind == NULL ) {
   fprintf(stderr, 
  "\n fatal error in InpMtx_inputMatrix(%p,%d,%d,%d,%d,%p,%p)"
  "\n bad input\n", inpmtx, nrow, ncol, rowstride, colstride, 
        rowind, colind) ;
   spoolesFatal();
}
if ( ! INPMTX_IS_INDICES_ONLY(inpmtx) ) {
   fprintf(stderr, 
 "\n fatal error in InpMtx_inputMatrix(%p,%d,%d,%d,%d,%p,%p)"
 "\n inputComplexMode must be INPMTX_INDICES_ONLY\n",
        inpmtx, nrow, ncol, rowstride, colstride, rowind, colind) ;
   spoolesFatal();
}
if ( nrow == 0 || ncol == 0 ) {
   return ;
}
inputMatrix(inpmtx, nrow, ncol, rowstride, colstride, 
            rowind, colind, NULL) ;

return ; }
Beispiel #6
0
/*
   ----------------------------------
   input a single entry in the matrix

   created -- 98jan28, cca
   ----------------------------------
*/
void
InpMtx_inputEntry (
   InpMtx   *inpmtx,
   int       row,
   int       col
) {
/*
   --------------
   check the data
   --------------
*/
if ( inpmtx == NULL || row < 0 || col < 0 ) {
   fprintf(stderr, 
           "\n fatal error in InpMtx_inputEntry(%p,%d,%d)"
           "\n bad input\n", inpmtx, row, col) ;
   spoolesFatal();
}
if ( !(   INPMTX_IS_BY_ROWS(inpmtx)
       || INPMTX_IS_BY_COLUMNS(inpmtx)
       || INPMTX_IS_BY_CHEVRONS(inpmtx) ) ) {
   fprintf(stderr, 
           "\n fatal error in InpMtx_inputEntry(%p,%d,%d)"
           "\n bad coordType = %d\n", inpmtx, row, col, 
           inpmtx->coordType) ;
   spoolesFatal();
}
if ( ! INPMTX_IS_INDICES_ONLY(inpmtx) ) {
   fprintf(stderr, 
           "\n fatal error in InpMtx_inputEntry(%p,%d,%d)"
           "\n inputMode is not INPMTX_INDICES_ONLY\n",
           inpmtx, row, col) ;
   spoolesFatal();
}
inputEntry(inpmtx, row, col, 0.0, 0.0) ;

return ; }
Beispiel #7
0
/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   ---------------------------------------------------
   read in (i, j, a(i,j)) triples, 
   construct a InpMtx object and
   write it out to a file

   created -- 97oct17, cca
   ---------------------------------------------------
*/
{
char     *inFileName, *outFileName ;
InpMtx   *inpmtx ;
FILE      *inputFile, *msgFile ;
int       dataType, flag, ient, msglvl, 
          ncol, nent, nrow, rc ;
int       *ivec1, *ivec2 ;

if ( argc != 7 ) {
   fprintf(stdout, 
   "\n\n usage : readAIJ msglvl msgFile dataType inputFile outFile flag"
   "\n    msglvl    -- message level"
   "\n    msgFile   -- message file"
   "\n    dataType  -- 0 for indices only, 1 for double, 2 for complex"
   "\n    inputFile -- input file for a(i,j) entries"
   "\n       the first line must be \"nrow ncol nentries\""
   "\n       if dataType == 0 then"
   "\n          next lines are \"irow jcol\""
   "\n       else if dataType == 1 then"
   "\n          next lines are \"irow jcol entry\""
   "\n       else if dataType == 2 then"
   "\n          next lines are \"irow jcol realEntry imagEntry\""
   "\n       endif"
   "\n    outFile -- output file, must be *.inpmtxf or *.inpmtxb"
   "\n    flag    -- flag for 0-based or 1-based addressing"
   "\n") ;
   return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], argv[2]) ;
   return(-1) ;
}
dataType    = atoi(argv[3]) ;
inFileName  = argv[4] ;
outFileName = argv[5] ;
flag        = atoi(argv[6]) ;
fprintf(msgFile, 
        "\n readAIJ "
        "\n msglvl    -- %d" 
        "\n msgFile   -- %s" 
        "\n dataType  -- %d" 
        "\n inputFile -- %s" 
        "\n outFile   -- %s" 
        "\n flag      -- %d" 
        "\n",
        msglvl, argv[2], dataType, inFileName, outFileName, flag) ;
fflush(msgFile) ;
/*
   ----------------------------
   open the input file and read
   #rows #columns #entries
   ----------------------------
*/
if ( (inputFile = fopen(inFileName, "r")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], inFileName) ;
   return(-1) ;
}
rc = fscanf(inputFile, "%d %d %d", &nrow, &ncol, &nent) ;
if ( rc != 3 ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n %d of 3 fields read on first line of file %s",
           argv[0], rc, inFileName) ;
   return(-1) ;
}
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n\n read in nrow = %d, ncol = %d, nent = %d",
           nrow, ncol, nent) ;
   fflush(msgFile) ;
}
/*
   --------------------------------------------------
   initialize the object
   set coordType = INPMTX_BY_ROWS --> row coordinates
   set inputMode = dataType 
   --------------------------------------------------
*/
inpmtx = InpMtx_new() ;
InpMtx_init(inpmtx, INPMTX_BY_ROWS, dataType, nent, 0) ;
/*
   -------------------------------------------------
   read in the entries and load them into the object
   -------------------------------------------------
*/
ivec1 = InpMtx_ivec1(inpmtx) ;
ivec2 = InpMtx_ivec2(inpmtx) ;
if ( INPMTX_IS_INDICES_ONLY(inpmtx) ) {
   for ( ient = 0 ; ient < nent ; ient++ ) {
      rc = fscanf(inputFile, "%d %d", ivec1 + ient, ivec2 + ient) ;
      if ( rc != 2 ) {
         fprintf(stderr, "\n fatal error in %s"
                 "\n %d of 2 fields read on entry %d of file %s",
                 argv[0], rc, ient, inFileName) ;
         return(-1) ;
      }
      if ( msglvl > 1 ) {
         fprintf(msgFile, "\n entry %d, row %d, column %d",
                 ient, ivec1[ient], ivec2[ient]) ;
         fflush(msgFile) ;
      }
   }
} else if ( INPMTX_IS_REAL_ENTRIES(inpmtx) ) {
   double   *dvec = InpMtx_dvec(inpmtx) ;
   for ( ient = 0 ; ient < nent ; ient++ ) {
      rc = fscanf(inputFile, "%d %d %le", 
                  ivec1 + ient, ivec2 + ient, dvec + ient) ;
      if ( rc != 3 ) {
         fprintf(stderr, "\n fatal error in %s"
                 "\n %d of 3 fields read on entry %d of file %s",
                 argv[0], rc, ient, argv[3]) ;
         return(-1) ;
      }
      if ( msglvl > 1 ) {
         fprintf(msgFile, "\n entry %d, row %d, column %d, value %e",
                 ient, ivec1[ient], ivec2[ient], dvec[ient]) ;
         fflush(msgFile) ;
      }
   }
} else if ( INPMTX_IS_COMPLEX_ENTRIES(inpmtx) ) {
   double   *dvec = InpMtx_dvec(inpmtx) ;
   for ( ient = 0 ; ient < nent ; ient++ ) {
      rc = fscanf(inputFile, "%d %d %le %le", 
                  ivec1 + ient, ivec2 + ient, 
                  dvec + 2*ient, dvec + 2*ient+1) ;
      if ( rc != 4 ) {
         fprintf(stderr, "\n fatal error in %s"
                 "\n %d of 4 fields read on entry %d of file %s",
                 argv[0], rc, ient, argv[3]) ;
         return(-1) ;
      }
      if ( msglvl > 1 ) {
         fprintf(msgFile, 
              "\n entry %d, row %d, column %d, value %12.4e + %12.4e*i",
              ient, ivec1[ient], ivec2[ient], 
              dvec[2*ient], dvec[2*ient+1]) ;
         fflush(msgFile) ;
      }
   }
}
inpmtx->nent = nent ;
if ( flag == 1 ) {
/*
   --------------------------------------------------
   indices were in FORTRAN mode, decrement for C mode
   --------------------------------------------------
*/
   for ( ient = 0 ; ient < nent ; ient++ ) {
      ivec1[ient]-- ; ivec2[ient]-- ;
   }
}
/*
   -----------------------------
   sort and compress the entries
   -----------------------------
*/
InpMtx_changeStorageMode(inpmtx, 3) ;
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n\n sorted, compressed and vector form") ;
   InpMtx_writeForHumanEye(inpmtx, msgFile) ;
   fflush(msgFile) ;
}
/*
   ---------------------------
   write out the InpMtx object
   ---------------------------
*/
if ( strcmp(outFileName, "none") != 0 ) {
   rc = InpMtx_writeToFile(inpmtx, outFileName) ;
   fprintf(msgFile, 
           "\n return value %d from InpMtx_writeToFile(%p,%s)",
           rc, inpmtx, outFileName) ;
}
/*
   ---------------------
   free the working data
   ---------------------
*/
InpMtx_free(inpmtx) ;

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return(1) ; }