diff --git a/include/argparse.h b/include/argparse.h index 16ea78b7828..152e01ccf53 100644 --- a/include/argparse.h +++ b/include/argparse.h @@ -216,7 +216,7 @@ class ArgumentParser { template T retrieve(const String& name) { String unstripped = unstrip(name); - if (index.count(unstripped) == 0) logFatal(1) << "'" << unstripped << "' is not a known argument"; + if (index.count(unstripped) == 0) fs::fatal() << "'" << unstripped << "' is not a known argument"; size_t N = index[unstripped]; T retrieved{}; // try to cast the arguments @@ -232,7 +232,7 @@ class ArgumentParser { fulltype = "std::vector<" + arguments[N].typeName() + ">"; sentence_starter = "These inputs are"; } - logFatal(1) << "invalid cast of argument '" << name << "'. " << sentence_starter << " of type '" + fs::fatal() << "invalid cast of argument '" << name << "'. " << sentence_starter << " of type '" << arguments[N].typeName() << "' and should be retrieved via " << term::dim() << "retrieve<" << fulltype << ">(\"" << name << "\")" << term::reset() << ". " << "To change the expected type, modify the call to " diff --git a/include/log.h b/include/log.h index 2fba97eb2fb..2c1a89c18dd 100644 --- a/include/log.h +++ b/include/log.h @@ -77,10 +77,6 @@ namespace fs { } -// temporary definitions -#define logWarning fs::warning() -#define logFatal(ret) fs::fatal(ret) - // old c-style error functions void ErrorExit(int ecode, const char *fmt, ...); void ErrorPrintf(int ecode, const char *fmt, ...); diff --git a/mri_refine_seg/mri_refine_seg.cpp b/mri_refine_seg/mri_refine_seg.cpp index ee0d68d8419..88c96a696f2 100644 --- a/mri_refine_seg/mri_refine_seg.cpp +++ b/mri_refine_seg/mri_refine_seg.cpp @@ -182,7 +182,7 @@ int main(int argc, char **argv) { // load input std::string segname = parser.retrieve("in"); MRI *seg = MRIread(segname.c_str()); - if (!seg) logFatal(1) << "could not read input volume " << segname; + if (!seg) fs::fatal() << "could not read input volume " << segname; MRI *orig_seg = MRIcopy(seg, NULL); // allocate buffer for label mask (used for efficient cluster-finding) diff --git a/mri_seg_overlap/mri_seg_overlap.cpp b/mri_seg_overlap/mri_seg_overlap.cpp index d66ddd11ccf..447a520ff1c 100644 --- a/mri_seg_overlap/mri_seg_overlap.cpp +++ b/mri_seg_overlap/mri_seg_overlap.cpp @@ -65,15 +65,15 @@ int main(int argc, char **argv) std::string seg1_fname = parser.retrieve("seg1"); MRI *seg1 = MRIread(seg1_fname.c_str()); - if (!seg1) logFatal(1) << "could not read input volume " << seg1; + if (!seg1) fs::fatal() << "could not read input volume " << seg1; std::string seg2_fname = parser.retrieve("seg2"); MRI *seg2 = MRIread(seg2_fname.c_str()); - if (!seg2) logFatal(1) << "could not read input volume " << seg2; + if (!seg2) fs::fatal() << "could not read input volume " << seg2; // check input dimensions - if (MRIdimMismatch(seg1, seg2, 0)) logFatal(1) << "input volumes must have matching dimensions"; - if (seg1->nframes != seg2->nframes) logFatal(1) << "input volumes must have the same number of frames"; + if (MRIdimMismatch(seg1, seg2, 0)) fs::fatal() << "input volumes must have matching dimensions"; + if (seg1->nframes != seg2->nframes) fs::fatal() << "input volumes must have the same number of frames"; // ------ retrieve user options ------ @@ -86,7 +86,7 @@ int main(int argc, char **argv) for (auto const &str : parser.retrieve>("measures")) { if (str == "dice") measures.push_back(OverlapMeasure("dice", &computeDice)); else if (str == "jaccard") measures.push_back(OverlapMeasure("jaccard", &computeJaccard)); - else logFatal(1) << "unknown measure '" << str << "'... options are: dice, jaccard"; + else fs::fatal() << "unknown measure '" << str << "'... options are: dice, jaccard"; } } else { // by default, only report dice scores @@ -95,11 +95,11 @@ int main(int argc, char **argv) // a few sanity checks on the user input if (parser.exists("labelfile") && parser.exists("labels")) { - logFatal(1) << "can't use both the --labels and --labelfile options together"; + fs::fatal() << "can't use both the --labels and --labelfile options together"; } else if (parser.exists("names") && !parser.exists("labels")) { - logFatal(1) << "the --names option must be used along with the --labels option"; + fs::fatal() << "the --names option must be used along with the --labels option"; } else if (parser.exists("seg") && (parser.exists("labelfile") || parser.exists("labels"))) { - logFatal(1) << "can't specify --seg in addition to a custom label list"; + fs::fatal() << "can't specify --seg in addition to a custom label list"; } // check if user wants to ignore label names @@ -116,7 +116,7 @@ int main(int argc, char **argv) // user provided custom label names as well std::vector names = parser.retrieve>("names"); if (names.size() != labels.size()) { - logFatal(1) << "number of label names (" << labelnames.size() << ") must match " + fs::fatal() << "number of label names (" << labelnames.size() << ") must match " "the number of specified labels (" << labels.size() << ")"; } for (unsigned int i = 0 ; i < labels.size() ; i++) labelnames[labels[i]] = names[i]; @@ -124,7 +124,7 @@ int main(int argc, char **argv) } else if (parser.exists("labelfile")) { // user specified labels via a file - assume lookup-table format LookupTable lut(parser.retrieve("labelfile")); - if (lut.empty()) logFatal(1) << "provided label file contains no valid labels"; + if (lut.empty()) fs::fatal() << "provided label file contains no valid labels"; labels = lut.labels(); if (lut.hasNameInfo()) for (int i : labels) labelnames[i] = lut[i].name; } else if (parser.exists("seg")) { @@ -190,13 +190,13 @@ int main(int argc, char **argv) } // sanity check to make sure the label list isn't empty - if (labels.empty()) logFatal(1) << "no matching labels to report on"; + if (labels.empty()) fs::fatal() << "no matching labels to report on"; // determine default label names (if not already known) via FreeSurferColorLUT if (reportNames && labelnames.empty()) { LookupTable lut(std::string(std::getenv("FREESURFER_HOME")) + "/FreeSurferColorLUT.txt"); if (lut.empty()) { - logWarning << "can't load default FreeSurferColorLUT - is FREESURFER_HOME set?"; + fs::warning() << "can't load default FreeSurferColorLUT - is FREESURFER_HOME set?"; reportNames = false; } else if (lut.hasNameInfo()) { for (int l : labels) labelnames[l] = lut[l].name; diff --git a/mris_annot_diff/mris_annot_diff.cpp b/mris_annot_diff/mris_annot_diff.cpp index 90a029c5622..d00576fd59e 100644 --- a/mris_annot_diff/mris_annot_diff.cpp +++ b/mris_annot_diff/mris_annot_diff.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) // compare lengths int length = annot1.size(); - if (length != annot2.size()) logFatal(1) << "annotation sizes (" << length << " and " << annot2.size() << ") do not match"; + if (length != annot2.size()) fs::fatal() << "annotation sizes (" << length << " and " << annot2.size() << ") do not match"; // diff labels int ndiffs = 0; @@ -27,6 +27,6 @@ int main(int argc, char *argv[]) if (annot1[i] != annot2[i]) ndiffs++; } - if (ndiffs > 0) logFatal(1) << "found " << ndiffs << " differences between annotations"; + if (ndiffs > 0) fs::fatal() << "found " << ndiffs << " differences between annotations"; exit(0); } diff --git a/mris_defects_pointset/mris_defects_pointset.cpp b/mris_defects_pointset/mris_defects_pointset.cpp index 63f9726ebc4..1697694495b 100644 --- a/mris_defects_pointset/mris_defects_pointset.cpp +++ b/mris_defects_pointset/mris_defects_pointset.cpp @@ -39,16 +39,16 @@ int main(int argc, char **argv) std::string surfpath = parser.retrieve("surf"); std::cout << "Reading in surface " << surfpath << std::endl; MRIS *surf = MRISread(surfpath.c_str()); - if (!surf) logFatal(1) << "could not read surface"; + if (!surf) fs::fatal() << "could not read surface"; // load defect overlay std::string defectpath = parser.retrieve("defects"); std::cout << "Reading in defect segmentation " << defectpath << std::endl; MRI *overlay = MRIread(defectpath.c_str()); - if (!overlay) logFatal(1) << "could not read defect segmentation"; + if (!overlay) fs::fatal() << "could not read defect segmentation"; if (overlay->width != surf->nvertices) { - logFatal(1) << "error: defect overlay (" << overlay->width << " points) " + fs::fatal() << "error: defect overlay (" << overlay->width << " points) " << "does not match surface (" << surf->nvertices << " vertices)"; } @@ -61,7 +61,7 @@ int main(int argc, char **argv) std::string labelpath = parser.retrieve("label"); std::cout << "Reading in label " << labelpath << std::endl; LABEL *label = LabelRead(NULL, labelpath.c_str()); - if (!label) logFatal(1) << "could not read label"; + if (!label) fs::fatal() << "could not read label"; // set values outside of the label to 0 MRI *tmp = MRISlabel2Mask(surf, label, NULL); for (int v = 0 ; v < surf->nvertices ; v++) { diff --git a/mris_resample/mris_resample.cpp b/mris_resample/mris_resample.cpp index 0652f276817..5db7b12aeff 100644 --- a/mris_resample/mris_resample.cpp +++ b/mris_resample/mris_resample.cpp @@ -173,8 +173,8 @@ IoParams::parse(int ac, char** av) annotation = false; - if (strAnnotationOut.empty() && !strAnnotationIn.empty()) logFatal(1) << "missing --annot_out flag"; - if (!strAnnotationOut.empty() && strAnnotationIn.empty()) logFatal(1) << "missing --annot_in flag"; + if (strAnnotationOut.empty() && !strAnnotationIn.empty()) fs::fatal() << "missing --annot_out flag"; + if (!strAnnotationOut.empty() && strAnnotationIn.empty()) fs::fatal() << "missing --annot_in flag"; if (!strAnnotationOut.empty() && !strAnnotationIn.empty()) { annotation = true; diff --git a/utils/annotation.cpp b/utils/annotation.cpp index ea3422b9ffe..d8172997888 100644 --- a/utils/annotation.cpp +++ b/utils/annotation.cpp @@ -85,7 +85,7 @@ int print_annotation_colortable(FILE *fp) std::vector readAnnotationIntoVector(const std::string& filename) { FILE *file = fopen(filename.c_str(), "r"); - if (!file) logFatal(1) << "could not open " << filename; + if (!file) fs::fatal() << "could not open " << filename; std::map annotmap; int num = freadInt(file); diff --git a/utils/argparse.cpp b/utils/argparse.cpp index 8183feae998..200940c57f1 100644 --- a/utils/argparse.cpp +++ b/utils/argparse.cpp @@ -13,11 +13,11 @@ static std::string verifyOption(const std::string& name) { if (name.empty()) - logFatal(1) << "invalid argument configuration. Argument names must not be empty"; + fs::fatal() << "invalid argument configuration. Argument names must not be empty"; if ((name.size() == 2 && name[0] != '-') || name.size() == 3) - logFatal(1) << "invalid argument configuration for '" << name << "'. Short names must begin with '-'"; + fs::fatal() << "invalid argument configuration for '" << name << "'. Short names must begin with '-'"; if (name.size() > 3 && (name[0] != '-' || name[1] != '-')) - logFatal(1) << "invalid argument configuration for '" << name << "'. Multi-character names must begin with '--'"; + fs::fatal() << "invalid argument configuration for '" << name << "'. Multi-character names must begin with '--'"; return name; } @@ -101,11 +101,11 @@ ArgumentParser::Argument::Argument(const ArgumentParser::String& _short_name, co // check for illogical option flags if ((min_args == 0) && (argtype != ArgType::Bool)) { - logFatal(1) << "invalid argument configuration for '" << canonicalName() << "'. " + fs::fatal() << "invalid argument configuration for '" << canonicalName() << "'. " << "Option flags that accept no input must be of type ArgType::Bool"; } if ((min_args == 0) && required) { - logFatal(1) << "invalid argument configuration for '" << canonicalName() << "'. " + fs::fatal() << "invalid argument configuration for '" << canonicalName() << "'. " << "Required flags must accept at least one input"; } } @@ -115,11 +115,11 @@ ArgumentParser::Argument::Argument(const ArgumentParser::String& _short_name, co void ArgumentParser::Argument::validate() { if (positional && consumed < min_args) - logFatal(2) << "not enough positional arguments supplied"; + fs::fatal(2) << "not enough positional arguments supplied"; if (fixed && fixed_nargs != consumed) - logFatal(2) << "not enough inputs passed to option '" << canonicalName() << "' (expected " << fixed_nargs << ")"; + fs::fatal(2) << "not enough inputs passed to option '" << canonicalName() << "' (expected " << fixed_nargs << ")"; if (!fixed && variable_nargs == '+' && consumed < 1) - logFatal(2) << "option '" << canonicalName() << "' requires at least one input"; + fs::fatal(2) << "option '" << canonicalName() << "' requires at least one input"; } @@ -216,7 +216,7 @@ void ArgumentParser::parse(size_t ac, char** av) if (index.count(future) == 0) args_following++; } if (arguments[index[element]].min_args > args_following) { - logFatal(2) << "not enough inputs supplied to '" << element << "'"; + fs::fatal(2) << "not enough inputs supplied to '" << element << "'"; } } } @@ -238,7 +238,7 @@ void ArgumentParser::parse(size_t ac, char** av) // if so, let's get the next set of positional arguments posidx++; if (posidx >= positionals.size()) { - logFatal(2) << "unexpected argument '" << element << "'"; + fs::fatal(2) << "unexpected argument '" << element << "'"; } else { active = positionals[posidx]; } @@ -284,7 +284,7 @@ void ArgumentParser::parse(size_t ac, char** av) } } } catch (...) { - logFatal(2) << "input '" << element << "' cannot be converted to expected type (" << active.typeName() << ")"; + fs::fatal(2) << "input '" << element << "' cannot be converted to expected type (" << active.typeName() << ")"; } variables[N].exists = true; active.consumed++; @@ -327,7 +327,7 @@ void ArgumentParser::parse(size_t ac, char** av) for (ArgumentVector::const_iterator it = arguments.begin(); it != arguments.end(); ++it) { Argument arg = *it; if (arg.required && !exists(arg.canonicalName())) { - logFatal(2) << "missing required input '" << arg.canonicalName() << "'"; + fs::fatal(2) << "missing required input '" << arg.canonicalName() << "'"; } } } @@ -351,7 +351,7 @@ bool ArgumentParser::exists(const String& name) { // first check if name is a valid argument key String unstripped = unstrip(name); - if (index.count(unstripped) == 0) logFatal(1) << "'" << unstripped << "' is not a known argument"; + if (index.count(unstripped) == 0) fs::fatal() << "'" << unstripped << "' is not a known argument"; return variables[index[unstripped]].exists; } @@ -369,7 +369,7 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg) case ArgType::Float : variables.push_back(float(0)); break; case ArgType::Bool : variables.push_back(false); break; case ArgType::String : variables.push_back(String()); break; - default : logFatal(1) << "unknown argument type for '" << arg.canonicalName() << "'"; + default : fs::fatal() << "unknown argument type for '" << arg.canonicalName() << "'"; } } else { switch(arg.argtype) { @@ -377,7 +377,7 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg) case ArgType::Float : variables.push_back(FloatVector()); break; case ArgType::Bool : variables.push_back(std::vector()); break; case ArgType::String : variables.push_back(StringVector()); break; - default : logFatal(1) << "unknown argument type for '" << arg.canonicalName() << "'"; + default : fs::fatal() << "unknown argument type for '" << arg.canonicalName() << "'"; } } @@ -385,7 +385,7 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg) for (IndexMap::iterator it = index.begin(); it != index.end(); it++) { String stripped = strip(it->first); if (stripped == strip(arg.short_name) || stripped == strip(arg.name)) { - logFatal(1) << "invalid argument configuration. '" << arg.canonicalName() << "' is used twice"; + fs::fatal() << "invalid argument configuration. '" << arg.canonicalName() << "' is used twice"; } } @@ -393,7 +393,7 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg) if (!arg.fixed) { if (arg.positional) { if (variable_positional) { - logFatal(1) << "invalid argument configuration for '" << arg.canonicalName() << "'. " + fs::fatal() << "invalid argument configuration for '" << arg.canonicalName() << "'. " << "Two positional arguments cannot both have a variable amount of inputs, " << "as this could lead to an undefined boundary between the two"; } @@ -402,7 +402,7 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg) variable_flag = true; } if (variable_positional && variable_flag) { - logFatal(1) << "invalid argument configuration for '" << arg.canonicalName() << "'. " + fs::fatal() << "invalid argument configuration for '" << arg.canonicalName() << "'. " << "A positional argument and flagged argument cannot both have a variable " << "amount of inputs, as this could lead to an undefined boundary between the two"; } @@ -411,4 +411,4 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg) // add argument name to the index if (!arg.short_name.empty()) index[arg.short_name] = N; if (!arg.name.empty()) index[arg.name] = N; -} \ No newline at end of file +} diff --git a/utils/mri.cpp b/utils/mri.cpp index 593af5180c6..d7e91a8d65a 100644 --- a/utils/mri.cpp +++ b/utils/mri.cpp @@ -99,11 +99,11 @@ extern int errno; MRI::Shape::Shape(const std::vector& shape) { // validate dimensions int dims = shape.size(); - if ((dims != 3) && (dims != 4)) logFatal(1) << "volume must be 3D or 4D (provided shape has " << dims << " dimensions)"; + if ((dims != 3) && (dims != 4)) fs::fatal() << "volume must be 3D or 4D (provided shape has " << dims << " dimensions)"; // validate size for (auto const & len : shape) { - if (len <= 0) logFatal(1) << "volume size must be greater than 0 in every dimension"; + if (len <= 0) fs::fatal() << "volume size must be greater than 0 in every dimension"; } width = shape[0]; @@ -150,7 +150,7 @@ MRI::MRI(Shape volshape, int dtype, bool alloc) : shape(volshape), type(dtype) // set data type bytes_per_vox = MRIsizeof(type); - if (bytes_per_vox < 1) logFatal(1) << "unsupported MRI data type: " << type; + if (bytes_per_vox < 1) fs::fatal() << "unsupported MRI data type: " << type; vox_per_row = width; vox_per_slice = vox_per_row * height; vox_per_vol = vox_per_slice * depth;