I thought my C code may be helpful to you. I have 5 data array of different size, and I do like this:<br><br>nvar=5;<br>/* Bytes and offsets for ParaView file */ <br> bytes[0] = (ndim*nnod)*sizeof(float); /* Coordinates */<br>
bytes[1] = (nenod*nelmt)*sizeof(int); /* Connectivity */<br> bytes[2] = (nelmt)*sizeof(int); /* Offsets */<br> bytes[3] = (nelmt)*sizeof(int); /* Types */<br> bytes[4] = (nelmt)*sizeof(float); /* Cell data */<br>
<br> off[0]=0; /* 1st offset */<br> for (i=0; i<nvar; i++){ <br> if(i<nvar-1)off[i+1]=off[i]+sizeof(int)+bytes[i];<br> bytes[i]=bytes[i]+sizeof(int); /* For each byte we must also add the sizeof(int) for itself also */ <br>
}<br><br>Best wishes,<br>Hom Nath<br><br><div class="gmail_quote">2009/4/1 David Mulholland <span dir="ltr"><<a href="mailto:d.t.mulholland@googlemail.com">d.t.mulholland@googlemail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="padding-left: 10px; padding-right: 10px; padding-top: 15px;" bgcolor="#ffffff" text="#000000" name="Compose message area">
<div><font face="Calibri">Hi Thorsten, </font></div>
<div><font face="Calibri"></font> </div>
<div><font face="Calibri">I just tried that and it is now giving me a segmentation
fault... I am using the following line: </font></div>
<div><font size="2">file.write(</font><font size="2" color="#40ffff"><font size="2" color="#40ffff">reinterpret_cast</font></font><font size="2"><</font><font size="2" color="#40ffff"><font size="2" color="#40ffff">const</font></font><font size="2">
</font><font size="2" color="#00bf00"><font size="2" color="#00bf00">char</font></font><font size="2">*>(size), 4);</font></div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><font size="3" face="Calibri"></font> </div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
<div><font size="3" face="Calibri">My size is calculated as - int size =
idim*jdim*sizeof(float). idim is currently in the region of 400 and jdim 200. I
am outputting big files and it is likely to get bigger.</font></div><font size="3" face="Calibri"></font></div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><font size="3" face="Calibri"></font><font size="3" face="Calibri"></font> </div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><font size="3" face="Calibri">Also, I intend to
include more data arrays each timestep, I just want to get it working with
pressure first and then I will include then which is why I want to calculate the
offset... I assuming it is just the number of bytes to the start of the next
datafield...</font></div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><font size="3" face="Calibri"></font> </div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><font size="3" face="Calibri">Thanks David</font>
<div><br></div>
<div style="background: rgb(245, 245, 245) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div><b>From:</b> <a title="th@tp1.rub.de" href="mailto:th@tp1.rub.de" target="_blank">Thorsten Hater</a> </div>
<div><b>Sent:</b> Wednesday, April 01, 2009 10:55 AM</div><div><div></div><div class="h5">
<div><b>To:</b> <a title="d.t.mulholland@googlemail.com" href="mailto:d.t.mulholland@googlemail.com" target="_blank">David Mulholland</a> </div>
<div><b>Cc:</b> <a title="paraview@paraview.org" href="mailto:paraview@paraview.org" target="_blank">paraview@paraview.org</a> </div>
<div><b>Subject:</b> Re: [Paraview] VTK XML Binary Output</div></div></div></div></div><div><div></div><div class="h5">
<div><br></div>Hello David,<br><br>the offset parameter is relevant if you
append mulitple data sections into a single file.<br>Every DataArray tag with
append format specifies the offset as the position in the <br>binary data in
bytes.<br>To write the integer I use the following:<br><br>std::ofstream os; //
binary mode (for windows ...) ofstream to your file<br>int N; // size in
bytes<br>os.write(reinterpret_cast<const char*>(N),
4);<br><br>Thorsten<br><br>David Mulholland schrieb:
<blockquote type="cite">
<div>Hi Thorsten,<br><br>That's really helpful. I don't quite know how to
write out the number of bits as a char? If you could explain a way of how to
do that it would be greatly appreciated. <br><br>Also, how do I calculate what
value goes in for the offset? I had a look at a couple of output files from
paraview and it wasnt obvious how it was
calculated.<br><br>Thanks<br>David</div>
<div style="font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
<div><br></div>
<div style="background: rgb(245, 245, 245) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div><b>From:</b> <a title="th@tp1.rub.de" href="mailto:th@tp1.rub.de" target="_blank">Thorsten Hater</a> </div>
<div><b>Sent:</b> Tuesday, March 31, 2009 2:23 PM</div>
<div><b>To:</b> <a title="d.t.mulholland@googlemail.com" href="mailto:d.t.mulholland@googlemail.com" target="_blank">David
Mulholland</a> </div>
<div><b>Cc:</b> <a title="paraview@paraview.org" href="mailto:paraview@paraview.org" target="_blank">paraview@paraview.org</a> </div>
<div><b>Subject:</b> Re: [Paraview] VTK XML Binary Output</div></div></div>
<div><br></div>Hello,<br><br>the solution might be to append your data
as<br><br>< DataArray ...
format="appended"><br></DataArray><br>< AppendedData
encoding="raw"><br>_NNNNData <br></AppendedData><br>where you should
replace NNNN with a four <br>byte integer containing the number of bytes
<br>in the data array as 4 chars.<br>Setting the encoding to "raw" tells
ParaView, that<br>the data is simply a stream of bytes rather than <br>base64
encoded.<br>If you want to write Image I can supply a small<br>writer project
for 2D data.<br><br> Thorsten<br> <br>David Mulholland
schrieb:
<blockquote type="cite">
<div>Hello,<br><br>I am currently trying to write my own quick output
routine to generate a <br>binary file using C++. I am currently trying to
avoid having to use the vtk <br>libraries because I only need a very basic
output that doesn't change much. <br>I so far have the ASCII output working
no problem but I can't get the binary <br>working.<br><br>I am using
file.write() function to output the binary data and that seems to <br>be
working no problem and when used in a legacy format application it works
<br>perfectly except that the data is LittleEndian instead of BigEndian.
That's <br>why I have moved to BigEndian because I don't want to have to
make the <br>output routine for the data anymore complicated that
file.write.<br><br>I started using the xml format and considering my output
is raw binary and <br>not base64 I changed it to be in the AppendedData
section instead of <br>DataArray. It still isn't working right, I get the
following error when I <br>try to load in ParaView:<br><br>ERROR: In
..\..\..\ParaView3\VTK\IO\vtkXMLStructuredDataReader.cxx, line
349<br>vtkXMLImageDataReader (0ADEC7F8): Error reading extent 0 422 0 242 0
1 from <br>piece 0<br><br><br>ERROR: In
..\..\..\ParaView3\VTK\IO\vtkXMLDataReader.cxx, line
537<br>vtkXMLImageDataReader (0ADEC7F8): Cannot read cell data array
"pressure" <br>from PointData in piece 0. The data array in the
element may be too short.<br><br>The format of my output file is as
follows:<br><br><?xml version="1.0"?><br><VTKFile type="ImageData"
version="0.1" byte_order="LittleEndian"><br><ImageData WholeExtent="0
422 0 242 0 1" Origin="0 0 0" Spacing="1 1 1"><br><Piece Extent="0 422
0 242 0 1"><br><PointData><br></PointData><br><CellData
Scalars="pressure"><br><DataArray type="Float32" Name="pressure"
format="appended"
offset="0"/><br></CellData><br></Piece><br></ImageData><br><AppendedData
encoding="raw"><br>_BINARYDATA<br></AppendedData><br></VTKFile><br><br>Note
following an error message I have added an _ at the start of the binary
<br>data. Is this required?<br><br>One final thing, when using appended
data, how do you calculate what the <br>offset should
be?<br><br>Thanks<br>David</div><pre><hr size="4" width="90%">
_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a>
Follow this link to subscribe/unsubscribe:
<a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a>
</pre></blockquote><br></blockquote><br></div></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a><br>
<br></blockquote></div><br>