00001 #include "ScanResultWriter.h"
00002 #include "dataTypes.h"
00003 #include "Sct/Exception.h"
00004
00005 #include <CommonWithDsp/processor.h>
00006 #include <CommonWithDsp/sctStructure.h>
00007 #include <CommonWithDsp/ABCD/ABCDscans.h>
00008
00009 #include <cstdio>
00010 #include <cstring>
00011
00012 using namespace std;
00013 using namespace SctData;
00014
00015
00016 void handleFile(const char* name, int i);
00017
00018
00019
00020 int main(int argc, char** argv) {
00021 Sct::setExceptionHandlers(argv[0]);
00022 for (int i=1; i<argc; ++i) {
00023 handleFile(argv[i], i);
00024 }
00025 return 0;
00026 }
00027
00028
00029
00030
00031 void handleFile(const char* name, int i) {
00032 try {
00033 FILE * pFile;
00034 long lSize;
00035
00036 pFile = fopen (name, "rb" );
00037 if (pFile==NULL) throw FileException(name, "File Not Found", __FILE__, __LINE__);
00038
00039
00040 fseek (pFile , 0 , SEEK_END);
00041 lSize = ftell (pFile);
00042 rewind (pFile);
00043
00044
00045 scan_result_ptrs scanResult;
00046
00047
00048 int n = fread(&scanResult.header, sizeof(ScanHeader), 1, pFile);
00049
00050
00051
00052
00053 scanResult.points = new FLOAT32[scanResult.header.npoints];
00054 scanResult.nEvents = new UINT32[scanResult.header.npoints];
00055 scanResult.nErrorEvents = new UINT32[scanResult.header.npoints];
00056
00057 fseek(pFile, scanResult.header.pntPoints, SEEK_SET);
00058 n = fread(scanResult.points, sizeof(FLOAT32), scanResult.header.npoints, pFile);
00059 if (n != scanResult.header.npoints) {
00060 ostringstream oss;
00061 oss << "Failed to read in ScanPoints. Expected: " << scanResult.header.npoints << " Read: " << n;
00062 throw StreamCorruptedException(oss.str(), __FILE__, __LINE__);
00063 }
00064
00065 fseek(pFile, scanResult.header.pntEvents, SEEK_SET);
00066 n = fread(scanResult.nEvents, sizeof(UINT32), scanResult.header.npoints, pFile);
00067 if (n != scanResult.header.npoints) {
00068 ostringstream oss;
00069 oss << "Failed to read in ScanPoints, nEvents. Expected: " << scanResult.header.npoints << " Read: " << n;
00070 throw StreamCorruptedException(oss.str(), __FILE__, __LINE__);
00071 }
00072
00073 fseek(pFile, scanResult.header.pntErrors, SEEK_SET);
00074 n = fread(scanResult.nErrorEvents, sizeof(UINT32), scanResult.header.npoints, pFile);
00075 if (n != scanResult.header.npoints) {
00076 ostringstream oss;
00077 oss << "Failed to read in ScanPoints, nErrorEvents. Expected: " << scanResult.header.npoints << " Read: " << n;
00078 throw StreamCorruptedException(oss.str(), __FILE__, __LINE__);
00079 }
00080
00081
00082
00083 scanResult.data = new short[scanResult.header.size];
00084
00085 fseek(pFile, scanResult.header.pntData, SEEK_SET);
00086 n = fread(scanResult.data, sizeof(UINT16), scanResult.header.size, pFile);
00087 if (n != scanResult.header.size) {
00088 ostringstream oss;
00089 oss << "Failed to read in data. Expected: " << scanResult.header.size << " Read: " << n;
00090 throw StreamCorruptedException(oss.str(), __FILE__, __LINE__);
00091 }
00092
00093
00094 fclose (pFile);
00095
00096 ScanResultWriter::publish(scanResult);
00097
00098
00099 delete [] scanResult.points;
00100 delete [] scanResult.nEvents;
00101 delete [] scanResult.nErrorEvents;
00102 delete [] (short*)scanResult.data;
00103 } catch (Sct::Throwable& t) {
00104 t.sendToMrs(MRS_ERROR);
00105 }
00106 }