PLUTO
|
Functions for handling binary I/O. More...
#include "pluto.h"
Go to the source code of this file.
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, double unit, int swap_endian) |
Functions for handling binary I/O.
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:
V = (void *) V3D[0][0]
V = (void *)(V3D[0][0]-1)
V = (void *)(V3D[0][-1])
V = (void *)(V3D[-1][0])
Definition in file bin_io.c.
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 |
Definition at line 78 of file bin_io.c.
float*** Convert_dbl2flt | ( | double *** | Vdbl, |
double | unit, | ||
int | swap_endian | ||
) |
Convert the a double-precision 3D array into single precision. Swap endianity if swap_endian == 1.
[in] | Vdbl | pointer to a 3D double precision aray |
[in] | unit | a multiplicative constant typically used to write in c.g.s units. |
[in] | swap_endian | when set to 1, swap endianity during the conversion. |
Definition at line 216 of file bin_io.c.
FILE* OpenBinaryFile | ( | char * | filename, |
int | sz, | ||
char * | mode | ||
) |
Open a file for write/reading in binary mode.
[in] | filename | a valid file name |
[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) |
Definition at line 31 of file bin_io.c.
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 |
Definition at line 143 of file bin_io.c.
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) |
Definition at line 98 of file bin_io.c.