Example #1
0
File: IO.c Project: 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) ; }
Example #2
0
/*
   --------------------------------------------------------
   purpose -- to read an ETree object from a formatted file

   return value -- 1 if success, 0 if failure

   created -- 95nov15, cca
   --------------------------------------------------------
*/
int
ETree_readFromFormattedFile ( 
   ETree   *etree, 
   FILE    *fp 
) {
int    rc ;
int    itemp[2] ;
/*
   ---------------
   check the input
   ---------------
*/
if ( etree == NULL || fp == NULL ) {
   fprintf(stderr, "\n error in ETree_readFromFormattedFile(%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 = IVfscanf(fp, 2, itemp)) != 2 ) {
   fprintf(stderr, "\n error in ETree_readFromFormattedFile(%p,%p)"
           "\n %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_readFromFormattedFile(etree->tree, fp) ;
/*
   ------------------------------
   read in the nodwghts IV object
   ------------------------------
*/
IV_readFromFormattedFile(etree->nodwghtsIV, fp) ;
/*
   ------------------------------
   read in the bndwghts IV object
   ------------------------------
*/
IV_readFromFormattedFile(etree->bndwghtsIV, fp) ;
/*
   --------------------------------
   read in the vtxToFront IV object
   --------------------------------
*/
IV_readFromFormattedFile(etree->vtxToFrontIV, fp) ;

return(1) ; }