[Paraview] how to output data from my C scripts to paraview format

Hom Nath Gharti hng.email at gmail.com
Mon Apr 28 09:44:37 EDT 2008


You have uniform grid size. So what about using the binary .vti file for
instance as follow:

I have number of grid points: nx,ny
Coordinates of origin: ox,oy
Grid spacing: dx, dy
Scalar variable: treal[nx*ny]

nvar=1; /* Plot only one variable set */
off[0]=0;
for (i=0; i<nvar; i++){
 bytes[i]=(nx*ny)*sizeof(float);
 if(i<nvar-1)off[i+1]=off[i]+sizeof(int)+bytes[i];
 bytes[i]=bytes[i]+sizeof(int);
}

outf_tfield=fopen("arrival_time_field.vti","w");
  fprintf(outf_tfield,"<?xml version=\"1.0\"?>\n");
  fprintf(outf_tfield,"<VTKFile type=\"ImageData\" version=\"0.1\"
byte_order=\"LittleEndian\">\n");
  fprintf(outf_tfield,"<ImageData WholeExtent=\"%d %d %d %d %d %d\"
Origin=\"%f %f %f\" Spacing=\"%f %f %f\">\n",0,nx-1,0,ny-1,0,0
   ,ox,oy,0.
   ,dx,dy,0.);
  fprintf(outf_tfield,"<Piece Extent=\"%d %d %d %d %d
%d\">\n",0,nx-1,0,ny-1,0,0);
  fprintf(outf_tfield,"<PointData Scalars=\"Arrival time (s)\">\n");
  fprintf(outf_tfield,"<DataArray type=\"Float32\" Name=\"Arrival time (s)\"
format=\"appended\" offset=\"%d\" />\n",off[0]);
  fprintf(outf_tfield,"</PointData>\n");
  fprintf(outf_tfield,"<CellData>\n");
  fprintf(outf_tfield,"</CellData>\n");
  fprintf(outf_tfield,"</Piece>\n");
  fprintf(outf_tfield,"</ImageData>\n");
  fprintf(outf_tfield,"<AppendedData encoding=\"raw\">\n");
  fprintf(outf_tfield,"_");
  /* Write arrival time field */
  fwrite(&bytes[0],sizeof(int),1,outf_tfield);
  for(i=0; i<nx*ny; i++){
    fwrite(&treal[i],sizeof(float),1,outf_tfield);
  }
  fprintf(outf_tfield,"\n");
  fprintf(outf_tfield,"</AppendedData>\n");
  fprintf(outf_tfield,"</VTKFile>\n");
  fclose(outf_tfield);

Good luck!
Hom Nath
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20080428/ebf449e7/attachment.htm>


More information about the ParaView mailing list