:orphan:
# PetscBinaryRead
Reads from a binary file. 
## Synopsis
```
PetscErrorCode PetscBinaryRead(int fd, void *data, PetscInt num, PetscInt *count, PetscDataType type)
```
Not Collective


## Input Parameters

- ***fd -*** the file descriptor
- ***num  -*** the maximum number of items to read
- ***type -*** the type of items to read (`PETSC_INT`, `PETSC_REAL`, `PETSC_SCALAR`, etc.)



## Output Parameters

- ***data -*** the buffer, this is an array of the type that matches the value in `type`
- ***count -*** the number of items read, optional





## Notes
If `count` is not provided and the number of items read is less than
the maximum number of items to read, then this routine errors.

`PetscBinaryRead()` uses byte swapping to work on all machines; the files
are written ALWAYS using big-endian ordering. On little-endian machines the numbers
are converted to the little-endian format when they are read in from the file.
When PETSc is ./configure with `--with-64-bit-indices` the integers are written to the
file as 64-bit integers, this means they can only be read back in when the option `--with-64-bit-indices`
is used.


## See Also
 `PetscBinaryWrite()`, `PetscBinaryOpen()`, `PetscBinaryClose()`, `PetscViewerBinaryGetDescriptor()`, `PetscBinarySynchronizedWrite()`,
`PetscBinarySynchronizedRead()`, `PetscBinarySynchronizedSeek()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/fileio/sysio.c.html#PetscBinaryRead">src/sys/fileio/sysio.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex15.c.html">src/dm/tutorials/ex15.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex54f.F90.html">src/ksp/ksp/tutorials/ex54f.F90</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex6.c.html">src/vec/vec/tutorials/ex6.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex6f.F90.html">src/vec/vec/tutorials/ex6f.F90</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/fileio/sysio.c)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
