Skip to content

Commit

Permalink
Add libhdf5.
Browse files Browse the repository at this point in the history
Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Will Graham <[email protected]>
  • Loading branch information
3 people committed Mar 9, 2023
1 parent 13dc5cf commit bd8e5d1
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
if: ${{ contains(matrix.os, 'ubuntu') }}
run: |
sudo apt-get update
sudo apt-get install libfftw3-dev libgomp1 python3
sudo apt-get install libfftw3-dev libhdf5-dev libgomp1 python3
# -------------------------------------------------------------------------------
# Windows
Expand All @@ -77,12 +77,14 @@ jobs:
run: |
conda install fftw --yes
echo "FFTWDIR=C:\Miniconda\envs\test\Library" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
conda install hdf5
echo "HDF5_DIR=C:\Miniconda\envs\test\Library" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
# -------------------------------------------------------------------------------
# MacOS
- name: Install dependencies for MacOS
if: ${{ contains(matrix.os, 'macos') }}
run: brew install fftw
run: brew install fftw hdf5

- name: Fix omp headers not linked on MacOS
if: ${{ contains(matrix.os, 'macos') }}
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ To compile on a Mac an x86 compiler with libraries for OpenMP are required,
which can be installed using [brew](https://brew.sh/) with `brew install llvm`
then (optionally) set the following cmake arguments

```{sh}
-DCMAKE_CXX_COMPILER=/Users/username/.local/homebrew/opt/llvm/bin/clang++
-DOMP_ROOT=/Users/username/.local/homebrew/opt/llvm/
-DCXX_ROOT=/Users/username/.local/homebrew/opt/llvm
```

On an ARM Mac install the x86 version of brew with
```bash
arch -x86_64 zsh
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch -x86_64 /usr/local/bin/brew install llvm
```
```{sh}
-DCMAKE_CXX_COMPILER=/Users/username/.local/homebrew/opt/llvm/bin/clang++
-DOMP_ROOT=/Users/username/.local/homebrew/opt/llvm/
-DCXX_ROOT=/Users/username/.local/homebrew/opt/llvm
-DHDF5_ROOT=/Users/username/.local/homebrew/opt/hdf5
```

On an ARM Mac install the x86 version of brew with
```bash
arch -x86_64 zsh
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch -x86_64 /usr/local/bin/brew install llvm hdf5
```
</details>


Expand Down
5 changes: 4 additions & 1 deletion tdms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# General setup ---------------------------------------------------------------
cmake_minimum_required(VERSION 3.21)

project(tdms LANGUAGES CXX)
project(tdms LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17)

# Allow building with testing, and default to off
Expand Down Expand Up @@ -57,6 +57,9 @@ else()
find_package(OpenMP REQUIRED)
endif()

# hdf5 ------------------------------------------------------------------------
find_package(HDF5 REQUIRED COMPONENTS CXX)
include_directories(${HDF5_INCLUDE_DIR})

# spdlog ----------------------------------------------------------------------
find_package(spdlog NO_CMAKE_PACKAGE_REGISTRY QUIET)
Expand Down
2 changes: 2 additions & 0 deletions tdms/cmake/targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function(release_target)
${Matlab_MX_LIBRARY}
${Matlab_MAT_LIBRARY}
${LIBCXX_LIBRARY}
${HDF5_CXX_LIBRARIES}
OpenMP::OpenMP_CXX
spdlog::spdlog
)
Expand Down Expand Up @@ -44,6 +45,7 @@ function(test_target)
${Matlab_MX_LIBRARY}
${Matlab_MAT_LIBRARY}
${LIBCXX_LIBRARY}
${HDF5_CXX_LIBRARIES}
OpenMP::OpenMP_CXX
spdlog::spdlog
)
Expand Down
9 changes: 9 additions & 0 deletions tdms/include/hdf5_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @file hdf5_io.h
* @brief File I/O using HDF5
*/

/**
* @brief Test of HDF5 I/O
*/
void test_hdf5();
65 changes: 65 additions & 0 deletions tdms/src/hdf5_io.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// own include
#include "hdf5_io.h"

// std
#include <string>

// external libraries
#include <H5Cpp.h>

// own headers


#define MAX_NAME_LENGTH 32
const std::string FileName("SimpleCompound.h5");
const std::string DatasetName("PersonalInformation");
const std::string member_age("Age");
const std::string member_sex("Sex");
const std::string member_name("Name");
const std::string member_height("Height");

typedef struct {
int age;
char sex;
char name[MAX_NAME_LENGTH];
float height;
} PersonalInformation;



void test_hdf5() {

// Data to write
PersonalInformation person_list[] = {
{ 18, 'M', "Mary", 152.0 },
{ 32, 'F', "Tom", 178.6 },
{ 29, 'M', "Tarou", 166.6 }
};
// the length of the data
//int length = sizeof(person_list) / sizeof(PersonalInformation);
// the array of each length of multidimentional data.
hsize_t dim[1];
dim[0] = sizeof(person_list) / sizeof(PersonalInformation);

// the length of dim
int rank = sizeof(dim) / sizeof(hsize_t);

// defining the datatype to pass HDF55
H5::CompType mtype(sizeof(PersonalInformation));
mtype.insertMember(member_age, HOFFSET(PersonalInformation, age), H5::PredType::NATIVE_INT);
mtype.insertMember(member_sex, HOFFSET(PersonalInformation, sex), H5::PredType::C_S1);
mtype.insertMember(member_name, HOFFSET(PersonalInformation, name), H5::StrType(H5::PredType::C_S1, MAX_NAME_LENGTH));
mtype.insertMember(member_height, HOFFSET(PersonalInformation, height), H5::PredType::NATIVE_FLOAT);

// preparation of a dataset and a file.
H5::DataSpace space(rank, dim);
H5::H5File *file = new H5::H5File(FileName, H5F_ACC_TRUNC);
H5::DataSet *dataset = new H5::DataSet(file->createDataSet(DatasetName, mtype, space));
// Write
dataset->write(person_list, mtype);

delete dataset;
delete file;
return;

}

0 comments on commit bd8e5d1

Please sign in to comment.