Bsoft  2.1.0
Bernard's software package
bmg2imod.cpp
Go to the documentation of this file.
1 
10 #include "mg_processing.h"
11 #include "mg_img_proc.h"
12 #include "mg_tomography.h"
13 #include "rwmg.h"
14 #include "rwmgIMOD.h"
15 #include "rwimg.h"
16 #include "linked_list.h"
17 #include "utilities.h"
18 #include "options.h"
19 #include "timer.h"
20 
21 // Declaration of global variables
22 extern int verbose; // Level of output to the screen
23 
25 
26 // Usage assistance
27 const char* use[] = {
28 " ",
29 "Usage: bmg2imod [options] input.mrc input.xf input.tlt input.xyz",
30 "----------------------------------------------------------------",
31 "Converts between IMOD files and a micrograph parameter file.",
32 " ",
33 "Actions:",
34 "-topif Flag to convert the image file to multi-image PIF (default not).",
35 " ",
36 "Parameters:",
37 "-verbose 7 Verbosity of output.",
38 "-sampling 1.5 Sampling (A/pixel).",
39 " ",
40 "Output:",
41 "-output file.star Output micrograph parameter file.",
42 "-imod file.xf Output IMOD parameter files.",
43 " ",
44 NULL
45 };
46 
47 
48 int main(int argc, char** argv)
49 {
50  // Initializing variables
51  int flag(0); // Flag to rewrite the image file
52  Vector3<double> sam; // A/pixel
53  Bstring outfile; // Output parameter file
54  Bstring imodfile; // IMOD output parameter file
55 
56  int optind;
57  Boption* option = get_option_list(use, argc, argv, optind);
58  Boption* curropt;
59  for ( curropt = option; curropt; curropt = curropt->next ) {
60  if ( curropt->tag == "topif" ) flag = 1;
61  if ( curropt->tag == "sampling" )
62  sam = curropt->scale();
63  if ( curropt->tag == "output" )
64  outfile = curropt->filename();
65  if ( curropt->tag == "imod" )
66  imodfile = curropt->filename();
67  }
68  option_kill(option);
69 
70  double ti = timer_start();
71 
72  // Read all the parameter files
73  Bstring* file_list = NULL;
74  while ( optind < argc ) string_add(&file_list, argv[optind++]);
75  if ( !file_list ) {
76  cerr << "Error: No parameter files specified!" << endl;
77  bexit(-1);
78  }
79 
80  Bproject* project = read_project(file_list, flag);
81 
82  string_kill(file_list);
83 
84  if ( project == NULL ) {
85  cerr << "Error: No project generated!" << endl;
86  bexit(-1);
87  }
88 
89  if ( sam[0] > 0.1 )
91 
92  if ( outfile.length() )
93  write_project(outfile, project, 0, 0);
94 
95  if ( imodfile.length() )
96  write_project_imod(imodfile, project);
97 
99 
100  if ( verbose & VERB_TIME )
101  timer_report(ti);
102 
103  bexit(0);
104 }
105 
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
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
verbose
int verbose
Bstring
Definition: Bstring.h:29
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.
use
const char * use[]
Definition: bmg2imod.cpp:27
rwmgIMOD.h
Converts between IMOD files and a micrograph parameter file.
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
rwmg.h
Header file for reading and writing micrograph parameters.
project_set_mg_pixel_size
int project_set_mg_pixel_size(Bproject *project, Vector3< double > pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:1997
main
int main(int argc, char **argv)
Definition: bmg2imod.cpp:48
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
mg_img_proc.h
Header file for image processing from micrograph structures.
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
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.
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
rwimg.h
Header file for 2D and 3D image I/O.
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
mg_processing.h
Header file for micrograph processing.
linked_list.h
Header file for generalized linked list functions.
Boption::filename
Bstring filename()
Definition: options.h:85
write_project_imod
int write_project_imod(Bstring &imodfile, Bproject *project)
Creates IMOD parameter files from a project structure.
Definition: rwmgIMOD.cpp:452
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
write_IMOD_parameters
int write_IMOD_parameters(Bstring &imodfile, Bproject *project)
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
mg_tomography.h
Header file for single particle image processing in Bsoft.