GNSS-SDR  0.0.21
An Open Source GNSS Software Defined Receiver
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 
25 template <typename T>
27 
28 template <>
29 struct 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 
35 template <>
36 struct 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 
42 template <>
43 struct 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 
49 template <>
50 struct 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 
56 template <>
57 struct 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 
63 template <>
64 struct 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 
70 template <>
71 struct 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 
78 template <size_t Rank, typename T>
79 void 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 
88 template <size_t Rank, typename T>
89 void 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