12 #include "../include/cal_curve.h" 13 #include "../include/uncal_date.h" 14 #include "../include/cal_date.h" 15 #include "../include/uncal_date_list.h" 16 #include "../include/cal_date_list.h" 20 #include <boost/program_options/options_description.hpp> 21 #include <boost/program_options/parsers.hpp> 22 #include <boost/program_options/variables_map.hpp> 30 using namespace boost;
42 for ( i = 0; i < a.size(); i++ )
43 if ( !isdigit ( a[i] ) )
return 1;
56 if( !input_string.empty() ) {
57 char first_char = input_string[0];
58 if (first_char ==
'{' || first_char ==
'['){
60 }
else if (first_char ==
'"' || first_char ==
'\'' || isalpha(first_char)) {
77 unsigned head_length = 0;
78 char first_char = in.front();
79 if (isalpha(first_char)) head_length = 1;
82 std::istringstream iss(in);
84 while (getline(iss, line)) {
88 if (counter >= head_length) {
89 std::stringstream iss(line);
93 std::getline(iss, name_str,
',');
95 std::getline(iss, bp_str,
',');
97 std::getline(iss, std_str,
',');
98 if (!name_str.empty() && !bp_str.empty() && !std_str.empty()) {
101 if (bp > 0 && std > 0) {
102 name_str.erase(
remove( name_str.begin(), name_str.end(),
'\"' ),name_str.end());
103 name_str.erase(
remove( name_str.begin(), name_str.end(),
'\'' ),name_str.end());
104 temp_json[
"bp"] = bp;
105 temp_json[
"std"] = std;
106 return_value[name_str] = temp_json;
119 cout <<
"Invalid file format!" << std::endl;
120 cout <<
"Please use \"DateName\",bp,std" << std::endl;
131 int main(
int argc ,
char **argv) {
138 options_description desc(
139 "\nA tool for 14C calibration from the command line.\n\nAllowed arguments");
142 (
"help,h",
"Produce this help message.")
143 (
"input-file,i", value< vector<string> >(),
144 "Specifies input file.")
145 (
"bp,b", value< vector<int> >(),
147 (
"std,s", value< vector<int> >(),
148 "The standard deviation.")
149 (
"json-string,j", value< vector<string> >(),
150 "Input as as JSON string. Format: {\"bp\": xx, \"std\": xx}")
151 (
"ranges,r",
"calculate sigma ranges (only for json output).")
152 (
"sum",
"calculate sum probability.")
153 (
"output,o", value<string>()->default_value(
"json"),
154 "csv for csv-output, json for json (default).");
156 positional_options_description p;
157 p.add(
"input-file", -1);
164 store(command_line_parser(
165 argc, argv).options(desc).positional(p).run(), vm);
167 }
catch (std::exception &e) {
168 cout << endl << e.what() << endl;
169 cout << desc << endl;
173 if (vm.count(
"help")) {
174 cout <<
"–help specified" << endl;
175 cout << desc << endl;
180 if (vm.count(
"input-file")) {
181 vector<string> inputFilename =
182 vm[
"input-file"].as< vector<string> >();
186 ifstream myfile(inputFilename[0]);
187 if (myfile.is_open()) {
188 while ( getline (myfile, line) ) {
189 file_content += line +
'\n';
193 cout <<
"Unable to open file";
198 j = json::parse(file_content);
204 cout <<
"Invalid file format!";
210 if (vm.count(
"json-string")) {
211 vector<string> json_string =
212 vm[
"json-string"].as< vector<string> >();
213 j = json::parse(json_string[0]);
217 string output_format =
218 vm[
"output"].as<
string>();
221 if (vm.count(
"bp") && vm.count(
"std")) {
224 vm[
"bp"].as< vector<int> >();
226 vm[
"std"].as< vector<int> >();
227 j_temp[
"bp"] = bp[0];
228 j_temp[
"std"] = std[0];
233 bool calc_sigma_ranges =
false;
234 if (vm.count(
"ranges")) {
235 calc_sigma_ranges =
true;
242 for (json::iterator it = j.begin(); it != j.end(); ++it) {
243 my_date =
UncalDate(it.key(), it.value()[
"bp"], it.value()[
"std"]);
248 string filename =
"data/intcal13.14c";
250 my_cal_curve.
import(filename);
257 if (vm.count(
"sum")) {
258 my_cal_date_list.
sum();
263 if (calc_sigma_ranges && output_format !=
"csv") {
264 for (
auto &this_date : my_cal_date_list.
_dates) {
265 this_date.calculate_sigma_ranges();
270 if (output_format ==
"json") {
271 std::cout << my_cal_date_list.
to_json() << std::endl;
272 }
else if (output_format ==
"csv") {
273 std::cout << my_cal_date_list.
to_csv() << std::endl;
275 cout <<
"Invalid output format!";
void push_back(UncalDate date)
int main(int argc, char **argv)
Main function.
Represents a list of uncalibrated dates.
CalDateList calibrate(CalCurve &calcurve)
json csv_input_to_json(string &in)
Converts a csv input string to json.
int validate_numeric_string(string &a)
Method to validate that a string contains numbers only.
Represents a list of calibrated dates.
Represents an uncalibrated date.
Represents the calibration curve.
int check_input_format(string &input_string)
Checks whether a string contains json or csv.