mesh_xml_file.cpp 54.7 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
#include "inmost.h"
2 3


4
#if defined(USE_MESH)
Kirill Terekhov's avatar
Kirill Terekhov committed
5 6 7

namespace INMOST
{
Kirill Terekhov's avatar
Kirill Terekhov committed
8 9 10 11 12 13 14 15 16

  std::string ToLower(std::string input)
  {
	  std::string ret(input);
	  for(size_t k = 0; k < ret.size(); ++k)
		  ret[k] = tolower(ret[k]);
	  return ret;
  }

Kirill Terekhov's avatar
Kirill Terekhov committed
17 18 19 20 21 22 23
  void Mesh::LoadXML(std::string File)
  {
    std::fstream infile(File.c_str(),std::ios::in);
    XMLReader reader(File,infile);
    std::vector<Tag> tags;
    std::vector<HandleType> new_nodes, new_edges, new_faces, new_cells, new_sets;
    std::vector<ElementSet::ComparatorType> set_comparators;
24 25 26 27 28 29
    XMLReader::XMLTag PassTag;
    bool pass_tag = false;
    int nmeshes = 1;

    XMLReader::XMLTag TagParallelMesh = reader.OpenTag();
    if( TagParallelMesh.name != "ParallelMesh" )
Kirill Terekhov's avatar
Kirill Terekhov committed
30
    {
31
      reader.Report("Incorrect XML tag %s expected ParallelMesh",TagParallelMesh.name.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
32 33
      throw BadFile;
    }
34 35

    for(int q = 0; q < TagParallelMesh.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
36
    {
37
      const XMLReader::XMLAttrib & attr = TagParallelMesh.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
38
      if( ToLower(attr.name) == "number" ) nmeshes = atoi(attr.value.c_str());
39
      else reader.Report("Unused attribute for ParallelMesh %s='%s'",attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
40
    }
41 42
    
    for(XMLReader::XMLTag TagMesh = reader.OpenTag(); !TagMesh.Finalize() && TagMesh.name == "Mesh"; reader.CloseTag(TagMesh), TagMesh = reader.OpenTag())
Kirill Terekhov's avatar
Kirill Terekhov committed
43 44
    {
      bool repair_orientation = false;
45
      for(int q = 0; q < TagMesh.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
46
      {
47
        const XMLReader::XMLAttrib & attr = TagMesh.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
48
        if( ToLower(attr.name) == "repairorientation" ) repair_orientation = reader.ParseBool(attr.value);
49
        else reader.Report("Unused attribute for Tags %s='%s'",attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
50
      }
51

Kirill Terekhov's avatar
Kirill Terekhov committed
52 53
      { //Nodes
        int nnodes = 0, ndims = 3;
54 55 56 57 58 59 60 61 62 63
        XMLReader::XMLTag TagNodes;
        if( pass_tag )
        {
          TagNodes = PassTag;
          pass_tag = false;
        }
        else
          TagNodes = reader.OpenTag();

        if( TagNodes.name != "Nodes" )
Kirill Terekhov's avatar
Kirill Terekhov committed
64
        {
65
          reader.Report("Incorrect XML tag %s expected Nodes",TagNodes.name.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
66 67
          throw BadFile;
        }
Kirill Terekhov's avatar
Kirill Terekhov committed
68
		  bool matchnnodes = false;
69 70

        for(int q = 0; q < TagNodes.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
71
        {
72
          const XMLReader::XMLAttrib & attr = TagNodes.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
73
          if( ToLower(attr.name) == "number" )
Kirill Terekhov's avatar
Kirill Terekhov committed
74 75 76 77
		  {
			  nnodes = atoi(attr.value.c_str());
			  matchnnodes = true;
		  }
Kirill Terekhov's avatar
Kirill Terekhov committed
78
          else if( ToLower(attr.name) == "dimensions" )
Kirill Terekhov's avatar
Kirill Terekhov committed
79
          {
80 81
            ndims = atoi(attr.value.c_str());
            if( GetDimensions() != ndims ) SetDimensions(ndims);
Kirill Terekhov's avatar
Kirill Terekhov committed
82
          }
83
          else reader.Report("Unused attribute for Tags %s='%s'",attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
84 85 86 87 88
        }

        new_nodes.reserve(nnodes);

        {
89 90 91 92 93
          if( reader.ReadOpenContents() )
          {
            std::vector<double> Vector;
            int Repeat;
            dynarray<Storage::real,3> xyz;
94
            for(std::string val = reader.GetContentsWord(); !reader.isContentsEnded(); val = reader.GetContentsWord() )
Kirill Terekhov's avatar
Kirill Terekhov committed
95
            {
96 97
              reader.ParseReal(val,Vector,Repeat,nnodes);
              for(int l = 0; l < Repeat; ++l)
Kirill Terekhov's avatar
Kirill Terekhov committed
98
              {
99
                for(int q = 0; q < (int)Vector.size(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
100
                {
101 102 103 104 105 106
                  xyz.push_back(Vector[q]);
                  if( xyz.size() == ndims )
                  {
                    new_nodes.push_back(CreateNode(xyz.data())->GetHandle());
                    xyz.clear();
                  }
Kirill Terekhov's avatar
Kirill Terekhov committed
107 108 109
                }
              }
            }
110
            reader.ReadCloseContents();
Kirill Terekhov's avatar
Kirill Terekhov committed
111
          }
112 113 114 115 116 117
          else 
          {
            reader.Report("Cannot find contents of XML tag");
            throw BadFile;
          }

118
          reader.CloseTag(TagNodes);
Kirill Terekhov's avatar
Kirill Terekhov committed
119 120
        }

Kirill Terekhov's avatar
Kirill Terekhov committed
121
        if( matchnnodes && new_nodes.size() != nnodes )
Kirill Terekhov's avatar
Kirill Terekhov committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135
        {
          reader.Report("Number of records for nodes %d do not match specified number of coordinates %d",new_nodes.size(),nnodes);
        }
      }

      { //Edges, Faces, Cells
        bool repeat = false;
          
        do
        {
          int nelems = 0, ntotconns = 0;
          bool matchelems = false;
          std::vector<HandleType> * elems;
          ElementType curtype;
136 137 138 139 140


          XMLReader::XMLTag TagElems;
          
          if( pass_tag )
Kirill Terekhov's avatar
Kirill Terekhov committed
141
          {
142 143 144 145 146 147 148 149 150
            TagElems = PassTag;
            pass_tag = false;
          }
          else
            TagElems = reader.OpenTag();

          if( !(TagElems.name == "Cells" || TagElems.name == "Faces" || TagElems.name == "Edges" ) )
          {
            reader.Report("Unexpected tag %s while waiting for either Cells or Faces or Edges",TagElems.name.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
151 152
            throw BadFile;
          }
153 154
          if( TagElems.name != "Cells" ) repeat = true; else repeat = false;
          if( TagElems.name == "Cells" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
155 156 157 158
          {
            elems = &new_cells;
            curtype = CELL;
          }
159
          else if( TagElems.name == "Faces" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
160 161 162 163
          {
            elems = &new_faces;
            curtype = FACE;
          }
164
          else if( TagElems.name == "Edges" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
165 166 167 168
          {
            elems = &new_edges;
            curtype = EDGE;
          }
Kirill Terekhov's avatar
Kirill Terekhov committed
169
          
170 171

          for(int q = 0; q < TagElems.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
172
          {
173
            const XMLReader::XMLAttrib & attr = TagElems.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
174
            if( ToLower(attr.name) == "number" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
175 176 177 178 179
            {
                nelems = atoi(attr.value.c_str());
                matchelems = true;
                //std::cout << "nelems: " << nelems << " text " << attr.value.c_str() << std::endl;
            }
180
            else reader.Report("Unused attribute for %ss %s='%s'",TagElems.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
181
          } 
182
          
Kirill Terekhov's avatar
Kirill Terekhov committed
183 184 185 186 187 188 189 190 191 192
          elems->reserve(nelems);

            
          HandleType * links[3] =
          {
            new_nodes.empty() ? NULL : &new_nodes[0],
            new_edges.empty() ? NULL : &new_edges[0],
            new_faces.empty() ? NULL : &new_faces[0]
          };

193 194 195
          
          XMLReader::XMLTag TagConns;
          for(TagConns = reader.OpenTag(); !TagConns.Finalize() && TagConns.name == "Connections"; reader.CloseTag(TagConns), TagConns = reader.OpenTag())
Kirill Terekhov's avatar
Kirill Terekhov committed
196
          {
Kirill Terekhov's avatar
Kirill Terekhov committed
197 198
			  bool matchnconns = false;
			  int nexpectconns = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
199 200
            int nconns = 0;
            int offset = 0;
201
			int dims = 3; //to distinguish 3d cells from 2d cells when they are created with nodes
Kirill Terekhov's avatar
Kirill Terekhov committed
202
            ElementType subtype = NODE;
203
            for(int q = 0; q < TagConns.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
204
            {
205
              const XMLReader::XMLAttrib & attr = TagConns.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
206
              if( ToLower(attr.name) == "number" )
Kirill Terekhov's avatar
Kirill Terekhov committed
207 208 209 210
			  {
				  nexpectconns = atoi(attr.value.c_str());
				  matchnconns = true;
			  }
Kirill Terekhov's avatar
Kirill Terekhov committed
211 212 213
			  else if( ToLower(attr.name) == "dimensions" ) dims = atoi(attr.value.c_str());
              else if( ToLower(attr.name) == "type" ) subtype = reader.atoes(attr.value.c_str());
              else if( ToLower(attr.name) == "offset" ) offset = atoi(attr.value.c_str());
214
              else reader.Report("Unused attribute for %ss %s='%s'",TagConns.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
215
            }
216
            
Kirill Terekhov's avatar
Kirill Terekhov committed
217
            //ntotconns += nconns;
Kirill Terekhov's avatar
Kirill Terekhov committed
218 219 220 221 222 223 224
            if( subtype >= curtype )
            {
              reader.Report("%ss cannot be constructed from %ss",ElementTypeName(curtype),ElementTypeName(subtype));
              throw BadFile;
            }
            reader.ReadOpenContents();
            ElementArray<Element> subarr(this);
225
            for(std::string val = reader.GetContentsWord(); !reader.isContentsEnded(); val = reader.GetContentsWord())
Kirill Terekhov's avatar
Kirill Terekhov committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
            {
              int num = atoi(val.c_str()), elem;
              subarr.clear();
              subarr.reserve(num);
              for(int q = 0; q < num && !reader.isContentsEnded(); ++q)
              {
                val = reader.GetContentsWord();
                elem = atoi(val.c_str());
                //subarr.push_back(ComposeHandle(subtype,elem-offset));
                subarr.push_back(links[ElementNum(subtype)][elem-offset]);
              }
              switch(curtype)
              {
              case EDGE:
                elems->push_back(CreateEdge(subarr.Convert<Node>()).first.GetHandle());
                break;
              case FACE:
                if( subtype == NODE )
244 245 246 247 248
				{
					Face f = CreateFace(subarr.Convert<Node>()).first;
					if( repair_orientation ) f.FixEdgeOrder();
					elems->push_back(f.GetHandle());
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
249
                else if( subtype == EDGE )
250
				{
251
					Face f = CreateFace(subarr.Convert<Edge>()).first;
252 253 254
					if( repair_orientation ) f.FixEdgeOrder();
					elems->push_back(f.GetHandle());
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
255 256 257 258
                break;
              case CELL:
                if( subtype == NODE )
                {
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
					if( dims == 3 )
					{
						switch(subarr.size())
						{
						case 4: //Tetrahedron
							{
								const integer nodesnum[12] = {0,2,1,0,1,3,1,2,3,0,3,2};
								const integer sizes[4] = {3,3,3,3};
								elems->push_back(CreateCell(subarr.Convert<Node>(),nodesnum,sizes,4).first.GetHandle());
							}
							break;
						case 5: //Pyramid
							{
								const integer nodesnum[16] = {0,4,3,0,1,4,1,2,4,3,4,2,0,3,2,1};
								const integer sizes[5] = {3,3,3,3,4};
								elems->push_back(CreateCell(subarr.Convert<Node>(),nodesnum,sizes,5).first.GetHandle());
							}
							break;
						case 6: //Wedge or Prism
							{
Kirill Terekhov's avatar
Kirill Terekhov committed
279 280
								//const integer nodesnum[18] = {0,2,5,3,1,4,5,2,0,3,4,1,3,5,4,0,1,2};
								const integer nodesnum[18] = { 0, 3, 5, 2, 0, 1, 4, 3, 1, 4, 5, 2, 3, 4, 5, 0, 2, 1 };
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
								const integer sizes[5] = {4,4,4,3,3};
								elems->push_back(CreateCell(subarr.Convert<Node>(),nodesnum,sizes,5).first.GetHandle());
							}
							break;
						case 8: //Hexahedron
							{
								const integer nodesnum[24] = {0,4,7,3,1,2,6,5,0,1,5,4,3,7,6,2,0,3,2,1,4,5,6,7};
								const integer sizes[6] = {4,4,4,4,4,4};
								elems->push_back(CreateCell(subarr.Convert<Node>(),nodesnum,sizes,6).first.GetHandle());
							}
							break;
						default: 
							reader.Report("Sorry, no rule to convert %d nodes into a cell",subarr.size());
							throw BadFile;
							break;
						}
					}
					else if( dims == 2 )
					{
						ElementArray<Node> e_nodes(this,1);
						ElementArray<Edge> f_edges(this,2);
						ElementArray<Face> c_faces;
						for(unsigned int k = 0; k < subarr.size(); k++)
						{
							e_nodes.at(0) = subarr.at(k);
							f_edges.at(0) = CreateEdge(e_nodes).first->GetHandle();
							e_nodes.at(0) = subarr.at((k+1)%subarr.size());
							f_edges.at(1) = CreateEdge(e_nodes).first->GetHandle();
							c_faces.push_back(CreateFace(f_edges).first);
						}
						Cell c = CreateCell(c_faces).first;
						if( repair_orientation ) c.FixEdgeOrder();
						elems->push_back(c.GetHandle());
					}
					else reader.Report("Sorry, cannot understand number of dimensions %d for a cell",dims);
Kirill Terekhov's avatar
Kirill Terekhov committed
316 317 318 319 320 321
                }
                else if( subtype == EDGE )
                {
                  reader.Report("Sorry, no rule to convert %d edges into a cell",subarr.size());
                  throw BadFile;
                }
322
				else if( subtype == FACE )
323 324
				{
					Cell c = CreateCell(subarr.Convert<Face>()).first;
Kirill Terekhov's avatar
Kirill Terekhov committed
325
					if( repair_orientation ) c.FixEdgeOrder();
326 327
					elems->push_back(c.GetHandle());
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
328 329
                break;
              }
Kirill Terekhov's avatar
Kirill Terekhov committed
330
				nconns++;
Kirill Terekhov's avatar
Kirill Terekhov committed
331 332
            }
            reader.ReadCloseContents();
Kirill Terekhov's avatar
Kirill Terekhov committed
333 334 335 336 337
			
			  ntotconns += nconns;
			  if( matchnconns && nconns != nexpectconns )
				  reader.Report("Number %d of elements encountered do not match to the specified number %d",nconns,nexpectconns);
          }
Kirill Terekhov's avatar
Kirill Terekhov committed
338 339 340

          if( matchelems && nelems != ntotconns) reader.Report("Number %d of elements encountered do not match to the specified number %d",ntotconns,nelems);

341 342 343 344 345 346 347 348
          reader.CloseTag(TagElems);

          if( !TagConns.Finalize() )
          {
            PassTag = TagConns;
            pass_tag = true;
          }

Kirill Terekhov's avatar
Kirill Terekhov committed
349 350 351 352 353 354 355
        } while(repeat);
      }

      { //Sets and Data
        bool repeat = false;
        do
        {
356 357 358 359 360 361 362 363
          XMLReader::XMLTag TagSetsData;
          if( pass_tag )
          {
            TagSetsData = PassTag;
            pass_tag = false;
          }
          else TagSetsData = reader.OpenTag();
          
364 365 366 367 368 369 370
		  if( TagSetsData.name == "Tags" )
		  {
			  repeat = true;
			  int ntags = 0;
			  bool matchntags = false;
			  for(int q = 0; q < TagSetsData.NumAttrib(); ++q)
			  {
371
				  const XMLReader::XMLAttrib & attr = TagSetsData.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
372
				  if( ToLower(attr.name) == "number" ) 
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
				  {
					  ntags = atoi(attr.value.c_str());
					  matchntags = true;
				  }
				  else reader.Report("Unused attribute for Tags %s='%s'",attr.name.c_str(),attr.value.c_str());
			  }

			  tags.reserve(ntags);


			  XMLReader::XMLTag TagTag;
			  for(TagTag = reader.OpenTag(); !TagTag.Finalize() && TagTag.name == "Tag"; reader.CloseTag(TagTag), TagTag = reader.OpenTag())
			  {
				  std::vector<std::string> parsed;
				  std::string tagname = "";
				  enumerator size = ENUMUNDEF;
				  DataType type = DATA_REAL;
				  ElementType sparse = NONE;
				  ElementType defined = NONE;
				  for(int q = 0; q < TagTag.NumAttrib(); ++q)
				  {
394
					  const XMLReader::XMLAttrib & attr = TagTag.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
395 396
					  if( ToLower(attr.name) == "name" ) tagname = attr.value;
					  else if( ToLower(attr.name) == "size" ) 
397
					  {
Kirill Terekhov's avatar
Kirill Terekhov committed
398
						  if( ToLower(attr.value) == "variable" )
399 400 401
							  size = ENUMUNDEF;
						  else size = atoi(attr.value.c_str());
					  }
Kirill Terekhov's avatar
Kirill Terekhov committed
402
					  else if( ToLower(attr.name) == "type" )
403
					  {
Kirill Terekhov's avatar
Kirill Terekhov committed
404 405 406 407 408
						  if( ToLower(attr.value) == "real" ) type = DATA_REAL;
						  else if( ToLower(attr.value) == "integer" ) type = DATA_INTEGER;
						  else if( ToLower(attr.value) == "reference" ) type = DATA_REFERENCE;
						  else if( ToLower(attr.value) == "remoteReference" ) type = DATA_REMOTE_REFERENCE;
						  else if( ToLower(attr.value) == "bulk" ) type = DATA_BULK;
409
#if defined(USE_AUTODIFF)
Kirill Terekhov's avatar
Kirill Terekhov committed
410
						  else if( ToLower(attr.value) == "variable" ) type = DATA_VARIABLE;
411 412
#endif
					  }
Kirill Terekhov's avatar
Kirill Terekhov committed
413
					  else if( ToLower(attr.name) == "sparse" )
414 415 416 417
					  { 
						  reader.ParseCommaSeparated(attr.value,parsed);
						  for(int q = 0; q < (int)parsed.size(); ++q) sparse |= reader.atoes(parsed[q].c_str());
					  }
Kirill Terekhov's avatar
Kirill Terekhov committed
418
					  else if( ToLower(attr.name) == "definition" )
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
					  {
						  reader.ParseCommaSeparated(attr.value,parsed);
						  for(int q = 0; q < (int)parsed.size(); ++q) defined |= reader.atoes(parsed[q].c_str());
					  }
					  else reader.Report("Unused attribute for Tags %s='%s'",attr.name.c_str(),attr.value.c_str());
				  }
				  if( tagname == "" )
					  reader.Report("Tag name was not specified");
				  else if( defined == NONE )
					  reader.Report("Domain of definition for the tag was not specified");
				  tags.push_back(CreateTag(tagname,type,defined,sparse,size));
			  }
			  reader.CloseTag(TagSetsData);

			  if( !TagTag.Finalize() )
			  {
				  PassTag = TagTag;
				  pass_tag = true;
			  }

			  if( matchntags && ntags != tags.size() ) reader.Report("Number %d of XML tags Tag red do not match to the specified number %d",tags.size(),ntags);
		  }
          else if( TagSetsData.name == "Sets" )
Kirill Terekhov's avatar
Kirill Terekhov committed
442 443 444 445 446 447 448 449 450 451 452 453
          {
            repeat = true;
            HandleType * links[4] =
            {
              new_nodes.empty() ? NULL : &new_nodes[0],
              new_edges.empty() ? NULL : &new_edges[0],
              new_faces.empty() ? NULL : &new_faces[0],
              new_cells.empty() ? NULL : &new_cells[0]
            };
            int nsets = 0, sets_offset = 0;
            int nsets_read = 0;
            bool matchsets = false;
454
            for(int q = 0; q < TagSetsData.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
455
            {
456
              const XMLReader::XMLAttrib & attr = TagSetsData.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
457
              if( ToLower(attr.name) == "number" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
458
              {
459
                nsets = atoi(attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
460 461
                matchsets = true;
              }
Kirill Terekhov's avatar
Kirill Terekhov committed
462
              else if( ToLower(attr.name) == "offset" ) sets_offset = atoi(attr.value.c_str());
463
              else reader.Report("Unused attribute for %ss %s='%s'",TagSetsData.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
464 465
            }
            new_sets.reserve(nsets);
466 467 468
            
            XMLReader::XMLTag Set;
            for(Set = reader.OpenTag(); !Set.Finalize() && Set.name == "Set"; reader.CloseTag(Set), Set = reader.OpenTag() )
Kirill Terekhov's avatar
Kirill Terekhov committed
469
            {
Kirill Terekhov's avatar
Kirill Terekhov committed
470 471
				int expectsize = 0;
				bool matchsize = false;
Kirill Terekhov's avatar
Kirill Terekhov committed
472 473 474 475 476
              int size = 0, offset = 0;
              std::string name;
              HandleType parent = InvalidHandle(), child = InvalidHandle(), sibling = InvalidHandle();
              ElementSet::ComparatorType comparator = ElementSet::UNSORTED_COMPARATOR;
              nsets_read++;
477
              for(int q = 0; q < Set.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
478
              {
479
                const XMLReader::XMLAttrib & attr = Set.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
480
                if( ToLower(attr.name) == "size" )
Kirill Terekhov's avatar
Kirill Terekhov committed
481 482 483 484
				{
					expectsize = atoi(attr.value.c_str());
					matchsize = true;
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
485 486 487
                else if( ToLower(attr.name) == "offset" ) offset = atoi(attr.value.c_str());
                else if( ToLower(attr.name) == "name" ) name = attr.value;
                else if( ToLower(attr.name) == "parent" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
488
                {
Kirill Terekhov's avatar
Kirill Terekhov committed
489
                  if( ToLower(attr.value) != "unset" )
490
                    parent = ComposeHandle(ESET,atoi(attr.value.c_str()));
Kirill Terekhov's avatar
Kirill Terekhov committed
491
                }
Kirill Terekhov's avatar
Kirill Terekhov committed
492
                else if( ToLower(attr.name) == "sibling" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
493
                {
Kirill Terekhov's avatar
Kirill Terekhov committed
494
                  if( ToLower(attr.value) != "unset" )
495
                    sibling = ComposeHandle(ESET,atoi(attr.value.c_str()));
Kirill Terekhov's avatar
Kirill Terekhov committed
496
                }
Kirill Terekhov's avatar
Kirill Terekhov committed
497
                else if( ToLower(attr.name) == "child" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
498
                {
Kirill Terekhov's avatar
Kirill Terekhov committed
499
                  if( ToLower(attr.value) != "unset" )
500
                    child = ComposeHandle(ESET,atoi(attr.value.c_str()));
Kirill Terekhov's avatar
Kirill Terekhov committed
501
                }
Kirill Terekhov's avatar
Kirill Terekhov committed
502
                else if( ToLower(attr.name) == "comparator" )
Kirill Terekhov's avatar
Kirill Terekhov committed
503
                {
Kirill Terekhov's avatar
Kirill Terekhov committed
504 505 506 507 508
                  if( ToLower(attr.value) == "unsorted" ) comparator = ElementSet::UNSORTED_COMPARATOR;
                  else if( ToLower(attr.value) == "identificator" ) comparator = ElementSet::GLOBALID_COMPARATOR;
                  else if( ToLower(attr.value) == "centroid" ) comparator = ElementSet::CENTROID_COMPARATOR;
                  else if( ToLower(attr.value) == "hierarchy" ) comparator = ElementSet::HIERARCHY_COMPARATOR;
                  else if( ToLower(attr.value) == "handle" ) comparator = ElementSet::HANDLE_COMPARATOR;
509
                  else reader.Report("Unexpected comparator type %s for attribute Comparator, expected Unsorted,Identificator,Centroid,Hierarchy,Handle",attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
510
                }
511
                else reader.Report("Unused attribute for %ss %s='%s'",Set.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
512 513 514 515 516 517 518 519 520 521 522 523 524
              } 
              ElementSet s = CreateSet(name).first;
              new_sets.push_back(s.GetHandle());
              set_comparators.push_back(comparator);
              Element::adj_type & hc = HighConn(s.GetHandle());
              Element::adj_type & lc = LowConn(s.GetHandle());
              //here we believe that all the connections are consistent
              //hc.resize(ElementSet::high_conn_reserved);
              if( parent != InvalidHandle() ) ElementSet::hParent(hc) = parent;
              if( child != InvalidHandle() ) ElementSet::hChild(hc) = child;
              if( sibling != InvalidHandle() ) ElementSet::hSibling(hc) = sibling;
              //s.SortSet(comparator);
              reader.ReadOpenContents();
525
              for(std::string val = reader.GetContentsWord(); !reader.isContentsEnded(); val = reader.GetContentsWord())
Kirill Terekhov's avatar
Kirill Terekhov committed
526 527 528
              {
                std::vector<std::pair<ElementType,int> > Vector;
                int Repeat;
Kirill Terekhov's avatar
Kirill Terekhov committed
529
                reader.ParseReference(val,Vector,Repeat,0);
Kirill Terekhov's avatar
Kirill Terekhov committed
530 531 532 533 534 535 536 537 538 539
                if( !Vector.empty() ) for(int l = 0; l < Repeat; ++l) 
                {
                  for(int q = 0; q < (int)Vector.size(); ++q)
                  {
                    if( ElementNum(Vector[q].first) < 4 )
                      lc.push_back(links[ElementNum(Vector[q].first)][Vector[q].second-offset]);
                    else if( ElementNum(Vector[q].first) == 4 ) //Set
                      lc.push_back(ComposeHandle(Vector[q].first,Vector[q].second-offset));
                    else //Mesh
                      lc.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
540
					size++;
Kirill Terekhov's avatar
Kirill Terekhov committed
541 542 543 544 545 546
                  }
                    //s.PutElement(links[ElementNum(Vector[q].first)][Vector[q].second-offset]);
                  //s.PutElements(Vector[0],(enumerator)Vector.size());
                }
              }
              reader.ReadCloseContents();
Kirill Terekhov's avatar
Kirill Terekhov committed
547 548
				
				if( matchsize && size != expectsize ) reader.Report("Number %d of elements encountered do not match to the specified set size %d",size, expectsize);
Kirill Terekhov's avatar
Kirill Terekhov committed
549
            }
550 551 552 553 554 555 556 557
            
            reader.CloseTag(TagSetsData);
            if( !Set.Finalize() )
            {
              PassTag = Set;
              pass_tag = true;
            }
            
Kirill Terekhov's avatar
Kirill Terekhov committed
558 559 560
            if( matchsets && nsets != nsets_read ) reader.Report("Number %d of XML tags Set read do not match to the number %d specified",nsets_read,nsets);

            //correct links between sets
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
561
            for(int q = 0; q < (int)new_sets.size(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
562 563 564 565 566 567 568 569 570 571 572 573 574 575
            {
              Element::adj_type & lc = HighConn(new_sets[q]);
              for(Element::adj_type::iterator jt = lc.begin(); jt != lc.end(); ++jt)
              {
                if( GetHandleElementType(*jt) == ESET )
                  *jt = new_sets[GetHandleID(*jt)];
              }
              Element::adj_type & hc = HighConn(new_sets[q]);
              if( ElementSet::hParent(hc) != InvalidHandle() ) ElementSet::hParent(hc) = new_sets[GetHandleID(ElementSet::hParent(hc))-sets_offset];
              if( ElementSet::hChild(hc) != InvalidHandle() ) ElementSet::hChild(hc) = new_sets[GetHandleID(ElementSet::hChild(hc))-sets_offset];
              if( ElementSet::hSibling(hc) != InvalidHandle() ) ElementSet::hSibling(hc) = new_sets[GetHandleID(ElementSet::hSibling(hc))-sets_offset];
              if( set_comparators[q] != ElementSet::UNSORTED_COMPARATOR ) ElementSet(this,new_sets[q]).SortSet(set_comparators[q]);
            }
          }
576
          else if( TagSetsData.name == "Data" )
Kirill Terekhov's avatar
Kirill Terekhov committed
577 578 579 580 581 582 583 584 585 586 587 588
          {
            repeat = false;
            HandleType * links[5] =
            {
              new_nodes.empty() ? NULL : &new_nodes[0],
              new_edges.empty() ? NULL : &new_edges[0],
              new_faces.empty() ? NULL : &new_faces[0],
              new_cells.empty() ? NULL : &new_cells[0],
              new_sets.empty() ? NULL : &new_sets[0]
            };
            int ndata = 0, ndatapass = 0;
            bool matchndata = false;
589 590

            for(int q = 0; q < TagSetsData.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
591
            {
592
              const XMLReader::XMLAttrib & attr = TagSetsData.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
593
              if( ToLower(attr.name) == "number" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
594
              {
595
                ndata = atoi(attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
596 597
                matchndata = true;
              }
598
              else reader.Report("Unused attribute for %ss %s='%s'",TagSetsData.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
599 600
            }

601 602
            XMLReader::XMLTag TagDataSet;
            for(TagDataSet = reader.OpenTag(); !TagDataSet.Finalize() && TagDataSet.name == "DataSet"; reader.CloseTag(TagDataSet), TagDataSet = reader.OpenTag())
Kirill Terekhov's avatar
Kirill Terekhov committed
603 604 605
            {
              ++ndatapass;
              int sparse_read = 2, offset = 0;
606 607
              std::string tagname = "", setname = "", meshname = "";
              Mesh * remote_mesh = NULL;
Kirill Terekhov's avatar
Kirill Terekhov committed
608
              ElementType etype = NONE;
609
              for(int q = 0; q < TagDataSet.NumAttrib(); ++q)
Kirill Terekhov's avatar
Kirill Terekhov committed
610
              {
611
                const XMLReader::XMLAttrib & attr = TagDataSet.GetAttrib(q);
Kirill Terekhov's avatar
Kirill Terekhov committed
612
                if( ToLower(attr.name) == "settype" ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
613
                {
Kirill Terekhov's avatar
Kirill Terekhov committed
614 615 616 617 618 619 620
                  if( ToLower(attr.value) == "cells" ) etype = CELL;
                  else if( ToLower(attr.value) == "faces" ) etype = FACE;
                  else if( ToLower(attr.value) == "edges" ) etype = EDGE;
                  else if( ToLower(attr.value) == "nodes" ) etype = NODE;
                  else if( ToLower(attr.value) == "sets" ) etype = ESET;
                  else if( ToLower(attr.value) == "mesh" ) etype = MESH;
                  else if( ToLower(attr.value) == "setdata" ) etype = NONE;
621
				  else reader.Report("Cannot understand attribute value for %s %s='%s'",TagDataSet.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
622
                }
Kirill Terekhov's avatar
Kirill Terekhov committed
623 624 625 626 627
                else if( ToLower(attr.name) == "tagname" ) tagname = attr.value;
                else if( ToLower(attr.name) == "setname" ) setname = attr.value;
                else if( ToLower(attr.name) == "meshname" ) meshname = attr.value;
                else if( ToLower(attr.name) == "sparse" ) sparse_read = reader.ParseBool(attr.value);
                else if( ToLower(attr.name) == "offset" ) offset = atoi(attr.value.c_str());
628
                else reader.Report("Unused attribute for %s %s='%s'",TagDataSet.name.c_str(),attr.name.c_str(),attr.value.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
629
              }
630
              
Kirill Terekhov's avatar
Kirill Terekhov committed
631 632 633 634 635 636 637 638 639 640
              if( tagname == "" )
              {
                reader.Report("DataSet had no attribute TagName");
                throw BadFile;
              }
              if( !HaveTag(tagname) )
              {
                reader.Report("Tag %s do not exist",tagname.c_str());
                throw BadFile;
              }
641 642 643 644 645 646
              if( meshname != "" )
              {
                remote_mesh = Mesh::GetMesh(meshname);
                if( !remote_mesh )
                  reader.Report("Remote mesh %s do not exist, you should create it first inside of your application",meshname.c_str());
              }
Kirill Terekhov's avatar
Kirill Terekhov committed
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693

              Tag t = GetTag(tagname);
              HandleType * set_elems = NULL, *it = NULL;
              enumerator set_size = 0;

              if( setname != "" )
              {
                if( etype != NONE ) reader.Report("Warning: SetType should be SetData for data specified for set.");
                ElementSet s = GetSet(setname);
                if( !s.isValid() )
                {
                  reader.Report("Set %s is not defined on the mesh",setname.c_str());
                  throw BadFile;
                }
                set_elems = s.getHandles();
                set_size = s.Size(); 
                if( sparse_read == 2 ) sparse_read = 0;
              }
              else
              {
                if( etype == NONE )
                {
                  for(ElementType test = NODE; test <= MESH; test = NextElementType(test) )
                    if( t.isDefined(test) ) etype |= test;
                  if( !OneType(etype) )
                  {
                    reader.Report("You must explicitly specify type of elements for which"
                                  "the data is written since tag %s is defined on multiple types of elements",tagname.c_str());
                    throw BadFile;
                  }
                }
                if( sparse_read == 2 )
                {
                  if( t.isSparse(etype) ) sparse_read = 1; //Expect data to be listed in sparse manner for sparse tag
                  else sparse_read = 0;
                }
                switch(etype)
                {
                case NODE: set_elems = &new_nodes[0]; set_size = (enumerator)new_nodes.size(); break;
                case EDGE: set_elems = &new_edges[0]; set_size = (enumerator)new_edges.size(); break;
                case FACE: set_elems = &new_faces[0]; set_size = (enumerator)new_faces.size(); break;
                case CELL: set_elems = &new_cells[0]; set_size = (enumerator)new_cells.size(); break;
                case ESET: set_elems = &new_sets[0]; set_size = (enumerator)new_sets.size(); break;
                case MESH: set_elems = &handle; set_size = 1; break;
                }
              }
              it = set_elems;
694 695
              reader.ReadOpenContents();
              for(std::string val = reader.GetContentsWord(); !reader.isContentsEnded(); val = reader.GetContentsWord())
Kirill Terekhov's avatar
Kirill Terekhov committed
696 697 698
              {
                if( sparse_read )
                {
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
				  int offset;
				  if( etype == ESET && ((val[0]=='\'' && val[val.size()-1] == '\'') || (val[0] == '"' && val[1] == '"')) )
				  {
					  //helps check that the set was not found
					  offset = -1;
					  //strip qoutes
					  val = val.substr(1,val.size()-2);
					  //find set with provided name
					  for(enumerator k = 0; k < set_size; ++k)
						  if( ElementSet(this,set_elems[k])->GetName() == val )
						  {
							  offset = k;
							  break;
						  }
					  if( offset == -1 )
					  {
						  reader.Report("Set with name %s was not found",val.c_str());
						  throw BadFile;
					  }
				  }
				  else offset = atoi(val.c_str());
                  it = set_elems + offset;
Kirill Terekhov's avatar
Kirill Terekhov committed
721 722 723 724 725 726 727 728 729
                  val = reader.GetContentsWord();
                }
                switch(t.GetDataType())
                {
                case DATA_REAL:
                  {
                    Storage::real_array data = RealArray(*it,t);
                    std::vector<Storage::real> Vector; int Repeat;
                    reader.ParseReal(val,Vector,Repeat,set_size);
Kirill Terekhov's avatar
Kirill Terekhov committed
730
					if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
Kirill Terekhov's avatar
Kirill Terekhov committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744
                    else if( t.GetSize() != Vector.size()*Repeat && sparse_read )
                    {
                      reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                      throw BadFile;
                    }
                      
                    for(int l = 0; l < Repeat; ++l)
                    {
                      for(int q = 0; q < (int)Vector.size(); ++q)
                      {
                        data[(q + l*((int)Vector.size()))%data.size()] = Vector[q];
                        if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                        {
                          ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
745
                          if( ((int)(it-set_elems)) < (int)set_size ) data = RealArray(*it,t);
Kirill Terekhov's avatar
Kirill Terekhov committed
746 747 748
                        }
                      }
                    }
Kirill Terekhov's avatar
Kirill Terekhov committed
749 750 751 752 753
					if( !sparse_read && t.GetSize() == ENUMUNDEF )
					{
						++it;
						if( ((int)(it-set_elems)) < (int)set_size ) data = RealArray(*it,t);
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
754 755 756 757 758 759 760 761
                  }
                  break;
                case DATA_INTEGER:
                  {
                    Storage::integer_array data = IntegerArray(*it,t);
                    std::vector<Storage::integer> Vector; int Repeat;
                    reader.ParseInteger(val,Vector,Repeat,set_size);
                    if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
762
                    else if( t.GetSize() != Vector.size()*Repeat && sparse_read)
Kirill Terekhov's avatar
Kirill Terekhov committed
763 764 765 766 767 768 769 770 771 772 773 774
                    {
                      reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                      throw BadFile;
                    }
                    for(int l = 0; l < Repeat; ++l)
                    {
                      for(int q = 0; q < (int)Vector.size(); ++q)
                      {
                        data[(q + l*((int)Vector.size()))%data.size()] = Vector[q];
                        if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                        {
                          ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
775
                          if( ((int)(it-set_elems)) < (int)set_size ) data = IntegerArray(*it,t);
Kirill Terekhov's avatar
Kirill Terekhov committed
776 777 778
                        }
                      }
                    }
Kirill Terekhov's avatar
Kirill Terekhov committed
779 780 781 782 783
					if( !sparse_read && t.GetSize() == ENUMUNDEF )
					{
						++it;
						if( ((int)(it-set_elems)) < (int)set_size ) data = IntegerArray(*it,t);
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
784 785 786 787 788 789 790 791
                  }
                  break;
                case DATA_BULK:
                  {
                    Storage::bulk_array data = BulkArray(*it,t);
                    std::string Vector; int Repeat;
                    reader.ParseBulk(val,Vector,Repeat,set_size);
                    if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
792
                    else if( t.GetSize() != Vector.size()*Repeat && sparse_read)
Kirill Terekhov's avatar
Kirill Terekhov committed
793 794 795 796 797 798 799 800 801 802 803 804
                    {
                      reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                      throw BadFile;
                    }
                    for(int l = 0; l < Repeat; ++l)
                    {
                      for(int q = 0; q < (int)Vector.size(); ++q)
                      {
                        data[(q + l*((int)Vector.size()))%data.size()] = Vector[q];
                        if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                        {
                          ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
805
                          if( ((int)(it-set_elems)) < (int)set_size ) data = BulkArray(*it,t);
Kirill Terekhov's avatar
Kirill Terekhov committed
806 807 808
                        }
                      }
                    }
Kirill Terekhov's avatar
Kirill Terekhov committed
809 810 811 812 813
					  if( !sparse_read && t.GetSize() == ENUMUNDEF )
					  {
						  ++it;
						  if( ((int)(it-set_elems)) < (int)set_size ) data = BulkArray(*it,t);
					  }
Kirill Terekhov's avatar
Kirill Terekhov committed
814 815 816 817 818 819 820 821
                  }
                  break;
                case DATA_REFERENCE:
                  {
                    Storage::reference_array data = ReferenceArray(*it,t);
                    std::vector<std::pair<ElementType,int> > Vector; int Repeat;
                    reader.ParseReference(val,Vector,Repeat,set_size);
                    if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
822
                    else if( t.GetSize() != Vector.size()*Repeat && sparse_read)
Kirill Terekhov's avatar
Kirill Terekhov committed
823 824 825 826 827 828 829 830 831 832 833 834
                    {
                      reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                      throw BadFile;
                    }
                    for(int l = 0; l < Repeat; ++l)
                    {
                      for(int q = 0; q < (int)Vector.size(); ++q)
                      {
                        data[(q + l*((int)Vector.size()))%data.size()] = Element(this,links[ElementNum(Vector[q].first)][Vector[q].second-offset]);
                        if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                        {
                          ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
835
                          if( ((int)(it-set_elems)) < (int)set_size ) data = ReferenceArray(*it,t);
Kirill Terekhov's avatar
Kirill Terekhov committed
836 837 838
                        }
                      }
                    }
Kirill Terekhov's avatar
Kirill Terekhov committed
839 840 841 842 843
					  if( !sparse_read && t.GetSize() == ENUMUNDEF )
					  {
						  ++it;
						  if( ((int)(it-set_elems)) < (int)set_size ) data = ReferenceArray(*it,t);
					  }
Kirill Terekhov's avatar
Kirill Terekhov committed
844 845
                  }
                  break;
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
                case DATA_REMOTE_REFERENCE:
                  {
                    Storage::remote_reference_array data = RemoteReferenceArray(*it,t);
                    if( remote_mesh != NULL )
                    {
                      std::vector<std::pair<ElementType,int> > Vector; int Repeat;
                      reader.ParseReference(val,Vector,Repeat,set_size);
                      if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
                      else if( t.GetSize() != Vector.size()*Repeat && sparse_read )
                      {
                        reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                        throw BadFile;
                      }
                      for(int l = 0; l < Repeat; ++l)
                      {
                        for(int q = 0; q < (int)Vector.size(); ++q)
                        {
                          data.at((q + l*((int)Vector.size()))%data.size()).first  = remote_mesh;
                          data.at((q + l*((int)Vector.size()))%data.size()).second = ComposeHandle(Vector[q].first,Vector[q].second-offset);
                          if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                          {
                            ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
868
                            if( ((int)(it-set_elems)) < (int)set_size ) data = RemoteReferenceArray(*it,t);
869 870 871
                          }
                        }
                      }
Kirill Terekhov's avatar
Kirill Terekhov committed
872 873 874 875 876
						if( !sparse_read && t.GetSize() == ENUMUNDEF )
						{
							++it;
							if( ((int)(it-set_elems)) < (int)set_size ) data = RemoteReferenceArray(*it,t);
						}
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
                    }
                    else
                    {
                      std::vector<std::pair<std::string,std::pair<ElementType,int> > > Vector; int Repeat;
                      reader.ParseRemoteReference(val,Vector,Repeat,set_size);
                      if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
                      else if( t.GetSize() != Vector.size()*Repeat && sparse_read )
                      {
                        reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                        throw BadFile;
                      }
                      for(int l = 0; l < Repeat; ++l)
                      {
                        for(int q = 0; q < (int)Vector.size(); ++q)
                        {
                          Mesh * m = GetMesh(Vector[q].first);
893
                          if( m == NULL ) reader.Report("Cannot find remote mesh %s, you should create it first inside of your application",Vector[q].first.c_str());
894 895 896 897 898
                          data.at((q + l*((int)Vector.size()))%data.size()).first = m;
                          data.at((q + l*((int)Vector.size()))%data.size()).second = ComposeHandle(Vector[q].second.first,Vector[q].second.second-offset);
                          if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                          {
                            ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
899
                            if( ((int)(it-set_elems)) < (int)set_size ) data = RemoteReferenceArray(*it,t);
900 901 902
                          }
                        }
                      }
Kirill Terekhov's avatar
Kirill Terekhov committed
903 904 905 906 907
						if( !sparse_read && t.GetSize() == ENUMUNDEF )
						{
							++it;
							if( ((int)(it-set_elems)) < (int)set_size ) data = RemoteReferenceArray(*it,t);
						}
908 909 910
                    }
                  }
                  break;
Kirill Terekhov's avatar
Kirill Terekhov committed
911 912 913 914 915 916 917
#if defined(USE_AUTODIFF)
                case DATA_VARIABLE:
                  {
                    Storage::var_array data = VariableArray(*it,t);
                    std::vector<Storage::var> Vector; int Repeat;
                    reader.ParseVariable(val,Vector,Repeat,set_size);
                    if( t.GetSize() == ENUMUNDEF ) data.resize((enumerator)Vector.size()*Repeat);
918
                    else if( t.GetSize() != Vector.size()*Repeat && sparse_read )
Kirill Terekhov's avatar
Kirill Terekhov committed
919 920 921 922 923 924 925 926 927 928 929 930
                    {
                      reader.Report("Cannot write record of size %d into tag data of size %d",Vector.size()*Repeat,t.GetSize());
                      throw BadFile;
                    }
                    for(int l = 0; l < Repeat; ++l)
                    {
                      for(int q = 0; q < (int)Vector.size(); ++q)
                      {
                        data[(q + l*((int)Vector.size()))%data.size()] = Vector[q];
                        if( !sparse_read && t.GetSize() != ENUMUNDEF && (q + l*((int)Vector.size())+1)%t.GetSize() == 0 )
                        {
                          ++it;
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
931
                          if( ((int)(it-set_elems)) < (int)set_size ) data = VariableArray(*it,t);
Kirill Terekhov's avatar
Kirill Terekhov committed
932 933 934
                        }
                      }
                    }
Kirill Terekhov's avatar
Kirill Terekhov committed
935 936 937 938 939
					  if( !sparse_read && t.GetSize() == ENUMUNDEF )
					  {
						  ++it;
						  if( ((int)(it-set_elems)) < (int)set_size ) data = VariableArray(*it,t);
					  }
Kirill Terekhov's avatar
Kirill Terekhov committed
940 941 942 943 944 945 946 947 948 949
                  }
                  break;
#endif
                }
              } 
              reader.ReadCloseContents();
            }

            if( matchndata && ndata != ndatapass ) reader.Report("warning: Number %d of DataSet tags encountered do not match to the specified %d",ndatapass,ndata);

950
            reader.CloseTag(TagSetsData);
Kirill Terekhov's avatar
Kirill Terekhov committed
951

952 953 954 955 956
            if( !TagDataSet.Finalize() )
            {
              PassTag = TagDataSet;
              pass_tag = true;
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
957
          }
958 959
		  else if( TagSetsData.name == "" )
			  repeat = false;
Kirill Terekhov's avatar
Kirill Terekhov committed
960 961
          else
          {
962
            reader.Report("Unexpected tag %s, expected Tags or Sets or Data",TagSetsData.name.c_str());
Kirill Terekhov's avatar
Kirill Terekhov committed
963 964 965 966
            throw BadFile;
          }
        } while(repeat);
      }
967 968
      RepairGeometricTags();

Kirill Terekhov's avatar
Kirill Terekhov committed
969 970 971 972 973 974 975 976
      if( repair_orientation )
      {
        int numfixed = 0;
        for(int q = 0; q < (int)new_faces.size(); ++q)
          if( Face(this,new_faces[q]).FixNormalOrientation() ) numfixed++;
        if( numfixed ) std::cout << "Fixed orientation of " << numfixed << " faces" << std::endl;
      }
    }
977
    reader.CloseTag(TagParallelMesh);
Kirill Terekhov's avatar
Kirill Terekhov committed
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
    infile.close();
  }

  void Mesh::SaveXML(std::string File)
  {
    std::fstream fout(File.c_str(),std::ios::out);
    fout << "<ParallelMesh>\n";
    fout << "\t<Mesh>\n";
    Tag idx = CreateTag("TEMPORARY_XML_ENUMERATOR",DATA_INTEGER,MESH|ESET|CELL|FACE|EDGE|NODE,NONE,1);
    Integer(GetHandle(),idx) = 0;
    fout << "\t\t<Nodes Number=\"" << NumberOfNodes() << "\" Dimensions=\"" << GetDimensions() << "\">\n";
    fout << "\t\t\t<![CDATA[\n";
    dynarray<Storage::real,3> xyz(GetDimensions());
    int cnt = 0;
    for(iteratorNode it = BeginNode(); it != EndNode(); ++it)
    {
      fout << "\t\t\t";
      it->Centroid(xyz.data());
      for(int q = 0; q < GetDimensions(); ++q)
        fout << xyz[q] << " ";
      fout << "\n";
      it->Integer(idx) = cnt++;
    }
    fout << "\t\t\t]]>\n";
    fout << "\t\t</Nodes>\n";
    fout << "\t\t<Edges>\n";
    fout << "\t\t\t<Connections Number=\"" << NumberOfEdges() << "\" Type=\"Nodes\">\n";
    fout << "\t\t\t<![CDATA[\n";
    cnt = 0;
    for(iteratorEdge it = BeginEdge(); it != EndEdge(); ++it)
    {
      ElementArray<Node> nodes = it->getNodes();
      fout << "\t\t\t" << nodes.size();
      for(ElementArray<Node>::iterator jt = nodes.begin(); jt != nodes.end(); ++jt)
        fout << " " << jt->Integer(idx);
      fout << "\n";
      it->Integer(idx) = cnt++;
    }
    fout << "\t\t\t]]>\n";
    fout << "\t\t\t</Connections>\n";
    fout << "\t\t</Edges>\n";
    fout << "\t\t<Faces>\n";
    fout << "\t\t\t<Connections Number=\"" << NumberOfFaces() << "\" Type=\"Edges\">\n";
    fout << "\t\t\t<![CDATA[\n";
    cnt = 0;
    for(iteratorFace it = BeginFace(); it != EndFace(); ++it)
    {
      ElementArray<Edge> edges = it->getEdges();
      fout << "\t\t\t" << edges.size();
      for(ElementArray<Edge>::iterator jt = edges.begin(); jt != edges.end(); ++jt)
        fout << " " << jt->Integer(idx);
      fout << "\n";
      it->Integer(idx) = cnt++;
    }
    fout << "\t\t\t]]>\n";
    fout << "\t\t\t</Connections>\n";
    fout << "\t\t</Faces>\n";
    fout << "\t\t<Cells>\n";
Kirill Terekhov's avatar
Kirill Terekhov committed
1036
    fout << "\t\t\t<Connections Number=\"" << NumberOfCells() << "\" Type=\"Faces\">\n";
Kirill Terekhov's avatar
Kirill Terekhov committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
    fout << "\t\t\t<![CDATA[\n";
    cnt = 0;
    for(iteratorCell it = BeginCell(); it != EndCell(); ++it)
    {
      ElementArray<Face> faces = it->getFaces();
      fout << "\t\t\t" << faces.size();
      for(ElementArray<Face>::iterator jt = faces.begin(); jt != faces.end(); ++jt)
        fout << " " << jt->Integer(idx);
      fout << "\n";
      it->Integer(idx) = cnt++;
    }
    fout << "\t\t\t]]>\n";
    fout << "\t\t\t</Connections>\n";
    fout << "\t\t</Cells>\n";
    fout << "\t\t<Sets>\n";
    cnt = 0;
    for(iteratorSet it = BeginSet(); it != EndSet(); ++it)
      it->Integer(idx) = cnt++;
    for(iteratorSet it = BeginSet(); it != EndSet(); ++it)
    {
      fout << "\t\t\t<Set Name=\"" << it->GetName() << "\"\n";
      if( it->HaveParent() )
      fout << "\t\t\t     Parent=\"" << it->GetParent()->Integer(idx) << "\"\n";
      if( it->HaveChild() )
      fout << "\t\t\t     Child=\"" << it->GetChild()->Integer(idx) << "\"\n";
      if( it->HaveSibling() )
      fout << "\t\t\t     Sibling=\"" << it->GetSibling()->Integer(idx) << "\"\n";
      if( it->GetComparator() != ElementSet::UNSORTED_COMPARATOR )
      {
        fout << "\t\t\t     Comparator=\"";
        switch(it->GetComparator())
        {
        case ElementSet::GLOBALID_COMPARATOR: fout << "Identificator"; break;
        case ElementSet::CENTROID_COMPARATOR: fout << "Centroid"; break;
        case ElementSet::HIERARCHY_COMPARATOR: fout << "Hierarchy"; break;
        case ElementSet::HANDLE_COMPARATOR: fout << "Handle"; break;
        }
        fout << "\"\n";
      }
      fout << "\t\t\t     Size=\"" << it->Size() << "\">\n";
      fout << "\t\t\t<![CDATA[\n";
      int endl_count = 0;
      fout << "\t\t\t";
      for(ElementSet::iterator jt = it->Begin(); jt != it->End(); ++jt)
      {
        switch(jt->GetElementType())
        {
        case NODE: fout << "Node:"; break;
        case EDGE: fout << "Edge:"; break;
        case FACE: fout << "Face:"; break;
        case CELL: fout << "Cell:"; break;
        case ESET: fout << "Set:"; break;
        case MESH: fout << "Mesh:"; break;
        }
        fout << jt->Integer(idx) << " ";
        endl_count++;
        if( endl_count % 8 == 0 )
          fout << "\n\t\t\t";
      }
      fout << "\n\t\t\t]]>\n";
      fout << "\t\t\t</Set>\n";
    }
    fout << "\t\t</Sets>\n";
Kirill Terekhov's avatar
Kirill Terekhov committed
1100 1101 1102
	fout << "\t\t<Tags>\n";
    for(int k = 0; k < (int)tags.size(); ++k)
    {
Kirill Terekhov's avatar
Kirill Terekhov committed
1103
	  if( tags[k] == idx ) continue;
Kirill Terekhov's avatar
Kirill Terekhov committed
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
      if( tags[k].GetTagName().substr(0,9) == "PROTECTED" ) continue;
      std::string names[6] = {"Nodes","Edges","Faces","Cells","Sets","Mesh"};
      std::string definition = "", sparse = "", type = "";
      switch(tags[k].GetDataType())
      {
      case DATA_REAL: type = "Real"; break;
      case DATA_INTEGER: type = "Integer"; break;
      case DATA_BULK: type = "Bulk"; break;
      case DATA_REFERENCE: type = "Reference"; break;
      case DATA_REMOTE_REFERENCE: type = "RemoteReference"; break;
#if defined(USE_AUTODIFF)
      case DATA_VARIABLE: type = "Variable"; break;
#endif
      }
      for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype) )
      {
        if( tags[k].isDefined(etype) ) definition += names[ElementNum(etype)] + ",";
        if( tags[k].isSparse(etype) ) sparse += names[ElementNum(etype)] + ",";
      }
      if( !definition.empty() ) definition.resize(definition.size()-1); //remove trailing comma
      if( !sparse.empty() ) sparse.resize(sparse.size()-1); //remove trailing comma
      if( sparse == "" ) sparse = "None";
      fout << "\t\t\t<Tag Name  =\"" << tags[k].GetTagName() << "\"\n";
      if( tags[k].GetSize() !=ENUMUNDEF )
      fout << "\t\t\t     Size  =\"" << tags[k].GetSize() << "\"\n";
      fout << "\t\t\t     Type  =\"" << type << "\"\n";
      fout << "\t\t\t     Sparse=\"" << sparse << "\"\n";
      fout << "\t\t\t     Definition=\"" << definition << "\"/>\n";
    }
	fout << "\t\t</Tags>\n";
Kirill Terekhov's avatar
Kirill Terekhov committed
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
    fout << "\t\t<Data>\n";
    for(iteratorTag t = BeginTag(); t != EndTag(); ++t)
    {
      if( *t == idx ) continue;
      if( t->GetTagName().substr(0,9) == "PROTECTED" ) continue;
      for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype)) if( t->isDefined(etype) )
      {
        fout << "\t\t\t<DataSet TagName=\"" << t->GetTagName() << "\"\n";
        fout << "\t\t\t         SetType=\"";
        switch(etype)
        {
        case NODE: fout << "Nodes"; break;
        case EDGE: fout << "Edges"; break;
        case FACE: fout << "Faces"; break;
        case CELL: fout << "Cells"; break;
        case ESET: fout << "Sets"; break;
        case MESH: fout << "Mesh"; break;
        }
        fout << "\">\n";
        fout << "\t\t\t<![CDATA[\n\t\t\t";
        int endl_count = 0;
        switch(t->GetDataType())
        {
        case DATA_REAL:
          for(iteratorStorage jt = Begin(etype); jt != End(); ++jt) if( jt->HaveData(*t) )
          {
            Storage::real_array data = jt->RealArray(*t);
            if( !data.empty() )
            {
              if( t->isSparse(etype) ) 
              {
                fout << jt->Integer(idx) << " ";
                endl_count++;
              }
              if( data.size() == 1 ) 
              {
                fout << data[0];
              }
              else
              {
                fout << "{";
                for(int q = 0; q < (int)data.size()-1; ++q)
                  fout << data[q] << ",";
                fout << data.back();
                fout << "}";
              }
              endl_count+=data.size();
              if( endl_count > 8 )
              {
                fout << "\n\t\t\t";
                endl_count = 0;
              }
              else fout << " ";
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
1188 1189
			else if( !t->isSparse(etype) ) fout << " { } ";

Kirill Terekhov's avatar
Kirill Terekhov committed
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
          }
          break;
        case DATA_INTEGER:
          for(iteratorStorage jt = Begin(etype); jt != End(); ++jt) if( jt->HaveData(*t) )
          {
            Storage::integer_array data = jt->IntegerArray(*t);
            if( !data.empty() )
            {
              if( t->isSparse(etype) ) 
              {
                fout << jt->Integer(idx) << " ";
                endl_count++;
              }
              if( data.size() == 1 ) fout << data[0];
              else
              {
                fout << "{";
                for(int q = 0; q < (int)data.size()-1; ++q)
                  fout << data[q] << ",";
                fout << data.back();
                fout << "}";
              }
              endl_count+=data.size();
              if( endl_count > 8 )
              {
                fout << "\n\t\t\t";
                endl_count = 0;
              }
              else fout << " ";
              //fout << std::endl;
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
1221
			else if( !t->isSparse(etype) ) fout << " { } ";
Kirill Terekhov's avatar
Kirill Terekhov committed
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
          }
          break;
        case DATA_BULK:
          for(iteratorStorage jt = Begin(etype); jt != End(); ++jt) if( jt->HaveData(*t) )
          {
            Storage::bulk_array data = jt->BulkArray(*t);
            if( !data.empty() )
            {
              if( t->isSparse(etype) ) 
              {
                fout << jt->Integer(idx) << " ";
                endl_count++;
              }
              if( data.size() == 1 ) fout << CharToHex(data[0]);
              else
              {
                fout << "{";
                for(int q = 0; q < (int)data.size()-1; ++q)
                  fout << CharToHex(data[q]) << ",";
                fout << CharToHex(data.back());
                fout << "}";
              }
              endl_count+=data.size();
              if( endl_count > 8 )
              {
                fout << "\n\t\t\t";
                endl_count = 0;
              }
              else fout << " ";
              //fout << std::endl;
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
1253
			else if( !t->isSparse(etype) ) fout << " { } ";
Kirill Terekhov's avatar
Kirill Terekhov committed
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
          }
          break;
        case DATA_REFERENCE:
          for(iteratorStorage jt = Begin(etype); jt != End(); ++jt) if( jt->HaveData(*t) )
          {
            Storage::reference_array data = jt->ReferenceArray(*t);
            if( !data.empty() )
            {
              if( t->isSparse(etype) ) 
              {
                fout << jt->Integer(idx) << " ";
                endl_count++;
              }
              if( data.size() == 1 ) 
              {
                if( data[0].isValid() )
                  fout << ReferenceToString(data.at(0),data[0].Integer(idx));
                else
                  fout << "None:0";
              }
              else
              {
                fout << "{";
                for(int q = 0; q < (int)data.size()-1; ++q)
                {
                  if( data[q].isValid() )
                    fout << ReferenceToString(data.at(q),data[q].Integer(idx)) << ",";
                  else
                    fout << "None:0,";
                }
                if( data[data.size()-1].isValid() )
                  fout << ReferenceToString(data.at(data.size()-1),data[data.size()-1].Integer(idx));
                else
                  fout << "None:0";
                fout << "}";
              }
              endl_count+=data.size();
              if( endl_count > 8 )
              {
                fout << "\n\t\t\t";
                endl_count = 0;
              }
              else fout << " ";
              //fout << std::endl;
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
1299
			else if( !t->isSparse(etype) ) fout << " { } ";
Kirill Terekhov's avatar
Kirill Terekhov committed
1300 1301
          }
          break;
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
        case DATA_REMOTE_REFERENCE:
          for(iteratorStorage jt = Begin(etype); jt != End(); ++jt) if( jt->HaveData(*t) )
          {
            Storage::remote_reference_array data = jt->RemoteReferenceArray(*t);
            if( !data.empty() )
            {
              if( t->isSparse(etype) ) 
              {
                fout << jt->Integer(idx) << " ";
                endl_count++;
              }
              if( data.size() == 1 ) 
              {
                if( data[0].isValid() )
                  fout << data.at(0).first->GetMeshName() << ":" << ReferenceToString(data.at(0).second,data[0].Integer(idx));
                else
                  fout << ":None:0";
              }
              else
              {
                fout << "{";
                for(int q = 0; q < (int)data.size()-1; ++q)
                {
                  if( data[q].isValid() )
                    fout << data.at(q).first->GetMeshName() << ":" << ReferenceToString(data.at(q).second,data[q].Integer(idx)) << ",";
                  else
                    fout << ":None:0,";
                }
                if( data[data.size()-1].isValid() )
                  fout << data.at(data.size()-1).first->GetMeshName() << ":" << ReferenceToString(data.at(data.size()-1).second,data[data.size()-1].Integer(idx));
                else
                  fout << ":None:0";
                fout << "}";
              }
              endl_count+=data.size();
              if( endl_count > 8 )
              {
                fout << "\n\t\t\t";
                endl_count = 0;
              }
              else fout << " ";
              //fout << std::endl;
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
1345
			else if( !t->isSparse(etype) ) fout << " { } ";
1346 1347
          }
          break;
Kirill Terekhov's avatar
Kirill Terekhov committed
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377
#if defined(USE_AUTODIFF)
        case DATA_VARIABLE:
          for(iteratorStorage jt = Begin(etype); jt != End(); ++jt) if( jt->HaveData(*t) )
          {
            Storage::var_array data = jt->VariableArray(*t);
            if( !data.empty() )
            {
              if( t->isSparse(etype) ) 
              {
                fout << jt->Integer(idx) << " ";
                endl_count++;
              }
              if( data.size() == 1 ) fout << VariableToString(data.at(0));
              else
              {
                fout << "{";
                for(int q = 0; q < (int)data.size()-1; ++q)
                  fout << VariableToString(data.at(q)) << ",";
                fout << VariableToString(data.back());
                fout << "}";
              }
              endl_count+=data.size();
              if( endl_count > 8 )
              {
                fout << "\n\t\t\t";
                endl_count = 0;
              }
              else fout << " ";
              //fout << std::endl;
            }
Kirill Terekhov's avatar
Kirill Terekhov committed
1378
			else if( !t->isSparse(etype) ) fout << " { } ";
Kirill Terekhov's avatar
Kirill Terekhov committed
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
          }
          break;
#endif
        }
        fout << "\n\t\t\t]]>\n";
        fout << "\t\t\t</DataSet>\n";
      }
    }
    DeleteTag(idx);
    fout << "\t\t</Data>\n";
    fout << "\t</Mesh>\n";
    fout << "</ParallelMesh>\n";
    fout.close();
  }
}

1395
#endif