From ce4ffaede5e55dfb18d872e0f50cefb5ac91656f Mon Sep 17 00:00:00 2001 From: Mark Jenkinson <mark@fmrib.ox.ac.uk> Date: Mon, 7 Feb 2011 15:07:53 +0000 Subject: [PATCH] Added error checking for missing output filenames --- fslmaths.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fslmaths.cc b/fslmaths.cc index 28ee42b..5413e66 100755 --- a/fslmaths.cc +++ b/fslmaths.cc @@ -156,6 +156,15 @@ void loadNewImage(volume4D<T> &oldI, volume4D<T> &newI, string filename) } } +int check_for_output_name(int i, int argc_1) +{ + if (i>argc_1) { + cerr << "Error: no output filename specified!" << endl; + exit(EXIT_FAILURE); + } + return 0; +} + template <class T> int inputParser(int argc, char *argv[], short output_dt, bool forceOutputType=false) @@ -167,7 +176,8 @@ int inputParser(int argc, char *argv[], short output_dt, bool forceOutputType=fa bool modifiedInput(false); bool setDisplayRange(false); - for (int i = 2; i < argc-1; i++) //main loop + int i=2; + for (i = 2; i < argc-1; i++) //main loop { volume4D<T> temp_volume; modifiedInput=true; @@ -1109,6 +1119,8 @@ if (!separatenoise) for(int j=5;j>0;j--) inputVolume.deletevolume(j); + // if i+1>argc-1 then can save (otherwise it is a syntax error with no specific output specified) + check_for_output_name(i+1,argc-1); save_volume(dti_L1,string(argv[argc-1])+"_L1"); save_volume(dti_L2,string(argv[argc-1])+"_L2"); save_volume(dti_L3,string(argv[argc-1])+"_L3"); @@ -1130,6 +1142,9 @@ if (!separatenoise) /******************************************************/ } + // if i>argc-1 then can save (otherwise it is a syntax error with no specific output specified) + check_for_output_name(i,argc-1); + double max(inputVolume.max()),min(inputVolume.min()); if ( !forceOutputType && ((int)max-(int)min)==0 && (max-min)!=0 && (output_dt<DT_FLOAT)) output_dt=DT_FLOAT; -- GitLab