FEDEM Solver  R8.0
Source code of the dynamics solver
Macros | Functions | Variables
binaryDB.c File Reference

Global C-functions for binary file IO. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <unistd.h>
#include "FFaLib/FFaOS/FFaTag_C.h"
#include "FFaLib/FFaOS/FFaFortran.H"
Include dependency graph for binaryDB.c:

Macros

#define _MAX_DBFIL   50
 

Functions

static int flushBinaryDB (int file, int doFlush)
 Flushes the in-core buffer of the specified file to disk. More...
 
void closeAllBinaryDB ()
 Closes all opened binary files. More...
 
static int writeBinaryDB (int ifile, const void *p, size_t nSize, size_t nData)
 Internal generic function to actually write binary data to file. More...
 
static int writeDoubleDB (int ifile, const double *data, size_t ndat)
 Internal function to write double precision data to file. More...
 
static int swapBytes (char *p, size_t m, size_t n)
 Performs byte swapping of an array in case of endian discrepancies. More...
 
static int readBinaryDB (int ifile, void *p, size_t nSize, size_t nData, char silence)
 Internal generic function to actually read binary data from file. More...
 

Variables

static char * fname [_MAX_DBFIL]
 
static char * fbuff [_MAX_DBFIL]
 
static size_t bptr [_MAX_DBFIL]
 
static size_t bsiz [_MAX_DBFIL]
 
static FT_FILE fdb [_MAX_DBFIL]
 
static short doSwap [_MAX_DBFIL]
 
static const float Version = 1.0f
 

Detailed Description

Global C-functions for binary file IO.

This file contains the C-implementation of the following Fortran-callable global functions for performing binary file IO, based on low-level fwrite/fread calls.

No further documentation of the above functions is provided here. They are documented in the binaryDBInterface.f90 file.

This file also contains some static data containers managing the binary files, and some private functions serving as utilities for the global functions.

Macro Definition Documentation

◆ _MAX_DBFIL

#define _MAX_DBFIL   50

Max number of binary files that can be open at the same time

Function Documentation

◆ closeAllBinaryDB()

void closeAllBinaryDB ( )

Closes all opened binary files.

Used by signal handlers only.

◆ flushBinaryDB()

static int flushBinaryDB ( int  file,
int  doFlush 
)
static

Flushes the in-core buffer of the specified file to disk.

Parameters
[in]fileIndex of the file to flush
[in]doFlushIf true, perform a physical flush of the file

◆ readBinaryDB()

static int readBinaryDB ( int  ifile,
void *  p,
size_t  nSize,
size_t  nData,
char  silence 
)
static

Internal generic function to actually read binary data from file.

Parameters
[in]ifileFile number in range <-_MAX_DBFIL,_MAX_DBFIL>.
If < 0, rewind the file before reading it.
[out]pPointer to memory segment in which to store the data read
[in]nSizeSize of each data item
[in]nDataNumber of data items to read
[in]silenceIf > 0, suppress error message on read failure
Returns
0 : Nothing is done (nData is zero)
> 0 : Number of bytes read
-1 : Illegal file number or file not opened
-2 : Error during read
-3 : Invalid record length
-99 : End-of-file detected (no data read)

◆ swapBytes()

static int swapBytes ( char *  p,
size_t  m,
size_t  n 
)
static

Performs byte swapping of an array in case of endian discrepancies.

◆ writeBinaryDB()

static int writeBinaryDB ( int  ifile,
const void *  p,
size_t  nSize,
size_t  nData 
)
static

Internal generic function to actually write binary data to file.

Parameters
[in]ifileFile number in range [0,_MAX_DBFIL-1]
[in]pPointer to the data to write
[in]nSizeSize of each data item
[in]nDataNumber of data items to write
Returns
0 : Nothing is done (nData is zero)
1 : Number of bytes written > INT_MAX
> 1 : Number of bytes written (≤ INT_MAX )
-1 : Illegal file number or file not opened
-2 : Error during write

◆ writeDoubleDB()

static int writeDoubleDB ( int  ifile,
const double *  data,
size_t  ndat 
)
static

Internal function to write double precision data to file.

Parameters
[in]ifileFile number in range [0,_MAX_DBFIL-1]
[in]dataPointer to the data to write
[in]ndatNumber of doubles to write

This function is a wrapper for writeBinaryDB() used for large double arrays. The data is written in 2GB chunks on Windows to avoid run-time failure.

Variable Documentation

◆ bptr

size_t bptr[_MAX_DBFIL]
static

Indices to next available buffer location

◆ bsiz

size_t bsiz[_MAX_DBFIL]
static

The size of each in-core buffer

◆ doSwap

short doSwap[_MAX_DBFIL]
static

Byte-swapping flags for each file

◆ fbuff

char* fbuff[_MAX_DBFIL]
static

In-core buffers for the binary files

◆ fdb

FT_FILE fdb[_MAX_DBFIL]
static

File pointers for each file

◆ fname

char* fname[_MAX_DBFIL]
static

Names of all opened binary files

◆ Version

const float Version = 1.0f
static

Internal file version tag