Skip to content
Snippets Groups Projects
Commit d614f766 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Implement HDF5 output of double precision complex values

parent 1b49f1f0
No related branches found
No related tags found
No related merge requests found
...@@ -81,7 +81,7 @@ HDFFile* HDFFile::from_schema( ...@@ -81,7 +81,7 @@ HDFFile* HDFFile::from_schema(
herr_t status; herr_t status;
string *rec_types = schema.get_record_types(); string *rec_types = schema.get_record_types();
string *rec_names = schema.get_record_names(); string *rec_names = schema.get_record_names();
string known_types[] = {"INT32", "FLOAT64"}; string known_types[] = {"INT32", "FLOAT64", "COMPLEX128"};
int rec_num = schema.get_record_number(); int rec_num = schema.get_record_number();
regex re; regex re;
smatch m; smatch m;
...@@ -99,8 +99,9 @@ HDFFile* HDFFile::from_schema( ...@@ -99,8 +99,9 @@ HDFFile* HDFFile::from_schema(
str_target = m.suffix().str(); str_target = m.suffix().str();
if (type_index == 1) data_type = H5Tcopy(H5T_NATIVE_INT); if (type_index == 1) data_type = H5Tcopy(H5T_NATIVE_INT);
else if (type_index == 2) data_type = H5Tcopy(H5T_NATIVE_DOUBLE); else if (type_index == 2) data_type = H5Tcopy(H5T_NATIVE_DOUBLE);
else if (type_index == 3) data_type = H5Tcopy(H5T_NATIVE_DOUBLE);
} }
if (type_index == 2) break; if (type_index == 3) break;
} }
if (found_type) { if (found_type) {
re = regex("[0-9]+"); re = regex("[0-9]+");
...@@ -119,6 +120,9 @@ HDFFile* HDFFile::from_schema( ...@@ -119,6 +120,9 @@ HDFFile* HDFFile::from_schema(
max_dims[ti] = dim; max_dims[ti] = dim;
str_target = m.suffix().str(); str_target = m.suffix().str();
} }
int multiplier = (type_index == 3) ? 2 : 1;
dims[rank - 1] *= multiplier;
max_dims[rank - 1] *= multiplier;
hid_t dataspace_id = H5Screate_simple(rank, dims, max_dims); hid_t dataspace_id = H5Screate_simple(rank, dims, max_dims);
hid_t dataset_id = H5Dcreate( hid_t dataset_id = H5Dcreate(
file_id, rec_names[ri].c_str(), data_type, dataspace_id, H5P_DEFAULT, file_id, rec_names[ri].c_str(), data_type, dataspace_id, H5P_DEFAULT,
...@@ -183,7 +187,7 @@ herr_t HDFFile::write( ...@@ -183,7 +187,7 @@ herr_t HDFFile::write(
hid_t mem_space_id, hid_t file_space_id, hid_t dapl_id, hid_t mem_space_id, hid_t file_space_id, hid_t dapl_id,
hid_t dxpl_id hid_t dxpl_id
) { ) {
string known_types[] = {"INT32", "FLOAT64"}; string known_types[] = {"INT32", "FLOAT64", "COMPLEX128"};
regex re; regex re;
smatch m; smatch m;
bool found_type = false; bool found_type = false;
...@@ -191,7 +195,7 @@ herr_t HDFFile::write( ...@@ -191,7 +195,7 @@ herr_t HDFFile::write(
while (!found_type) { while (!found_type) {
re = regex(known_types[type_index++]); re = regex(known_types[type_index++]);
found_type = regex_search(data_type, m, re); found_type = regex_search(data_type, m, re);
if (type_index == 2) break; if (type_index == 3) break;
} }
if (found_type) { if (found_type) {
hid_t dataset_id = H5Dopen2(file_id, dataset_name.c_str(), dapl_id); hid_t dataset_id = H5Dopen2(file_id, dataset_name.c_str(), dapl_id);
...@@ -201,6 +205,8 @@ herr_t HDFFile::write( ...@@ -201,6 +205,8 @@ herr_t HDFFile::write(
mem_type_id = H5T_NATIVE_INT; break; mem_type_id = H5T_NATIVE_INT; break;
case 2: case 2:
mem_type_id = H5T_NATIVE_DOUBLE; break; mem_type_id = H5T_NATIVE_DOUBLE; break;
case 3:
mem_type_id = H5T_NATIVE_DOUBLE; break;
default: default:
throw UnrecognizedParameterException("unrecognized data type \"" + data_type + "\""); throw UnrecognizedParameterException("unrecognized data type \"" + data_type + "\"");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment