Bsoft  2.1.0
Bernard's software package
bzfft.cpp
Go to the documentation of this file.
1 
9 #include "rwmg.h"
10 #include "mg_tomo_rec.h"
11 #include "file_util.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15 
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18 
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: bzfft [options] input.img/input.star [input2.img/input2.star...]",
23 "-----------------------------------------------------------------------",
24 "Assembles slabs and back-transform z-lines for tomogram reconstruction.",
25 " ",
26 "Actions:",
27 "-ytile 50,25 Tile start and size along y dimension (default 0 and y size).",
28 "-rescale -0.1,5.2 Rescale data to average and standard deviation.",
29 "-truncate -0.5,1.2 Truncate data to minimum and maximum after rescaling.",
30 " ",
31 "Parameters:",
32 "-verbose 7 Verbosity of output.",
33 "-datatype u Force writing of a new data type.",
34 "-sampling 1.5,1.5,1.5 Sampling of input images (A/pixel; a single value can be given).",
35 " ",
36 "Output:",
37 "-output new.star Output parameter file name.",
38 "-reconstruction new.map Output image file name.",
39 " ",
40 NULL
41 };
42 
43 int main(int argc, char **argv)
44 {
45  DataType nudatatype(Unknown_Type); // Conversion to new type
46  double avg(0), std(0); // Values for rescaling
47  double cutmin(0), cutmax(0); // Truncation
48  Vector3<double> sam; // Units for the three axes (A/pixel)
49  int ystart(0), ysize(0); // Y tile start and size
50  Bstring recfile; // Output image file
51  Bstring outfile; // Output parameter file
52 
53  int optind;
54  Boption* option = get_option_list(use, argc, argv, optind);
55  Boption* curropt;
56  for ( curropt = option; curropt; curropt = curropt->next ) {
57  if ( curropt->tag == "rescale" ) {
58  if ( curropt->values(avg, std) < 2 )
59  cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
60  if ( std <= 0 )
61  cerr << "-rescale: A positive standard deviation must be specified!" << endl;
62  }
63  if ( curropt->tag == "truncate" ) {
64  if ( curropt->values(cutmin, cutmax) < 2 )
65  cerr << "-truncate: Both min and max must be specified!" << endl;
66  if ( cutmin > cutmax ) swap(cutmin, cutmax);
67  }
68  if ( curropt->tag == "datatype" )
69  nudatatype = curropt->datatype();
70  if ( curropt->tag == "sampling" )
71  sam = curropt->scale();
72  if ( curropt->tag == "ytile" )
73  if ( curropt->values(ystart, ysize) < 2 )
74  cerr << "-ytile: Both start and size must be specified!" << endl;
75  if ( curropt->tag == "output" )
76  outfile = curropt->filename();
77  if ( curropt->tag == "reconstruction" )
78  recfile = curropt->filename();
79  }
80  option_kill(option);
81 
82  if ( verbose && argc < 3 ) {
83  cerr << "Error: No input files given!" << endl;
84  bexit(-1);
85  }
86 
87  double ti = timer_start();
88 
89  Bstring* file_list = NULL;
90  while ( optind < argc ) string_add(&file_list, argv[optind++]);
91  Bstring paramfile(*file_list);
92  Bproject* project = NULL;
93  Breconstruction* rec;
94 
95  if ( file_type(paramfile) == Micrograph ) {
96  project = read_project(file_list);
97  string_kill(file_list);
98  file_list = NULL;
99  for ( rec = project->rec; rec; rec = rec->next )
100  string_add(&file_list, rec->frec);
102  }
103 
104  Bimage* pmap = NULL;
105 
106  if ( ysize > 0 ) {
107  pmap = img_extract_ytile(file_list, ystart, ysize);
108  if ( !pmap ) bexit(-1);
110  if ( std > 0 ) pmap->rescale_to_avg_std(avg, std);
111  if ( cutmin < cutmax ) pmap->truncate_to_min_max(cutmin, cutmax);
112  pmap->change_type(nudatatype);
113  if ( sam.volume() > 0 ) pmap->sampling(sam);
114  write_img(recfile, pmap, 0);
115  } else {
116  pmap = img_backtransform_z_on_disk(file_list, recfile, nudatatype,
117  avg, std, cutmin, cutmax);
118  if ( !pmap ) bexit(-1);
119  if ( sam.volume() > 0 ) pmap->sampling(sam);
120  }
121 
122  Bstring id("1");
123  if ( outfile.length() ) {
124  project = read_project(paramfile);
125  if ( !project->rec ) rec = reconstruction_add(&project->rec, id);
126  else rec = project->rec;
127  rec->frec = recfile;
128  write_project(outfile, project, 0, 0);
130  }
131 
132  delete pmap;
133  string_kill(file_list);
134 
135  if ( verbose & VERB_TIME )
136  timer_report(ti);
137 
138  bexit(0);
139 }
140 
Boption
A class for a command line input option.
Definition: options.h:26
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
Boption::scale
Vector3< double > scale()
Definition: options.h:190
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
file_util.h
Header file for file checking functions.
Bstring
Definition: Bstring.h:29
main
int main(int argc, char **argv)
Definition: bzfft.cpp:43
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
options.h
Header file for option handlers.
img_backtransform_z_lines
int img_backtransform_z_lines(Bimage *p)
The lines along the z-dimensions of a disk-based block is Fourier back-transformed.
Definition: mg_tomo_rec.cpp:1357
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
rwmg.h
Header file for reading and writing micrograph parameters.
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Micrograph
@ Micrograph
Definition: file_util.h:23
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
Bimage::truncate_to_min_max
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
Definition: Bimage_rescale.cpp:331
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
utilities.h
Header file for general utilities.
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
img_extract_ytile
Bimage * img_extract_ytile(Bstring *file_list, int ystart, int ysize)
Extracts a tile from the image with limits in y.
Definition: mg_tomo_rec.cpp:1107
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Vector3::volume
double volume()
Definition: Vector3.h:237
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
img_backtransform_z_on_disk
Bimage * img_backtransform_z_on_disk(Bstring *file_list, Bstring &recfile, DataType datatype, double avg, double std, double cutmin, double cutmax)
The lines along the z-dimensions of a disk-based block is Fourier back-transformed.
Definition: mg_tomo_rec.cpp:1208
use
const char * use[]
Definition: bzfft.cpp:20
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:398
verbose
int verbose
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
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