37 {
38 cout << "JMarkovPathSelecter" << endl
39 << "Written by Martijn Jongen" << endl
40 << endl ;
41 cout << "Type '" << argv[0] << " -h!' to display the command-line options." << endl ;
42 cout << endl ;
43
44 string ifname = "" ;
45 string ofname = "" ;
46
47
48 bool shadow = false ;
51 double z ;
52 double r ;
53
54 try {
56 zap[
"f"] =
make_field(ifname,
"input file name (binary file containing JPhotonPaths)") ;
57 zap[
"o"] =
make_field(ofname,
"output file name (binary file containing a selection of the JPhotonPaths)") ;
58 zap[
"shadow"] =
make_field(shadow,
"flag to turn on shadowing") ;
59 zap[
"x"] =
make_field(x,
"x coordinate for shadowing") = 0 ;
60 zap[
"y"] =
make_field(y,
"y coordinate for shadowing") = 0 ;
61 zap[
"z"] =
make_field(z,
"z coordinate for shadowing") = 0.5*37 ;
62 zap[
"r"] =
make_field(r,
"radius for shadowing") = 0.2159 ;
63
64 if (zap.
read(argc, argv) != 0) {
65 return 1 ;
66 }
67 }
68 catch(const exception &error) {
69
70 cerr << error.what() ;
71 exit(1) ;
72 }
73
74
75 cout << "SELECTION CRITERIA:" << endl ;
76 if( shadow ) {
77 cout << "Will exclude all paths intersecting a sphere of radius " << r << " m"
78 <<
", centered at (" <<
x <<
", " <<
y <<
", " << z <<
")" << endl ;
79 }
80 cout << endl ;
81
82
84 reader.open(ifname.c_str()) ;
85 if( !reader.is_open() ) {
86 cerr << "FATAL ERROR: unable to open input file '" << ifname << "'." << endl ;
87 exit(1) ;
88 }
89
90 int nread = 0 ;
92 cout << "Reading file" << endl ;
94 while( reader.hasNext() ) {
95 p = reader.next() ;
96 paths.push_back(*p) ;
97 ++nread ;
98 }
99
100 if( nread == 0 ) {
101 cerr << "FATAL ERROR: could not read any JPhotonPaths from the input file '" << ifname << "'." << endl ;
102 exit(1) ;
103 }
104 cout << "Done reading file. Read " << nread << " paths from it." << endl ;
105 cout << endl ;
106
108
109
110 int nselected = 0 ;
111 cout << "Writing selected paths to '" << ofname << "'." << endl ;
113 writer.
open(ofname.c_str()) ;
115 if( shadow && it->hitsSphere(DOMpos,r) ) continue ;
116
117 ++nselected ;
119 }
121 cout << endl ;
122
123 cout << "Selected " << nselected << " / " << nread
124 << " photon paths." << endl
125 << "Output written to '" << ofname << "'." << endl ;
126}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Data structure for position in three dimensions.
virtual void open(const char *file_name) override
Open file.
virtual void close()
Close file.
virtual bool put(const T &object)=0
Object output.
Utility class to parse command line options.
int read(const int argc, const char *const argv[])
Parse the program's command line options.