Hi David, All

Thanks for the suggestion. However, I cannot incorporate any dependencies into 
my code. Since posting my message, I have discovered that I can put a text 
header (similar to VTK ASCII) and then the data in binary into the output 
files. The problem (if there a problem!) has now evolved to getting the binary 
fwrite to be big endian - or is there another way? For completeness, the 
revised bit of code is here:

        // write to file
        if (fcnt == 40) { 
                str = malloc (64*sizeof(char));
                sprintf (str, "fhn_2d_%d.vtk", cnt++);
// the ASCII works.
                out1 = fopen (str, "wt");
                free(str);
                fprintf(out1, "# vtk DataFile Version 2.0\n");
                fprintf(out1, "vtk output\n");
                fprintf(out1, "ASCII\n");
                fprintf(out1, "DATASET STRUCTURED_POINTS\n");
                fprintf(out1, "DIMENSIONS %d %d 1\n",N+1,M+1); // N+1 columns, 
M+1+header rows
                fprintf(out1, "SPACING 1 1 1\n");
                fprintf(out1, "ORIGIN 0 0 0\n");
                fprintf(out1, "POINT_DATA %d\n",(N+1)*(M+1)); // total number 
of points on structured data.
                fprintf(out1, "SCALARS ImageFile float 1\n");
                fprintf(out1, "LOOKUP_TABLE default\n");
                for (m = 0; m <= M; m++) {
                        for (n = 0; n <= N; n++)
                        fprintf (out1, "%6.4f ", u[n][m]);
                        fprintf (out1, "\n");
                }
                fclose (out1);

                // binary output of the same data. this does not work.
                str = malloc(64*sizeof(char));
                sprintf(str,"fhn2d%d.bin.vtk",cnt);
                out1 = fopen(str,"wab");
                free(str);
                fprintf(out1, "# vtk DataFile Version 2.0\n");
                fprintf(out1, "vtk output\n");
                fprintf(out1, "BINARY\n");
                fprintf(out1, "DATASET STRUCTURED_POINTS\n");
                fprintf(out1, "DIMENSIONS %d %d 1\n",N+1,M+1); // N+1 columns, 
M+1+header rows
                fprintf(out1, "SPACING 1 1 1\n");
                fprintf(out1, "ORIGIN 0 0 0\n");
                fprintf(out1, "POINT_DATA %d\n",(N+1)*(M+1)); // total number 
of points on structured data.
                fprintf(out1, "SCALARS ImageFile float 1\n");
                fprintf(out1, "LOOKUP_TABLE default\n");
                fwrite(u,sizeof(float),(N+1)*(M+1),out1);
                fclose(out1);


                fcnt = 0;
        }



________________________________________
From: David Doria [[email protected]]
Sent: 17 August 2012 14:02
To: Kharche, Sanjay
Cc: [email protected]
Subject: Re: [Paraview] Paraview binary format

On Fri, Aug 17, 2012 at 7:21 AM, Kharche, Sanjay
<[email protected]> wrote:
>
> Dear All
>
> I am new to ParaView. I need to write binary files from my C code for viz
> with ParaView. So far, I assign values to a M x N 2D array, and write legacy
> VTK files - that works fine. I used code as pasted below to see if I can get
> the binary output (which uses a simple fwrite) working, but was unable to
> viz the data in the binary output. Can someone suggest how to write ParaView
> raw binary files (hopefully with minimal headers), and how to viz them
> interactively using the GUI.
>
> thanks
> Sanjay

Why don't you construct VTK objects and use a VTK writer to write the file?

Something like this:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/XMLStructuredGridWriter

It seems like you are reinventing the wheel a little bit by actually
formatting the file to VTK file format specifications manually.

David
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to