70 tmv = * localtime( &today );
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" );
87 fprintf (stream->
file(),
"POINTS %ld float\n", n);
107 fprintf (stream->
file(),
"POINT_DATA %ld\n", n);
115 fprintf (stream->
file(),
"CELL_DATA %ld\n", n);
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"); }
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);
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");
155 void print_values (
char *auxs,
int n,
const double *values,
int precision)
162 sprintf (auxs+pos,
"%*.*e", n1, precision, values[0]); pos += n1;
164 for (
int i=1; i<n; i++) {
165 sprintf (auxs+pos,
" %*.*e", n1, precision, values[i]);
170 if (auxs[pos] !=
'\0')
179 for (
long i=0; i<len; i++)
180 sprintf (auxs+i*(n1+1),
"%*.*e ", n1, precision, values[i]);
182 auxs[len*(n1+1) - 1] =
'\0';
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 );
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]);
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 );
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]);
216 if (auxs[20000] !=
'\0')
217 _errorr(
"line length exceeds 20000, something is wrong");
219 if (lgc) fprintf (stream->
file(),
"%s\n", auxs);
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"); }
249 sprintf (auxs,
"Error in section %s", name);
270 double ABSZERO = 1.e-15;
271 double RELZERO = 2.e-2;
276 filename =
new char[255];
277 strcpy(filename, file1);
283 filename =
new char[255];
284 strcpy(filename, file2);
297 bool lgc = stream1->
isFile();
298 if (lgc != stream2->
isFile())
303 if (lgc) WORD1 =
new char[255];
304 if (lgc) WORD2 =
new char[255];
316 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
396 long nn, NN, NE, auxl1, auxl2, noel1, noel2;
400 const char *str1, *str2;
401 char LINE1[1023], LINE2[1023];
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) {
422 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
433 if (
_STRCMP(WORD1,
"Points") == 0) {
455 status += (noel1 == noel2) ? 0 : 1;
460 while (noel1) { noel1--;
461 if (lgc) { status += ( fscanf (stream1->
file(),
"%lf", &auxd1) != 1 ); }
463 if (lgc) { status += ( fscanf (stream2->
file(),
"%lf", &auxd2) != 1 ); }
465 status +=
areSame (ABSZERO, RELZERO, auxd1, auxd2) ? 0 : 1;
476 else if (
_STRCMP(WORD1,
"CELLS") == 0) {
495 status += (noel1 == noel2) ? 0 : 1;
496 status += (auxl1 == auxl2) ? 0 : 1;
501 while (noel1) { noel1--;
503 if (lgc) { fscanf (stream1->
file(),
"%ld",&auxl1); }
506 if (lgc) { fscanf (stream2->
file(),
"%ld",&auxl2); }
507 status += (auxl1 == auxl2) ? 0 : 1;
511 if (lgc) fscanf (stream1->
file(),
"%ld", &auxl1);
513 if (lgc) fscanf (stream2->
file(),
"%ld", &auxl2);
515 status += (auxl1 == auxl2) ? 0 : 1;
524 fgets (LINE1, lLINE, stream1->
file()); str1=LINE1;
530 fgets (LINE2, lLINE, stream2->
file()); str2=LINE2;
535 while (noel2) { noel2--;
536 if (lgc) fscanf (stream1->
file(),
"%ld",&auxl1);
538 if (lgc) fscanf (stream2->
file(),
"%ld",&auxl2);
540 status += (auxl1 == auxl2) ? 0 : 1;
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);
556 else if (
_STRCMP(WORD1,
"POINT_DATA") == 0 ||
_STRCMP(WORD1,
"PointData") == 0) {
568 else if (
_STRCMP(WORD1,
"CELL_DATA") == 0 ||
_STRCMP(WORD1,
"CellData") == 0) {
580 else if (
_STRCMP(WORD1,
"FIELD") == 0) {
583 if (!lgc)
_errorr(
"FIELD in nonlegacy");
588 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
593 status += (noel1 == noel2) ? 0 : 1;
595 for (
int i=0; i<noel1; i++) {
598 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
600 fscanf (stream1->
file(),
"%ld", &auxl1);
601 fscanf (stream2->
file(),
"%ld", &auxl2);
602 status += (auxl1 == auxl2) ? 0 : 1;
606 fscanf (stream1->
file(),
"%ld", &auxl1);
607 fscanf (stream2->
file(),
"%ld", &auxl2);
608 status += (auxl1 == auxl2) ? 0 : 1;
614 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
618 status += ( fscanf (stream1->
file(),
"%ld", &auxl1) != 1 );
619 status += ( fscanf (stream2->
file(),
"%ld", &auxl2) != 1 );
620 status += (auxl1 == auxl2) ? 0 : 1;
622 else if (
_STRCMP(WORD1,
"float") == 0 ||
_STRCMP(WORD1,
"Float32") == 0)
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;
633 else if (
_STRCMP(WORD1,
"SCALARS") == 0 ||
_STRCMP(WORD1,
"VECTORS") == 0 ||
_STRCMP(WORD1,
"TENSORS") == 0 ||
_STRCMP(WORD1,
"DataArray") == 0) {
636 char type = WORD1[0];
642 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
647 status += (strcmp(WORD1, WORD2) == 0) ? 0 : 1;
653 status += (auxl1 == auxl2) ? 0 : 1;
658 else if (type ==
'V') nn = 3;
659 else if (type ==
'T') nn = 9;
660 else if (type ==
'F') nn = 0;
670 if (ed ==
'p') nn = nn* NN;
671 else if (ed ==
'c') nn = nn* NE;
676 if (lgc) { status += ( fscanf (stream1->
file(),
"%ld", &auxl1) != 1 ); }
678 if (lgc) { status += ( fscanf (stream2->
file(),
"%ld", &auxl2) != 1 ); }
680 status += (auxl1 == auxl2) ? 0 : 1;
682 else if (
_STRCMP(WORD1,
"float") == 0 ||
_STRCMP(WORD1,
"Float32") == 0)
684 if (lgc) { status += ( fscanf (stream1->
file(),
"%lf", &auxd1) != 1 ); }
686 if (lgc) { status += ( fscanf (stream2->
file(),
"%lf", &auxd2) != 1 ); }
688 status +=
areSame (ABSZERO, RELZERO, auxd1, auxd2) ? 0 : 1;
696 else if (
_STRCMP(WORD1,
"") == 0) {;}
698 _errorr2 (
"Invalid structure of the given VTK file, unexpected key word \"%s\"", WORD1);
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);
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLText * NewText(const char *text)
Create a new Text associated with this Document.
bool FP_skip_line(FILE *stream, int n)
move file descriptor to the start of the n-th new line //[former read_line]
void print_values_Scalar(char *auxs, const double *values, long len, int precision)
len = pocet scalar cisel
#define SP_scan_expected_word_exit(_1, _2, _3, _4)
XMLDocument * tix_doc(void)
#define SP_scan_expected_number_exit(_1, _2, _3)
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 ...
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
The element is a container class.
void open(Stream_type t, const char *rw, const char *&fn, XMLNode *node=NULL)
*** SET ***
#define SP_scan_expected_word2_exit(_1, _2, _3, _4, _5)
#define NUM_DIGITS_IN_PRINTED_EXPONENT
The header file of usefull macros.
FILE * file(void)
*** GET ***
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
A Document binds together all the functionality.
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
XMLElement * NewElement(const char *name)
Create a new Element associated with this Document.
void print_VTK_FINISH(Stream *stream)
void print_VTK_head(FILE *stream, const char *type)
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
void print_auxs(bool lgc, Stream *stream, XMLElement *da, const char *auxs)
bool FP_scan_expected_word(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
void print_VTK_init_cell_data(Stream *stream, long n)
void print_VTK_init_point_data(Stream *stream, long n)
void print_VTK_START(Stream *stream, const char *filename)
Print head of vtk file.
bool areSame(double abszero, double relzero, double a, double b)
XMLElement * print_VTK_nodes_head(Stream *stream, long n)
const char * XP_giveDAtext(const XMLNode *xelem, int n, bool last, const char *format, const char *type, const char *name, int *noc)
void redefine(FILE *stream)
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
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 ].
XMLDeclaration * NewDeclaration(const char *text=0)
Create a new Declaration associated with this Document.
#define FP_scan_expected_word_exit(_1, _2, _3, _4)
void print_values_Vector(char *auxs, const double *values, bool twodim, int precision)
dim == dimenze vstupnich dat - 2d ano nebo ne
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
XMLNode * InsertEndChild(XMLNode *addThis)
Add a child node as the last (right) child.
void print_values(char *auxs, int n, const double *values, int precision)
XMLElement * print_VTK_data_head(Stream *stream, const char *name, char type, char format, int slen)