forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelicaIO.h
176 lines (149 loc) · 6.64 KB
/
ModelicaIO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* ModelicaIO.h - Array I/O functions header
Copyright (C) 2016-2020, Modelica Association and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* The following #define's are available.
NO_FILE_SYSTEM : A file system is not present (e.g. on dSPACE or xPC).
NO_LOCALE : locale.h is not present (e.g. on AVR).
MODELICA_EXPORT: Prefix used for function calls. If not defined, blank is used
Useful definition:
- "__declspec(dllexport)" if included in a DLL and the
functions shall be visible outside of the DLL
Changelog:
Dec. 22, 2020: by Thomas Beutlich
Added reading of CSV files (ticket #1153)
Mar. 08, 2017: by Thomas Beutlich, ESI ITI GmbH
Added ModelicaIO_readRealTable from ModelicaStandardTables
(ticket #2192)
Mar. 03, 2016: by Thomas Beutlich, ITI GmbH and Martin Otter, DLR
Implemented a first version (ticket #1856)
*/
#ifndef MODELICA_IO_H_
#define MODELICA_IO_H_
#include <stdlib.h>
#if !defined(MODELICA_EXPORT)
#if defined(__cplusplus)
#define MODELICA_EXPORT extern "C"
#else
#define MODELICA_EXPORT
#endif
#endif
/*
* Non-null pointers and esp. null-terminated strings need to be passed to
* external functions.
*
* The following macros handle nonnull attributes for GNU C and Microsoft SAL.
*/
#undef MODELICA_NONNULLATTR
#if defined(__GNUC__)
#define MODELICA_NONNULLATTR __attribute__((nonnull))
#else
#define MODELICA_NONNULLATTR
#endif
#if !defined(__ATTR_SAL)
#undef _In_
#undef _In_z_
#undef _Inout_
#undef _Out_
#define _In_
#define _In_z_
#define _Inout_
#define _Out_
#endif
MODELICA_EXPORT void ModelicaIO_readMatrixSizes(_In_z_ const char* fileName,
_In_z_ const char* matrixName,
_Out_ int* dim) MODELICA_NONNULLATTR;
/* Read matrix dimensions from file
-> fileName: Name of file
-> matrixName: Name of matrix
-> dim: Output array for number of rows and columns
*/
MODELICA_EXPORT void ModelicaIO_readRealMatrix(_In_z_ const char* fileName,
_In_z_ const char* matrixName,
_Inout_ double* matrix, size_t m, size_t n,
int verbose) MODELICA_NONNULLATTR;
/* Read matrix from file
-> fileName: Name of file
-> matrixName: Name of matrix
-> matrix: Output array of dimensions m by n
-> m: Number of rows
-> n: Number of columns
-> verbose: Print message that file is loading
*/
MODELICA_EXPORT int ModelicaIO_writeRealMatrix(_In_z_ const char* fileName,
_In_z_ const char* matrixName,
_In_ const double* matrix, size_t m, size_t n,
int append,
_In_z_ const char* version) MODELICA_NONNULLATTR;
/* Write matrix to file
-> fileName: Name of file
-> matrixName: Name of matrix
-> matrix: Input array of dimensions m by n
-> m: Number of rows
-> n: Number of columns
-> append: File append flag
= 1: if matrix is to be appended to (existing) file,
= 0: if file is to be newly created
-> version: Desired file version
= "4": MATLAB MAT-file of version 4
= "6": MATLAB MAT-file of version 6
= "7": MATLAB MAT-file of version 7
= "7.3": MATLAB MAT-file of version 7.3
*/
MODELICA_EXPORT double* ModelicaIO_readRealTable(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_Out_ size_t* m, _Out_ size_t* n,
int verbose) MODELICA_NONNULLATTR;
/* Read matrix and its dimensions from file
Note: Only called from ModelicaStandardTables, but impossible to be called
from a Modelica environment
-> fileName: Name of file
-> matrixName: Name of matrix
-> m: Number of rows
-> n: Number of columns
-> verbose: Print message that file is loading
<- RETURN: Array of dimensions m by n
*/
MODELICA_EXPORT double* ModelicaIO_readRealTable2(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_Out_ size_t* m, _Out_ size_t* n,
int verbose, _In_z_ const char* delimiter,
int nHeaderLines) MODELICA_NONNULLATTR;
/* Read matrix and its dimensions from file
Note: Only called from ModelicaStandardTables, but impossible to be called
from a Modelica environment
-> fileName: Name of file
-> matrixName: Name of matrix
-> m: Number of rows
-> n: Number of columns
-> verbose: Print message that file is loading
-> delimiter: Column delimiter character (CSV file only)
-> nHeaderLines: Number of header lines to ignore (CSV file only)
<- RETURN: Array of dimensions m by n
*/
MODELICA_EXPORT void ModelicaIO_freeRealTable(double* table);
/* Free table
Note: Only called from ModelicaStandardTables to free the allocated memory by
ModelicaIO_readRealTable
*/
#endif