Skip to content

Commit 97d9d6a

Browse files
committed
fix macos build with clang 12.0
1 parent 34fae49 commit 97d9d6a

File tree

5 files changed

+243
-194
lines changed

5 files changed

+243
-194
lines changed

.clang-format

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ SpaceBeforeParens: ControlStatements
4949
SpaceInEmptyParentheses: false
5050
SpacesInAngles: false
5151
MaxEmptyLinesToKeep: 1
52-
ColumnLimit: 0
52+
ColumnLimit: 0
53+
ForEachMacros:
54+
- foreach
55+
- Q_FOREACH
56+
- BOOST_FOREACH

CMake/CommonMacros.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ MACRO(USE_OPENMP)
77
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
88
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
99
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
10+
LIST( APPEND MY_EXTERNAL_LINK_LIBRARIES ${OpenMP_CXX_LIBRARIES} )
1011
ELSE()
1112
MESSAGE("OpenMP not found. Disabling OpenMP parallelization.")
1213
ADD_DEFINITIONS(-DNO_OPENMP_SUPPORT)

Core/HDF5Reader.cpp

+139-99
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ HDF5Reader::HDF5Reader()
3333
HDF5Reader::~HDF5Reader() { close(); }
3434

3535
void HDF5Reader::decompose(std::string& filename, std::string& dataname,
36-
const std::string& pathname)
36+
const std::string& pathname)
3737
{
3838
const std::string::size_type idx = pathname.find(':');
3939

@@ -85,15 +85,15 @@ bool HDF5Reader::existsValidHdf5(const std::string& fname)
8585
if (!exists)
8686
{
8787
std::cerr << "HDF5Reader::existsValidHdf5() : error, '" << fname
88-
<< "' does not exist" << std::endl;
88+
<< "' does not exist" << std::endl;
8989
return false;
9090
}
9191
#else
9292
FILE* pFile = fopen(fname.c_str(), "r");
9393
if (pFile == nullptr)
9494
{
9595
std::cerr << "HDF5Reader::existsValidHdf5() : error, '" << fname
96-
<< "' does not exist" << std::endl;
96+
<< "' does not exist" << std::endl;
9797
return false;
9898
}
9999
else
@@ -118,7 +118,7 @@ int HDF5Reader::open(const std::string& fname)
118118
if (!HDF5Reader::existsValidHdf5(fname))
119119
{
120120
std::cerr << "HDF5Reader::open() : " << fname
121-
<< " does not exist or is not a valid hdf5 file" << std::endl;
121+
<< " does not exist or is not a valid hdf5 file" << std::endl;
122122
return 0;
123123
}
124124
file = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
@@ -148,7 +148,7 @@ int HDF5Reader::close()
148148
}
149149

150150
int HDF5Reader::getDatasetInfo(std::string& type, std::vector<size_type>& extents,
151-
const std::string& name)
151+
const std::string& name)
152152
{
153153
if (file < 0)
154154
{
@@ -165,7 +165,7 @@ int HDF5Reader::getDatasetInfo(std::string& type, std::vector<size_type>& extent
165165
{
166166
if (loud)
167167
std::cerr << "HDF5Reader::getDatasetInfo() : no such dataset: " << name
168-
<< std::endl;
168+
<< std::endl;
169169
type = "none";
170170
return 0;
171171
}
@@ -226,7 +226,7 @@ int HDF5Reader::getDatasetInfo(std::string& type, std::vector<size_type>& extent
226226
else
227227
{
228228
std::cerr << "HDF5Reader::getDatasetInfo() : warning, unsupported native type"
229-
<< std::endl;
229+
<< std::endl;
230230
status = H5Tclose(native_type);
231231
status = H5Tclose(datatype);
232232
status = H5Dclose(dataset);
@@ -260,48 +260,88 @@ int HDF5Reader::getDatasetInfo(std::string& type, std::vector<size_type>& extent
260260
template<typename T>
261261
struct HdfType
262262
{
263-
static hid_t type() { return -1; }
263+
static hid_t type() { return -1; }
264264
};
265265

266-
template <> struct HdfType<double> { static hid_t type() { return H5T_NATIVE_DOUBLE; } };
267-
template <> struct HdfType<float> { static hid_t type() { return H5T_NATIVE_FLOAT; } };
268-
template <> struct HdfType<std::uint8_t> { static hid_t type() { return H5T_NATIVE_UINT8; } };
269-
template <> struct HdfType<std::uint16_t> { static hid_t type() { return H5T_NATIVE_UINT16; } };
270-
template <> struct HdfType<std::uint32_t> { static hid_t type() { return H5T_NATIVE_UINT32; } };
271-
template <> struct HdfType<std::uint64_t> { static hid_t type() { return H5T_NATIVE_UINT64; } };
272-
template <> struct HdfType<std::int8_t> { static hid_t type() { return H5T_NATIVE_INT8; } };
273-
template <> struct HdfType<std::int16_t> { static hid_t type() { return H5T_NATIVE_INT16; } };
274-
template <> struct HdfType<std::int32_t> { static hid_t type() { return H5T_NATIVE_INT32; } };
275-
template <> struct HdfType<std::int64_t> { static hid_t type() { return H5T_NATIVE_INT64; } };
266+
template<>
267+
struct HdfType<double>
268+
{
269+
static hid_t type() { return H5T_NATIVE_DOUBLE; }
270+
};
271+
template<>
272+
struct HdfType<float>
273+
{
274+
static hid_t type() { return H5T_NATIVE_FLOAT; }
275+
};
276+
template<>
277+
struct HdfType<std::uint8_t>
278+
{
279+
static hid_t type() { return H5T_NATIVE_UINT8; }
280+
};
281+
template<>
282+
struct HdfType<std::uint16_t>
283+
{
284+
static hid_t type() { return H5T_NATIVE_UINT16; }
285+
};
286+
template<>
287+
struct HdfType<std::uint32_t>
288+
{
289+
static hid_t type() { return H5T_NATIVE_UINT32; }
290+
};
291+
template<>
292+
struct HdfType<std::uint64_t>
293+
{
294+
static hid_t type() { return H5T_NATIVE_UINT64; }
295+
};
296+
template<>
297+
struct HdfType<std::int8_t>
298+
{
299+
static hid_t type() { return H5T_NATIVE_INT8; }
300+
};
301+
template<>
302+
struct HdfType<std::int16_t>
303+
{
304+
static hid_t type() { return H5T_NATIVE_INT16; }
305+
};
306+
template<>
307+
struct HdfType<std::int32_t>
308+
{
309+
static hid_t type() { return H5T_NATIVE_INT32; }
310+
};
311+
template<>
312+
struct HdfType<std::int64_t>
313+
{
314+
static hid_t type() { return H5T_NATIVE_INT64; }
315+
};
276316

277317
int HDF5Reader::read(double* _data, const std::string& name)
278318
{
279-
return this->readData(_data, name);
319+
return this->readData(_data, name);
280320
}
281321

282322
int HDF5Reader::read(float* _data, const std::string& name)
283323
{
284-
return this->readData(_data, name);
324+
return this->readData(_data, name);
285325
}
286326

287327
int HDF5Reader::read(int* _data, const std::string& name)
288328
{
289-
return this->readData(_data, name);
329+
return this->readData(_data, name);
290330
}
291331

292332
int HDF5Reader::read(unsigned int* _data, const std::string& name)
293333
{
294-
return this->readData(_data, name);
334+
return this->readData(_data, name);
295335
}
296336

297337
int HDF5Reader::read(long* _data, const std::string& name)
298338
{
299-
return this->readData(_data, name);
339+
return this->readData(_data, name);
300340
}
301341

302342
int HDF5Reader::read(unsigned char* _data, const std::string& name)
303343
{
304-
return this->readData(_data, name);
344+
return this->readData(_data, name);
305345
}
306346

307347
int HDF5Reader::read(unsigned short* _data, const std::string& name)
@@ -311,125 +351,125 @@ int HDF5Reader::read(unsigned short* _data, const std::string& name)
311351

312352
int HDF5Reader::read(std::vector<double>& v, const std::string& name)
313353
{
314-
return readVec(v, name);
354+
return readVec(v, name);
315355
}
316356

317357
int HDF5Reader::read(std::vector<float>& v, const std::string& name)
318358
{
319-
return readVec(v, name);
359+
return readVec(v, name);
320360
}
321361

322362
int HDF5Reader::read(std::vector<int>& v, const std::string& name)
323363
{
324-
return readVec(v, name);
364+
return readVec(v, name);
325365
}
326366

327367
int HDF5Reader::read(std::vector<unsigned int>& v, const std::string& name)
328368
{
329-
return readVec(v, name);
369+
return readVec(v, name);
330370
}
331371

332372
int HDF5Reader::read(std::vector<long>& v, const std::string& name)
333373
{
334-
return readVec(v, name);
374+
return readVec(v, name);
335375
}
336376

337377
int HDF5Reader::read(std::vector<unsigned char>& v, const std::string& name)
338378
{
339-
return readVec(v, name);
379+
return readVec(v, name);
340380
}
341381

342382
int HDF5Reader::read(std::vector<unsigned short>& v, const std::string& name)
343383
{
344-
return readVec(v, name);
384+
return readVec(v, name);
345385
}
346386

347387
template<typename T>
348388
int HDF5Reader::readVec(std::vector<T>& v, const std::string& name)
349389
{
350-
std::string type;
351-
std::vector<size_type> dims;
352-
if (!getDatasetInfo(type, dims, name))
353-
return 0;
354-
if (dims.size() != 1)
355-
{
356-
warning("HDF5Reader::read() : rank must be 1 for std::vectors, returning");
357-
return 0;
358-
}
359-
v.resize(dims[0]);
360-
return this->readData(v.data(), name);
390+
std::string type;
391+
std::vector<size_type> dims;
392+
if (!getDatasetInfo(type, dims, name))
393+
return 0;
394+
if (dims.size() != 1)
395+
{
396+
warning("HDF5Reader::read() : rank must be 1 for std::vectors, returning");
397+
return 0;
398+
}
399+
v.resize(dims[0]);
400+
return this->readData(v.data(), name);
361401
}
362402

363403
int HDF5Reader::read(float* data, size_type offset, size_type length,
364-
const std::string& name)
404+
const std::string& name)
365405
{
366406
return HDF5IO().readData(file, name, offset, length, data) ? 1 : 0;
367407
}
368408

369409
int HDF5Reader::read(unsigned short* data, size_type offset,
370-
size_type length, const std::string& name)
410+
size_type length, const std::string& name)
371411
{
372412
return HDF5IO().readData(file, name, offset, length, data) ? 1 : 0;
373413
}
374414

375415
template<typename T>
376416
int HDF5Reader::readData(T* Array, const std::string& name)
377417
{
378-
if (file < 0)
379-
{
380-
std::cerr << "HDF5Reader::readData() : no file open" << std::endl;
381-
return 0;
382-
}
383-
if (!Array)
384-
{
385-
std::cerr << "HDF5Reader::readData() : no pointer to data" << std::endl;
386-
return 0;
387-
}
388-
389-
if (loud)
390-
std::cerr << "HDF5Reader::readData() : loading dataset " << name << std::endl;
391-
392-
bool ok = false;
393-
394-
hid_t dataset = H5Dopen2(file, name.c_str(), H5P_DEFAULT);
395-
if (dataset >= 0)
396-
{
397-
hid_t dataspace = H5Dget_space(dataset);
398-
if (dataspace >= 0)
399-
{
400-
int rank = H5Sget_simple_extent_ndims(dataspace);
401-
if (rank >= 0)
402-
{
403-
std::vector<hsize_t> dims(rank);
404-
H5Sget_simple_extent_dims(dataspace, dims.data(), nullptr);
405-
H5Sselect_all(dataspace);
406-
407-
if (H5Sselect_valid(dataspace) >= 0)
408-
{
409-
// Define the memory space to read dataset.
410-
hid_t memoryspace = H5Screate_simple(rank, dims.data(), nullptr);
411-
412-
hid_t type_id = HdfType<T>::type();
413-
if (HdfType<T>::type < 0)
414-
{
415-
// get data type from file
416-
type_id = H5Dget_type(dataset);
417-
}
418-
419-
herr_t status = H5Dread(dataset, type_id, memoryspace, dataspace, H5P_DEFAULT, Array);
420-
ok = (status >= 0);
421-
422-
if (HdfType<T>::type() < 0)
423-
H5Tclose(type_id);
424-
H5Sclose(memoryspace);
425-
}
426-
}
427-
H5Sclose(dataspace);
428-
}
429-
H5Dclose(dataset);
430-
}
431-
432-
return ok ? 1 : 0;
418+
if (file < 0)
419+
{
420+
std::cerr << "HDF5Reader::readData() : no file open" << std::endl;
421+
return 0;
422+
}
423+
if (!Array)
424+
{
425+
std::cerr << "HDF5Reader::readData() : no pointer to data" << std::endl;
426+
return 0;
427+
}
428+
429+
if (loud)
430+
std::cerr << "HDF5Reader::readData() : loading dataset " << name << std::endl;
431+
432+
bool ok = false;
433+
434+
hid_t dataset = H5Dopen2(file, name.c_str(), H5P_DEFAULT);
435+
if (dataset >= 0)
436+
{
437+
hid_t dataspace = H5Dget_space(dataset);
438+
if (dataspace >= 0)
439+
{
440+
int rank = H5Sget_simple_extent_ndims(dataspace);
441+
if (rank >= 0)
442+
{
443+
std::vector<hsize_t> dims(rank);
444+
H5Sget_simple_extent_dims(dataspace, dims.data(), nullptr);
445+
H5Sselect_all(dataspace);
446+
447+
if (H5Sselect_valid(dataspace) >= 0)
448+
{
449+
// Define the memory space to read dataset.
450+
hid_t memoryspace = H5Screate_simple(rank, dims.data(), nullptr);
451+
452+
hid_t type_id = HdfType<T>::type();
453+
if (type_id < 0)
454+
{
455+
// get data type from file
456+
type_id = H5Dget_type(dataset);
457+
}
458+
459+
herr_t status = H5Dread(dataset, type_id, memoryspace, dataspace, H5P_DEFAULT, Array);
460+
ok = (status >= 0);
461+
462+
if (HdfType<T>::type() < 0)
463+
H5Tclose(type_id);
464+
H5Sclose(memoryspace);
465+
}
466+
}
467+
H5Sclose(dataspace);
468+
}
469+
H5Dclose(dataset);
470+
}
471+
472+
return ok ? 1 : 0;
433473
}
434474

435475
} // namespace iseg

0 commit comments

Comments
 (0)