PetscBinaryWrite

Writes to a binary file.

Synopsis

#include "petscsys.h"    
PetscErrorCode  PetscBinaryWrite(int fd,void *p,PetscInt n,PetscDataType type,PetscTruth istemp)
Not Collective

Input Parameters

fd - the file
p - the buffer
n - the number of items to write
type - the type of items to read (PETSC_INT, PETSC_DOUBLE or PETSC_SCALAR)
istemp - PETSC_FALSE if buffer data should be preserved, PETSC_TRUE otherwise.

Notes

PetscBinaryWrite() uses byte swapping to work on all machines; the files are written using big-endian ordering to the file. On small-endian machines the numbers are converted to the big-endian format when they are written to disk. Integers are stored on the file as 32 bits long, regardless of whether they are stored in the machine as 32 bits or 64 bits, this means the same binary file may be read on any machine. It also means that 64 bit integers larger than roughly 2 billion are TRUNCATED/WRONG when written to the file.

The Buffer p should be read-write buffer, and not static data. This way, byte-swapping is done in-place, and then the buffer is written to the file.

This routine restores the original contents of the buffer, after it is written to the file. This is done by byte-swapping in-place the second time. If the flag istemp is set to PETSC_TRUE, the second byte-swapping operation is not done, thus saving some computation, but the buffer corrupted is corrupted.

See Also

PetscBinaryRead(), PetscBinaryOpen(), PetscBinaryClose(), PetscViewerBinaryGetDescriptor()

Level:advanced
Location:
src/sys/fileio/sysio.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/vec/vec/examples/tutorials/ex6.c.html