예제 #1
0
파일: IO.c 프로젝트: bialk/SPOOLES
/*
   ----------------------------------------------
   purpose -- to read in an IV object from a file

   input --

      fn -- filename, must be *.ivb or *.ivf

   return value -- 1 if success, 0 if failure

   created -- 95oct06, cca
   ----------------------------------------------
*/
int
IV_readFromFile ( 
   IV    *iv, 
   char   *fn 
) {
FILE   *fp ;
int    fnlength, rc, sulength ;
/*
   ---------------
   check the input
   ---------------
*/
if ( iv == NULL || fn == NULL ) {
   fprintf(stderr, 
    "\n error in IV_readFromFile(%p,%s), file %s, line %d"
    "\n bad input\n", iv, fn, __FILE__, __LINE__) ;
   return(0) ;
}
/*
   -------------
   read the file
   -------------
*/
fnlength = strlen(fn) ;
sulength = strlen(suffixb) ;
if ( fnlength > sulength ) {
   if ( strcmp(&fn[fnlength-sulength], suffixb) == 0 ) {
      if ( (fp = fopen(fn, "rb")) == NULL ) {
         fprintf(stderr, "\n error in IV_readFromFile(%p,%s)"
                 "\n unable to open file %s", iv, fn, fn) ;
         rc = 0 ;
      } else {
         rc = IV_readFromBinaryFile(iv, fp) ;
         fclose(fp) ;
      }
   } else if ( strcmp(&fn[fnlength-sulength], suffixf) == 0 ) {
      if ( (fp = fopen(fn, "r")) == NULL ) {
         fprintf(stderr, "\n error in IV_readFromFile(%p,%s)"
                 "\n unable to open file %s", iv, fn, fn) ;
         rc = 0 ;
      } else {
         rc = IV_readFromFormattedFile(iv, fp) ;
         fclose(fp) ;
      }
   } else {
      fprintf(stderr, "\n error in IV_readFromFile(%p,%s)"
              "\n bad IV file name %s,"
              "\n must end in %s (binary) or %s (formatted)\n",
              iv, fn, fn, suffixb, suffixf) ;
      rc = 0 ;
   }
} else {
   fprintf(stderr, "\n error in IV_readFromFile(%p,%s)"
       "\n bad IV file name %s,"
       "\n must end in %s (binary) or %s (formatted)\n",
       iv, fn, fn, suffixb, suffixf) ;
   rc = 0 ;
}
return(rc) ; }
예제 #2
0
파일: IO.c 프로젝트: damiannz/spooles
/*
   ----------------------------------------------------
   purpose -- to read an ETree object from a binary file

   return value -- 1 if success, 0  if failure

   created -- 95nov15, cca
   ----------------------------------------------------
*/
int
ETree_readFromBinaryFile ( 
   ETree    *etree, 
   FILE   *fp 
) {
int    rc ;
int    itemp[2] ;
/*
   ---------------
   check the input
   ---------------
*/
if ( etree == NULL || fp == NULL ) {
   fprintf(stderr, "\n fatal error in ETree_readFromBinaryFile(%p,%p)"
           "\n bad input\n", etree, fp) ;
   return(0) ;
}
/*
   ---------------------
   clear the data fields
   ---------------------
*/
ETree_clearData(etree) ;
/*
   ---------------------------
   initialize the ETree object
   ---------------------------
*/
ETree_init1(etree, 0, 0) ;
/*
   -----------------------------
   read in the two scalar fields
   -----------------------------
*/
if ( (rc = fread((void *) itemp, sizeof(int), 2, fp)) != 2 ) {
   fprintf(stderr, "\n error in ETree_readFromBinaryFile(%p,%p)"
           "\n itemp(2) : %d items of %d read\n", etree, fp, rc, 2) ;
  return(0) ;
}
etree->nfront = itemp[0] ;
etree->nvtx   = itemp[1] ;
/*
   -----------------------
   read in the Tree object
   -----------------------
*/
Tree_readFromBinaryFile(etree->tree, fp) ;
/*
   ------------------------------
   read in the nodwghts IV object
   ------------------------------
*/
IV_readFromBinaryFile(etree->nodwghtsIV, fp) ;
/*
   ------------------------------
   read in the bndwghts IV object
   ------------------------------
*/
IV_readFromBinaryFile(etree->bndwghtsIV, fp) ;
/*
   --------------------------------
   read in the vtxToFront IV object
   --------------------------------
*/
IV_readFromBinaryFile(etree->vtxToFrontIV, fp) ;

return(1) ; }