#include #include #include #include // I will use the fits class by TB for reading the interesting data from the files #include "izstream.h" #define HAVE_ZLIB #include "fits.h" 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->PrintColumns(); int size_of_offset = 1440*1024; float * offset_mV = new float[size_of_offset]; short * offset = new short[size_of_offset]; calib->SetPtrAddress("BaselineMean",offset_mV, size_of_offset); calib->GetNextRow(); 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