0

I want to know is it possible to generate .raw file format using C++. If yes then which class deals with it? If possible kindly put down a sample code.

I have data of the format (X Y Z) <Number> which represents the number of particles between (X Y Z) and (X+1 Y+1 Z+1). I need to represent this data graphically using ParaView and hence need my data in binary format. So would like to know is it possible to directly generate .raw file format?

Chris
  • 39,262
  • 15
  • 126
  • 145
user1466705
  • 55
  • 1
  • 4
  • 2
    `.raw` files are usually image files. "Raw format" used by [ParaView](http://paraview.org/) is a completely different thing, so you might want to emphasize this in your question. Do you have exact specifications of this format? [This page](http://paraview.org/Wiki/ParaView:FAQ) only mentions: *ParaView supports reading raw uniform rectilinear data from a file. The default file extension is .raw. The user specifies the dimensions and data type, and the reader computes the header size*, which is a bit vague (at least for me). – Groo Jun 19 '12 at 14:37
  • 1
    This was the biggest problem. The wikipage does not mention clearly for a novice like me. Anyways eventually we have to figure it out – user1466705 Jun 19 '12 at 15:22

2 Answers2

2

Generally, to write binary data to a file in C++, you will want to use an ofstream:

#include <fstream.h>
...

{
   MyData myData = GetData();
   ofstream binaryFile ("file.raw", ios::out | ios::binary);
   binaryFile.write ((char*)&myData, sizeof (MyData));
   binaryFile.close();
}

It is up to you to determine the actual format (like the Data structure in the example above) that this application uses, and then write it to a file.

Groo
  • 45,930
  • 15
  • 109
  • 179
0

There are many definitions of raw image files, it very much depends on the context. The oldest and simplest definition is a file with no header and with pixel values packed in binary without any compression. This is trivial to implement, just write each pixel as 3 unsigned char values for red, green, and blue, from left to right and top to bottom.

Mark Ransom
  • 271,357
  • 39
  • 345
  • 578