GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
matlab_writter_helper.h
Go to the documentation of this file.
1/*!
2 * \file matlab_writter_helper.h
3 * \brief Utility functions for logging to a matlab file
4 * \authors <ul>
5 * <li> Mathieu Favreau, 2025. favreau.mathieu(at)hotmail.com
6 * </ul>
7 *
8 * -----------------------------------------------------------------------------
9 *
10 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
11 * This file is part of GNSS-SDR.
12 *
13 * Copyright (C) 2010-2025 (see AUTHORS file for a list of contributors)
14 * SPDX-License-Identifier: GPL-3.0-or-later
15 *
16 * -----------------------------------------------------------------------------
17 */
18
19#ifndef GNSS_SDR_MATLAB_WRITTER_HELPER_H
20#define GNSS_SDR_MATLAB_WRITTER_HELPER_H
21
22#include <matio.h>
23#include <array>
24
25template <typename T>
27
28template <>
29struct matlab_type_traits<int32_t>
30{
31 static constexpr matio_classes class_type = MAT_C_INT32;
32 static constexpr matio_types data_type = MAT_T_INT32;
33};
34
35template <>
36struct matlab_type_traits<uint32_t>
37{
38 static constexpr matio_classes class_type = MAT_C_UINT32;
39 static constexpr matio_types data_type = MAT_T_UINT32;
40};
41
42template <>
43struct matlab_type_traits<uint8_t>
44{
45 static constexpr matio_classes class_type = MAT_C_UINT8;
46 static constexpr matio_types data_type = MAT_T_UINT8;
47};
48
49template <>
50struct matlab_type_traits<int64_t>
51{
52 static constexpr matio_classes class_type = MAT_C_INT64;
53 static constexpr matio_types data_type = MAT_T_INT64;
54};
55
56template <>
57struct matlab_type_traits<uint64_t>
58{
59 static constexpr matio_classes class_type = MAT_C_UINT64;
60 static constexpr matio_types data_type = MAT_T_UINT64;
61};
62
63template <>
64struct matlab_type_traits<float>
65{
66 static constexpr matio_classes class_type = MAT_C_SINGLE;
67 static constexpr matio_types data_type = MAT_T_SINGLE;
68};
69
70template <>
71struct matlab_type_traits<double>
72{
73 static constexpr matio_classes class_type = MAT_C_DOUBLE;
74 static constexpr matio_types data_type = MAT_T_DOUBLE;
75};
76
77
78template <size_t Rank, typename T>
79void write_matlab_var(const char* name, T data, mat_t* matfp, std::array<size_t, 2>& dims)
80{
81 using traits = matlab_type_traits<T>;
82 matvar_t* matvar = Mat_VarCreate(name, traits::class_type, traits::data_type, Rank, dims.data(), &data, 0);
83 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB);
84 Mat_VarFree(matvar);
85}
86
87
88template <size_t Rank, typename T>
89void write_matlab_var(const char* name, T* data, mat_t* matfp, std::array<size_t, 2>& dims)
90{
91 using traits = matlab_type_traits<T>;
92 matvar_t* matvar = Mat_VarCreate(name, traits::class_type, traits::data_type, Rank, dims.data(), data, 0);
93 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB);
94 Mat_VarFree(matvar);
95}
96
97#endif // GNSS_SDR_NAV_MESSAGE_MONITOR_H