// hkl2ang.cxx #include #include #include #include #include using namespace std; struct phase_struct{ double a, b, c, alpha, beta, gamma; string MaterialName, Formula, Symmetry; }; int main(int argc, char* argv[]) { // check argument list // open file objects ifstream hkl(argv[1]); ofstream tsl(argv[2]); // HKL header data, in order string Channel, Prj, Author, JobMode; int XCells, YCells; double XStep, YStep, AcqE1, AcqE2, AcqE3; int Mag, Coverage, Device, KV, TiltAngle, TiltAxis; int Phases; // TSL header data, in order double TEM_PIXperUM, xstar, ystar, zstar, WorkingDistance; string GRID; double XSTEP, YSTEP; int NCOLS_ODD, NCOLS_EVEN, NROWS; string OPERATOR, SAMPLEID, SCANID; vector phases; // read HKL header cout<<"This converts an HKL .ctf file to a TSL .ang "<<" \n"; cout<<"note that 30 degrees is subtracted from the "<<" \n"; cout<<" 3rd Euler angle (phi 2) "<<" \n"; cout<<"and 90 degrees is added to the 1st Euler angle (phi1) "<<" \n\n"; cout<<"If you don't want the 30 degr offset, then edit this program!"<<" \n\n"; cout<<"Mainly written by Jason Gruber, with"<<" \n"; cout<<" mods by AD Rollett, March 2007"<<"\n"; while (1) { string line, label; getline(hkl,line); stringstream sstream(line); sstream>>label; if (label=="Channel") sstream>>Channel; if (label=="Prj") sstream>>Prj; if (label=="Author") sstream>>Author; if (label=="JobMode") sstream>>JobMode; if (label=="XCells") sstream>>XCells; if (label=="YCells") sstream>>YCells; if (label=="XStep") sstream>>XStep; if (label=="YStep") sstream>>YStep; if (label=="AcqE1") sstream>>AcqE1; if (label=="AcqE2") sstream>>AcqE2; if (label=="AcqE3") sstream>>AcqE3; if (label=="Euler") { sstream>>label>>label>>label>>label; sstream>>label>>label>>label; sstream>>label>>Mag; sstream>>label>>Coverage; sstream>>label>>Device; sstream>>label>>KV; sstream>>label>>TiltAngle; sstream>>label>>TiltAxis; } if (label=="Phases") { sstream>>Phases; break; } } phases.resize(Phases+1); for (int i=1; i<=Phases; i++) { string line; getline(hkl,line); int p = line.find(',',0); while (p!=string::npos) {line[p]='.'; p=line.find(',',p);} p = line.find(';',0); while (p!=string::npos) {line[p]=' '; p=line.find(';',p);} stringstream sstream(line); sstream>>phases[i].a>>phases[i].b>>phases[i].c; sstream>>phases[i].alpha>>phases[i].beta>>phases[i].gamma; sstream>>phases[i].MaterialName; phases[i].Formula = ""; phases[i].Symmetry = ""; } hkl.ignore(1000,'\n'); // convert HKL header data to TSL header data TEM_PIXperUM = 1.0; // ? xstar = AcqE1; ystar = AcqE2; zstar = AcqE3; WorkingDistance = 15.0; // ? GRID = "SqGrid"; XSTEP = XStep; YSTEP = YStep; NCOLS_ODD = XCells; NCOLS_EVEN = XCells; NROWS = YCells; OPERATOR = Author; SAMPLEID = ""; SCANID = Prj; // write TSL header tsl<<"# TEM_PIXperUM "<>Phase>>X>>Y>>Bands>>Error; sstream>>Euler1>>Euler2>>Euler3>>MAD>>BC>>BS; // convert HKL record to TSL record phi1 = M_PI/180.0 * (Euler1 + 90.) ; PHI = M_PI/180.0 * Euler2 ; phi2 = M_PI/180.0 * (Euler3 - 30.) ; x = X; y = Y; IQ = 1.0; // ? CI = 1.0; // ? A = 0; // ? phase = Phase; // ? B = 1.0; // ? // write TSL record to file tsl<