// reading a complete binary file #include #include #include // I will use the fits class by TB for reading the interesting data from the files #define HAVE_ZLIB #include "fits" using namespace std; ifstream::pos_type size; char * memblock; int main (int argc, char * argv[]) { if (argc < 3) { cout << "Usage: " << argv[0] << " data-file-name calib-file-name [ouput-file-name]" << endl; cout << "" << endl; } char * data_file_name = argv[1]; char * calib_file_name = argv[2]; char * out_file_name = 0; if (argc == 4) { out_file_name = argv[3]; } else { out_file_name = new char[strlen(data_file_name)+4]; strcpy(out_file_name, data_file_name); strcpy(out_file_name+strlen(data_file_name),".fc"); out_file_name[strlen(data_file_name)+3] = 0; } //========================================================================= // CALIBRATION CONSTANTS //========================================================================= fits * calib =new fits(calib_file_name); calib->PrintKeys(); calib->PrintColums(); offset_mV = new float[] // I need the offset calibration constants from the calibration files // they are stored as floats at a known position inside the calibration file... long position_of_calibration_constants = 0x1000; // The calibration constants are stored in units of pseudo-mV. // but I need them in ADC units // I will first read offset_mV from the file, then multiply (or divide) // with the conversion factor 2000/4096.; // then I will convert it to shorts. // From that point on I will only use the shorts in *offset*, so I can // free the memory for *offset_mV* already. int size_of_offset = 1440*1024; int size_of_offset_memblock = 1440*1024*sizeof(float); float * offset_mV = new float[size_of_offset]; short * offset = new short[size_of_offset]; char * memblock = new char[size_of_offset_memblock]; ifstream calib (calib_file_name, ios::in|ios::binary); if ( !calib.is_open() ) { cerr << "Could not open Calibration File:" << calib_file_name << ".. ABORT." << endl; return 1; } else // file was opened, I can go on... { calib.seekg(position_of_calibration_constants, ios::beg); calib.read(memblock, size_of_offset_memblock); offset_mV = (float*)memblock; for (int i=0; i= -32 && diffs[i] <= 31) //~ sizes[i] = 6; //~ else if (diffs[i] >= -128 && diffs[i] <= 127) //~ sizes[i] = 8; //~ else if (diffs[i] >= -512 && diffs[i] <= 511) //~ sizes[i] = 10; //~ else //~ sizes[i] = 16; if (diffs[i] >= -128 && diffs[i] <= 127) sizes[i] = 8; else sizes[i] = 16; } // calculate group sizes int counter = 0; unsigned char last_size = sizes[0]; vector group_sizes; vector groups; for (int i=0 ; i < diff_size; i++) { if (sizes[i] != last_size) { group_sizes.push_back( counter ); groups.push_back( last_size ); last_size = sizes[i]; } counter++; } groups.push_back( last_size ); group_sizes.push_back( counter ); // write the first short out.write(memblock, 1*sizeof(short) ); // for all groups write header and group short header = 0; int diff_index = 0; for ( int i = 0 ; i < (int)groups.size() ; i++) { // write header if (groups[i] == 8) { header = short(group_sizes[i]); } else { header = 0x8000 | short(group_sizes[i] ); } out.write( (char*)&header, sizeof(short)); // write group if (groups[i] == 8) { for (int j = 0; j