[Paraview] binary file error
Massimiliano Di Domenico
Massimiliano . Didomenico at dlr . de
Wed, 11 Jun 2003 10:50:13 +0200
--Boundary-00=_G1u5+auxEBsJIvu
Content-Type: text/plain;
charset="windows-1252"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hello everybody
I am starting to use Paraview why I would like to get a valid (and free :-)
substitute of programs like Tecplot.
I have two questions:
1- Is it possible to select different scalar variables from a VTK file? I have
searched in the documentation but I did not find anything...
2- I am approaching the common problem to write a "translator" from my file
format to VTK file format. If I write a ASCII file I have no problem to read
it with Paraview, but when try to write a binary file I can not read it (I
get a segmentation fault error). I am not a C expert but the code that I
wrote (see attached file test.c) produce a valid output (see out.vtk), at
least for points coordinates.
Can you help me?
Thank you
--Boundary-00=_G1u5+auxEBsJIvu
Content-Type: text/x-csrc;
charset="windows-1252";
name="test.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="test.c"
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <string.h>
#define VTKVERSION "3.0"
static FILE *vtkfile;
static int binary;
/*------------------------------------------------------------------------------
| Initialize VTK file
------------------------------------------------------------------------------*/
void vtkinit(char *vtkfilename, char *title, int bin_flg)
{
if( bin_flg )
{
vtkfile = fopen(vtkfilename, "wb");
binary = TRUE;
}
else
{
vtkfile = fopen(vtkfilename, "w");
binary = FALSE;
}
if(vtkfile == NULL)
fatal_error("Can not open file %s!!\n", vtkfilename);
fprintf(vtkfile, "# vtk DataFile Version %s\n", VTKVERSION);
fprintf(vtkfile, "%s\n", title);
if(bin_flg)
fprintf(vtkfile, "BINARY\n");
else
fprintf(vtkfile, "ASCII\n");
fprintf(vtkfile, "DATASET UNSTRUCTURED_GRID\n");
}
/*------------------------------------------------------------------------------
| Write coordinates of gridpoints
------------------------------------------------------------------------------*/
void writegridpoint(double (*x)[3], PointMapping *pm)
{
int pnt, i;
long int ngridpnts = pm->np_grid;
double dmydbl;
int dmyint;
fprintf(vtkfile, "POINTS %d double\n", ngridpnts);
if( binary )
for(pnt = 0; pnt < ngridpnts; pnt++)
for(i = 0; i < 3; i++)
fwrite(&x[pnt][i], sizeof( double ), 1, vtkfile);
}
else
{
for(pnt = 0; pnt < ngridpnts; pnt++)
{
for(i = 0; i < 3; i++)
fprintf(vtkfile, " %g ", x[pnt][i]);
fprintf(vtkfile, "\n");
}
}
}
/*------------------------------------------------------------------------------
| Close VTK file
------------------------------------------------------------------------------*/
void vtkend(char *vtkfilename)
{
fclose(vtkfile);
printf("File %s closed\n", vtkfilename);
printf("\n");
fflush(stdout);
}
/*------------------------------------------------------------------------------
| test output file
------------------------------------------------------------------------------*/
void testgridpoint(char *vtkfilename, PointMapping *pm, int bin_flg)
{
int pnt, i;
int ngridpnts = pm->np_grid;
char dummystr[1024];
double x;
if( bin_flg )
{
vtkfile = fopen(vtkfilename, "rb");
binary = TRUE;
}
else
{
vtkfile = fopen(vtkfilename, "r");
binary = FALSE;
}
for(i = 0; i < 4; i++)
{
fgets(dummystr, 1024, vtkfile);
printf("%s\n", dummystr);
}
fscanf(vtkfile, "%s %d %s\n", dummystr, &ngridpnts, dummystr);
printf("%s\n", dummystr);
printf("Number of points:\t%d\n", ngridpnts);
for(pnt = 0; pnt < ngridpnts; pnt++)
for(i = 1; i < 3; i++)
{
fread(&x, sizeof( double ), 1, vtkfile);
printf("val = %f\n", x);
}
fclose(vtkfile);
}
--Boundary-00=_G1u5+auxEBsJIvu
Content-Type: application/octet-stream;
name="out.vtk"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="out.vtk"
IyB2dGsgRGF0YUZpbGUgVmVyc2lvbiAzLjAKR3JpZDogZmxhbWVfdGVzdC5ncmQgCkJJTkFSWQpE
QVRBU0VUIFVOU1RSVUNUVVJFRF9HUklEClBPSU5UUyAxMCBkb3VibGUKAAAAAAAAAAC9CgDAd7yx
P9lQ/V/heqQ/AAAAAAAAAADZUP1f4Xq0PwAAAAAAAAAAAAAAAAAAAADXTPt/v2BMP3kk+d9NYkA/
AAAAAAAAAAC3/tzfTWJQPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABg
He3fZ9glPwAAAAAAAAAAAAAAAAAAAAAiQwngZ9g1PwAAAAAAAAAAAAAAAAAAAAB5JPnfTWJAPwAA
AAAAAAAAAAAAAAAAAABBMPvfZ9hFPwAAAAAAAAAAAAAAAAAAAAAMUP6/gU5LPwAAAAAAAAAACgo=
--Boundary-00=_G1u5+auxEBsJIvu--