FMS  v0.2
Field and Mesh Specification
Macros | Functions
fmsio.c File Reference
#include <fmsio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <ctype.h>
#include <inttypes.h>
Include dependency graph for fmsio.c:

Go to the source code of this file.

Macros

#define _XOPEN_SOURCE   600
 
#define FREE(PTR)
 
#define FMS_ELE_PER_LINE   3u
 
#define FMS_LU   "%" PRIu64
 
#define StrToFmsInt   strtoull
 
#define FOR_EACH_INT_TYPE(macro)
 
#define FOR_EACH_SCALAR_TYPE(macro)
 
#define FMS_PRETTY_FUNCTION   __func__
 
#define E_RETURN(code)
 
#define PRINT_MACRO(typename, T, format)
 
#define CASES(typename, T, format)
 
#define PRINT_MACRO(typename, T, format)
 
#define CASES(typename, T, format)
 
#define FMS_BUFFER_SIZE   512
 
#define READ_ARRAY_DATA(DEST_T, FUNC)
 
#define READ_ARRAY_DATA(DEST_T, FUNC, SIZE)
 
#define CASES(typename, T, format)
 

Functions

int FmsIOWrite (const char *filename, const char *protocol, FmsDataCollection dc)
 Writes the provided FmsDataCollection to a file. More...
 
int FmsIORead (const char *filename, const char *protocol, FmsDataCollection *dc)
 Reads an FmsDataCollection from a file. More...
 

Macro Definition Documentation

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   600

Definition at line 19 of file fmsio.c.

◆ CASES [1/3]

#define CASES (   typename,
  T,
  format 
)
Value:
case typename: \
PRINT_MACRO(typename, T, format); \
break;

◆ CASES [2/3]

#define CASES (   typename,
  T,
  format 
)
Value:
case typename: \
PRINT_MACRO(typename, T, format); \
break;

◆ CASES [3/3]

#define CASES (   typename,
  T,
  format 
)
Value:
case typename: \
{ \
T *vs = (T*)tagvalues; \
(*io->add_int)(ctx, kv, (FmsInt)vs[i]); \
break; \
}
uint64_t FmsInt
Type used by fms for representing and storing sizes and indices.
Definition: fms.h:43

◆ E_RETURN

#define E_RETURN (   code)
Value:
do { \
if (code) { \
FmsErrorDebug(code, FMS_PRETTY_FUNCTION, __FILE__, __LINE__); \
} \
return (code); \
} while (0)
#define FMS_PRETTY_FUNCTION
Definition: fmsio.c:97

Definition at line 101 of file fmsio.c.

◆ FMS_BUFFER_SIZE

#define FMS_BUFFER_SIZE   512

Definition at line 488 of file fmsio.c.

◆ FMS_ELE_PER_LINE

#define FMS_ELE_PER_LINE   3u

Definition at line 44 of file fmsio.c.

◆ FMS_LU

#define FMS_LU   "%" PRIu64

Definition at line 47 of file fmsio.c.

◆ FMS_PRETTY_FUNCTION

#define FMS_PRETTY_FUNCTION   __func__

Definition at line 97 of file fmsio.c.

◆ FOR_EACH_INT_TYPE

#define FOR_EACH_INT_TYPE (   macro)
Value:
macro(FMS_INT8, int8_t, "%" PRId8) \
macro(FMS_INT16, int16_t, "%" PRId16) \
macro(FMS_INT32, int32_t, "%" PRId32) \
macro(FMS_INT64, int64_t, "%" PRId64) \
macro(FMS_UINT8, uint8_t, "%" PRIu8) \
macro(FMS_UINT16, uint16_t, "%" PRIu16) \
macro(FMS_UINT32, uint32_t, "%" PRIu32) \
macro(FMS_UINT64, uint64_t, "%" PRIu64)
Definition: fms.h:50
Definition: fms.h:53
Definition: fms.h:48
Definition: fms.h:54
Definition: fms.h:51
Definition: fms.h:56
Definition: fms.h:49
Definition: fms.h:55

Definition at line 58 of file fmsio.c.

◆ FOR_EACH_SCALAR_TYPE

#define FOR_EACH_SCALAR_TYPE (   macro)
Value:
macro(FMS_FLOAT, float, "%f") \
macro(FMS_DOUBLE, double, "%f") \
macro(FMS_COMPLEX_FLOAT, float, "%f") \
macro(FMS_COMPLEX_DOUBLE, double, "%f")
Definition: fms.h:325

Definition at line 68 of file fmsio.c.

◆ FREE

#define FREE (   PTR)
Value:
do { \
if(PTR) \
free(PTR); \
} while(0)

Definition at line 37 of file fmsio.c.

◆ PRINT_MACRO [1/2]

#define PRINT_MACRO (   typename,
  T,
  format 
)
Value:
do { \
const T *v = (const T *)(values); \
fprintf(ctx->fp, "%s/Values: [", path); \
for(i = 0; i < n;) { \
for(j = 0; j < epl && i < n; j++, i++) { \
fprintf(ctx->fp, format, v[i]); \
if(i < n-1) \
fprintf(ctx->fp, ", "); \
} \
if(i < n-1) \
fprintf(ctx->fp, "\n"); \
} \
fprintf(ctx->fp, "]\n"); \
} while(0)

◆ PRINT_MACRO [2/2]

#define PRINT_MACRO (   typename,
  T,
  format 
)
Value:
do { \
const T *v = (const T *)(values); \
fprintf(ctx->fp, "%s/Values: [", path); \
for(i = 0; i < n;) { \
for(j = 0; j < epl && i < n; j++, i++) { \
fprintf(ctx->fp, format, v[i]); \
if(i < n-1) \
fprintf(ctx->fp, ", "); \
} \
if(i < n-1) \
fprintf(ctx->fp, "\n"); \
} \
fprintf(ctx->fp, "]\n"); \
} while(0)

◆ READ_ARRAY_DATA [1/2]

#define READ_ARRAY_DATA (   DEST_T,
  FUNC 
)
Value:
do { \
DEST_T *data = malloc(sizeof(DEST_T) * *n); \
FmsInt i = 0; \
while(1) { \
size_t len = strlen(v); \
char *off = v, *newoff = NULL; \
if(off[0] == '[') \
off++; \
while(len && i < *n) { \
data[i++] = (DEST_T)FUNC(off, &newoff, 10); \
newoff++; \
if(*newoff == ' ') newoff++; /* Current flaw in the file format, last element has no trialing space */ \
if(newoff >= v + len) break; \
off = newoff; \
} \
if(strchr(v, ']')) break; \
if(FmsIOReadLine(ctx, v)) break; \
} \
*values = (void*)data; \
} while(0)

◆ READ_ARRAY_DATA [2/2]

#define READ_ARRAY_DATA (   DEST_T,
  FUNC,
  SIZE 
)
Value:
do { \
DEST_T *data = malloc(sizeof(DEST_T) * SIZE); \
FmsInt i = 0; \
while(1) { \
size_t len = strlen(v); \
char *off = v, *newoff = NULL; \
if(off[0] == '[') \
off++; \
while(len && i < SIZE) { \
data[i++] = (DEST_T)FUNC(off, &newoff); \
newoff++; \
if(*newoff == ' ') newoff++; /* Current flaw in the file format, last element has no trialing space */ \
if(newoff >= v + len) break; \
off = newoff; \
} \
if(strchr(v, ']')) break; \
if(FmsIOReadLine(ctx, v)) break; \
} \
*values = (void*)data; \
} while(0)

◆ StrToFmsInt

#define StrToFmsInt   strtoull

Definition at line 51 of file fmsio.c.

Function Documentation

◆ FmsIORead()

int FmsIORead ( const char *  filename,
const char *  protocol,
FmsDataCollection dc 
)

Reads an FmsDataCollection from a file.

Parameters
filenameThe name of the file to read.
protocolThe type of file to be read. By default, the protocol should be "ascii". If FMS is compiled with Conduit support then the protocol can match the supported Conduit protocols, which can include: "json", "yaml", "conduit_bin", "hdf5". Adding a protocol will help FMS and Conduit decide which method is appropriate for reading the file. If Conduit support is enabled and protocol is NULL an educated guess will be made for which protocol to use.
[out]dcThe FMS object that was read from the file.
Returns
The function returns 0 on success and non-zero for failure. If Conduit support is enabled then a return value of 2 indicates the given protocol is unsupported by the Conduit runtime.

Added in version: v0.2.

Definition at line 3524 of file fmsio.c.

◆ FmsIOWrite()

int FmsIOWrite ( const char *  filename,
const char *  protocol,
FmsDataCollection  dc 
)

Writes the provided FmsDataCollection to a file.

Parameters
filenameThe name of the file to save. If the filename does not include an appropriate file extension, one may be added.
protocolThe type of file to be saved. By default, the protocol should be "ascii". If FMS is compiled with Conduit support then the protocol can match the supported Conduit protocols, which can include: "json", "yaml", "conduit_bin", "hdf5".
dcThe FMS object that will be written to the file.
Returns
The function returns 0 on success and non-zero for failure. If Conduit support is enabled then a return value of 2 indicates the given protocol is unsupported by the Conduit runtime.

Added in version: v0.2.

Definition at line 3471 of file fmsio.c.