/* This file contains simple binary read/write routines. */ #include #include #include #if defined(PETSC_HAVE_UNISTD_H) #include #endif #if defined(PETSC_HAVE_IO_H) #include #endif #include const char *const PetscFileModes[] = {"READ","WRITE","APPEND","UPDATE","APPEND_UPDATE","PetscFileMode","PETSC_FILE_",0}; /* --------------------------------------------------------- */ /* PetscByteSwapEnum - Swap bytes in a PETSc Enum */ PetscErrorCode PetscByteSwapEnum(PetscEnum *buff,PetscInt n) { PetscInt i,j; PetscEnum tmp = ENUM_DUMMY; char *ptr1,*ptr2 = (char*)&tmp; PetscFunctionBegin; for (j=0; j 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_READ,"Read past end of file"); if (err < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_READ,"Error reading from file, errno %d",errno); m -= err; pp += err; } #if defined(PETSC_USE_REAL___FLOAT128) if (type == PETSC_SCALAR && readdouble) { PetscScalar *pv = (PetscScalar*) p; PetscInt i; #if !defined(PETSC_WORDS_BIGENDIAN) ierr = PetscByteSwapDouble(ppp,n);CHKERRQ(ierr); #endif for (i=0; i 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Can only binary view a single function at a time"); ierr = PetscFPTFind(*(void**)p,&fnametmp);CHKERRQ(ierr); ierr = PetscStrncpy(fname,fnametmp,m);CHKERRQ(ierr); #else ierr = PetscStrncpy(fname,"",m);CHKERRQ(ierr); #endif type = PETSC_CHAR; pp = (char*)fname; #if !defined(PETSC_WORDS_BIGENDIAN) ptmp = (void*)fname; #endif } #if defined(PETSC_USE_REAL___FLOAT128) ierr = PetscOptionsGetBool(NULL,NULL,"-binary_write_double",&writedouble,NULL);CHKERRQ(ierr); /* If using __float128 precision we still write in doubles to file */ if (type == PETSC_SCALAR && writedouble) { m = m/2; ierr = PetscMalloc1(n,&ppp);CHKERRQ(ierr); pv = (PetscReal*)pp; for (i=0; i