|
D Haley |
eb3bc15 |
diff -r cf4c3eefdead -r a369c6597982 src/backend/APT/APTFileIO.cpp
|
|
D Haley |
eb3bc15 |
--- src/backend/APT/APTFileIO.cpp Sun Feb 05 14:33:21 2017 +0000
|
|
D Haley |
eb3bc15 |
+++ src/backend/APT/APTFileIO.cpp Sun Feb 05 18:27:46 2017 +0000
|
|
D Haley |
eb3bc15 |
@@ -24,7 +24,6 @@
|
|
D Haley |
eb3bc15 |
#include "../../common/translation.h"
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
-
|
|
D Haley |
eb3bc15 |
#include <cstring>
|
|
D Haley |
eb3bc15 |
#include <new>
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
@@ -1123,7 +1122,7 @@
|
|
D Haley |
eb3bc15 |
return 0;
|
|
D Haley |
eb3bc15 |
}
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
-//Load a TAPSIM Binfile
|
|
D Haley |
eb3bc15 |
+//Load a TAPSIM Binfile, which is the input geometry format for TAPSIM
|
|
D Haley |
eb3bc15 |
unsigned int loadTapsimBinFile(const char *fileName, unsigned int &progress, ATOMIC_BOOL &wantAbort, vector<IonHit> &posIons)
|
|
D Haley |
eb3bc15 |
{
|
|
D Haley |
eb3bc15 |
ifstream f(fileName,std::ios::binary);
|
|
D Haley |
eb3bc15 |
@@ -1136,7 +1135,7 @@
|
|
D Haley |
eb3bc15 |
fileSize = f.tellg();
|
|
D Haley |
eb3bc15 |
f.seekg(0,std::ios::beg);
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
- //TAPSIM's binary geometery input format is not totally clearly documented
|
|
D Haley |
eb3bc15 |
+ //TAPSIM's binary geometry input format is not totally clearly documented
|
|
D Haley |
eb3bc15 |
// but an example is provided. So best efforts are us.
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
std::string str;
|
|
D Haley |
eb3bc15 |
@@ -1202,7 +1201,7 @@
|
|
D Haley |
eb3bc15 |
return TAPSIM_ERR_FILE_FORMAT_FAIL;
|
|
D Haley |
eb3bc15 |
}
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
- //Contrary to docuemntation, ids appear to be "short", not "unsigned int"
|
|
D Haley |
eb3bc15 |
+ //Contrary to documentation, ids appear to be "short", not "unsigned int"
|
|
D Haley |
eb3bc15 |
size_t recordSize=( (numbersPresent ? 1:0 )*sizeof(unsigned int) +
|
|
D Haley |
eb3bc15 |
3*sizeof(float) + (idsPresent ?1:0)*sizeof(short));
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
@@ -1222,11 +1221,24 @@
|
|
D Haley |
eb3bc15 |
//Transfer position data
|
|
D Haley |
eb3bc15 |
#ifdef __LITTLE_ENDIAN__
|
|
D Haley |
eb3bc15 |
h.setPos(Point3D((float*)(buffer)));
|
|
D Haley |
eb3bc15 |
-#elif __BIG_ENDIAN__
|
|
D Haley |
eb3bc15 |
- static_assert(false); //TODO: IMPLEMENT ME
|
|
D Haley |
eb3bc15 |
-#endif
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
//assign the ID as the mass to charge
|
|
D Haley |
eb3bc15 |
h.setMassToCharge(*( (short*)(buffer+12) ));
|
|
D Haley |
eb3bc15 |
+#elif __BIG_ENDIAN__
|
|
D Haley |
eb3bc15 |
+ {
|
|
D Haley |
eb3bc15 |
+ Point3D pt((float*)(buffer));
|
|
D Haley |
eb3bc15 |
+ pt.switchEndian();
|
|
D Haley |
eb3bc15 |
+ h.setPos(pt);
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
+ uint16_t s;
|
|
D Haley |
eb3bc15 |
+ s =*( (uint16_t*)(buffer+12) );
|
|
D Haley |
eb3bc15 |
+ shortSwapBytes(s);
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
+ }
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
+#endif
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
posIons[ui]=h;
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
@@ -1291,7 +1303,7 @@
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
if(!flip)
|
|
D Haley |
eb3bc15 |
{
|
|
D Haley |
eb3bc15 |
- //Fkip the endinanness
|
|
D Haley |
eb3bc15 |
+ //Flip the endinanness
|
|
D Haley |
eb3bc15 |
for(size_t ui=0;ui<4;ui++)
|
|
D Haley |
eb3bc15 |
floatSwapBytes(buffer+ui);
|
|
D Haley |
eb3bc15 |
}
|
|
D Haley |
eb3bc15 |
@@ -1300,7 +1312,7 @@
|
|
D Haley |
eb3bc15 |
outF.write((char*)&intData,4);
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
intData=3;
|
|
D Haley |
eb3bc15 |
- //Write out verion num as "3"
|
|
D Haley |
eb3bc15 |
+ //Write out version num as "3"
|
|
D Haley |
eb3bc15 |
outF.write((char*)&intData,4);
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
for(size_t ui=0;ui
|
|
D Haley |
eb3bc15 |
@@ -1339,7 +1351,7 @@
|
|
D Haley |
eb3bc15 |
TEST((ions[0].getPos().sqrDist(Point3D(1,1,0)) < sqrtf(std::numeric_limits<float>::epsilon())),"Checking read/write OK");
|
|
D Haley |
eb3bc15 |
//Load using auto-detection of endinanness
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
- //Load, forcing assuming cont4ents are little endianness as requried
|
|
D Haley |
eb3bc15 |
+ //Load, forcing assuming contents are little endianness as required
|
|
D Haley |
eb3bc15 |
TEST(!LoadATOFile(filename.c_str(),ions,dummyProgress,wantAbort,1),"ATO load test (forced endianness)");
|
|
D Haley |
eb3bc15 |
TEST(ions.size() == 100,"ion size check");
|
|
D Haley |
eb3bc15 |
TEST((ions[0].getPos().sqrDist(Point3D(1,1,0)) < sqrtf(std::numeric_limits<float>::epsilon())),"checking read/write OK");
|
|
D Haley |
eb3bc15 |
diff -r cf4c3eefdead -r a369c6597982 src/common/endianTest.h
|
|
D Haley |
eb3bc15 |
--- src/common/endianTest.h Sun Feb 05 14:33:21 2017 +0000
|
|
D Haley |
eb3bc15 |
+++ src/common/endianTest.h Sun Feb 05 18:27:46 2017 +0000
|
|
D Haley |
eb3bc15 |
@@ -51,7 +51,7 @@
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
inline int is_littleendian() { return (*(char*)&ENDIAN_TEST) == 1 ;}
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
-
|
|
D Haley |
eb3bc15 |
+//this may fail on some compilers??
|
|
D Haley |
eb3bc15 |
inline void floatSwapBytes(float *inFloat)
|
|
D Haley |
eb3bc15 |
{
|
|
D Haley |
eb3bc15 |
//Use a union to avoid strict-aliasing error
|
|
D Haley |
eb3bc15 |
@@ -69,5 +69,19 @@
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
*inFloat=fb.f;
|
|
D Haley |
eb3bc15 |
}
|
|
D Haley |
eb3bc15 |
+inline void shortSwapBytes(short *inShort)
|
|
D Haley |
eb3bc15 |
+{
|
|
D Haley |
eb3bc15 |
+ //Use a union to avoid strict-aliasing error
|
|
D Haley |
eb3bc15 |
+ union ShortSwapUnion{
|
|
D Haley |
eb3bc15 |
+ short s;
|
|
D Haley |
eb3bc15 |
+ char c[2];
|
|
D Haley |
eb3bc15 |
+ } ;
|
|
D Haley |
eb3bc15 |
+ ShortSwapUnion sa,sb;
|
|
D Haley |
eb3bc15 |
+ sa.s = *inShort;
|
|
D Haley |
eb3bc15 |
|
|
D Haley |
eb3bc15 |
+ sb.c[0] = sa.c[1];
|
|
D Haley |
eb3bc15 |
+ sb.c[1] = sa.c[0];
|
|
D Haley |
eb3bc15 |
+
|
|
D Haley |
eb3bc15 |
+ *inShort=sb.s;
|
|
D Haley |
eb3bc15 |
+}
|
|
D Haley |
eb3bc15 |
#endif
|