| Bsoft 2.0.5 Bernard's software package

bstar.cpp
Go to the documentation of this file.
1
9 #include "rwstar.h"
10 #include "utilities.h"
11 #include "options.h"
12 #include "timer.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17 // Usage assistance
18 const char* use[] = {
19 " ",
20 "Usage: bstar [options] input.star [input.star]",
21 "----------------------------------------------",
22 "Examines and modifies STAR format files.",
23 " ",
24 "Actions:",
25 "-header 85 List all the header lines limited to the indicated length.",
26 "-split 3 Split the data blocks into individual files, inserting digits before the extension.",
27 "-list time_unit List all items with this STAR tag.",
28 "-delete resolution Delete all items with this STAR tag.",
29 "-blockdelete symmetry Delete all data blocks containing this STAR tag.",
30 "-integerscale select,1,3 Scale and shift all integer items with this STAR tag.",
31 "-floatscale psi,1.5,-5.1 Scale and shift all floating point items with this STAR tag.",
32 " ",
33 "Parameters:",
34 "-verbose 7 Verbosity of output.",
35 "-linelength 120 Output line length (default 100).",
36 " ",
37 "Output:",
38 "-output file.star Output STAR format file.",
39 " ",
40 NULL
41 };
42
43 int main(int argc, char **argv)
44 {
45 // Initialize variables
46 long header(0); // Show header lines using this length
47 int showflag(1); // Default show tags
48 Bstring tag_to_list; // STAR item which should be listed
49 Bstring tag_to_be_deleted; // STAR item which should be deleted
50 Bstring block_to_be_deleted; // STAR item in block which should be deleted
51 Bstring tag_integer; // Integer STAR item which should be scaled and shifted
52 int iscale(1);
53 int ishift(0);
54 Bstring tag_float; // Floating point STAR item which should be scaled and shifted
55 double scale(1);
56 double shift(0);
57 Bstring outstar; // Output STAR format file
58
59 // Initialize the STAR database
60 Bstar* star = init_star();
61 star->line_length = 120; // Set the output line length
62
63 int optind;
64 Boption* option = get_option_list(use, argc, argv, optind);
65 Boption* curropt;
66 Bstring* strarr;
67 for ( curropt = option; curropt; curropt = curropt->next ) {
68 if ( curropt->tag == "header" )
69 if ( ( header = curropt->value.integer() ) < 1 )
70 cerr << "-header: A line length must be specified!" << endl;
71 strarr = curropt->value.split(",");
72 if ( curropt->tag == "split" ) {
73 if ( curropt->value.contains("dat") ) star->split = 9;
74 else if ( ( star->split = curropt->value.integer() ) < 1 )
75 cerr << "-split: An integer must be specified!" << endl;
76 else
77 if ( star->split > 4 ) star->split = 4;
78 }
79 if ( curropt->tag == "linelength" ) {
80 if ( ( star->line_length = curropt->value.integer() ) < 1 )
81 cerr << "-linelength: A line length must be specified!" << endl;
82 else
83 star->line_length = 120;
84 }
85 if ( curropt->tag == "list" ) {
86 showflag = 0;
87 tag_to_list = curropt->value;
88 if ( tag_to_list.length() < 1 )
89 cerr << "-list: A STAR tag must be specified!" << endl;
90 }
91 if ( curropt->tag == "delete" ) {
92 showflag = 0;
93 tag_to_be_deleted = curropt->value;
94 if ( tag_to_be_deleted.length() < 1 )
95 cerr << "-delete: A STAR tag must be specified!" << endl;
96 }
97 if ( curropt->tag == "blockdelete" ) {
98 showflag = 0;
99 block_to_be_deleted = curropt->value;
100 if ( block_to_be_deleted.length() < 1 )
101 cerr << "-blockdelete: A STAR tag must be specified!" << endl;
102 }
103 if ( curropt->tag == "integerscale" ) {
104 showflag = 0;
105 tag_integer = *strarr;
106 if ( tag_integer.length() < 1 )
107 cerr << "-integerscale: A STAR tag must be specified!" << endl;
108 else {
109 if ( strarr->next ) iscale = strarr->next->integer();
110 if ( strarr->next->next ) ishift = strarr->next->next->integer();
111 }
112 }
113 if ( curropt->tag == "floatscale" ) {
114 showflag = 0;
115 tag_float = *strarr;
116 if ( tag_float.length() < 1 )
117 cerr << "-floatscale: A STAR tag must be specified!" << endl;
118 else {
119 if ( strarr->next ) scale = strarr->next->real();
120 if ( strarr->next->next ) shift = strarr->next->next->real();
121 }
122 }
123 if ( curropt->tag == "output" )
124 outstar = curropt->filename();
125 string_kill(strarr);
126 }
127 option_kill(option);
128
129 double ti = timer_start();
130
131 // Read all the STAR format files
132 while ( optind < argc )
133 read_star(argv[optind++], star);
134
135 if ( header )
136 star_list_comments(star, header);
137
138 if ( tag_to_list.length() > 0 )
139 item_list(star, tag_to_list);
140
141 if ( tag_to_be_deleted.length() > 0 )
142 item_delete_all(star, tag_to_be_deleted.c_str());
143
144 if ( block_to_be_deleted.length() > 0 )
145 block_delete(star, block_to_be_deleted);
146
147 if ( tag_integer.length() > 0 )
148 item_integer_scale_shift(star, tag_integer, iscale, ishift);
149
150 if ( tag_float.length() > 0 )
151 item_float_scale_shift(star, tag_float, scale, shift);
152
153 if ( showflag && verbose ) show_tags(star);
154
155 // write an output STAR format file if a name is given
156 if ( outstar.length() ) {
157 star_update_comment(star, argc, argv);
158 write_star(outstar, star);
159 }
160
161 kill_star(star);
162
163 if ( verbose & VERB_TIME )
164 timer_report(ti);
165
166 bexit(0);
167 }
read_star
int read_star(const char *filename, Bstar *star)
Reads paramaters and data into a STAR data base from a list of files.
Definition: rwstar.cpp:224
Bstring::real
double real()
Definition: Bstring.cpp:545
Bstar::split
int split
Definition: rwstar.h:79
item_integer_scale_shift
int item_integer_scale_shift(Bstar *star, Bstring &tag, int iscale, int ishift)
Scales and shifts all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1709
show_tags
int show_tags(Bstar *star)
Prints the list of tags in the STAR data base.
Definition: rwstar.cpp:991
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
write_star
int write_star(const char *filename, Bstar *star)
Writes a STAR data base to one or more STAR format files.
Definition: rwstar.cpp:666
init_star
Bstar * init_star()
Creates a STAR data base.
Definition: rwstar.cpp:111
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bstar
Definition: rwstar.h:78
kill_star
int kill_star(Bstar *star)
Destroys a STAR data base.
Definition: rwstar.cpp:132
block_delete
int block_delete(Bstar *star, Bstring &tag)
Deletes all blocks with a given tag from the STAR data base.
Definition: rwstar.cpp:1662
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
Boption::filename
Bstring filename()
Definition: options.h:85
item_delete_all
int item_delete_all(Bstar *star, const char *tag)
Deletes all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1603
verbose
int verbose
timer.h
Utilities for timing functions.
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bstar::line_length
int line_length
Definition: rwstar.h:80
Bstring::next
Bstring * next
Definition: Bstring.h:31
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
use
const char * use[]
Definition: bstar.cpp:18
main
int main(int argc, char **argv)
Definition: bstar.cpp:43
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
rwstar.h
A header file for STAR format files.
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
item_float_scale_shift
int item_float_scale_shift(Bstar *star, Bstring &tag, float scale, float shift)
Scales and shifts all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1751
Bstring::integer
long integer()
Definition: Bstring.cpp:539
options.h
Header file for option handlers.
star_list_comments
long star_list_comments(Bstar *star, long len)
Lists the command lines in the STAR header.
Definition: rwstar.cpp:907
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
star_update_comment
int star_update_comment(Bstar *star, int n, char **strings)
Puts a set of strings and time in the main comment of the STAR data base.
Definition: rwstar.cpp:880
item_list
int item_list(Bstar *star, Bstring &tag)
Lists all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1571
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bstring::split
Bstring * split()
Definition: Bstring.cpp:597
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760