PLUTO  4.0
 All Data Structures Files Functions Variables Enumerations Macros Pages
Functions
bin_io.c File Reference

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)
 

Detailed Description

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:

Authors
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
G. Muscianisi (g.mus.nosp@m.cian.nosp@m.isi@c.nosp@m.inec.nosp@m.a.it)
Date
Sep 18, 2012

Function Documentation

int CloseBinaryFile ( FILE *  fbin,
int  sz 
)

Close file.

Parameters
[in]fbinpointer to the FILE that needs to be closed (serial mode only)
[in]szthe distributed array descriptor for parallel mode
Returns
Returns 0 on success
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.

Parameters
[in]filenamea valid file name
[in]dsizethe size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode.
[in]szthe distributed array descriptor. This parameter replaces dsize in parallel mode
[in]modea string giving the opening mode (only "w" or "r" are allowed)
Returns
The pointer to the file.
void ReadBinaryArray ( void *  V,
size_t  dsize,
int  sz,
FILE *  fl,
int  istag,
int  swap_endian 
)

Read a double-precision array from binary file.

Parameters
[in]Vpointer to a 3D array, V[k][j][i] –> V[i + NX1*j + NX1*NX2*k]. Must start with index 0
[in]dsizethe size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode.
[in]szthe distributed array descriptor. This parameter replaces dsize in parallel mode
[in]fla valid FILE pointer
[in]istaga 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_endiana flag for swapping endianity
Returns
This function has no return value.
Remarks
The data array V is assumed to start always with index 0 for both cell-centered and staggered arrays.
void WriteBinaryArray ( void *  V,
size_t  dsize,
int  sz,
FILE *  fl,
int  istag 
)

Write an array to disk in binary format.

Parameters
[in]Vsingle pointer to a 3D array, V[k][j][i] –> V[i + NX1*j + NX1*NX2*k]. Must start with index 0
[in]dsizethe size of the each buffer element (sizeof(double) or sizeof(float)). This parameter is used only in serial mode.
[in]szthe distributed array descriptor. This parameter replaces dsize in parallel mode
[in]fla valid FILE pointer
[in]istaga 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)
Returns
This function has no return value.
Remarks
The data array is assumed to start always with index 0 for both cell-centered and staggered arrays.