Functions for handling binary I/O. More...
#include "pluto.h"
Functions | |
FILE * | OpenBinaryFile (char *filename, int sz, char *mode) |
int | CloseBinaryFile (FILE *fbin, int sz) |
void | WriteBinaryArray (void *V, size_t dsize, int sz, FILE *fl, int istag) |
void | ReadBinaryArray (void *V, size_t dsize, int sz, FILE *fl, int istag, int swap_endian) |
float *** | Convert_dbl2flt (double ***Vdbl, int swap_endian) |
This file provides a number of handy functions for opening, reading and writing binary files using single or double precision in serial or parallel mode. It is employed by the following output formats: .dbl, .flt and .vtk.
In parallel mode these functions work as wrappers to the actual parallel implementations contained in AL_io.c.
Pointer to data array must be cast into (void *) and are assumed to start with index 0 for both cell-centered and staggered data arrays. This means that if V3D is a 3D array then:
int CloseBinaryFile | ( | FILE * | fbin, |
int | sz | ||
) |
Close file.
[in] | fbin | pointer to the FILE that needs to be closed (serial mode only) |
[in] | sz | the distributed array descriptor for parallel mode |
float*** Convert_dbl2flt | ( | double *** | Vdbl, |
int | swap_endian | ||
) |
Convert the array dbl_arr (in double precision) to single precision in flt_arr. Swap endianity if swap_endian == 1.
FILE* OpenBinaryFile | ( | char * | filename, |
int | sz, | ||
char * | mode | ||
) |
Open a file for write/reading.
[in] | filename | a valid file name |
[in] | dsize | the size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode. |
[in] | sz | the distributed array descriptor. This parameter replaces dsize in parallel mode |
[in] | mode | a string giving the opening mode (only "w" or "r" are allowed) |
void ReadBinaryArray | ( | void * | V, |
size_t | dsize, | ||
int | sz, | ||
FILE * | fl, | ||
int | istag, | ||
int | swap_endian | ||
) |
Read a double-precision array from binary file.
[in] | V | pointer to a 3D array, V[k][j][i] –> V[i + NX1*j + NX1*NX2*k]. Must start with index 0 |
[in] | dsize | the size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode. |
[in] | sz | the distributed array descriptor. This parameter replaces dsize in parallel mode |
[in] | fl | a valid FILE pointer |
[in] | istag | a flag to identify cell-centered (istag = -1) or staggered field data (istag = 0,1 or 2 for staggering in the x1, x2 or x3 directions) |
[in] | swap_endian | a flag for swapping endianity |
void WriteBinaryArray | ( | void * | V, |
size_t | dsize, | ||
int | sz, | ||
FILE * | fl, | ||
int | istag | ||
) |
Write an array to disk in binary format.
[in] | V | single pointer to a 3D array, V[k][j][i] –> V[i + NX1*j + NX1*NX2*k]. Must start with index 0 |
[in] | dsize | the size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode. |
[in] | sz | the distributed array descriptor. This parameter replaces dsize in parallel mode |
[in] | fl | a valid FILE pointer |
[in] | istag | a flag to identify cell-centered (istag = -1) or staggered field data (istag = 0,1 or 2 for staggering in the x1, x2 or x3 directions) |