FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
hdf5_handler.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file hdf5_handler.h
10 * @brief Header file for HDF5 data export and import functions.
11 */
12
13#pragma once
14
15#include <mutex>
16#include <string>
17#include <vector>
18
19#include "core/config.h"
21
22namespace HighFive
23{
24 class File;
25}
26
27namespace serial
28{
29 /**
30 * @brief Global mutex to protect all HDF5 C-library calls, which are not thread-safe.
31 */
32 extern std::mutex hdf5_global_mutex;
33
34 /**
35 * @brief Adds a chunk of data to an HDF5 file.
36 *
37 * @param file The HDF5 file where the chunk is written.
38 * @param data A vector of complex data to be written.
39 * @param time The time attribute associated with the chunk.
40 * @param fullscale The fullscale attribute for the chunk.
41 * @param count The sequential count number for chunk naming.
42 * @throws std::runtime_error If there is an error writing data or setting attributes.
43 */
44 void addChunkToFile(HighFive::File& file, const std::vector<ComplexType>& data, RealType time, RealType fullscale,
45 unsigned count, const core::PulseChunkMetadata* metadata = nullptr);
46
47 /**
48 * @brief Writes additive FERS output metadata attributes to an open HDF5 file.
49 *
50 * The caller must hold `hdf5_global_mutex`.
51 */
52 void writeOutputFileMetadataAttributes(HighFive::File& file, const core::OutputFileMetadata& metadata);
53
54 /**
55 * @brief Reads pulse data from an HDF5 file.
56 *
57 * @param name The name of the HDF5 file.
58 * @param data A reference to a vector where the complex data will be stored.
59 * @throws std::runtime_error If the file does not exist or the datasets "I" and "Q" have mismatched sizes.
60 */
61 void readPulseData(const std::string& name, std::vector<ComplexType>& data);
62
63 /**
64 * @brief Reads a 2D pattern dataset from an HDF5 file.
65 *
66 * @param name The name of the HDF5 file.
67 * @param datasetName The name of the dataset to be read.
68 * @return A 2D vector containing the pattern data.
69 * @throws std::runtime_error If there is an error handling the file or if the dataset dimensions are invalid.
70 */
71 std::vector<std::vector<RealType>> readPattern(const std::string& name, const std::string& datasetName);
72}
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
std::mutex hdf5_global_mutex
Global mutex to protect all HDF5 C-library calls, which are not thread-safe.
void writeOutputFileMetadataAttributes(HighFive::File &file, const core::OutputFileMetadata &metadata)
Writes additive FERS output metadata attributes to an open HDF5 file.
void addChunkToFile(HighFive::File &file, const std::vector< ComplexType > &data, const RealType time, const RealType fullscale, const unsigned count, const core::PulseChunkMetadata *metadata)
Adds a chunk of data to an HDF5 file.
void readPulseData(const std::string &name, std::vector< ComplexType > &data)
Reads pulse data from an HDF5 file.
std::vector< std::vector< RealType > > readPattern(const std::string &name, const std::string &datasetName)
Reads a 2D pattern dataset from an HDF5 file.