<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7000.0"></HEAD>
<BODY style="PADDING-LEFT: 10px; PADDING-RIGHT: 10px; PADDING-TOP: 15px" 
id=MailContainerBody leftMargin=0 topMargin=0 CanvasTabStop="true" 
name="Compose message area">
<DIV><FONT face=Calibri>Well, I kept working and took a few guesses and I've got 
it all working now.</FONT></DIV>
<DIV><FONT face=Calibri></FONT>&nbsp;</DIV>
<DIV><FONT face=Calibri>Thank you all for your help! Much appreciated and I now 
have some very fast binary output working compared to my previous ASCII 
output.</FONT></DIV>
<DIV><FONT face=Calibri></FONT>&nbsp;</DIV>
<DIV><FONT face=Calibri>David</FONT></DIV>
<DIV style="FONT: 10pt Tahoma">
<DIV><BR></DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=hng.email@gmail.com 
href="mailto:hng.email@gmail.com">Hom Nath Gharti</A> </DIV>
<DIV><B>Sent:</B> Wednesday, April 01, 2009 1:59 PM</DIV>
<DIV><B>To:</B> <A title=d.t.mulholland@googlemail.com 
href="mailto:d.t.mulholland@googlemail.com">David Mulholland</A> </DIV>
<DIV><B>Cc:</B> <A title=th@tp1.rub.de href="mailto:th@tp1.rub.de">Thorsten 
Hater</A> ; <A title=paraview@paraview.org 
href="mailto:paraview@paraview.org">paraview@paraview.org</A> </DIV>
<DIV><B>Subject:</B> Re: [Paraview] VTK XML Binary Output</DIV></DIV></DIV>
<DIV><BR></DIV>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 */&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; bytes[0] = 
(ndim*nnod)*sizeof(float); &nbsp;&nbsp;&nbsp; /* Coordinates 
*/<BR>&nbsp;&nbsp;&nbsp; bytes[1] = (nenod*nelmt)*sizeof(int); 
&nbsp;&nbsp;&nbsp; /* Connectivity */<BR>&nbsp;&nbsp;&nbsp; bytes[2] = 
(nelmt)*sizeof(int); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* Offsets 
*/<BR>&nbsp;&nbsp;&nbsp; bytes[3] = (nelmt)*sizeof(int); &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; /* Types */<BR>&nbsp;&nbsp;&nbsp; bytes[4] = 
(nelmt)*sizeof(float); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* Cell data 
*/<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; off[0]=0; /* 1st offset 
*/<BR>&nbsp;&nbsp;&nbsp; for (i=0; i&lt;nvar; i++){&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
if(i&lt;nvar-1)off[i+1]=off[i]+sizeof(int)+bytes[i];<BR>&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; bytes[i]=bytes[i]+sizeof(int); /* For each byte we must also 
add the sizeof(int) for itself also */ &nbsp; <BR>&nbsp;&nbsp;&nbsp; 
}<BR><BR>Best wishes,<BR>Hom Nath<BR><BR>
<DIV class=gmail_quote>2009/4/1 David Mulholland <SPAN dir=ltr>&lt;<A 
href="mailto:d.t.mulholland@googlemail.com">d.t.mulholland@googlemail.com</A>&gt;</SPAN><BR>
<BLOCKQUOTE 
style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote>
  <DIV style="PADDING-LEFT: 10px; PADDING-RIGHT: 10px; PADDING-TOP: 15px" 
  name="Compose message area" bgcolor="#ffffff" text="#000000">
  <DIV><FONT face=Calibri>Hi Thorsten, </FONT></DIV>
  <DIV><FONT face=Calibri></FONT>&nbsp;</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 color=#40ffff size=2><FONT 
  color=#40ffff size=2>reinterpret_cast</FONT></FONT><FONT 
  size=2>&lt;</FONT><FONT color=#40ffff size=2><FONT color=#40ffff 
  size=2>const</FONT></FONT><FONT size=2> </FONT><FONT color=#00bf00 
  size=2><FONT color=#00bf00 size=2>char</FONT></FONT><FONT size=2>*&gt;(size), 
  4);</FONT></DIV>
  <DIV 
  style="FONT: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT 
  size=3 face=Calibri></FONT>&nbsp;</DIV>
  <DIV style="FONT: 10pt Tahoma; 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: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT 
  size=3 face=Calibri></FONT><FONT size=3 face=Calibri></FONT>&nbsp;</DIV>
  <DIV 
  style="FONT: 10pt Tahoma; 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: 10pt Tahoma; font-size-adjust: none; font-stretch: normal"><FONT 
  size=3 face=Calibri></FONT>&nbsp;</DIV>
  <DIV 
  style="FONT: 10pt Tahoma; 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); -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&lt;const char*&gt;(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: 10pt Tahoma; font-size-adjust: none; font-stretch: normal">
    <DIV><BR></DIV>
    <DIV 
    style="BACKGROUND: rgb(245,245,245) 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>&lt; DataArray ... 
    format="appended"&gt;<BR>&lt;/DataArray&gt;<BR>&lt; AppendedData 
    encoding="raw"&gt;<BR>_NNNNData <BR>&lt;/AppendedData&gt;<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>&nbsp;&nbsp;&nbsp; 
    Thorsten<BR>&nbsp;<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.&nbsp; The data array in the 
      element may be too short.<BR><BR>The format of my output file is as 
      follows:<BR><BR>&lt;?xml version="1.0"?&gt;<BR>&lt;VTKFile 
      type="ImageData" version="0.1" 
      byte_order="LittleEndian"&gt;<BR>&lt;ImageData WholeExtent="0 422 0 242 0 
      1" Origin="0 0 0" Spacing="1 1 1"&gt;<BR>&lt;Piece Extent="0 422 0 242 0 
      1"&gt;<BR>&lt;PointData&gt;<BR>&lt;/PointData&gt;<BR>&lt;CellData 
      Scalars="pressure"&gt;<BR>&lt;DataArray type="Float32" Name="pressure" 
      format="appended" 
      offset="0"/&gt;<BR>&lt;/CellData&gt;<BR>&lt;/Piece&gt;<BR>&lt;/ImageData&gt;<BR>&lt;AppendedData 
      encoding="raw"&gt;<BR>_BINARYDATA<BR>&lt;/AppendedData&gt;<BR>&lt;/VTKFile&gt;<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></BODY></HTML>