PLUTO  4.4-patch2
Functions
bin_io.c File Reference

Functions for handling binary I/O. More...

#include "pluto.h"

Functions

float *** Convert_dbl2flt (double ***Vdbl, double unit, int swap_endian)
 
int FileClose (FILE *fbin, int sz)
 
FILE * FileOpen (char *filename, int sz, char *mode)
 
void FileReadData (void *V, size_t dsize, int sz, FILE *fl, int istag, int swap_endian)
 
void FileWriteData (void *V, size_t dsize, int sz, FILE *fl, int istag)
 
int FileDelete (char *fname)
 
void FileWriteArray (void *buf, long int offset, long int cnt, size_t size, char *fname)
 
void FileWriteHeader (char *buffer, char fname[], int mode)
 

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
Apr 02, 2019

Function Documentation

◆ Convert_dbl2flt()

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.

Parameters
[in]Vdblpointer to a 3D double precision aray
[in]unita multiplicative constant typically used to write in c.g.s units.
[in]swap_endianwhen set to 1, swap endianity during the conversion.
Returns
a pointer to a 3D array in single precision.

◆ FileClose()

int FileClose ( 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

◆ FileDelete()

int FileDelete ( char *  fname)

Delete a file (parallel mode only). Useful on some architecture where MPI_File_open will just overwrite the file without erasing it.

Parameters
[in]filenamea valid file name
Returns
The pointer to the file.

◆ FileOpen()

FILE* FileOpen ( char *  filename,
int  sz,
char *  mode 
)

Open a file for write/reading in binary mode.

Parameters
[in]filenamea valid file name
[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.

◆ FileReadData()

void FileReadData ( void *  V,
size_t  dsize,
int  sz,
FILE *  fl,
int  istag,
int  swap_endian 
)

Read a 3D grid data array V[k][j][i] from a 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.

◆ FileWriteArray()

void FileWriteArray ( void *  buf,
long int  offset,
long int  cnt,
size_t  size,
char *  fname 
)

Write an array to file using raw binary format. No AL distributed array descriptor is used here.

Parameters
[in]bufaddress of buffer to be written
[in]offsetfile offset in bytes [Only for parallel writing]
[in]cntthe number of element to be written
[in]sizethe sizeof() datatype
[in]fnamethe file name

◆ FileWriteData()

void FileWriteData ( void *  V,
size_t  dsize,
int  sz,
FILE *  fl,
int  istag 
)

Write a 3D grid data array V[k][j][i] to a binary file.

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.

◆ FileWriteHeader()

void FileWriteHeader ( char *  buffer,
char  fname[],
int  mode 
)

Write or Append an ASCII header to a file.

Parameters
[in]bufferthe input buffer (a string).
[in]fnamethe file name
[in]modean integer specifying if the file has to be opened for the first time (mode = -1) or appended (mode >= 0)