Skip to content

Instantly share code, notes, and snippets.

@kempj
Created April 24, 2013 22:37
Show Gist options
  • Save kempj/5456177 to your computer and use it in GitHub Desktop.
Save kempj/5456177 to your computer and use it in GitHub Desktop.
void DataFile::convertFile( int dimension[], string inName, string outName ) {
ifstream input( inName.c_str(), ios::in| ios::binary );
ofstream outputFile;
char *buffer, *fileName;
int z = dimension[0], y = dimension[1], x = dimension[2], sliceSize = z * y;
float ***data = new float**[z];
buffer = new char[4];
fileName = new char[strlen(outName.c_str()) + 100];
if( x > 0 && y > 0 && z > 0 && !input.fail() ) {
for(int i = 0; i < z; i++) {
data[i] = new float*[y];
for(int j = 0; j < y; j++) {
data[i][j] = new float[x];
}
}
for(int k = 0; k < x; k++) {
for(int j = 0; j < y; j++) {
for( int i = 0; i < z; i++) {
input.read(buffer, 4);
data[i][j][k] = (float)*buffer;
// cout << data[i][j][k] << " " ;
}
cout << endl << "Length = " << input.tellg() << endl;
}
}
input.close();
for(int i = 0; i < z; i++ ) {
sprintf(fileName, "%s.%d", inName.c_str(), i);
outputFile.open( fileName, ios::out | ios::binary );
for(int j = 0; j < y; j++) {
for(int k = 0; k < x; k++) {
outputFile << data[i][j][k];
}
}
outputFile.write( buffer, sliceSize );
outputFile.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment