| Bsoft 2.0.5 Bernard's software package

btube.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "options.h"
11 #include "utilities.h"
12 #include "timer.h"
13
14
15 // Declaration of global variables
16 extern int verbose; // Level of output to the screen
17
18
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: btube [options] input.img output.img",
23 "-------------------------------------------",
24 "Symmetrizes helical tubes with hexagonal lattices.",
25 " ",
26 "Actions:",
27 "-lattice 5,9 Lattice parameters (units along u and v vectors).",
28 "-normalize Normalize symmetrized output, use for maps close to symmetry (default not).",
29 "-background Calculate new background values.",
30 "-rescale -0.1,5.2 Rescale data to average and standard deviation.",
31 " ",
32 "Parameters:",
33 "-verbose 1 Verbosity of output.",
34 "-datatype u Force writing of a new data type.",
35 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
36 "-origin 110,50,44 Origin for tube (default 0,0,0 or from image).",
37 "-constant 95 Lattice constant: distance between units in angstrom (default 1).",
38 "-zlimits 8,47 Range of slices along the helical axis to use (default 0,inf).",
39 "-radius 22 Radial limit for symmetrization in pixels (default from image).",
40 " ",
41 //"Output:",
42 //"-Postscript file.ps Postscript output file name.",
43 //" ",
44 NULL
45 };
46
47 int main(int argc, char **argv)
48 {
49 // Initialize variables
50 int h(0), k(0); // Lattice parameters
51 int calc_background(0); // Flag to calculate background values
52 int norm_flag(0); // Normalization flag
53 double nuavg(0), nustd(0); // For rescaling
54 DataType nudatatype(Unknown_Type); // Conversion to new type
55 int set_sampling(0);
56 Vector3<double> sampling; // Units for the three axes (A/pixel)
57 Vector3<double> origin; // Helix origin
58 int set_origin(0); // Flag to set origin
59 double latconst(1); // Lattice constant
60 int zmin(0), zmax(1000000); // Limits along the helical axis
61 double radius(0); // Radial limit for symmetrization
62
63 int optind;
64 Boption* option = get_option_list(use, argc, argv, optind);
65 Boption* curropt;
66 for ( curropt = option; curropt; curropt = curropt->next ) {
67 if ( curropt->tag == "lattice" )
68 if ( curropt->values(h, k) < 2 )
69 cerr << "-lattice: Both lattice parameters must be specified" << endl;
70 if ( curropt->tag == "normalize" ) norm_flag = 1;
71 if ( curropt->tag == "background" ) calc_background = 1;
72 if ( curropt->tag == "rescale" )
73 if ( curropt->values(nuavg, nustd) < 2 )
74 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
75 if ( curropt->tag == "datatype" )
76 nudatatype = curropt->datatype();
77 if ( curropt->tag == "sampling" ) {
78 sampling = curropt->sampling();
79 set_sampling = 1;
80 }
81 if ( curropt->tag == "origin" ) {
82 if ( curropt->value[0] == 'c' ) {
83 set_origin = 2;
84 } else {
85 origin = curropt->origin();
86 set_origin = 1;
87 }
88 }
89 if ( curropt->tag == "constant" )
90 if ( ( latconst = curropt->value.real() ) < 0.001 )
91 cerr << "-constant: A lattice constant must be specified" << endl;
92 if ( curropt->tag == "zlimits" )
93 if ( curropt->values(zmin, zmax) < 2 )
94 cerr << "-zlimits: Both limits on the helical axis must be specified" << endl;
95 if ( curropt->tag == "radius" )
96 if ( ( radius = curropt->value.real() ) < 0.001 )
97 cerr << "-radius: A radius must be specified" << endl;
98 }
99 option_kill(option);
100
101 double ti = timer_start();
102
103 Bimage* p = read_img(argv[optind++], 1, -1);
104
105 if ( !p ) {
106 cerr << "Error: No input file!" << endl;
107 bexit(-1);
108 }
109
110 if ( set_origin ) {
111 if ( set_origin == 2 ) p->origin(p->size()/2);
112 else p->origin(origin);
113 }
114
115 if ( set_sampling ) p->sampling(sampling);
116
117 if ( calc_background ) p->calculate_background();
118
119 if ( h ) p->tube_symmetrize(h, k, latconst, zmin, zmax, radius, norm_flag);
120
121 if ( optind < argc ) {
122 if ( nustd > 0 ) p->rescale_to_avg_std(nuavg, nustd);
123 p->change_type(nudatatype);
124 p->label(get_cmd_line(argc, argv));
125 write_img(argv[optind], p, 0);
126 }
127
128 delete p;
129
130 if ( verbose & VERB_TIME )
131 timer_report(ti);
132
133 bexit(0);
134 }
135
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bstring::real
double real()
Definition: Bstring.cpp:545
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
verbose
int verbose
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
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::tube_symmetrize
double tube_symmetrize(int h, int k, double latconst, int zmin, int zmax, double radius, int norm_flag=1)
Symmetrizes an image given tubular lattice parameters.
Definition: Bimage_helix.cpp:633
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
main
int main(int argc, char **argv)
Definition: btube.cpp:47
Vector3< double >
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
use
const char * use[]
Definition: btube.cpp:20
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563