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"
|
| 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...
|
| |
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.
◆ _MAX_DBFIL
Max number of binary files that can be open at the same time
◆ 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] | file | Index of the file to flush |
| [in] | doFlush | If 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] | ifile | File number in range <-_MAX_DBFIL,_MAX_DBFIL>.
If < 0, rewind the file before reading it. |
| [out] | p | Pointer to memory segment in which to store the data read |
| [in] | nSize | Size of each data item |
| [in] | nData | Number of data items to read |
| [in] | silence | If > 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] | ifile | File number in range [0,_MAX_DBFIL-1] |
| [in] | p | Pointer to the data to write |
| [in] | nSize | Size of each data item |
| [in] | nData | Number 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] | ifile | File number in range [0,_MAX_DBFIL-1] |
| [in] | data | Pointer to the data to write |
| [in] | ndat | Number 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.
◆ bptr
Indices to next available buffer location
◆ bsiz
The size of each in-core buffer
◆ doSwap
Byte-swapping flags for each file
◆ fbuff
In-core buffers for the binary files
◆ fdb
File pointers for each file
◆ fname
Names of all opened binary files
◆ Version
| const float Version = 1.0f |
|
static |
Internal file version tag