Debian Codegraph @

src/writers/aslMATFormat.cxx

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 #include "aslMATFormat.h"
25
26 #include <matio.h>
27
28 #include <utilities/aslMATLABCasters.h>
29 #include <data/aslDataWrapper.h>
30 #include <data/aslProbe.h>
31
32 #include "math/aslVectors.h"
33 #include "acl/acl.h"
34
35 using namespace std;
36
37 namespace asl {
38
39 void writeMAT(const string &fileName, const AbstractData & data, const string & name)
40 {
41 mat_t* matFile(Mat_Create(fileName.c_str(),"This file was created by ASL <http://asl.org.il>"));
42
43 unsigned int nComp(data.getDContainer().size());
44 std::vector<string> names(nComp,name);
45 for (unsigned int i(0); i < nComp; ++i)
46 names[i]+="-"+numToStr(i);
47
48 SPMatVar var(castMATLABCellArray(data,names));
49 Mat_VarWrite(matFile,var->var, 0);
50 Mat_Close(matFile);
51 }
52
53
54 void writeMAT(const string &fileName, vector<pair<SPAbstractData,string>> data)
55 {
56 mat_t* matFile(Mat_Create(fileName.c_str(),"This file was created by ASL <http://asl.org.il>"));
57
58 for(unsigned int k(0); k<data.size(); ++k)
59 {
60 unsigned int nComp(data[k].first->getDContainer().size());
61 std::vector<string> names(nComp,data[k].second);
62 for (unsigned int i(0); i < nComp; ++i)
63 names[i]+="-"+numToStr(i);
64
65 SPMatVar var(castMATLABCellArray(*data[k].first,names));
66 Mat_VarWrite(matFile,var->var, 0);
67 }
68 Mat_Close(matFile);
69 }
70
71 void writeMAT(const string &fileName, vector<pair<acl::Element,string>> data)
72 {
73 mat_t* matFile(Mat_Create(fileName.c_str(),"This file was created by ASL <http://asl.org.il>"));
74
75 for(unsigned int k(0); k<data.size(); ++k)
76 {
77 SPMatVar var(castMATLABCellArray(data[k].first,data[k].second));
78 Mat_VarWrite(matFile,var->var, 0);
79 }
80 Mat_Close(matFile);
81 }
82
83
84 void writeMAT(const string &fileName,Probe & probe, unsigned int component, const string & name)
85 {
86 mat_t* matFile(Mat_Create(fileName.c_str(),"This file was created by ASL <http://asl.org.il>"));
87
88 SPMatVar var(castMATLABCellArray(probe,component,name));
89 Mat_VarWrite(matFile,var->var, 0);
90 Mat_Close(matFile);
91 }
92
93 } //asl
94
95