ASCOT5
Loading...
Searching...
No Matches
Functions
hdf5_helpers.c File Reference

HDF5 wrappers and shortcuts. More...

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <hdf5.h>
#include <hdf5_hl.h>
#include "../ascot5.h"
#include "../print.h"

Go to the source code of this file.

Functions

void hdf5_init (void)
 Initialize hdf5, right now just disables automatic error messages.
 
hid_t hdf5_create (const char *filename)
 Create an hdf5 file, fail if file exists. A negative value is returned on failure.
 
hid_t hdf5_open (const char *filename)
 Open a hdf5 file for reading and writing. A negative value is returned on failure.
 
hid_t hdf5_open_ro (const char *filename)
 Open a hdf5 file for read only. A negative value is returned on failure.
 
herr_t hdf5_close (hid_t file_id)
 Close access to given hdf5 file identifier. A negative value is returned on failure.
 
hid_t hdf5_create_group (hid_t loc, const char *path)
 Create a group (with parent groups if necessary). Returns a handle to the group. Negative on failure.
 
herr_t hdf5_find_group (hid_t loc, const char *path)
 Checks if given group exists within given hdf5 file. Negative value is returned if the group doesn't exist.
 
char * hdf5_generate_qid_path (const char *original, char *qid, char *path)
 Generate a valid path from a given template and qid.
 
char * hdf5_gen_path (const char *original, char *qid, char *path)
 Generate a valid path from a given template and qid.
 
int hdf5_read_double (const char *var, real *ptr, hid_t file, char *qid, const char *errfile, int errline)
 Read double-valued data from ASCOT5 HDF5 file.
 
int hdf5_read_int (const char *var, int *ptr, hid_t file, char *qid, const char *errfile, int errline)
 Read int-valued data from ASCOT5 HDF5 file.
 
int hdf5_read_long (const char *var, long *ptr, hid_t file, char *qid, const char *errfile, int errline)
 Read long-valued data from ASCOT5 HDF5 file.
 
herr_t hdf5_write_string_attribute (hid_t loc, const char *path, const char *attrname, const char *string)
 Write string attribute with null-padding.
 
herr_t hdf5_write_extendible_dataset_double (hid_t group, const char *datasetname, int length, double *data)
 Create and write to an extendible dataset for double data.
 
herr_t hdf5_write_extendible_dataset_long (hid_t group, const char *datasetname, int length, long *data)
 Create and write to an extendible dataset for long data.
 
herr_t hdf5_write_extendible_dataset_int (hid_t group, const char *datasetname, int length, int *data)
 Create and write to an extendible dataset int data.
 

Detailed Description

HDF5 wrappers and shortcuts.

Definition in file hdf5_helpers.c.

Function Documentation

◆ hdf5_init()

void hdf5_init ( void )

Initialize hdf5, right now just disables automatic error messages.

Definition at line 18 of file hdf5_helpers.c.

◆ hdf5_create()

hid_t hdf5_create ( const char * filename)

Create an hdf5 file, fail if file exists. A negative value is returned on failure.

Definition at line 26 of file hdf5_helpers.c.

◆ hdf5_open()

hid_t hdf5_open ( const char * filename)

Open a hdf5 file for reading and writing. A negative value is returned on failure.

Definition at line 36 of file hdf5_helpers.c.

◆ hdf5_open_ro()

hid_t hdf5_open_ro ( const char * filename)

Open a hdf5 file for read only. A negative value is returned on failure.

Definition at line 46 of file hdf5_helpers.c.

◆ hdf5_close()

herr_t hdf5_close ( hid_t file_id)

Close access to given hdf5 file identifier. A negative value is returned on failure.

Definition at line 56 of file hdf5_helpers.c.

◆ hdf5_create_group()

hid_t hdf5_create_group ( hid_t loc,
const char * path )

Create a group (with parent groups if necessary). Returns a handle to the group. Negative on failure.

Definition at line 66 of file hdf5_helpers.c.

◆ hdf5_find_group()

herr_t hdf5_find_group ( hid_t loc,
const char * path )

Checks if given group exists within given hdf5 file. Negative value is returned if the group doesn't exist.

Definition at line 100 of file hdf5_helpers.c.

◆ hdf5_generate_qid_path()

char * hdf5_generate_qid_path ( const char * original,
char * qid,
char * path )

Generate a valid path from a given template and qid.

Data in ASCOT5 HDF5 files is stored in groups, where each group is assigned a unique identifier. The paths are then in format such as "bfield/B_2D-0123456789". This function turns a template e.g. "bfield/B_2D-XXXXXXXXXX" to a valid path.

Definition at line 112 of file hdf5_helpers.c.

◆ hdf5_gen_path()

char * hdf5_gen_path ( const char * original,
char * qid,
char * path )

Generate a valid path from a given template and qid.

Data in ASCOT5 HDF5 files is stored in groups, where each group is assigned a unique identifier. The paths are then in format such as "bfield/B_2D-0123456789". This function turns a template e.g. "bfield/B_2D-XXXXXXXXXX" to a valid path.

Definition at line 131 of file hdf5_helpers.c.

◆ hdf5_read_double()

int hdf5_read_double ( const char * var,
real * ptr,
hid_t file,
char * qid,
const char * errfile,
int errline )

Read double-valued data from ASCOT5 HDF5 file.

Datasets in ASCOT5 are located in the HDF5 file at paths that look like this: "/options/opt-XXXXXXXXXX/dataset", where X's is the QID value that is used differentiate between inputs of same type. This function constructs the path for a given dummy path, dataset, and qid, reads the dataset, and writes error message if the dataset could not be read.

This function reads data that has type double.

The file is opened and closed outside of this function.

Parameters
var"dummy" (otherwise valid but with X's) path to variable
ptrpointer where data will be stored
fileHDF5 file
qidQID value
errfileuse macro FILE here to indicate the file this function was called
errlineuse macro LINE here to indicate the line this function was called
Returns
zero if success

Definition at line 166 of file hdf5_helpers.c.

◆ hdf5_read_int()

int hdf5_read_int ( const char * var,
int * ptr,
hid_t file,
char * qid,
const char * errfile,
int errline )

Read int-valued data from ASCOT5 HDF5 file.

Datasets in ASCOT5 are located in the HDF5 file at paths that look like this: "/options/opt-XXXXXXXXXX/dataset", where X's is the QID value that is used differentiate between inputs of same type. This function constructs the path for a given dummy path, dataset, and qid, reads the dataset, and writes error message if the dataset could not be read.

This function reads data that has type double.

The file is opened and closed outside of this function.

Parameters
var"dummy" (otherwise valid but with X's) path to variable
ptrpointer where data will be stored
fileHDF5 file
qidQID value
errfileuse macro FILE here to indicate the file this function was called
errlineuse macro LINE here to indicate the line this function was called
Returns
zero if success

Definition at line 201 of file hdf5_helpers.c.

◆ hdf5_read_long()

int hdf5_read_long ( const char * var,
long * ptr,
hid_t file,
char * qid,
const char * errfile,
int errline )

Read long-valued data from ASCOT5 HDF5 file.

Datasets in ASCOT5 are located in the HDF5 file at paths that look like this: "/options/opt-XXXXXXXXXX/dataset", where X's is the QID value that is used differentiate between inputs of same type. This function constructs the path for a given dummy path, dataset, and qid, reads the dataset, and writes error message if the dataset could not be read.

This function reads data that has type double.

The file is opened and closed outside of this function.

Parameters
var"dummy" (otherwise valid but with X's) path to variable
ptrpointer where data will be stored
fileHDF5 file
qidQID value
errfileuse macro FILE here to indicate the file this function was called
errlineuse macro LINE here to indicate the line this function was called
Returns
zero if success

Definition at line 236 of file hdf5_helpers.c.

◆ hdf5_write_string_attribute()

herr_t hdf5_write_string_attribute ( hid_t loc,
const char * path,
const char * attrname,
const char * string )

Write string attribute with null-padding.

There is a H5LTset_attribute_string function but it writes strings as null-terminated. However, string attributes in ASCOT5 HDF5 file are assumed to be null-padded.

Definition at line 254 of file hdf5_helpers.c.

◆ hdf5_write_extendible_dataset_double()

herr_t hdf5_write_extendible_dataset_double ( hid_t group,
const char * datasetname,
int length,
double * data )

Create and write to an extendible dataset for double data.

Definition at line 295 of file hdf5_helpers.c.

◆ hdf5_write_extendible_dataset_long()

herr_t hdf5_write_extendible_dataset_long ( hid_t group,
const char * datasetname,
int length,
long * data )

Create and write to an extendible dataset for long data.

Definition at line 329 of file hdf5_helpers.c.

◆ hdf5_write_extendible_dataset_int()

herr_t hdf5_write_extendible_dataset_int ( hid_t group,
const char * datasetname,
int length,
int * data )

Create and write to an extendible dataset int data.

Definition at line 362 of file hdf5_helpers.c.