| Bsoft 2.0.5 Bernard's software package

options.h
Go to the documentation of this file.
1
9 #include "Bstring.h"
10 //#include "rwimg.h"
11 #include "Vector3.h"
12 #include "View.h"
13 #include "Euler.h"
14 #include "symmetry.h"
15 #include "UnitCell.h"
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
26 class Boption {
27 public:
28 Boption* next;
29 Bstring tag;
30 Bstring value;
31 private:
32 int err;
33 public:
34 Boption(char* arg, char* arg1, const char* use[]) : next(NULL), err(0) {
35 // cout << arg << tab << arg1 << endl;
36 Bstring usetag;
37 for ( int n=0; use[n] != NULL; n++ ) {
38 usetag = use[n];
39 // cout << usetag << endl;
40 if ( usetag[0] == '-' ) {
41 if ( usetag.find(arg, 0) == 0 ) {
42 if ( tag.length() ) {
43 cerr << "Error: Ambiguous option " << arg << endl;
44 err++;
45 } else {
46 tag = usetag.pre(' ').post('-');
47 if ( usetag.post(' ').pre(' ').length() ) value = arg1;
48 if ( verbose & VERB_DEBUG )
49 cout << "DEBUG Boption: usetag=" << tag << " value=" << value << endl;
50 }
51 }
52 }
53 }
54 if ( tag.length() < 1 ) {
55 cerr << "Error: Option " << arg << " is not defined!" << endl;
56 err++;
57 }
58 }
59 /* int verbosity(char* optarg) {
60 Bstring arg(optarg);
61 return verbosity(arg);
62 }
63 int verbosity(Bstring& optarg) {
64 verbose = optarg.integer();
65 Bstring arg = optarg.lower();
66 if ( arg.contains("non") ) verbose |= VERB_NONE;
67 if ( arg.contains("res") ) verbose |= VERB_RESULT;
68 if ( arg.contains("lab") ) verbose |= VERB_LABEL;
69 if ( arg.contains("pro") ) verbose |= VERB_PROCESS;
70 if ( arg.contains("sta") ) verbose |= VERB_STATS;
71 if ( arg.contains("ful") ) verbose |= VERB_FULL;
72 if ( arg.contains("tim") ) verbose |= VERB_TIME;
73 if ( arg.contains("mem") ) verbose |= VERB_MEMORY;
74 if ( arg.contains("deb") ) verbose |= VERB_DEBUG;
75 if ( arg.contains("star") ) verbose |= VERB_DEBUG_STAR;
76 if ( arg.contains("dm") ) verbose |= VERB_DEBUG_DM;
77 return verbose;
78 }*/
79 int errors() {
80 int n(0);
81 Boption* opt;
82 for ( opt = this; opt; opt = opt->next ) n += opt->err;
83 return n;
84 }
85 Bstring filename() {
86 if ( value.length() < 1 ) {
87 cerr << "-" << tag << ": A valid file name must be specified!" << endl;
88 err++;
89 }
90 if ( value.contains(",") ) return value.pre(',');
91 else return value;
92 }
93 DataType datatype() {
94 if ( value.length() < 1 ) {
95 cerr << "-datatype: A data type must be specified!" << endl;
96 err++;
97 }
98 return getdatatype(value[0]);
99 }
100 long integer() {
101 if ( value.length() < 1 ) {
102 cerr << "-" << tag << ": An integer must be specified!" << endl;
103 err++;
104 }
105 return value.integer();
106 }
107 double real() {
108 if ( value.length() < 1 ) {
109 cerr << "-" << tag << ": A real value must be specified!" << endl;
110 err++;
111 }
112 return value.real();
113 }
114 template <typename T1, typename T2>
115 long values(T1& v1, T2& v2) {
116 vector<double> d = value.split_into_doubles(",");
117 if ( d.size() > 0 ) v1 = (T1)d[0];
118 if ( d.size() > 1 ) v2 = (T2)d[1];
119 return d.size();
120 }
121 template <typename T1, typename T2, typename T3>
122 long values(T1& v1, T2& v2, T3& v3) {
123 vector<double> d = value.split_into_doubles(",");
124 if ( d.size() > 0 ) v1 = (T1)d[0];
125 if ( d.size() > 1 ) v2 = (T2)d[1];
126 if ( d.size() > 2 ) v3 = (T3)d[2];
127 return d.size();
128 }
129 template <typename T1, typename T2, typename T3, typename T4>
130 long values(T1& v1, T2& v2, T3& v3, T4& v4) {
131 vector<double> d = value.split_into_doubles(",");
132 if ( d.size() > 0 ) v1 = (T1)d[0];
133 if ( d.size() > 1 ) v2 = (T2)d[1];
134 if ( d.size() > 2 ) v3 = (T3)d[2];
135 if ( d.size() > 3 ) v4 = (T4)d[3];
136 return d.size();
137 }
138 double fill(int& fill_type) {
139 double f = value.real();
140 fill_type = FILL_USER;
141 Bstring arg = value.lower();
142 if ( arg[0] == 'a' ) fill_type = FILL_AVERAGE;
143 if ( arg[0] == 'b' ) fill_type = FILL_BACKGROUND;
144 if ( arg.contains("mi") ) fill_type = FILL_MIN;
145 if ( arg.contains("ma") ) fill_type = FILL_MAX;
146 return f;
147 }
148 Vector3<double> vector3() {
149 Vector3<double> vec;
150 vector<double> d = value.split_into_doubles(",");
151 if ( d.size() < 2 ) {
152 cerr << "-" << tag << ": At least 2 values for the vector must be specified!" << endl;
153 err++;
154 }
155 for ( unsigned long i=0; i<d.size(); i++ ) vec[i] = d[i];
156 return vec;
157 }
158 Vector3<double> normalized_vector3() {
159 Vector3<double> vec = vector3();
160 vec.normalize();
161 return vec;
162 }
163 Vector3<long> size() {
164 Vector3<long> v(1,1,1);
165 vector<double> d = value.split_into_doubles(",");
166 if ( d.size() < 1 ) {
167 cerr << "-size: At least one size value must be specified!" << endl;
168 err++;
169 }
170 for ( unsigned long i=0; i<d.size(); i++ ) v[i] = (long) (d[i] + 0.5);
171 if ( d.size() < 2 ) v[2] = v[1] = v[0];
172 else if ( d.size() < 3 ) v[2] = 1;
173 return v;
174 }
175 Vector3<long> size2() {
176 Vector3<long> v = size();
177 v[2] = 1;
178 return v;
179 }
180 Vector3<double> origin() {
181 Vector3<double> ori;
182 vector<double> d = value.split_into_doubles(",");
183 if ( d.size() < 1 ) {
184 cerr << "-origin: At least one origin value must be specified!" << endl;
185 err++;
186 }
187 for ( unsigned long i=0; i<d.size(); i++ ) ori[i] = d[i];
188 return ori;
189 }
190 Vector3<double> scale() {
191 Vector3<double> sc;
192 vector<double> d = value.split_into_doubles(",");
193 if ( d.size() < 1 ) {
194 cerr << "-scale: At least one scale value must be specified!" << endl;
195 err++;
196 }
197 for ( unsigned long i=0; i<d.size(); i++ ) sc[i] = d[i];
198 if ( d.size() < 2 ) sc[2] = sc[1] = sc[0];
199 else if ( d.size() < 3 ) sc[2] = 1;
200 return sc;
201 }
202 Vector3<double> sampling() {
203 Vector3<double> sam(1,1,1);
204 vector<double> d = value.split_into_doubles(",");
205 if ( d.size() < 1 ) {
206 cerr << "-sampling: At least one pixel size value must be specified!" << endl;
207 err++;
208 }
209 for ( unsigned long i=0; i<d.size(); i++ ) sam[i] = d[i];
210 if ( d.size() < 2 ) sam[2] = sam[1] = sam[0];
211 return sam;
212 }
213 template <typename T1, typename T2>
214 long box(Vector3<T1>& st, Vector3<T2>& sz) {
215 long i, n(0);
216 vector<double> d = value.split_into_doubles(",");
217 n = d.size();
218 if ( n < 4 ) {
219 cerr << "-" << tag << ": At least one size value must be specified!" << endl;
220 err++;
221 }
222 for ( i=0; i<n && i<3; i++ ) st[i] = (T1) d[i];
223 for ( i=3; i<n && i<6; i++ ) sz[i-3] = (T2) d[i];
224 if ( n < 4 ) sz[2] = sz[1] = sz[0];
225 else if ( n < 5 ) sz[2] = 1;
226 if ( sz.volume() < 1 ) sz = sz.max(1);
227 return n;
228 }
229 template <typename T1, typename T2>
230 long box(vector<T1>& st, vector<T2>& sz) {
231 long i, n(0);
232 vector<double> d = value.split_into_doubles(",");
233 n = d.size();
234 if ( n < 4 ) {
235 cerr << "-" << tag << ": At least one size value must be specified!" << endl;
236 err++;
237 }
238 for ( i=0; i<n && i<3; i++ ) st[i] = (T1) d[i];
239 for ( i=3; i<n && i<6; i++ ) sz[i-3] = (T2) d[i];
240 if ( n < 4 ) sz[2] = sz[1] = sz[0];
241 else if ( n < 5 ) sz[2] = 1;
242 if ( volume(sz) < 1 ) sz = vecmax(sz, 1);
243 return n;
244 }
245 Bstring symmetry_string() {
246 if ( value.length() < 1 ) {
247 cerr << "-symmetry: A symmetry must be specified!" << endl;
248 err++;
249 }
250 return symmetry_clean_pointgroup(value);
251 }
252 Bsymmetry* symmetry() {
253 if ( value.length() < 1 ) {
254 cerr << "-symmetry: A symmetry must be specified!" << endl;
255 err++;
256 }
257 return init_point_group_symmetry(value);
258 }
259 View view() {
260 View v;
261 vector<double> d = value.split_into_doubles(",");
262 if ( d.size() < 3 ) {
263 cerr << "-View: At least 3 values for the vector must be specified!" << endl;
264 err++;
265 }
266 for ( unsigned long i=0; i<d.size(); i++ ) v[i] = d[i];
267 v[3] *= M_PI/180;
268 v.normalize();
269 return v;
270 }
271 Euler euler() {
272 Euler e;
273 vector<double> d = value.split_into_doubles(",");
274 if ( d.size() < 3 ) {
275 cerr << "-Euler: All three angles must be specified!" << endl;
276 err++;
277 }
278 for ( long i=0; i<3; i++ ) e[i] = d[i]*M_PI/180.0;
279 return e;
280 }
281 double mass() {
282 double m = value.real();
283 if ( value.contains("k") || value.contains("K") )
284 m *= 1e3;
285 else if ( value.contains("m") || value.contains("M") )
286 m *= 1e6;
287 else if ( value.contains("g") || value.contains("G") )
288 m *= 1e9;
289 return m;
290 }
291 UnitCell unit_cell() {
292 UnitCell uc(0,0,0,M_PI_2,M_PI_2,M_PI_2);
293 vector<double> d = value.split_into_doubles(",");
294 if ( d.size() < 6 ) {
295 cerr << "-unitcell: All 6 values for the unit cell must be specified!" << endl;
296 err++;
297 }
298 for ( unsigned long i=0; i<d.size(); i++ ) uc[i] = d[i];
299 uc.degrees_to_radians();
300 uc.set_angle_range();
301 return uc;
302 }
303 int ctf_action() {
304 int action(0);
305 if ( value.length() < 1 )
306 cerr << "-action: An action must be specified!" << endl;
307 else {
308 action = value.integer();
309 value = value.lower();
310 if ( value.contains("fli") ) action = 1;
311 if ( value.contains("app") ) action = 2;
312 if ( value.contains("cor") ) action = 3;
313 if ( value.contains("wie") ) action = 4;
314 if ( value.contains("bas") ) action = 5;
315 if ( value.contains("baseline2") ) action = 6;
316 if ( value.contains("basef") ) action = 7;
317 if ( value.contains("basec") ) action = 8;
318 if ( value.contains("env") ) action = 9;
319 if ( value.contains("app") &&
320 value.contains("env") ) action = 10;
321 if ( value.contains("prep") ) action = 11;
322 if ( value.contains("fit") ) action = 12;
323 if ( value.contains("prep") &&
324 value.contains("fit") ) action = 13;
325 }
326 return action;
327 }
328 } ;
329
330 // Function prototypes
331 Boption* get_option_list(const char* use[], int argc, char* argv[], int& optind);
332 int option_kill(Boption* option);
333 int get_option_verbose(char* optarg);
334 int get_option_verbose(Bstring& optarg);
335 double get_option_mass(Bstring& optarg);
336
Boption::unit_cell
UnitCell unit_cell()
Definition: options.h:291
M_PI_2
#define M_PI_2
Definition: utilities.h:62
UnitCell
Definition: UnitCell.h:22
Bstring::real
double real()
Definition: Bstring.cpp:545
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
getdatatype
DataType getdatatype(char letter)
Get the data type indicated by a single letter code.
Definition: utilities.cpp:288
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
Vector3::normalize
double normalize()
Definition: Vector3.h:236
Boption::euler
Euler euler()
Definition: options.h:271
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:394
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Euler
Definition: Euler.h:28
Boption::normalized_vector3
Vector3< double > normalized_vector3()
Definition: options.h:158
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:245
Boption::Boption
Boption(char *arg, char *arg1, const char *use[])
Definition: options.h:34
symmetry.h
Header file for general symmetry functions.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Bstring::find
long find(const Bstring &s)
Definition: Bstring.h:103
Boption::tag
Bstring tag
Definition: options.h:29
Boption::real
double real()
Definition: options.h:107
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
Bstring::length
long length() const
Definition: Bstring.cpp:263
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
get_option_verbose
int get_option_verbose(char *optarg)
Sets the verbose option.
Definition: options.cpp:143
verbose
int verbose
Boption::filename
Bstring filename()
Definition: options.h:85
UnitCell::set_angle_range
void set_angle_range()
Definition: UnitCell.h:48
Vector3::max
Type max()
Definition: Vector3.h:175
Boption::size
Vector3< long > size()
Definition: options.h:163
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Boption::mass
double mass()
Definition: options.h:281
M_PI
#define M_PI
Definition: utilities.h:59
Boption::integer
long integer()
Definition: options.h:100
Boption::box
long box(Vector3< T1 > &st, Vector3< T2 > &sz)
Definition: options.h:214
Boption::view
View view()
Definition: options.h:259
Boption
A class for a command line input option.
Definition: options.h:26
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:381
FILL_MAX
#define FILL_MAX
Definition: utilities.h:176
Boption::size2
Vector3< long > size2()
Definition: options.h:175
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
Boption::scale
Vector3< double > scale()
Definition: options.h:190
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
use
const char * use[]
Definition: b3v.cpp:19
Boption::box
long box(vector< T1 > &st, vector< T2 > &sz)
Definition: options.h:230
View::normalize
double normalize()
Definition: View.h:106
FILL_USER
#define FILL_USER
Definition: utilities.h:172
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Bsymmetry
Definition: symmetry.h:38
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::values
long values(T1 &v1, T2 &v2, T3 &v3)
Definition: options.h:122
volume
T volume(vector< T > v)
Definition: Vector3.h:545
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
UnitCell::degrees_to_radians
void degrees_to_radians()
Definition: UnitCell.h:54
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
UnitCell.h
Header file for unit cell functions.
Vector3< double >
vecmax
vector< T1 > vecmax(vector< T1 > v1, vector< T2 > v2)
Definition: Vector3.h:589
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:308
Bstring.h
Header file for the string class.
Vector3.h
Class for 3-value vectors.
View
Definition: View.h:26
Boption::ctf_action
int ctf_action()
Definition: options.h:303
Boption::errors
int errors()
Definition: options.h:79
FILL_MIN
#define FILL_MIN
Definition: utilities.h:175
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
View.h
View object.
Vector3::volume
double volume()
Definition: Vector3.h:235
Boption::values
long values(T1 &v1, T2 &v2, T3 &v3, T4 &v4)
Definition: options.h:130
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
Euler.h
Euler object.
get_option_mass
double get_option_mass(Bstring &optarg)
Returns the adjusted mass based on the added character.
Definition: options.cpp:175
symmetry_clean_pointgroup
Bstring symmetry_clean_pointgroup(Bstring &symmetry_string)
Corrects an existing point group string.
Definition: symmetry.cpp:226