19 H5Eset_auto1(NULL, NULL);
28 file = H5Fcreate(filename, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
38 file = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
48 file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
58 err = H5Fclose(file_id);
74 const char* end = strstr(start,
"/");
77 hid_t g = H5Gcreate2(loc, start, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
80 char* group = (
char*) malloc((strlen(path) + 1) *
sizeof(char));
81 strncpy(group, start, end-start);
82 group[end-start] =
'\0';
85 hid_t g = H5Gopen2(loc, group, H5P_DEFAULT);
87 g = H5Gcreate2(loc, group, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
101 return H5Gget_objinfo (loc, path, 0, NULL);
113 strcpy(path, original);
114 char* ptr = strstr(path,
"XXXXXXXXXX");
116 for(
int i = 0; i < 10; i++) {
132 strcpy(path, original);
133 char* ptr = strstr(path,
"XXXXXXXXXX");
135 for(
int i = 0; i < 10; i++) {
167 const char* errfile,
int errline) {
169 if( H5LTread_dataset_double(file,
hdf5_gen_path(var, qid, temp), ptr) < 0 ){
170 print_err(
"Error: could not read HDF5 dataset %s FILE %s LINE %d\n",
171 temp, errfile, errline);
202 const char* errfile,
int errline) {
204 if( H5LTread_dataset_int(file,
hdf5_gen_path(var, qid, temp), ptr) < 0 ){
205 print_err(
"Error: could not read HDF5 dataset %s FILE %s LINE %d\n",
206 temp, errfile, errline);
237 const char* errfile,
int errline) {
239 if( H5LTread_dataset_long(file,
hdf5_gen_path(var, qid, temp), ptr) < 0 ){
240 print_err(
"Error: could not read HDF5 dataset %s FILE %s LINE %d\n",
241 temp, errfile, errline);
255 const char* attrname,
const char*
string) {
258 hid_t grp = H5Gopen(loc, path, H5P_DEFAULT);
259 hid_t aid = H5Screate(H5S_SCALAR);
260 hid_t atype = H5Tcopy(H5T_C_S1);
261 H5Tset_size(atype, strlen(
string));
262 H5Tset_strpad(atype,H5T_STR_NULLPAD);
264 hid_t attr = H5Aopen(grp, attrname, H5P_DEFAULT);
268 H5Adelete(grp, attrname);
272 attr = H5Acreate2(grp, attrname, atype, aid, H5P_DEFAULT, H5P_DEFAULT);
274 err = H5Awrite(attr, atype,
string);
275 if(err) {
return err;}
278 if(err) {
return err;}
280 err = H5Tclose(atype);
281 if(err) {
return err;}
283 err = H5Aclose(attr);
284 if(err) {
return err;}
287 if(err) {
return err;}
296 const char* datasetname,
297 int length,
double* data) {
299 hsize_t dim[1] = {length};
300 hsize_t maxdim[1] = {H5S_UNLIMITED};
301 hid_t dataspace = H5Screate_simple(1, dim, maxdim);
304 hsize_t chunk_dim[1] = {(int)ceil(length/2.0)};
305 hid_t prop = H5Pcreate(H5P_DATASET_CREATE);
306 H5Pset_chunk (prop, 1, chunk_dim);
309 hid_t dataset = H5Dcreate2(group, datasetname, H5T_IEEE_F64LE, dataspace,
310 H5P_DEFAULT, prop, H5P_DEFAULT);
314 if( H5Dwrite(dataset, H5T_IEEE_F64LE, H5S_ALL, H5S_ALL,
315 H5P_DEFAULT, data) < 0) {
330 const char* datasetname,
331 int length,
long* data) {
333 hsize_t dim[1] = {length};
334 hsize_t maxdim[1] = {H5S_UNLIMITED};
335 hid_t dataspace = H5Screate_simple(1, dim, maxdim);
338 hsize_t chunk_dim[1] = {(int)ceil(length/2.0)};
339 hid_t prop = H5Pcreate(H5P_DATASET_CREATE);
340 H5Pset_chunk (prop, 1, chunk_dim);
343 hid_t dataset = H5Dcreate2(group, datasetname, H5T_STD_I64LE, dataspace,
344 H5P_DEFAULT, prop, H5P_DEFAULT);
348 if( H5Dwrite(dataset, H5T_STD_I64LE, H5S_ALL, H5S_ALL,
349 H5P_DEFAULT, data) < 0 ) {
363 const char* datasetname,
364 int length,
int* data) {
366 hsize_t dim[1] = {length};
367 hsize_t maxdim[1] = {H5S_UNLIMITED};
368 hid_t dataspace = H5Screate_simple(1, dim, maxdim);
371 hsize_t chunk_dim[1] = {(int)ceil(length/2.0)};
372 hid_t prop = H5Pcreate(H5P_DATASET_CREATE);
373 H5Pset_chunk (prop, 1, chunk_dim);
376 hid_t dataset = H5Dcreate2(group, datasetname, H5T_STD_I32LE, dataspace,
377 H5P_DEFAULT, prop, H5P_DEFAULT);
381 if( H5Dwrite(dataset, H5T_STD_I32LE, H5S_ALL, H5S_ALL,
382 H5P_DEFAULT, data) < 0 ) {
Main header file for ASCOT5.
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_write_string_attribute(hid_t loc, const char *path, const char *attrname, const char *string)
Write string attribute with null-padding.
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 ...
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.
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_long(const char *var, long *ptr, hid_t file, char *qid, const char *errfile, int errline)
Read long-valued data from ASCOT5 HDF5 file.
hid_t hdf5_create(const char *filename)
Create an hdf5 file, fail if file exists. 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.
char * hdf5_gen_path(const char *original, char *qid, char *path)
Generate a valid path from a given template and qid.
void hdf5_init(void)
Initialize hdf5, right now just disables automatic error messages.
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_write_extendible_dataset_double(hid_t group, const char *datasetname, int length, double *data)
Create and write to an extendible dataset for double data.
hid_t hdf5_open(const char *filename)
Open a hdf5 file for reading and writing. A negative value is returned on failure.
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.
char * hdf5_generate_qid_path(const char *original, char *qid, char *path)
Generate a valid path from a given template and qid.
Macros for printing console output.
#define print_err(...)
Print to standard error.