From dc79f6b6a257373e0b7ae0feb3968e7c1927cba4 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 2 Jul 2025 11:38:01 +0200 Subject: [PATCH] fix: update readflash to more moderne HDF5 --- src/h5_readFlash.cpp | 85 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/h5_readFlash.cpp b/src/h5_readFlash.cpp index 6e2ec3a..bc2a080 100644 --- a/src/h5_readFlash.cpp +++ b/src/h5_readFlash.cpp @@ -7,16 +7,16 @@ This software is a computer program whose purpose is to provide a toolbox for co data analysis (e.g. filters, generalized Fourier transforms, power spectra, ...) This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, +abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". +"http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited -liability. +liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the @@ -25,9 +25,9 @@ that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. @@ -59,8 +59,8 @@ int ipvz_out = 5; /* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx */ -/* n*_runtime_parameters should be set by the caller to - the maximum number of runtime parameters to read. +/* n*_runtime_parameters should be set by the caller to + the maximum number of runtime parameters to read. */ void h5_read_runtime_parameters @@ -100,12 +100,12 @@ void h5_read_runtime_parameters nreal_runtime_parameters = MAX_PARM; /* integer runtime parameters */ - int_rt_parms = (int_runtime_params_t *) malloc(nint_runtime_parameters * sizeof(int_runtime_params_t)); + int_rt_parms = (int_runtime_params_t *) malloc(nint_runtime_parameters * sizeof(int_runtime_params_t)); rank = 1; DataSet dataset = file->openDataSet("integer runtime parameters"); - - IntType int_rt_type = dataset.getIntType(); + + IntType int_rt_type = dataset.getIntType(); //int_rt_type = H5Dget_type(dataset); DataSpace dataspace = dataset.getSpace(); @@ -124,6 +124,8 @@ void h5_read_runtime_parameters //memspace = H5Screate_simple(rank, &dimens_1d, NULL); dataset.read(int_rt_parms, int_rt_type, memspace, dataspace); + //status = H5Dread(dataset, int_rt_type, memspace, dataspace, + // H5P_DEFAULT, int_rt_parms); for (i = 0; i < nint_runtime_parameters; i++) { @@ -142,14 +144,14 @@ void h5_read_runtime_parameters /* reals */ - real_rt_parms = (real_runtime_params_t *) malloc(nreal_runtime_parameters * sizeof(real_runtime_params_t)); - + real_rt_parms = (real_runtime_params_t *) malloc(nreal_runtime_parameters * sizeof(real_runtime_params_t)); + rank = 1; dataset = file->openDataSet("real runtime parameters"); - //dataset = H5Dopen(*file_identifier, "real runtime parameters"); - + //dataset = H5Dopen(*file_identifier, "real runtime parameters"); + dataspace = dataset.getSpace(); - FloatType real_rt_type = dataset.getFloatType(); + FloatType real_rt_type = dataset.getFloatType(); ndims = dataspace.getSimpleExtentDims(&dimens_1d, NULL); //dataspace = H5Dget_space(dataset); //real_rt_type = H5Dget_type(dataset); @@ -165,6 +167,8 @@ void h5_read_runtime_parameters //memspace = H5Screate_simple(rank, &dimens_1d, NULL); dataset.read(real_rt_parms, real_rt_type, memspace, dataspace); + //status = H5Dread(dataset, real_rt_type, memspace, dataspace, +// H5P_DEFAULT, real_rt_parms); for (i = 0; i < nreal_runtime_parameters; i++) { @@ -187,7 +191,7 @@ void h5_read_runtime_parameters *LBox = real_runtime_parameter_values[i]; } if (strncmp(real_runtime_parameter_names[i],"hubbleconstant", 14) == 0 ) { - *hubble = real_runtime_parameter_values[i]; + *hubble = real_runtime_parameter_values[i]; } if (strncmp(real_runtime_parameter_names[i],"omegamatter", 11) == 0 ) { *omegam = real_runtime_parameter_values[i]; @@ -199,7 +203,7 @@ void h5_read_runtime_parameters *omegalambda = real_runtime_parameter_values[i]; } } - + for (i = 0; i < nint_runtime_parameters; i++) { if (strncmp(int_runtime_parameter_names[i],"pt_numx",7) == 0 ) { *numPart = int_runtime_parameter_values[i]; @@ -208,7 +212,7 @@ void h5_read_runtime_parameters } } - + /* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ void h5_read_flash3_particles (H5File* file, int* totalparticles, @@ -235,8 +239,8 @@ void h5_read_flash3_particles (H5File* file, char *propName; double *partBuffer; char part_names[50][OUTPUT_PROP_LENGTH]; - int string_size; - + int string_size; + // char part_names[NPART_PROPS][OUTPUT_PROP_LENGTH]; hsize_t dimens_2d[2], maxdimens_2d[2]; hsize_t start_2d[2], count_2d[2], stride_2d[2]; @@ -259,12 +263,12 @@ void h5_read_flash3_particles (H5File* file, //total number of particle properties numProps = dimens_2d[0]; - + string_size = OUTPUT_PROP_LENGTH; StrType string_type = H5Tcopy(H5T_C_S1); string_type.setSize(string_size); //status = H5Tset_size(string_type, string_size); - + rank = 2; start_2d[0] = 0; @@ -276,20 +280,22 @@ void h5_read_flash3_particles (H5File* file, count_2d[0] = dimens_2d[0]; count_2d[1] = dimens_2d[1]; - dataspace.selectHyperslab(H5S_SELECT_SET, count_2d, start_2d); + dataspace.selectHyperslab(H5S_SELECT_SET, count_2d, start_2d); //status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start_2d, // stride_2d, count_2d, NULL); DataSpace memspace(rank, dimens_2d); //memspace = H5Screate_simple(rank, dimens_2d, NULL); - dataset.read(part_names, string_type); - + dataset.read(part_names, string_type, H5S_ALL, H5S_ALL); + //status = H5Dread(dataset, string_type, H5S_ALL, H5S_ALL, + // H5P_DEFAULT, part_names); + string_type.close(); memspace.close(); dataspace.close(); - dataset.close(); + dataset.close(); //H5Tclose(string_type); //H5Sclose(memspace); //H5Sclose(dataspace); @@ -305,7 +311,7 @@ void h5_read_flash3_particles (H5File* file, if (strncmp(part_names[i], "velz", 4) == 0) { ipvz = i+1; } } - if ((iptag < 0) || (ipx < 0) || (ipy < 0) || (ipz < 0) || (ipvx < 0) || + if ((iptag < 0) || (ipx < 0) || (ipy < 0) || (ipz < 0) || (ipvx < 0) || (ipvy < 0) || (ipvz < 0) ) { printf("One or more required particle attributes not found in file!\n"); return; @@ -317,7 +323,7 @@ void h5_read_flash3_particles (H5File* file, //read particles dataset = file->openDataSet("tracer particles"); //dataset = H5Dopen(*file_identifier, "tracer particles"); - + FloatType datatype = dataset.getFloatType(); //datatype = H5Dget_type(dataset); @@ -330,7 +336,7 @@ void h5_read_flash3_particles (H5File* file, ndims = dataspace.getSimpleExtentDims(dimens_2d, NULL); //dataspace = H5Dget_space(dataset); //H5Sget_simple_extent_dims(dataspace, dimens_2d, maxdimens_2d); - + /*insert particle properties (numPartBuffer) particles at a time*/ pstack = (*localnp); poffset = 0; @@ -358,7 +364,7 @@ void h5_read_flash3_particles (H5File* file, dimens_2d[0] = (pcount); dimens_2d[1] = (numProps); - dataspace.selectHyperslab(H5S_SELECT_SET, count_2d, start_2d); + dataspace.selectHyperslab(H5S_SELECT_SET, count_2d, start_2d); //status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start_2d, // stride_2d, count_2d, NULL); @@ -367,6 +373,7 @@ void h5_read_flash3_particles (H5File* file, /* read data from the dataset */ dataset.read(partBuffer, datatype, memspace, dataspace); + //status = H5Dread(dataset, datatype, memspace, dataspace, H5P_DEFAULT, partBuffer); /* convert buffer into particle struct */ @@ -382,8 +389,8 @@ void h5_read_flash3_particles (H5File* file, pos3[p+poffset] = (float) *(partBuffer+ipz-1+p*numProps); } } - - + + if (vel1 && vel2 && vel3) { for(p=0; p < (pcount); p++) { vel1[p+poffset] = (float) *(partBuffer+ipvx-1+p*numProps); @@ -414,7 +421,7 @@ void h5_read_flash3_particles (H5File* file, //status = H5Sclose(dataspace); //status = H5Dclose(dataset); } - + /*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ @@ -442,7 +449,7 @@ void h5_read_flash3_header_info(H5File* file, H5std_string DATASET_NAME; - string_type = H5Tcopy(H5T_C_S1); + string_type = H5Tcopy(H5T_C_S1); H5Tset_size(string_type, MAX_STRING_LENGTH); DataSet dataset = file->openDataSet("real scalars"); @@ -458,13 +465,13 @@ void h5_read_flash3_header_info(H5File* file, /* malloc a pointer to a list of real_list_t's */ real_list = (real_list_t *) malloc(dimens_1d * sizeof(real_list_t)); - // create a new simple dataspace of 1 dimension and size of 'dimens_1d' + // create a new simple dataspace of 1 dimension and size of 'dimens_1d' DataSpace memspace(1, &dimens_1d); - // create an empty vessel sized to hold one real_list_t's worth of data + // create an empty vessel sized to hold one real_list_t's worth of data CompType real_list_type( sizeof(real_list_t) ); - // subdivide the empty vessel into its component sections (name and value) + // subdivide the empty vessel into its component sections (name and value) real_list_type.insertMember( "name", HOFFSET(real_list_t, name), @@ -475,7 +482,7 @@ void h5_read_flash3_header_info(H5File* file, HOFFSET(real_list_t, value), PredType::NATIVE_DOUBLE); - // read the data into 'real_list' + // read the data into 'real_list' dataset.read( real_list, real_list_type, memspace, dataspace);