[vtkusers] Legacy VTK Structured Grid Binary output

Giorgos Momferratos g.momferratos at echonet.gr
Sun Oct 31 07:21:53 EST 2004


Hallo vtkusers!
	I've been trying to get legacy vtk (.vtk) output from the following c 
routine:
#include <stdio.h>

void vtk_output_(int *pimax, int *pjmax, int *pkmax, double *x, double *area, 
double *theta, double *asp) {
    int imax,jmax,kmax;
    int ncoor, npts;
    int i, j;
    FILE *gf;
    /*x are the coordinates of the rectilinear grid*/
    /*area, theta, asp are point data*/	
    gf=fopen("b.vtk","w");
    imax=*pimax;
    jmax=*pjmax;
    kmax=*pkmax;
    ncoor=3*imax*jmax*kmax;
    npts=imax*jmax*kmax;
    
    /*vtk output*/
    fprintf(gf, "# vtk DataFile Version 2.0\n");
    fprintf(gf, "Elliptic grid\n");
    fprintf(gf, "BINARY\n");
    fprintf(gf, "\n");
    fprintf(gf, "DATASET STRUCTURED_GRID\n");
    fprintf(gf, "DIMENSIONS  %d  %d  %d\n", imax, jmax, kmax);
    fprintf(gf, "POINTS  %d  double\n", npts);
    fprintf(gf, "\n");
    fwrite(x,sizeof(double),(size_t)ncoor,gf);
    fprintf(gf, "\n");
    fprintf(gf, "FIELD metrics 3\n");
    fprintf(gf, "area  1 %d  double\n", (size_t)npts);
    fwrite(area,sizeof(double),(size_t)npts,gf);
    fprintf(gf, "\n");
    fprintf(gf, "theta 1 %d  double\n",npts);
    fwrite(theta,sizeof(double),(size_t)npts,gf);
    fprintf(gf, "\n");
    fprintf(gf, "aspectratio  1 %d  double\n",(size_t)npts);
    fwrite(asp,sizeof(double),(size_t)npts,gf);
    fprintf(gf, "\n");
    fclose(gf);
    return;
}

As you can see, the dataset is a structured grid with a 3-scalar field. 
My goal is to write it down so i can read it and visualise it in paraview.
I'd like to write binary data because of disk space and cpu time limitations.
Data comes from an f95 program.
If i write my dataset and points in ascii, everything works fine (the f95-c 
interface works fine), but when I am trying to write them in binary, paraview 
either reads completely wrong data, either chrashes immediatelly (depending 
on the presence of newlines before and after binary data). The .pdf 
describing the vtk fileformats offers no help on this issue. I would be very 
grateful if anyone could correct the above code, or even better, point me to 
information about writing such datasets through vtk library calls.

Thanx for your help.







More information about the vtkusers mailing list