#define PETSC_DLL /* This file contains simple binary read/write routines. */ #include "petsc.h" #include "petscsys.h" /*I "petscsys.h" I*/ #include #include #if defined(PETSC_HAVE_UNISTD_H) #include #endif #if defined (PETSC_HAVE_IO_H) #include #endif #include "petscbt.h" #if (PETSC_SIZEOF_INT == 8) #define PetscInt32 short #else #define PetscInt32 int #endif #if !defined(PETSC_WORDS_BIGENDIAN) #undef __FUNCT__ #define __FUNCT__ "PetscByteSwapInt" /* PetscByteSwapInt - Swap bytes in a 32 bit integer. NOT a PetscInt! Note that PETSc binary read and write always store and read only 32 bit integers! (See PetscBinaryRead(), PetscBinaryWrite()). */ PetscErrorCode PETSC_DLLEXPORT PetscByteSwapInt(PetscInt32 *buff,PetscInt n) { PetscInt i,j,tmp = 0; PetscInt *tptr = &tmp; /* Need to access tmp indirectly to get */ char *ptr1,*ptr2 = (char*)&tmp; /* arround the bug in DEC-ALPHA g++ */ PetscFunctionBegin; for (j=0; j 0) SETERRQ(PETSC_ERR_FILE_READ,"Read past end of file"); if (err < 0) SETERRQ1(PETSC_ERR_FILE_READ,"Error reading from file, errno %d",errno); m -= err; pp += err; } #if !defined(PETSC_WORDS_BIGENDIAN) if (type == PETSC_INT) {ierr = PetscByteSwapInt((PetscInt32*)ptmp,n);CHKERRQ(ierr);} else if (type == PETSC_ENUM) {ierr = PetscByteSwapInt((PetscInt32*)ptmp,n);CHKERRQ(ierr);} else if (type == PETSC_TRUTH) {ierr = PetscByteSwapInt((PetscInt32*)ptmp,n);CHKERRQ(ierr);} else if (type == PETSC_SCALAR) {ierr = PetscByteSwapScalar((PetscScalar*)ptmp,n);CHKERRQ(ierr);} else if (type == PETSC_DOUBLE) {ierr = PetscByteSwapDouble((double*)ptmp,n);CHKERRQ(ierr);} else if (type == PETSC_SHORT) {ierr = PetscByteSwapShort((short*)ptmp,n);CHKERRQ(ierr);} #endif #if (PETSC_SIZEOF_INT == 8) || defined(PETSC_USE_64BIT_INDICES) if (type == PETSC_INT) { PetscInt *p_int = (PetscInt*)p,i; PetscInt32 *p_short = (PetscInt32 *)ptmp; for (i=0; i