23 bool binary,
int physical)
25 if(filetype != 0)
return;
35 const GEntity *entity,
int physical,
36 std::vector<std::vector<std::pair<MElement *, int> > > &elems)
41 elems[elemtype - 1].push_back(
48 double scalingFactor,
int filetype)
55 filetype = LOAD_GMSH2;
60 "Binary format not available for Matlab, saving into ASCII format");
64 FILE *fp =
Fopen(name.c_str(), binary ?
"wb" :
"w");
66 Msg::Error(
"Unable to open file '%s'", name.c_str());
77 fprintf(fp,
"\%\% Matlab mesh\n");
78 fprintf(fp,
"\%\% %s, Created by Gmsh\n",
getName().c_str());
80 fprintf(fp,
"\%\% BINARY\n");
82 fprintf(fp,
"\%\% ASCII\n");
85 std::vector<GEntity *> entities;
89 if(filetype == SIMPLE) {
90 fprintf(fp,
"gVertices = %d;\n", numVertices);
91 fprintf(fp,
"gXYZ = [\n");
92 for(std::size_t i = 0; i < entities.size(); i++)
93 for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++)
94 entities[i]->mesh_vertices[j]->
writeMATLAB(fp, filetype, binary,
98 fprintf(fp,
"\%\%\n");
99 fprintf(fp,
"gTri=[\n");
100 for(std::size_t i = 0; i < entities.size(); i++) {
103 else if(entities[i]->getPhysicalEntities().size()) {
104 for(std::size_t k = 0; k < entities[i]->getPhysicalEntities().size();
106 int physical = entities[i]->getPhysicalEntities()[k];
112 fprintf(fp,
"nTri=size(gTri,1);\n");
116 if(filetype == LOAD_GMSH2) {
117 fprintf(fp,
"clear msh;\n");
118 fprintf(fp,
"msh.nbNod = %d;\n", numVertices);
119 fprintf(fp,
"msh.POS = [\n");
120 for(std::size_t i = 0; i < entities.size(); i++)
121 for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++)
122 entities[i]->mesh_vertices[j]->
writeMATLAB(fp, filetype, binary,
125 fprintf(fp,
"msh.MAX = max(msh.POS);\n");
126 fprintf(fp,
"msh.MIN = min(msh.POS);\n");
129 std::vector<std::vector<std::pair<MElement *, int> > > elems(
MSH_MAX_NUM);
131 for(std::size_t i = 0; i < entities.size(); i++) {
135 for(std::size_t iphys = 0;
136 iphys < entities[i]->getPhysicalEntities().size(); iphys++) {
137 int physical = entities[i]->getPhysicalEntities()[iphys];
143 for(
int elemtype = 1; elemtype <
MSH_MAX_NUM + 1; elemtype++) {
144 if(elems[elemtype - 1].
empty())
continue;
147 for(std::size_t i = 0; i < elems[elemtype - 1].size(); i++) {
148 elems[elemtype - 1][i].first->writeMATLAB(
149 fp, filetype, elems[elemtype - 1][i].second, binary);