Commit ef558501 authored by Jason Rhinelander's avatar Jason Rhinelander

Added --list-write/-nowrite options

These can extract the list of simulations that will be used for
analysis (so that these could then be used to generate series files).
parent db0ab83b
......@@ -44,6 +44,8 @@ void Results::addOptions() {
output_desc.add_options()
("output,o", value(output.filename), "If specified, data analysis results will be written to the given filename instead of displayed. The file must not exist unless --overwrite is specified.")
("list-write", value(output.list_filtered_write), "If specified, instead of calculating results, simply list (one-per-line) the input source filenames that will be considered to have writing in every period. (Simulations filtered out by --policy are not included)")
("list-nowrite", value(output.list_filtered_nowrite), "Like --list-write, but lists all simulations omitted because of no writing. (Simulations filtered out by --policy are not included)")
//("dump-write", value(output.dump_writing), "If specified, dump intermediate data of simulations with writing in each stage to the given CSV file. The file must not exist unless --overwrite is specified.")
//("dump-nowrite", value(output.dump_nowriting), "If specified, dump intermediate data of simulations *without* writing in one or more stages to the given CSV file. The file must not exist unless --overwrite is specified.")
//("overwrite,O", value(output.overwrite), "If specified, files given to --output, --dump-write or --dump-nowrite will be overwritten if they exist.")
......
......@@ -77,6 +77,9 @@ class Results : public CmdArgs {
bool overwrite = false; ///< If true, overwrite the above, otherwise throw exception.
bool no_preamble = false; ///< If true, suppress preamble/postamble (HTML/LaTeX only)
bool list_filtered_write = false; ///< If true, show has-writing simulation source files
bool list_filtered_nowrite = false; ///< If true, show non-writing simulation source files
} output;
......
......@@ -50,6 +50,24 @@ int main(int argc, char *argv[]) {
exit(1);
}
std::ofstream f;
if (not args.output.filename.empty()) {
if (not args.output.overwrite and fs::exists(args.output.filename)) {
std::cerr << "Error: `" << args.output.filename << "' already exists; specify a different file or add `--overwrite' option to overwrite\n";
exit(1);
}
try {
f.exceptions(f.failbit | f.badbit);
f.open(args.output.filename, std::ios_base::trunc);
}
catch (std::ios_base::failure &c) {
// Catch, wrap message, and rethrow:
throw std::ios_base::failure("Unable to open " + args.output.filename + ": " + strerror(errno));
}
}
std::ostream &out = args.output.filename.empty() ? std::cout : f;
// The minimum value of books_written that needs to be satisified to count as writing occuring
// during a period:
double writing_threshold = 0.2;
......@@ -84,6 +102,14 @@ int main(int argc, char *argv[]) {
},
shortrun_filter
);
if (args.output.list_filtered_write) {
for (const auto &source : data_writing_always.sourceFiles()) {
out << source << "\n";
}
return 0; // Done, exit.
}
// Observations with no writing under piracy, but with writing in policy (and pre)
TreatmentFilter data_no_piracy_writing(*data, [&](const TreatmentFilter::Properties &p) {
// Require that this data actually has pre, piracy, and policy:
......@@ -124,23 +150,14 @@ int main(int argc, char *argv[]) {
shortrun_filter
);
std::ofstream f;
if (not args.output.filename.empty()) {
if (not args.output.overwrite and fs::exists(args.output.filename)) {
std::cerr << "Error: `" << args.output.filename << "' already exists; specify a different file or add `--overwrite' option to overwrite\n";
exit(1);
}
try {
f.exceptions(f.failbit | f.badbit);
f.open(args.output.filename, std::ios_base::trunc);
}
catch (std::ios_base::failure &c) {
// Catch, wrap message, and rethrow:
throw std::ios_base::failure("Unable to open " + args.output.filename + ": " + strerror(errno));
if (args.output.list_filtered_nowrite) {
for (auto &list : {data_no_pre_writing, data_no_piracy_writing, data_no_pol_writing, data_no_post_writing}) {
for (const auto &source : list.sourceFiles()) {
out << source << "\n";
}
}
return 0; // Done, exit
}
std::ostream &out = args.output.filename.empty() ? std::cout : f;
tabulation_options tabopts(args.format.type, args.format.precision, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment