Last active
October 19, 2016 06:46
-
-
Save xiaoqiangwang/dd97529032fe80e713ab7a8a1d695f9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <iostream> | |
#include <vector> | |
#include <list> | |
#include "wseswrappermain.h" | |
#include "werror.h" | |
int main(int argc, char **argv) | |
{ | |
if (argc != 3) { | |
printf("Usage: test <working directory> <instrument file>"); | |
return -1; | |
} | |
std::string sesWorkingDirectory = argv[1]; | |
std::string instrumentFilePath = sesWorkingDirectory + "\\data\\" + argv[2]; | |
std::string sesInstrument = "dll\\SESInstrument.dll"; | |
printf("* working directory = %s\n* instrument file = %s\n", | |
sesWorkingDirectory.c_str(), | |
instrumentFilePath.c_str()); | |
std::string env = "SES_BASE_DIR=" + sesWorkingDirectory; | |
_putenv(env.c_str()); | |
std::cout << "Get SES instance" << std::endl; | |
WSESWrapperMain *ses = WSESWrapperMain::instance(); | |
WError *werror = WError::instance(); | |
std::cout << "Initialise" << std::endl; | |
int err = ses->setProperty("lib_working_dir", 0, sesWorkingDirectory.c_str()); | |
err |= ses->setProperty("instrument_library", 0, sesInstrument.c_str()); | |
err |= ses->initialize(0); | |
if (err) { | |
printf("! SES library initialisation failed: %d %s\n", err, werror->message(err)); | |
return -1; | |
} | |
std::cout << "Load instrument" << std::endl; | |
err = ses->loadInstrument(instrumentFilePath.c_str()); | |
if (err) { | |
printf("! LoadInstrument file: %s failed; %s\n", instrumentFilePath, werror->message(err)); | |
return -1; | |
} | |
if (!ses->isInitialized()) | |
{ | |
printf("! SES initialisation failed"); | |
return -1; | |
} | |
/* get analyzer setup */ | |
SESWrapperNS::WAnalyzerRegion analyzer; | |
err = ses->getProperty("analyzer_region", 0, &analyzer); | |
if (err) { | |
printf("! Get analyzer region failed: %s\n", werror->message(err)); | |
return -1; | |
} | |
/* get detector setup */ | |
SESWrapperNS::WDetectorRegion detector; | |
err = ses->getProperty("detector_region", 0, &detector); | |
if (err) { | |
printf("! Get detector region failed: %s\n", werror->message(err)); | |
return -1; | |
} | |
/* find out lens mode options */ | |
int num_lens_mode = 0; | |
ses->getProperty("lens_mode_count", -1, &num_lens_mode); | |
printf("* %d lens modes:\n", num_lens_mode); | |
std::list<std::string> lens_mode_list; | |
for (int i=0; i<num_lens_mode; i++) { | |
char lens_mode[100]; | |
int size = 100; | |
ses->getProperty("lens_mode", i, lens_mode, size); | |
lens_mode_list.push_back(lens_mode); | |
printf("* %d: %s\n", i, lens_mode); | |
} | |
/* find out pass energy options */ | |
int num_pass = 0; | |
ses->getProperty("pass_energy_count", -1, &num_pass); | |
printf("* %d pass energy:\n", num_pass); | |
std::vector<double> pass_energy_list; | |
for (int i=0; i<num_pass; i++) { | |
double pass; | |
ses->getProperty("pass_energy", i, &pass); | |
pass_energy_list.push_back(pass); | |
printf("* %d: %.0f\n", i, pass); | |
} | |
/* find out element set options */ | |
int num_element_set = 0; | |
ses->getProperty("element_set_count", -1, &num_element_set); | |
printf("* %d element set:\n", num_element_set); | |
std::list<std::string> element_set_list; | |
for (int i=0; i<num_element_set; i++) { | |
char element_set[100]; | |
int size = 100; | |
ses->getProperty("element_set", i, element_set, size); | |
element_set_list.push_back(element_set); | |
printf("* %d: %s\n", i, element_set); | |
} | |
/* setup acquisition | |
pass energy is 2, lens mode is Transmission | |
*/ | |
ses->setProperty("lens_mode", -1, "Angular60"); | |
double pass = 10; | |
ses->setProperty("pass_energy", -1, &pass); | |
bool sweep = false; | |
if (sweep) { | |
/* Sweep mode */ | |
analyzer.fixed_ = false; | |
analyzer.lowEnergy_ = 65.3; | |
analyzer.highEnergy_ = 65.8; | |
analyzer.energyStep_ = 0.01; | |
analyzer.dwellTime_ = 2000; // ms | |
} else { | |
/* Snapshot mode */ | |
analyzer.fixed_ = true; | |
analyzer.centerEnergy_ = 65.4; | |
analyzer.dwellTime_ = 300000; // ms | |
} | |
err = ses->setProperty("analyzer_region", 0, &analyzer); | |
if (err) { | |
printf("! Set analyzer region failed: %s\n", werror->message(err)); | |
return -1; | |
} | |
/* validate acquisition */ | |
int nsteps = 0; | |
double total_time = 0, min_step = 0; | |
err = ses->initAcquisition(!analyzer.fixed_, false); | |
if (err) { | |
printf("! initAcquisition failed: %s\n", werror->message(err)); | |
return -1; | |
} | |
err = ses->checkAnalyzerRegion(&analyzer, &nsteps, &total_time, &min_step); | |
if (err) { | |
printf("! checkAnalyzerRegion failed: %s\n", werror->message(err)); | |
return -1; | |
} else | |
printf("* num of steps = %d, total time = %f, minimal step = %f\n", nsteps, total_time/1000., min_step); | |
/* find out data size */ | |
int channels; | |
int slices; | |
int dummy = 0; | |
err = ses->getAcquiredData("acq_channels", 0, &channels,dummy); | |
err = ses->getAcquiredData("acq_slices", 0, &slices, dummy); | |
printf("* detector channels = %d, slices = %d\n", channels, slices); | |
/* acquire */ | |
err = ses->startAcquisition(); | |
if (err) { | |
printf("! start acquisition failed: %s\n", werror->message(err)); | |
return -1; | |
} | |
/* wait */ | |
if (sweep) { | |
for(int i=0; i<nsteps; i++) { | |
while(ses->waitForPointReady(-1) == WError::ERR_TIMEOUT) { | |
} | |
printf("* Point %d is ready\n", i); | |
ses->continueAcquisition(); | |
} | |
} | |
while(ses->waitForRegionReady(-1) == WError::ERR_TIMEOUT) { | |
} | |
/* get acquired image */ | |
int image_size = channels * slices; | |
double *pImage = (double *) calloc(image_size, sizeof(double)); | |
err = ses->getAcquiredData("acq_image", 0, pImage, image_size); | |
if (err) { | |
printf("! get acquired image failed: %s\n", werror->message(err)); | |
return -1; | |
} | |
/* write acquired image */ | |
FILE *fid = fopen("C:\\Temp\\img.txt", "w"); | |
for(int i=0; i<slices; i++) { | |
for(int j=0; j<channels; j++) { | |
fprintf(fid, "%.3f ", pImage[i*channels + j]); | |
} | |
fprintf(fid, "\n"); | |
} | |
fclose(fid); | |
/* finalise */ | |
werror->release(); | |
ses->finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment