The SIMION SL™ Toolkit (version 1.2.1.0 - 2004-11-09)

SL Libraries -- C++

buncher.cpp

Go to the documentation of this file.
00001 /** 00002 * @file buncher.cpp 00003 * Example of Buncher functionality reimplemented in C++. 00004 * This is only intended as a demonstration. An example as simple as 00005 * this probably should instead be implemented entirely in SL for 00006 * efficiency. 00007 * 00008 * David Manura, Scientific Instrument Services, Inc. 00009 * Based on the logic in BUNCHER.PRG of SIMION 7.0. 00010 * $Revision: 1.4 $ $Date: 2004/07/17 20:48:50 $ Created 2003-12-03. 00011 */ 00012 00013 #include <simion/remote.h> 00014 //#include <simion/remote.cpp> 00015 #include <iostream> 00016 #include <cmath> 00017 00018 inline double my_min(double a, double b) {return a < b ? a : b;} 00019 inline double my_max(double a, double b) {return a < b ? a : b;} 00020 00021 using namespace std; 00022 using namespace simion; 00023 00024 double buncher_voltage = 900; // buncher deceleration voltage 00025 double switch_time = 1.7; // switch time in microseconds 00026 00027 bool update_flag = true; // pe surface update flag set on at start 00028 00029 void time_step( 00030 double ion_time_of_flight, double ion_time_step, 00031 double& ion_time_step_out) 00032 { 00033 ion_time_step_out = ion_time_step; 00034 00035 if(ion_time_of_flight < switch_time) 00036 ion_time_step_out = my_min(ion_time_step, switch_time-ion_time_of_flight); 00037 00038 //cout << "TRACE: time_step_ret:" << ion_time_step_out << "," 00039 // << ion_time_of_flight << "," << ion_time_step << endl; 00040 } 00041 00042 void buncher_voltage_control( 00043 double ion_time_of_flight, 00044 double& adj_elect01_out) 00045 { 00046 adj_elect01_out = 00047 ion_time_of_flight < switch_time ? buncher_voltage : 0; 00048 00049 //cout << "TRACE: buncher_voltage_control:" << adj_elect01_out << "," 00050 // << ion_time_of_flight << endl; 00051 } 00052 00053 void other_stuff( 00054 double ion_time_of_flight, double ion_color, 00055 double& update_pe_surface_out, double& ion_color_out, double& do_mark) 00056 { 00057 update_pe_surface_out = 0; 00058 ion_color_out = ion_color; 00059 do_mark = 0; 00060 00061 if(fabs(ion_time_of_flight - switch_time) < 1E-12) { 00062 ion_color_out = 3; // blue 00063 do_mark = 1; 00064 update_flag = true; 00065 } 00066 else if(update_flag) { 00067 update_flag = false; 00068 update_pe_surface_out = 1; 00069 } 00070 00071 //cout << "TRACE: other_stuff:" << update_pe_surface_out << "," 00072 // << ion_color_out << "," << ion_time_of_flight << "," 00073 // << ion_color << endl; 00074 } 00075 00076 00077 int main() 00078 { 00079 cout << "Running buncher server in background...\n"; 00080 00081 // create remote object. 00082 SLRemote remote; 00083 //remote.debug_trace(true); 00084 00085 // register call-back subroutines. 00086 remote.handler(1, slremote_handler(time_step)); 00087 remote.handler(2, slremote_handler(buncher_voltage_control)); 00088 remote.handler(3, slremote_handler(other_stuff)); 00089 00090 // start background thread for responding to SL remote calls. 00091 remote.run(); 00092 00093 // wait for background thread to terminate. 00094 remote.wait_for_run_complete(); 00095 00096 return 0; 00097 } 00098 00099
(c) 2003-2004. Scientific Instrument Services, Inc. All Rights Reserved.
Please report any errors/comments regarding this web page:
  Name/e-mail/phone (optional):
 
The SIMION SL Toolkit™ and documentation is (c) 2003-2004 Scientific Instrument Services, Inc. All Rights Reserved.