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

SL Libraries -- C++

pa2text.cpp

Go to the documentation of this file.
00001 /** 00002 * @file pa2text.cpp 00003 * Reads the contents of a SIMION potential array file and writes the 00004 * contents to standard output. 00005 * 00006 * David Manura, Scientific Instrument Services, Inc. 00007 * $Revision: 1.5 $ $Date: 2004/07/17 20:48:50 $ Created 2003-10. 00008 */ 00009 #include <iostream> 00010 #include <fstream> 00011 #include <simion/pa.h> 00012 00013 using namespace std; 00014 using namespace simion; 00015 00016 void print_usage() 00017 { 00018 cerr << "usage: pa2text <file>" << endl; 00019 } 00020 00021 // note: issue on precision of double printing 00022 int main(int argc, char** argv) 00023 { 00024 ifstream is; 00025 00026 if(argc < 2) { 00027 print_usage(); 00028 return 1; 00029 } 00030 00031 string filename = argv[1]; 00032 00033 ofstream outfile((filename + ".txt").c_str()); 00034 00035 PA pa; 00036 pa.load(filename); 00037 00038 outfile 00039 << "file_type=" << "simion_pa" << endl; 00040 00041 outfile 00042 << "begin_header" << endl 00043 << "mode=" << pa.mode() << endl 00044 << "symmetry=" << (pa.symmetry() == CYLINDRICAL ? 00045 "cylindrical" : "PLANAR") << endl 00046 << "max_voltage=" << pa.max_voltage() << endl 00047 << "nx=" << pa.nx() << endl 00048 << "ny=" << pa.ny() << endl 00049 << "nz=" << pa.nz() << endl 00050 << "mirror_x=" << !!(pa.mirror_x()) << endl 00051 << "mirror_y=" << !!(pa.mirror_y()) << endl 00052 << "mirror_z=" << !!(pa.mirror_z()) << endl 00053 << "magnetic_pa=" << pa.field_string(pa.field_type()) << endl 00054 << "ng=" << pa.ng() << endl 00055 ; 00056 outfile 00057 << "end_header" << endl; 00058 00059 // note: output in row-major order: 00060 // double points[nz][ny][nz] 00061 outfile << "begin_points" << endl; 00062 00063 for(int z=0; z<pa.nz(); z++) { 00064 for(int y=0; y<pa.ny(); y++) { 00065 for(int x=0; x<pa.nx(); x++) { 00066 PAPoint point = pa.point(x, y, z); 00067 outfile << point.electrode << "," << point.potential << endl; 00068 } 00069 } 00070 } 00071 outfile << "end_points" << endl; 00072 00073 return 0; 00074 } 00075 00076
(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.