-
Notifications
You must be signed in to change notification settings - Fork 27
HDF5 Routines
FTI_InitType
FTI_InitComplexType
FTI_AddSimpleField
FTI_AddComplexField
FTI_InitGroup
FTI_RenameGroup
FTI_DefineDataset
FTI_Protect
FTI_ProtectWithName
HDF5 struct example
DESCRIPTION
FTI_InitType
initializes a FTI data-type that will be treated as binary data in hdf5 file (see: FTI_InitType for more information).
EXAMPLE
typedef struct A {
int a;
int b;
} A;
FTIT_type structAinfo ;
//sizeof sturct is safest due to padding
//in more complex structs
FTI_InitType(&structAinfo , sizeof(A));
- Initializes a complex data type with structure information for hdf5 file.
DEFINITION
int FTI_InitComplexType ( FTIT_type *newType, FTIT_complexType *typeDefinition, int length, size_t size, char* name )
INPUT
Variable | What for? |
---|---|
FTIT_type * newType |
The data-type to be initialized |
FTIT_complexType * typeDefinition |
The definition of the data-type to be initialized |
int length |
Number of fields in a structure |
size_t size |
The size of a structure |
char * name |
Name of the new datatype in hdf5file. |
OUTPUT
Value | Reason |
---|---|
FTI_SCES |
Success |
FTI_NSCS |
No success |
DESCRIPTION
FTI_InitComplexType
initializes a complex FTI data-type with structure information for hdf5 file.
If name
is set to NULL
FTI will set default value ("Type{id}"
).
EXAMPLE
typedef struct A {
int a;
int b;
} A;
typedef struct B {
A structA;
int c[5][4];
} B;
FTIT_complexType structAdef;
addSimpleField(&structAdef, &FTI_INTG, offsetof(A, a), 0, "int a");
addSimpleField(&structAdef, &FTI_INTG, offsetof(A, b), 1, "int b");
FTIT_type structAinfo;
FTI_InitComplexType(&structAinfo , &structAdef), 2, sizeof(A), "struct A", NULL);
FTIT_complexType structBdef;
addSimpleField(&structBdef, &structAinfo, offsetof(B, structA), 0, "A structA");
int dimLength[] = {5, 4};
addComplexField(&structBdef, &FTI_INTG, offsetof(B, c), 2, dimLength, 1, "int array c");
FTIT_type structBinfo;
FTI_InitComplexType(&structBinfo , &structBdef, 2, sizeof(B), "struct B", NULL);
- Adds information about a field to a type definition.
- Simple field is a field that isn't an array.
DEFINITION
void FTI_AddSimpleField ( FTIT_complexType* typeDefinition, FTIT_type* ftiType, size_t offset, int id, char* name )
INPUT
Variable | What for? |
---|---|
FTIT_complexType * typeDefinition |
The definition of the data-type to add field |
FTIT_type * ftiType |
The definition of the data-type to be initialized |
size_t offset |
Offset of the field in the structure |
int id |
Id of the field |
char * name |
Name of the field in hdf5file. |
DESCRIPTION
FTI_AddSimpleField
adds information about a simple field in complex datatype to a type definition.
If user pass NULL
to name
then default name is used.
If given id was previously added, the field with that id is updated.
EXAMPLE
typedef struct A {
int a;
int b;
} A;
FTIT_complexType structAdef;
FTI_AddSimpleField(&structAdef, $FTI_INTG, offsetof(A, a), 0, "int a");
FTI_AddSimpleField(&structAdef, $FTI_INTG, offsetof(A, b), 1, "int b");
FTIT_type structAinfo;
FTI_InitComplexType(&structAinfo , &structAdef, 2, sizeof(A), "struct A", NULL);
- Adds information about a field to a type definition.
- Complex field is a field that is an array.
DEFINITION
void FTI_AddComplexField ( FTIT_complexType* typeDefinition, FTIT_type* ftiType, size_t offset, int rank, int* dimLength, int id, char* name )
INPUT
Variable | What for? |
---|---|
FTIT_complexType * typeDefinition |
The definition of the data-type to add field |
FTIT_type * ftiType |
The definition of the data-type to be initialized |
size_t offset |
Offset of the field in the structure |
int rank |
Number of dimensions |
int * dimLength |
Length of each dimension |
int id |
Id of the field |
char * name |
Name of the field in hdf5file. |
DESCRIPTION
FTI_AddComplexField
adds information about a complex field in complex datatype to a type definition.
Complex field is a field that is an array.
If user pass NULL
to name
then default name is used.
If given id was previously added, the field with that id is updated.
EXAMPLE
typedef struct A {
int a;
int b[5][4];
} A;
FTIT_complexType structAdef;
FTI_AddSimpleField(&structAdef, $FTI_INTG, offsetof(A, a), 0, "int a");
int dimLength[] = {5, 4};
FTI_AddComplexField(&structAdef, $FTI_INTG, offsetof(A, b), 2, &dimLength, 1, "int array b");
FTIT_type structAinfo;
FTI_InitComplexType(&structAinfo , &structAdef, 2, sizeof(A), "struct A", NULL);
- Initializes information about a hdf5 group.
- If parent is set to
NULL
, parent will be set to the root group.
DEFINITION
int FTI_InitGroup ( FTIT_H5Group* h5group, char* name, FTIT_H5Group* parent )
INPUT
Variable | What for? |
---|---|
FTIT_H5Group * h5group |
The definition of the group to add field |
char * name |
Name of the group to be initialized |
FTIT_H5Group * parent |
The parent group of the group |
OUTPUT
Value | Reason |
---|---|
FTI_SCES |
Success |
FTI_NSCS |
No success |
DESCRIPTION
FTI_InitGroup
inits a hdf5 group with given name and parent group. If parent group is set to NULL
, then the root group is the parent of this group.
EXAMPLE
FTIT_H5Group group1;
FTIT_H5Group group2;
//root is the parent of group1
FTI_InitGroup(&group1, "Group 1", NULL);
//group1 is the parent of group2
FTI_InitGroup(&group2, "Group 2", &group1);
- Renames a group.
DEFINITION
int FTI_RenameGroup ( FTIT_H5Group* h5group, char* name )
INPUT
Variable | What for? |
---|---|
FTIT_H5Group * h5group |
Group to change name |
char * name |
New name of the group |
OUTPUT
Value | Reason |
---|---|
FTI_SCES |
Success |
DESCRIPTION
FTI_RenameGroup
renames given group to the given name.
EXAMPLE
FTIT_H5Group group;
//group name is "Group"
FTI_InitGroup(&group, "Group", NULL);
//group name is now "New name"
FTI_RenameGroup(&group, "New name");
- Defines a dataset.
DEFINITION
int FTI_DefineDataset ( int id, int rank, int* dimLength, char* name, FTIT_H5Group* h5group )
INPUT
Variable | What for? |
---|---|
int id |
Id of the dataset |
int rank |
Rank of the array |
int * dimLength |
Length of each dimension |
char * name |
New name of the dataset |
FTIT_H5Group * h5group |
Group of the dataset |
OUTPUT
Value | Reason |
---|---|
FTI_SCES |
Success |
FTI_NSCS |
No success |
DESCRIPTION
FTI_DefineDataset
gives FTI all information needed by HDF5 to correctly save the dataset in the checkpoint file. If the h5group is set to NULL
, dataset is assigned to the root group.
EXAMPLE
int x;
int y[5][5];
FTIT_H5Group group;
FTI_InitGroup(&group, "Group", NULL);
FTI_Protect(1, &x, 1, FTI_INTG);
FTI_DefineDataset(1, 0, NULL, "single int", NULL);
FTI_Protect(2, &y, 25, FTI_INTG);
int dimLength[] = {5, 5};
FTI_DefineDataset(2, 2, dimLength, "single int", &group);
- Stores metadata concerning the variable to protect.
- Name of a variable is set to default.
DESCRIPTION
FTI_Protect
(see: FTI_Protect for more information) is used to add data fields to the list of protected variables.
EXAMPLE
typedef struct A {
int a;
int b;
} A;
FTIT_complexType structAdef;
FTIT_type structAinfo;
.
.
.
FTI_InitComplexType(&structAinfo , &structAdef, 2, sizeof(A), NULL, NULL);
A someVariable;
FTI_Protect(1, &someVariable, structAinfo);
- Stores metadata concerning the variable to protect.
- Name of a variable is given by user.
DEFINITION
int FTI_ProtectWithName ( int id, void *ptr, long count, FTIT_type type, char *name )
INPUT
Variable | What for? |
---|---|
int id |
Unique ID of the variable to protect |
void * ptr |
Pointer to memory address of variable |
long count |
Number of elements at memory address |
FTIT_type type |
FTI data type of variable to protect |
char * name |
Name of the variable to write in hdf5 file |
OUTPUT
Value | Reason |
---|---|
FTI_SCES |
Success |
FTI_NSCS |
No success |
DESCRIPTION
FTI_ProtectWithName
is used the same way as FTI_Protect
. The difference is that this function provides a name of variable to protect that will be stored in hdf5 checkpoint file.
EXAMPLE
typedef struct A {
int a;
int b;
} A;
FTIT_complexType structAdef;
FTIT_type structAinfo;
.
.
.
FTI_InitComplexType(&structAinfo , &structAdef, 2, sizeof(A), "struct A", NULL);
A someVariable;
FTI_ProtectWithName(1, &someVariable, structAinfo, "someVariable");
Code of the struct in example:
struct myStruct {
char myChars[10];
int intArray3D[2][3][4];
long myLong;
};
FTIT_complexType myStructDef;
int dimLength[3];
dimLength[0] = 10;
addComplexField(&myStructDef, &FTI_CHAR, offsetof(struct myStruct, myChars), 1, dimLength, 0, "my_sweet_chars");
dimLength[0] = 2;
dimLength[1] = 3;
dimLength[2] = 4;
addComplexField(&myStructDef, &FTI_INTG, offsetof(struct myStruct, intArray3D), 3, dimLength, 1, "3D_int_array");
addSimpleField(&myStructDef, &FTI_LONG, offsetof(struct myStruct, myLong), 2, "my_long");
FTIT_type myStructInfo;
InitComplexType(&myStructInfo, &myStructDef, 3, sizeof(struct myStruct), "my_complex_struct", NULL);
struct myStruct example;
sprintf(example.myChars, "simplestr");
int i, j, k;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
for(k = 0; k < 4; k++)
example.intArray3D[i][j][k] = 100 * i + 10 * j + k;
example.myLong = 1234560;
FTI_ProtectWithName(1, &example, 1, myStructInfo, "example");
OUTPUT:
HDF5 "Type2.h5" {
GROUP "/" {
GROUP "dataset" {
DATASET "example" {
DATATYPE "/datatype/my_complex_struct"
DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
DATA {
(0): {
[ 115, 105, 109, 112, 108, 101, 115, 116, 114, 0 ],
[ 0, 1, 2, 3,
10, 11, 12, 13,
20, 21, 22, 23,
100, 101, 102, 103,
110, 111, 112, 113,
120, 121, 122, 123 ],
1234560
}
}
}
}
GROUP "datatype" {
DATATYPE "my_complex_struct" H5T_COMPOUND {
H5T_ARRAY { [10] H5T_STD_I8LE } "my_sweet_chars";
H5T_ARRAY { [2][3][4] H5T_STD_I32LE } "3D_int_array";
H5T_STD_I64LE "my_long";
}
}
}
}