Пример #1
0
/*
   -----------------------------------------------
   purpose -- to read an object from a binary file

   return value -- 1 if success, 0  if failure

   created -- 98may01, cca
   -----------------------------------------------
*/
int
A2_readFromBinaryFile ( 
   A2    *mtx, 
   FILE   *fp 
) {
int   rc, size ;
int   itemp[5] ;
/*
   ---------------
   check the input
   ---------------
*/
if ( mtx == NULL || fp == NULL ) {
   fprintf(stderr, "\n fatal error in A2_readFromBinaryFile(%p,%p)"
           "\n bad input", mtx, fp) ;
   return(0) ;
}
/*
   ---------------------
   clear the data fields
   ---------------------
*/
A2_clearData(mtx) ;
/*
   ------------------------------------------------------------
   read in the five scalar parameters: type, n1, n2, inc1, inc2
   ------------------------------------------------------------
*/
if ( (rc = fread((char *) itemp, sizeof(int), 5, fp)) != 5 ) {
   fprintf(stderr, "\n error in A2_readFromBinaryFile"
           "\n %d items of %d read\n", rc, 5) ;
   return(0) ;
}
fprintf(stdout, "\n itemp = {%d, %d, %d, %d, %d}", 
        itemp[0], itemp[1], itemp[2], itemp[3], itemp[4]) ;
fflush(stdout) ;
/*
   ---------------------
   initialize the object
   ---------------------
*/
A2_init(mtx, itemp[0], itemp[1], itemp[2], itemp[3], itemp[4], NULL) ;
/*
   ----------------------------
   read in the entries[] vector
   ----------------------------
*/
if ( (size = 1 + (mtx->n1-1)*mtx->inc1 + (mtx->n2-1)*mtx->inc2) > 0 ) {
   if ( A2_IS_REAL(mtx) ) {
      if ( (rc = fread(mtx->entries, sizeof(double), size, fp)) 
           != size ) {
         fprintf(stderr, "\n error in A2_readFromBinaryFile"
                 "\n %d items of %d read\n", rc, size) ;
         return(0) ;
      }
   } else if ( A2_IS_COMPLEX(mtx) ) {
      if ( (rc = fread(mtx->entries, sizeof(double), 2*size, fp)) 
           != 2*size ) {
         fprintf(stderr, "\n error in A2_readFromBinaryFile"
                 "\n %d items of %d read\n", rc, 2*size) ;
         return(0) ;
      }
   }
}

return(1) ; }
Пример #2
0
/*
   --------------------------------------------------
   purpose -- to read an object from a formatted file

   return value -- 1 if success, 0 if failure

   created -- 98may01, cca
   --------------------------------------------------
*/
int
A2_readFromFormattedFile ( 
   A2    *mtx, 
   FILE   *fp 
) {
int   rc, size ;
int   itemp[5] ;
/*
   ---------------
   check the input
   ---------------
*/
if ( mtx == NULL || fp == NULL ) {
   fprintf(stderr, "\n error in A2_readFromFormattedFile(%p,%p)"
           "\n bad input", mtx, fp) ;
   return(0) ;
}
/*
   ---------------------
   clear the data fields
   ---------------------
*/
A2_clearData(mtx) ;
/*
   -----------------------------------------------------------
   read in the five scalar parameters: type n1, n2, inc1, inc2
   -----------------------------------------------------------
*/
if ( (rc = IVfscanf(fp, 5, itemp)) != 5 ) {
   fprintf(stderr, "\n error in A2_readFromFormattedFile()"
           "\n %d items of %d read\n", rc, 5) ;
   return(0) ;
}
/*
   ---------------------
   initialize the object
   ---------------------
*/
A2_init(mtx, itemp[0], itemp[1], itemp[2], itemp[3], itemp[4], NULL) ;
/*
   ----------------------------
   read in the entries[] vector
   ----------------------------
*/
if ( (size = 1 + (mtx->n1-1)*mtx->inc1 + (mtx->n2-1)*mtx->inc2) > 0 ) {
   if ( A2_IS_REAL(mtx) ) {
      if ( (rc = DVfscanf(fp, size, mtx->entries)) != size ) {
         fprintf(stderr, "\n error in A2_readFromFormattedFile"
                 "\n %d items of %d read\n", rc, size) ;
         return(0) ;
      }
   } else if ( A2_IS_COMPLEX(mtx) ) {
      if ( (rc = DVfscanf(fp, 2*size, mtx->entries)) != 2*size ) {
         fprintf(stderr, "\n error in A2_readFromFormattedFile"
                 "\n %d items of %d read\n", rc, 2*size) ;
         return(0) ;
      }
   }
}

return(1) ; }
Пример #3
0
Файл: IO.c Проект: bialk/SPOOLES
/*
   ----------------------------------------
   purpose -- to write the object to a file
              in human readable form

   created -- 98apr30, cca
   ----------------------------------------
*/
void
Chv_writeForHumanEye (
   Chv    *chv,
   FILE   *fp
) {
A2    mtx ;
int   ierr, ncol, nD, nL, nrow, nU ;
int   *colind, *rowind ; 
/*
   ---------------
   check the input
   ---------------
*/
if ( chv == NULL || fp == NULL ) {
   fprintf(stderr, "\n fatal error in Chv_writeForHumanEye(%p,%p)"
           "\n bad input\n", chv, fp) ;
   exit(-1) ;
}
Chv_dimensions(chv, &nD, &nL, &nU) ;
fprintf(fp, 
       "\n Chv object at address %p"
       "\n id = %d, nD = %d, nL = %d, nU = %d, type = %d, symflag = %d",
       chv, chv->id, nD, nL, nU, chv->type, chv->symflag) ;
if ( CHV_IS_REAL(chv) ) {
   if ( CHV_IS_SYMMETRIC(chv) ) {
      fprintf(fp, "\n chv is real and symmetric") ;
   } else if ( CHV_IS_NONSYMMETRIC(chv) ) {
      fprintf(fp, "\n chv is real and nonsymmetric") ;
   } else {
      fprintf(fp, "\n chv has unknown symmetry type %d", chv->symflag) ;
   }
} else if ( CHV_IS_COMPLEX(chv) ) {
   if ( CHV_IS_SYMMETRIC(chv) ) {
      fprintf(fp, "\n chv is complex and symmetric") ;
   } else if ( CHV_IS_HERMITIAN(chv) ) {
      fprintf(fp, "\n chv is complex and hermitian") ;
   } else if ( CHV_IS_NONSYMMETRIC(chv) ) {
      fprintf(fp, "\n chv is complex and nonsymmetric") ;
   } else {
      fprintf(fp, "\n chv has unknown symmetry type %d", chv->symflag) ;
   }
} else {
   fprintf(fp, "\n chv has unknown type %d", chv->type) ;
}
Chv_rowIndices(chv, &nrow, &rowind) ;
if ( nrow > 0 && rowind != NULL ) {
   fprintf(fp, "\n chv's row indices at %p", rowind) ;
   IVfp80(fp, nrow, rowind, 80, &ierr) ;
}
Chv_columnIndices(chv, &ncol, &colind) ;
if ( ncol > 0 && colind != NULL ) {
   fprintf(fp, "\n chv's column indices at %p", colind) ;
   IVfp80(fp, ncol, colind, 80, &ierr) ;
}
/*
   --------------------
   load the (1,1) block
   --------------------
*/
A2_setDefaultFields(&mtx) ;
Chv_fill11block(chv, &mtx) ;
fprintf(fp, "\n (1,1) block") ;
A2_writeForHumanEye(&mtx, fp) ;
if ( nU > 0 ) {
/*
   --------------------
   load the (1,2) block
   --------------------
*/
   Chv_fill12block(chv, &mtx) ;
   fprintf(fp, "\n (1,2) block") ;
   A2_writeForHumanEye(&mtx, fp) ;
}
if ( nL > 0 && CHV_IS_NONSYMMETRIC(chv) == 1 ) {
/*
   --------------------
   load the (2,1) block
   --------------------
*/
   Chv_fill21block(chv, &mtx) ;
   fprintf(fp, "\n (2,1) block") ;
   A2_writeForHumanEye(&mtx, fp) ;
}
A2_clearData(&mtx) ;

return ; }