コード例 #1
0
ファイル: IO.c プロジェクト: bialk/SPOOLES
/*
   -------------------------------------------
   purpose -- to write an IV object to a file

   input --

      fn -- filename
        *.ivb -- binary
        *.ivf -- formatted
        anything else -- for human eye

   return value -- 1 if success, 0 otherwise

   created -- 95oct06, cca
   -------------------------------------------
*/
int
IV_writeToFile ( 
   IV    *iv, 
   char   *fn 
) {
FILE   *fp ;
int    fnlength, rc, sulength ;
/*
   ---------------
   check the input
   ---------------
*/
if ( iv == NULL || fn == NULL ) {
   fprintf(stderr, "\n fatal error in IV_writeToFile(%p,%s)"
    "\n bad input\n", iv, fn) ; 
}
/*
   ------------------
   write out the file
   ------------------
*/
fnlength = strlen(fn) ;
sulength = strlen(suffixb) ;
if ( fnlength > sulength ) {
   if ( strcmp(&fn[fnlength-sulength], suffixb) == 0 ) {
      if ( (fp = fopen(fn, "wb")) == NULL ) {
         fprintf(stderr, "\n error in IV_writeToFile(%p,%s)"
                 "\n unable to open file %s", iv, fn, fn) ;
         rc = 0 ;
      } else {
         rc = IV_writeToBinaryFile(iv, fp) ;
         fclose(fp) ;
      }
   } else if ( strcmp(&fn[fnlength-sulength], suffixf) == 0 ) {
      if ( (fp = fopen(fn, "w")) == NULL ) {
         fprintf(stderr, "\n error in IV_writeToFile(%p,%s)"
                 "\n unable to open file %s", iv, fn, fn) ;
         rc = 0 ;
      } else {
         rc = IV_writeToFormattedFile(iv, fp) ;
         fclose(fp) ;
      }
   } else {
      if ( (fp = fopen(fn, "a")) == NULL ) {
         fprintf(stderr, "\n error in IV_writeToFile(%p,%s)"
                 "\n unable to open file %s", iv, fn, fn) ;
         rc = 0 ;
      } else {
         rc = IV_writeForHumanEye(iv, fp) ;
         fclose(fp) ;
      }
   }
} else {
   if ( (fp = fopen(fn, "a")) == NULL ) {
      fprintf(stderr, "\n error in IV_writeToFile(%p,%s)"
              "\n unable to open file %s", iv, fn, fn) ;
      rc = 0 ;
   } else {
      rc = IV_writeForHumanEye(iv, fp) ;
      fclose(fp) ;
   }
}
return(rc) ; }
コード例 #2
0
ファイル: IO.c プロジェクト: damiannz/spooles
/*
   ---------------------------------------------------
   purpose -- to write an ETree object to a binary file

   return value -- 1 if success, 0 otherwise

   created -- 95nov15, cca
   ---------------------------------------------------
*/
int
ETree_writeToBinaryFile ( 
   ETree    *etree, 
   FILE   *fp 
) {
int   rc ;
int   itemp[2] ;
/*
   ---------------
   check the input
   ---------------
*/
if ( etree == NULL || fp == NULL || etree->tree == NULL ) {
   fprintf(stderr, "\n fatal error in ETree_writeToBinaryFile(%p,%p)"
           "\n bad input\n", etree, fp) ;
   exit(-1) ;
}
/*
   ---------------------------
   write the two scalar fields
   ---------------------------
*/
itemp[0] = etree->nfront ;
itemp[1] = etree->nvtx   ;
rc = fwrite((void *) itemp, sizeof(int), 2, fp) ;
if ( rc != 2 ) {
   fprintf(stderr, "\n error in ETree_writeToBinaryFile(%p,%p)"
           "\n %d of %d scalar items written\n", etree, fp, rc, 2) ;
   return(0) ;
}
/*
   ---------------------------------
   write the Tree object to the file 
   ---------------------------------
*/
rc = Tree_writeToBinaryFile(etree->tree, fp) ;
if ( rc < 0 ) {
   fprintf(stderr, "\n fatal error in ETree_writeToBinaryFile(%p,%p)"
           "\n rc = %d, return from writing Tree to file\n", 
           etree, fp, rc) ;
   return(0) ;
}
/*
   ----------------------------------------
   write the nodwghts IV object to the file 
   ----------------------------------------
*/
rc = IV_writeToBinaryFile(etree->nodwghtsIV, fp) ;
if ( rc < 0 ) {
   fprintf(stderr, "\n fatal error in ETree_writeToBinaryFile(%p,%p)"
           "\n rc = %d, return from writing nodwghtsIV to file\n", 
           etree, fp, rc) ;
   return(0) ;
}
/*
   ----------------------------------------
   write the bndwghts IV object to the file 
   ----------------------------------------
*/
rc = IV_writeToBinaryFile(etree->bndwghtsIV, fp) ;
if ( rc < 0 ) {
   fprintf(stderr, "\n fatal error in ETree_writeToBinaryFile(%p,%p)"
           "\n rc = %d, return from writing bndwghtsIV to file\n", 
           etree, fp, rc) ;
   return(0) ;
}
/*
   ------------------------------------------
   write the vtxToFront IV object to the file 
   ------------------------------------------
*/
rc = IV_writeToBinaryFile(etree->vtxToFrontIV, fp) ;
if ( rc < 0 ) {
   fprintf(stderr, "\n fatal error in ETree_writeToBinaryFile(%p,%p)"
           "\n rc = %d, return from writing vtxToFrontIV to file\n", 
           etree, fp, rc) ;
   return(0) ;
}

return(1) ; }