muMECH  1.0
vtk.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: vtk.cpp
10 // author(s): Ladislav Svoboda
11 // language: C, C++
12 // license: This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 //********************************************************************************************************
26 
27 #include "vtk.h"
28 
29 #include "macros.h"
30 #include "librw.h"
31 #include "mathlib.h"
32 
33 #include <time.h>
34 #include <math.h>
35 
36 
37 namespace mumech {
38 
39 
40 //* *** START ***
41 void print_VTK_START (Stream *stream, const char *filename)
42 {
43  if (stream->isFile()) {
44  stream->open(STRM_file, "w", filename);
45  }
46  else {
47  // xml document
49 
50  doc->InsertEndChild( doc->NewDeclaration() );
51 
52  XMLElement *VTKFile = doc->NewElement("VTKFile"); doc->InsertEndChild(VTKFile);
53  VTKFile->SetAttribute("type", "UnstructuredGrid");
54  VTKFile->SetAttribute("version", "0.1");
55  VTKFile->SetAttribute("byte_order", "LittleEndian");
56 
57  // initiate stream
58  stream->open(STRM_tixel, "w", filename, VTKFile -> InsertEndChild(doc->NewElement("UnstructuredGrid"))->ToElement()->InsertEndChild(doc->NewElement("Piece")) );
59  }
60 }
61 
62 //* *** HEAD ***
63 void print_VTK_head (FILE *stream, const char *type)
64 {
65  struct tm tmv;
66  time_t today;
67 
68  //time and dates
69  time( &today );
70  tmv = * localtime( &today );
71 
72  // printing of the header
73  fprintf( stream, "# vtk DataFile Version 3.0\n");
74  fprintf( stream, "%s ", type);
75  fprintf( stream, "VTK file created by muMECH on %d/%d/%d at %d:%d:%d\n",
76  tmv.tm_year + 1900, tmv.tm_mon +1, tmv.tm_mday, tmv.tm_hour, tmv.tm_min, tmv.tm_sec );
77  fprintf( stream, "ASCII\n" );
78  fprintf( stream, "DATASET UNSTRUCTURED_GRID\n" );
79 }
80 
81 //* *** NODES ***
83 {
84  XMLElement *da = NULL;
85 
86  if (stream->isFile())
87  fprintf (stream->file(), "POINTS %ld float\n", n);
88  else {
89  stream->tixel()->ToElement()->SetAttribute("NumberOfPoints", (int)n);
90  //
91  da = stream->tix_doc()->NewElement("DataArray");
92  da->SetAttribute("format", "ascii");
93  da->SetAttribute("type", "Float32");
94  da->SetAttribute("NumberOfComponents", "3");
95 
96  stream->tixel()->InsertEndChild(stream->tix_doc()->NewElement("Points") );
97  stream->tixel()->LastChild()->InsertEndChild(da);
98  }
99 
100  return da;
101 }
102 
103 
104 //* *** HEAD ***
105 void print_VTK_init_point_data (Stream *stream, long n) {
106  if (stream->isFile())
107  fprintf (stream->file(), "POINT_DATA %ld\n", n);
108  else {
109  stream->tixel()->InsertEndChild( stream->tix_doc()->NewElement("PointData") );
110  stream->relink_downL();
111  }
112 }
113 void print_VTK_init_cell_data (Stream *stream, long n) {
114  if (stream->isFile())
115  fprintf (stream->file(), "CELL_DATA %ld\n", n);
116  else {
117  stream->tixel()->InsertEndChild( stream->tix_doc()->NewElement("CellData") );
118  stream->relink_downL();
119  }
120 }
121 
122 
123 
124 // *** SCALAR / VECTOR / TENSOR body ***
125 XMLElement* print_VTK_data_head (Stream *stream, const char *name, char type, char format, int slen)
126 {
127  XMLElement *da = NULL;
128 
129  char flint[8];
130  if (format == 'i') { if (stream->isFile()) sprintf(flint,"int"); else sprintf(flint,"Int32"); }
131  else if (format == 'f') { if (stream->isFile()) sprintf(flint,"float"); else sprintf(flint,"Float32"); }
132  else errol;
133 
134  if (stream->isFile()) {
135  if (type == 's') { fprintf (stream->file(), "SCALARS %s %s %d\n", name, flint, slen); fprintf (stream->file(), "LOOKUP_TABLE default\n"); }
136  else if (type == 'v') fprintf (stream->file(), "VECTORS %s %s\n", name, flint);
137  else if (type == 't') fprintf (stream->file(), "TENSORS %s %s\n", name, flint);
138  else _errorr ("error");
139  }
140  else {
141  da = stream->tix_doc()->NewElement("DataArray"); stream->tixel()->InsertEndChild(da);
142  da->SetAttribute("format", "ascii");
143  da->SetAttribute("type", flint);
144  da->SetAttribute("Name", name);
145  if (type == 's') da->SetAttribute("NumberOfComponents", "1");
146  else if (type == 'v') da->SetAttribute("NumberOfComponents", "3");
147  else if (type == 't') da->SetAttribute("NumberOfComponents", "9");
148  else _errorr ("error");
149  }
150 
151  return da;
152 }
153 
155 void print_values (char *auxs, int n, const double *values, int precision)
156 {
157  if (n==0) _errorr("");
158 
159  int n1 = 5 + precision + NUM_DIGITS_IN_PRINTED_EXPONENT;
160  int pos = 0;
161 
162  sprintf (auxs+pos, "%*.*e", n1, precision, values[0]); pos += n1;
163 
164  for (int i=1; i<n; i++) {
165  sprintf (auxs+pos, " %*.*e", n1, precision, values[i]);
166  pos += n1+1;
167  }
168 
169  //sprintf (auxs+pos, "\n");
170  if (auxs[pos] != '\0')
171  errol;
172 }
173 
175 void print_values_Scalar (char *auxs, const double *values, long len, int precision)
176 {
177  int n1 = 5 + precision + NUM_DIGITS_IN_PRINTED_EXPONENT;
178 
179  for (long i=0; i<len; i++)
180  sprintf (auxs+i*(n1+1), "%*.*e ", n1, precision, values[i]);
181 
182  auxs[len*(n1+1) - 1] = '\0';
183 }
185 void print_values_Vector (char *auxs, const double *values, bool twodim, int precision)
186 {
187  int n1 = 5 + precision + NUM_DIGITS_IN_PRINTED_EXPONENT;
188 
189  if (twodim) {
190  sprintf (auxs+0*(n1+1), "%*.*e ", n1, precision, values[0]); sprintf (auxs+1*(n1+1), "%*.*e ", n1, precision, values[1]); sprintf (auxs+2*(n1+1), "%*.*e", n1, precision, 0.0 );
191  }
192  else {
193  sprintf (auxs+0*(n1+1), "%*.*e ", n1, precision, values[0]); sprintf (auxs+1*(n1+1), "%*.*e ", n1, precision, values[1]); sprintf (auxs+2*(n1+1), "%*.*e", n1, precision, values[2]);
194  }
195 }
197 void print_values_Tensor (char *auxs, const double *values, bool twodim, int precision)
198 {
199  int n1 = 5 + precision + NUM_DIGITS_IN_PRINTED_EXPONENT;
200 
201  if (twodim) {
202  sprintf (auxs+0*(n1+1), "%*.*e ", n1, precision, values[0]); sprintf (auxs+1*(n1+1), "%*.*e ", n1, precision, values[2]); sprintf (auxs+2*(n1+1), "%*.*e ", n1, precision, 0.0 );
203  sprintf (auxs+3*(n1+1), "%*.*e ", n1, precision, values[2]); sprintf (auxs+4*(n1+1), "%*.*e ", n1, precision, values[1]); sprintf (auxs+5*(n1+1), "%*.*e ", n1, precision, 0.0 );
204  sprintf (auxs+6*(n1+1), "%*.*e ", n1, precision, 0.0 ); sprintf (auxs+7*(n1+1), "%*.*e ", n1, precision, 0.0 ); sprintf (auxs+8*(n1+1), "%*.*e", n1, precision, 0.0 );
205  }
206  else {
207  sprintf (auxs+0*(n1+1), "%*.*e ", n1, precision, values[0]); sprintf (auxs+1*(n1+1), "%*.*e ", n1, precision, values[3]); sprintf (auxs+2*(n1+1), "%*.*e ", n1, precision, values[5]);
208  sprintf (auxs+3*(n1+1), "%*.*e ", n1, precision, values[3]); sprintf (auxs+4*(n1+1), "%*.*e ", n1, precision, values[1]); sprintf (auxs+5*(n1+1), "%*.*e ", n1, precision, values[4]);
209  sprintf (auxs+6*(n1+1), "%*.*e ", n1, precision, values[5]); sprintf (auxs+7*(n1+1), "%*.*e ", n1, precision, values[4]); sprintf (auxs+8*(n1+1), "%*.*e", n1, precision, values[2]);
210  }
211 }
212 
214 void print_auxs (bool lgc, Stream *stream, XMLElement *da, const char *auxs)
215 {
216  if (auxs[20000] != '\0')
217  _errorr("line length exceeds 20000, something is wrong");
218 
219  if (lgc) fprintf (stream->file(), "%s\n", auxs);
220  else da->InsertEndChild( stream->tix_doc()->NewText(auxs) );
221 }
222 
223 //* *** END ***
224 void print_VTK_FINISH (Stream *stream)
225 {
226  stream->close();
227 }
228 
229 
241 void scan_DATA_field_head (Stream *stream, Stream *strm, const char *str, char type, int nexc, char format, const char *name)
242 {
243  char flint[8];
244  if (format == 'i') { if (stream->isFile()) sprintf(flint,"int"); else sprintf(flint,"Int32"); }
245  else if (format == 'f') { if (stream->isFile()) sprintf(flint,"float"); else sprintf(flint,"Float32"); }
246  else errol;
247 
248  char auxs[255];
249  sprintf (auxs, "Error in section %s", name);
250 
251  if (stream->isFile()) {
252  SP_scan_expected_word_exit (str, flint, auxs, CASE);
253  if (type == 'S') {
254  SP_scan_expected_number_exit (str, nexc, auxs);
255  FP_scan_expected_word_exit (stream->file(), "LOOKUP_TABLE default", auxs, CASE);
256  FP_skip_line (stream->file());
257  }
258  strm->redefine( stream->file() );
259  }
260  else {
261  strm->redefine( XP_giveDAtext (stream->tixel(), 0, false, "ascii", flint, name, &nexc));
262  }
263 }
264 
265 
266 
268 bool cmp_vtk_file (const char *file1, const char *file2, int verbose)
269 {
270  double ABSZERO = 1.e-15;
271  double RELZERO = 2.e-2;
272 
273  char *filename;
274 
275  // open stream with automatic detection VTK legaci/XML file format
276  filename = new char[255];
277  strcpy(filename, file1);
278  Stream *stream1 = new Stream();
279  stream1->open(STRM_void, "r", (const char*&)filename); // do not delete filename, it is deleted inside of the function
280  filename = NULL;
281 
282  // open stream with automatic detection VTK legaci/XML file format
283  filename = new char[255];
284  strcpy(filename, file2);
285  Stream *stream2 = new Stream();
286  stream2->open(STRM_void, "r", (const char*&)filename); // do not delete filename, it is deleted inside of the function
287  filename = NULL;
288 
289 
290  bool status = false; //prnt = false;
291 
292  //
293  char *WORD1 = NULL;
294  char *WORD2 = NULL;
295  //const XMLElement *xnel = NULL;
296  //
297  bool lgc = stream1->isFile();
298  if (lgc != stream2->isFile())
299  status++;
300 
301  //bool amd = false;
302  //
303  if (lgc) WORD1 = new char[255];
304  if (lgc) WORD2 = new char[255];
305  //
306 
307  // HEAD OD FILE
308  if (lgc) {
309  // 1. line
310  FP_skip_line (stream1->file());
311  FP_skip_line (stream2->file());
312 
313  // 2. line
314  FP_scan_word (stream1->file(), WORD1); FP_skip_line (stream1->file());
315  FP_scan_word (stream2->file(), WORD2); FP_skip_line (stream2->file());
316  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
317 
318  // 3. line
319  FP_scan_expected_word_exit (stream1->file(), "ASCII", "Invalid structure of the given VTK file", true); FP_skip_line (stream1->file());
320  FP_scan_expected_word_exit (stream2->file(), "ASCII", "Invalid structure of the given VTK file", true); FP_skip_line (stream2->file());
321 
322  // 4. line
323  FP_scan_expected_word_exit (stream1->file(), "DATASET UNSTRUCTURED_GRID", "Invalid structure of the given VTK file", true); FP_skip_line (stream1->file());
324  FP_scan_expected_word_exit (stream2->file(), "DATASET UNSTRUCTURED_GRID", "Invalid structure of the given VTK file", true); FP_skip_line (stream2->file());
325  }
326  else {
327  _errorr("not implemented");
328  // // check head of xml file and read possible ctrl section
329  // // return XMLElement "Piece"
330  // const XMLNode *parent = stream->tixnod();
331  //
332  // //* declaration - delete if present
333  // if (parent->FirstChild()->ToDeclaration() != NULL) stream->tixnod()->DeleteChild( stream->tixnod()->FirstChild() );
334  //
335  // //* comment - delete if present
336  // while (true)
337  // if (parent->FirstChild()->ToComment() != NULL) stream->tixnod()->DeleteChild( stream->tixnod()->FirstChild() );
338  // else break;
339  //
340  // //
341  // parent = XP_give_unique_expected_elem (parent, "VTKFile");
342  // stream->relink_downF();
343  //
344  // ///
345  // XP_check_expected_attribute (parent, "type", "UnstructuredGrid");
346  // XP_check_expected_attribute (parent, "version", "0.1");
347  // XP_check_expected_attribute (parent, "byte_order", "LittleEndian");
348  //
349  // //
350  // parent = XP_give_unique_expected_elem (parent, "UnstructuredGrid", false);
351  // stream->relink_downF();
352  //
353  // // read AppendedData section
354  // parent = parent->NextSibling();
355  // if (! parent)
356  // _errorr("No AppendedData section");
357  //
358  // if (_STRCMP(parent->Value(), "AppendedData") != 0) _errorr ("name of xelement is not \"AppendedData\"");
359  //
360  // if (! (parent = parent->FirstChild ())) _errorr("No child in AppendedData");
361  // if ( parent->Value()[0] != '_' ) _errorr("There is no character \'_\' at the start of section AppendedData");
362  // parent = parent->NextSibling();
363  //
364  // if (_STRCMP(parent->Value(), "Input_Type") != 0) _errorr("name of xelement is not Input_Type");
365  // amd = this->file_type_s2e (parent->ToElement()->GetText());
366  //
367  // while (parent->NextSibling()) {
368  // parent = parent->NextSibling();
369  // const char *text = parent->Value();
370  // long auxl;
371  //
372  // if (_STRCMP(text, "SBA_mode") == 0) {
373  // sscanf (parent->ToElement()->GetText(), "%ld", &auxl);
374  // SBA_optimized = (bool)(auxl-1);
375  // }
376  // else if (_STRCMP(text, "Matrix_record") == 0) {
377  // double e, nu;
378  // sscanf (parent->ToElement()->GetText(), "%lf %lf", &e, &nu);
379  // this->set_matrixRecord (e, nu);
380  // }
381  // else if (_STRCMP(text, "Min_axes_diff") == 0) { double m; sscanf (parent->ToElement()->GetText(), "%lf", &m); this->set_semiaxes_min_difference(m); }
382  // else if (_STRCMP(text, "Max_axes_diff") == 0) { double m; sscanf (parent->ToElement()->GetText(), "%lf", &m); this->set_semiaxes_max_difference(m); }
383  // }
384  //
385  // // go to Piece
386  // XP_give_unique_expected_elem (stream->tixnod(), "Piece");
387  // stream->relink_downF();
388  // xnel = stream->tixel();
389  }
390 
391 
393  //Stream auxstrm;
395  //int auxi, lc, les, ges;
396  long nn, NN, NE, auxl1, auxl2, noel1, noel2; // , offset;
397  double auxd1, auxd2;
398  char ed='-';
399  //const char *typs, *data=NULL, *offs=NULL;
400  const char *str1, *str2;
401  char LINE1[1023], LINE2[1023];
402  int lLINE=1023;
403  VTKrange range = VTKR_void;
404  //
405 
406  //cno = 0;
407  //prnt = true;
408  while (true) {
409  //* key WORD
410  if (lgc) {
411  if (fgets (LINE1, lLINE, stream1->file()) == NULL) { delete [] WORD1; WORD1 = NULL; }
412  if (fgets (LINE2, lLINE, stream2->file()) == NULL) { delete [] WORD2; WORD2 = NULL; }
413  if (WORD1 == NULL || WORD2 == NULL) {
414  if (WORD1 != WORD2)
415  status++;
416 
417  break;
418  }
419 
420  str1 = LINE1; SP_scan_word (str1, WORD1);
421  str2 = LINE2; SP_scan_word (str2, WORD2);
422  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
423  }
424  else {
425  // if (prnt) { if (! stream->relink_downF()) errol; else prnt = false; }
426  // else { if (! stream->relink_next()) break; }
427  // WORD = (char *)stream->tixel()->Value();
428  }
429 
430  //* ******************
431  //* *** POINTS ***
432  //* ******************
433  if (_STRCMP(WORD1, "Points") == 0) {
434  if (range == VTKR_void) range = VTKR_points; else errol;
435 
436  // number of nodes
437  if (lgc) {
438  SP_scan_number (str1, noel1);
439  SP_scan_expected_word2_exit (str1, "double", "float", "Invalid structure of the given VTK file, unsupported datatype of POINTS", CASE);
440  }
441  else {
442  //xnel->ToElement()->QueryLongAttribute("NumberOfPoints", &noel);
443  //data = XP_giveDAtext (stream->tixel(), 1, true, "ascii", "Float32", NULL, &(auxi=3));
444  }
445 
446  // number of nodes
447  if (lgc) {
448  SP_scan_number (str2, noel2);
449  SP_scan_expected_word2_exit (str2, "double", "float", "Invalid structure of the given VTK file, unsupported datatype of POINTS", CASE);
450  }
451  else {
452  //xnel->ToElement()->QueryLongAttribute("NumberOfPoints", &noel);
453  //data = XP_giveDAtext (stream->tixel(), 1, true, "ascii", "Float32", NULL, &(auxi=3));
454  }
455  status += (noel1 == noel2) ? 0 : 1;
456  NN = noel1;
457 
458  // coords
459  noel1 *= 3;
460  while (noel1) { noel1--;
461  if (lgc) { status += ( fscanf (stream1->file(), "%lf", &auxd1) != 1 ); }
462  // else { status += ( sscanf (data, "%lf %lf %lf", inclRec[noIncl]->origin, inclRec[noIncl]->origin+1, inclRec[noIncl]->origin+2) == 3 ); if (inclRec[noIncl]->origin[2] != 0.0) _errorr("3. coordinates is not 0.0"); status += (SP_skip_word(data) && SP_skip_word(data) && SP_skip_word(data)); }
463  if (lgc) { status += ( fscanf (stream2->file(), "%lf", &auxd2) != 1 ); }
464  // else { status += ( sscanf (data, "%lf %lf %lf", inclRec[noIncl]->origin, inclRec[noIncl]->origin+1, inclRec[noIncl]->origin+2) == 3 ); if (inclRec[noIncl]->origin[2] != 0.0) _errorr("3. coordinates is not 0.0"); status += (SP_skip_word(data) && SP_skip_word(data) && SP_skip_word(data)); }
465  status += areSame (ABSZERO, RELZERO, auxd1, auxd2) ? 0 : 1;
466 
467 
468  }
469 
470  if (lgc) FP_skip_line (stream1->file());
471  if (lgc) FP_skip_line (stream2->file());
472  }
473  //* *************************************
474  //* *** UNSTRUCTURED GRID - CELLS ***
475  //* *************************************
476  else if (_STRCMP(WORD1, "CELLS") == 0) {
477  if (range == VTKR_points) range = VTKR_cells; else errol;
478 
479  // number of cells
480  if (lgc) {
481  SP_scan_number (str1, noel1);
482  SP_scan_number (str1, auxl1);
483  }
484  // else {
485  // xnel->ToElement()->QueryLongAttribute("NumberOfCells" , &noel);
486  // data = XP_giveDAtext (stream->tixel(), 1, false, "ascii", "Int32", "connectivity", NULL);
487  // offs = XP_giveDAtext (stream->tixel(), 2, false, "ascii", "Int32", "offsets", NULL);
488  // typs = XP_giveDAtext (stream->tixel(), 3, true, "ascii", "UInt8", "types", NULL);
489  // }
490  // number of cells
491  if (lgc) {
492  SP_scan_number (str2, noel2);
493  SP_scan_number (str2, auxl2);
494  }
495  status += (noel1 == noel2) ? 0 : 1;
496  status += (auxl1 == auxl2) ? 0 : 1;
497  NE = noel1;
498 
499  //if (!lgc) offset = 0;
500  // elem nodes
501  while (noel1) { noel1--;
502  // nn
503  if (lgc) { fscanf (stream1->file(),"%ld",&auxl1); }
504  //else { nn = offset; status += SP_scan_number (offs, offset); nn = offset - nn; }
505  //
506  if (lgc) { fscanf (stream2->file(),"%ld",&auxl2); }
507  status += (auxl1 == auxl2) ? 0 : 1;
508 
509  nn = auxl1;
510  while (nn) { nn--;
511  if (lgc) fscanf (stream1->file(),"%ld", &auxl1);
512  //else status += SP_scan_number (data, auxl);
513  if (lgc) fscanf (stream2->file(),"%ld", &auxl2);
514 
515  status += (auxl1 == auxl2) ? 0 : 1;
516  }
517  }
518 
519  if (lgc) FP_skip_line (stream1->file(), 1);
520  if (lgc) FP_skip_line (stream2->file(), 1);
521 
522  // types of elems
523  if (lgc) {
524  fgets (LINE1, lLINE, stream1->file()); str1=LINE1;
525  SP_scan_expected_word_exit (str1, "CELL_TYPES", "Invalid structure of the given VTK file", CASE);
526  SP_scan_expected_number_exit (str1, noel2, "Invalid structure of the given VTK file, the number following CELL_TYPES");
527  }
528  // types of elems
529  if (lgc) {
530  fgets (LINE2, lLINE, stream2->file()); str2=LINE2;
531  SP_scan_expected_word_exit (str2, "CELL_TYPES", "Invalid structure of the given VTK file", CASE);
532  SP_scan_expected_number_exit (str2, noel2, "Invalid structure of the given VTK file, the number following CELL_TYPES");
533  }
534 
535  while (noel2) { noel2--;
536  if (lgc) fscanf (stream1->file(),"%ld",&auxl1);
537  //else status += SP_scan_number (typs, auxl);
538  if (lgc) fscanf (stream2->file(),"%ld",&auxl2);
539  //else status += SP_scan_number (typs, auxl);
540  status += (auxl1 == auxl2) ? 0 : 1;
541  }
542 
543  if (lgc) FP_skip_line (stream1->file(), 1);
544  if (lgc) FP_skip_line (stream2->file(), 1);
545  }
546 
547  //* *******************************
548  //* *** POLYDATA - ELEMENTS ***
549  //* *******************************
550  else if (_STRCMP(WORD1, "LINES") == 0 || _STRCMP(WORD1, "POLYGONS" ) == 0 || _STRCMP(WORD1, "POLYS") == 0 || _STRCMP(WORD1, "Vertices") == 0 || _STRCMP(WORD1, "Verts") == 0 || _STRCMP(WORD1, "Strips") == 0) {
551  _errorr2("Invalid structure of the given VTK file, the key word %s is not supported", WORD1);
552  }
553  //* **********************
554  //* *** POINT_DATA ***
555  //* **********************
556  else if (_STRCMP(WORD1, "POINT_DATA") == 0 || _STRCMP(WORD1, "PointData") == 0) {
557  if (range == VTKR_cells || range == VTKR_fields) range = VTKR_pd; else errol;
558  ed = 'p';
559  // head
560  if (lgc) { SP_scan_expected_number_exit (str1, NN, "The number following POINT_DATA is not equal to number of inclusions"); }
561  //else { prnt = true; }
562  if (lgc) { SP_scan_expected_number_exit (str2, NN, "The number following POINT_DATA is not equal to number of inclusions"); }
563  //else { prnt = true; }
564  }
565  //* *********************
566  //* *** CELL_DATA ***
567  //* *********************
568  else if (_STRCMP(WORD1, "CELL_DATA") == 0 || _STRCMP(WORD1, "CellData") == 0) {
569  if (range == VTKR_cells || range == VTKR_data) range = VTKR_cd; else errol;
570  ed = 'c';
571  // head
572  if (lgc) { SP_scan_expected_number_exit (str1, NE, "The number following CELL_DATA is not equal to number of inclusions"); }
573  //else { prnt = true; }
574  if (lgc) { SP_scan_expected_number_exit (str2, NE, "The number following CELL_DATA is not equal to number of inclusions"); }
575  //else { prnt = true; }
576  }
577  //* ******************
578  //* *** FIELDS ***
579  //* ******************
580  else if (_STRCMP(WORD1, "FIELD") == 0) {
581  if (range == VTKR_cells || range == VTKR_data) range = VTKR_fields; else errol;
582 
583  if (!lgc) _errorr("FIELD in nonlegacy");
584 
585  // head
586  if (lgc) SP_scan_word (str1, WORD1);
587  if (lgc) SP_scan_word (str2, WORD2);
588  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
589 
590  // number of fields
591  SP_scan_number (str1, noel1);
592  SP_scan_number (str2, noel2);
593  status += (noel1 == noel2) ? 0 : 1;
594 
595  for (int i=0; i<noel1; i++) {
596  FP_scan_word (stream1->file(), WORD1);
597  FP_scan_word (stream2->file(), WORD2);
598  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
599 
600  fscanf (stream1->file(), "%ld", &auxl1);
601  fscanf (stream2->file(), "%ld", &auxl2);
602  status += (auxl1 == auxl2) ? 0 : 1;
603 
604  nn = auxl1;
605 
606  fscanf (stream1->file(), "%ld", &auxl1);
607  fscanf (stream2->file(), "%ld", &auxl2);
608  status += (auxl1 == auxl2) ? 0 : 1;
609 
610  nn *= auxl1;
611 
612  FP_scan_word (stream1->file(), WORD1);
613  FP_scan_word (stream2->file(), WORD2);
614  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
615 
616  if (_STRCMP(WORD1, "int") == 0 || _STRCMP(WORD1, "Int32") == 0)
617  while (nn) { nn--;
618  status += ( fscanf (stream1->file(), "%ld", &auxl1) != 1 );
619  status += ( fscanf (stream2->file(), "%ld", &auxl2) != 1 );
620  status += (auxl1 == auxl2) ? 0 : 1;
621  }
622  else if (_STRCMP(WORD1, "float") == 0 || _STRCMP(WORD1, "Float32") == 0)
623  while (nn) { nn--;
624  status += ( fscanf (stream1->file(), "%lf", &auxd1) != 1 );
625  status += ( fscanf (stream2->file(), "%lf", &auxd2) != 1 );
626  status += areSame (ABSZERO, RELZERO, auxd1, auxd2) ? 0 : 1;
627  }
628  }
629  }
630  //* **************************
631  //* *** DATA - SCALARS ***
632  //* **************************
633  else if (_STRCMP(WORD1, "SCALARS") == 0 || _STRCMP(WORD1, "VECTORS") == 0 || _STRCMP(WORD1, "TENSORS") == 0 || _STRCMP(WORD1, "DataArray") == 0) {
634  if (range == VTKR_pd || range == VTKR_cd || range == VTKR_data) range = VTKR_data; else errol;
635 
636  char type = WORD1[0]; // save type of data - Scalar, Vector, Tensor, DataArray
637  // head
638  if (lgc) SP_scan_word (str1, WORD1);
639  //else { WORD = (char *)stream->tixel()->ToElement()->Attribute("Name"); if (!WORD) _errorr ("there is no attribute \"Name\""); }
640  if (lgc) SP_scan_word (str2, WORD2);
641  //else { WORD = (char *)stream->tixel()->ToElement()->Attribute("Name"); if (!WORD) _errorr ("there is no attribute \"Name\""); }
642  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
643 
644  // type
645  if (lgc) SP_scan_word (str1, WORD1);
646  if (lgc) SP_scan_word (str2, WORD2);
647  status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
648 
649  if (lgc) {
650  if (type == 'S') {
651  SP_scan_number (str1, auxl1);
652  SP_scan_number (str2, auxl2);
653  status += (auxl1 == auxl2) ? 0 : 1;
654  nn = auxl1;
655  status += FP_scan_expected_word (stream1->file(), "LOOKUP_TABLE default", CASE) ? 0 : 1;
656  status += FP_scan_expected_word (stream2->file(), "LOOKUP_TABLE default", CASE) ? 0 : 1;
657  }
658  else if (type == 'V') nn = 3;
659  else if (type == 'T') nn = 9;
660  else if (type == 'F') nn = 0;
661  else errol;
662  }
663  //else status += SP_scan_number (data, auxl);
664  // strm->redefine( stream->file() );
665  // else {
666  // strm->redefine( XP_giveDAtext (stream->tixel(), 0, false, "ascii", flint, name, &nexc));
667  // }
668  //FP_skip_line (stream->file());
669 
670  if (ed == 'p') nn = nn* NN;
671  else if (ed == 'c') nn = nn* NE;
672  else errol;
673 
674  if (_STRCMP(WORD1, "int") == 0 || _STRCMP(WORD1, "Int32") == 0)
675  while (nn) { nn--;
676  if (lgc) { status += ( fscanf (stream1->file(), "%ld", &auxl1) != 1 ); }
677  // else { status += ( sscanf (data, "%lf %lf %lf", inclRec[noIncl]->origin, inclRec[noIncl]->origin+1, inclRec[noIncl]->origin+2) == 3 ); if (inclRec[noIncl]->origin[2] != 0.0) _errorr("3. coordinates is not 0.0"); status += (SP_skip_word(data) && SP_skip_word(data) && SP_skip_word(data)); }
678  if (lgc) { status += ( fscanf (stream2->file(), "%ld", &auxl2) != 1 ); }
679  // else { status += ( sscanf (data, "%lf %lf %lf", inclRec[noIncl]->origin, inclRec[noIncl]->origin+1, inclRec[noIncl]->origin+2) == 3 ); if (inclRec[noIncl]->origin[2] != 0.0) _errorr("3. coordinates is not 0.0"); status += (SP_skip_word(data) && SP_skip_word(data) && SP_skip_word(data)); }
680  status += (auxl1 == auxl2) ? 0 : 1;
681  }
682  else if (_STRCMP(WORD1, "float") == 0 || _STRCMP(WORD1, "Float32") == 0)
683  while (nn) { nn--;
684  if (lgc) { status += ( fscanf (stream1->file(), "%lf", &auxd1) != 1 ); }
685  // else { status += ( sscanf (data, "%lf %lf %lf", inclRec[noIncl]->origin, inclRec[noIncl]->origin+1, inclRec[noIncl]->origin+2) == 3 ); if (inclRec[noIncl]->origin[2] != 0.0) _errorr("3. coordinates is not 0.0"); status += (SP_skip_word(data) && SP_skip_word(data) && SP_skip_word(data)); }
686  if (lgc) { status += ( fscanf (stream2->file(), "%lf", &auxd2) != 1 ); }
687  // else { status += ( sscanf (data, "%lf %lf %lf", inclRec[noIncl]->origin, inclRec[noIncl]->origin+1, inclRec[noIncl]->origin+2) == 3 ); if (inclRec[noIncl]->origin[2] != 0.0) _errorr("3. coordinates is not 0.0"); status += (SP_skip_word(data) && SP_skip_word(data) && SP_skip_word(data)); }
688  status += areSame (ABSZERO, RELZERO, auxd1, auxd2) ? 0 : 1;
689  }
690 
691  //* *** DATA for CELLS ***
692  if (lgc) FP_skip_line (stream1->file(), 1);
693  //else { if (stream->tixel()->NextSibling() == NULL) stream->relink_up(); }
694  if (lgc) FP_skip_line (stream2->file(), 1);
695  }
696  else if (_STRCMP(WORD1, "") == 0) {;}
697  else
698  _errorr2 ("Invalid structure of the given VTK file, unexpected key word \"%s\"", WORD1);
699 
700  // if (lgc) { if (cno) _errorr2 ("cno(%ld) is not zero", cno); }
701  // else {
702  // if (data && data[0] != '\0') _errorr2("CellData of name \"%s\" has too many numbers", WORD);
703  // if (offs && offs[0] != '\0') _errorr("error");
704  // }
705  }
706 
707  //if (lgc) delete [] WORD;
708 
710  stream1->close();
711  stream2->close();
712  delete stream1;
713  delete stream2;
714  //
715 
716  if (verbose > 0 && status > 0) printf( " ERROR diffless %s %s \n", file1, file2);
717  if (verbose > 1 && status == 0) printf( " OK diffless %s %s \n", file1, file2);
718 
719  return (status > 0);
720 } // end of function Problem :: read_vtk_file (const char *vtkTopologyFile)
721 
722 
723 
724 } // end of namespace mumech
725 
726 /*end of file*/
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1130
XMLText * NewText(const char *text)
Create a new Text associated with this Document.
Definition: tinyxml2.cpp:1573
bool FP_skip_line(FILE *stream, int n)
move file descriptor to the start of the n-th new line //[former read_line]
Definition: librw.cpp:178
void print_values_Scalar(char *auxs, const double *values, long len, int precision)
len = pocet scalar cisel
Definition: vtk.cpp:175
#define SP_scan_expected_word_exit(_1, _2, _3, _4)
Definition: librw.h:223
Input / output function.
XMLDocument * tix_doc(void)
Definition: tixy2.h:144
#define SP_scan_expected_number_exit(_1, _2, _3)
Definition: librw.h:249
void print_values_Tensor(char *auxs, const double *values, bool twodim, int precision)
dim == dimenze vstupnich dat - 2d ano nebo ne; values musi byt v notaci STRN_THEORETICAL_FEEP ...
Definition: vtk.cpp:197
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:647
XMLElement * tixel(void)
Definition: tixy2.h:142
The element is a container class.
Definition: tinyxml2.h:1116
void open(Stream_type t, const char *rw, const char *&fn, XMLNode *node=NULL)
*** SET ***
Definition: tixy2.h:75
#define SP_scan_expected_word2_exit(_1, _2, _3, _4, _5)
Definition: librw.h:224
#define NUM_DIGITS_IN_PRINTED_EXPONENT
Definition: gelib.h:41
#define errol
Definition: gelib.h:151
bool relink_downL(void)
Definition: tixy2.h:156
The header file of usefull macros.
#define _errorr2(_1, _2)
Definition: gelib.h:154
FILE * file(void)
*** GET ***
Definition: tixy2.h:140
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1299
A Document binds together all the functionality.
Definition: tinyxml2.h:1445
VTKrange
Definition: tixy2.h:29
void scan_DATA_field_head(Stream *stream, Stream *strm, const char *str, char type, int nexc, char format, const char *name)
scan_DATA_field_head
Definition: vtk.cpp:241
XMLElement * NewElement(const char *name)
Create a new Element associated with this Document.
Definition: tinyxml2.cpp:1555
void print_VTK_FINISH(Stream *stream)
Definition: vtk.cpp:224
void print_VTK_head(FILE *stream, const char *type)
Definition: vtk.cpp:63
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
Definition: librw.cpp:714
void print_auxs(bool lgc, Stream *stream, XMLElement *da, const char *auxs)
Definition: vtk.cpp:214
#define _STRCMP
Definition: macros.h:57
bool FP_scan_expected_word(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:487
void print_VTK_init_cell_data(Stream *stream, long n)
Definition: vtk.cpp:113
I/O VTK functions.
void print_VTK_init_point_data(Stream *stream, long n)
Definition: vtk.cpp:105
#define _errorr(_1)
Definition: gelib.h:160
void print_VTK_START(Stream *stream, const char *filename)
Print head of vtk file.
Definition: vtk.cpp:41
bool areSame(double abszero, double relzero, double a, double b)
Definition: mathlib.cpp:319
void close(void)
Definition: tixy2.h:113
Mathematic functions.
#define CASE
Definition: macros.h:56
XMLElement * print_VTK_nodes_head(Stream *stream, long n)
Definition: vtk.cpp:82
const char * XP_giveDAtext(const XMLNode *xelem, int n, bool last, const char *format, const char *type, const char *name, int *noc)
Definition: tixy2.cpp:145
void redefine(FILE *stream)
Definition: tixy2.h:135
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:689
bool isFile(void)
Definition: tixy2.h:151
bool cmp_vtk_file(const char *file1, const char *file2, int verbose)
Compare two VTK files. Return false if same. [ return hodnota byly kdysi opacna ].
Definition: vtk.cpp:268
XMLDeclaration * NewDeclaration(const char *text=0)
Create a new Declaration associated with this Document.
Definition: tinyxml2.cpp:1582
#define FP_scan_expected_word_exit(_1, _2, _3, _4)
Definition: librw.h:137
void print_values_Vector(char *auxs, const double *values, bool twodim, int precision)
dim == dimenze vstupnich dat - 2d ano nebo ne
Definition: vtk.cpp:185
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:455
XMLNode * InsertEndChild(XMLNode *addThis)
Add a child node as the last (right) child.
Definition: tinyxml2.cpp:658
void print_values(char *auxs, int n, const double *values, int precision)
Definition: vtk.cpp:155
XMLElement * print_VTK_data_head(Stream *stream, const char *name, char type, char format, int slen)
Definition: vtk.cpp:125