28 #define MATLAB "-MATLAB"
63 bool ParseCmdLine(
int argc,
char* argv[],
float &threshold,
bool & matlabIndexing);
73 int main(
int argc,
char* argv[])
78 vector <TPairedExtrema> pairs;
84 cout <<
"No filename" << endl;
85 cout <<
"Usage: " << argv[0] <<
" <filename> [threshold] [-MATLAB]" << endl;
90 char * filename = argv[1];
91 char * outfilename =
new char[strlen(filename) + strlen(
"_res.txt")];
92 strcpy(outfilename, filename);
94 outfilename[strlen(filename)-4] =
'\0';
95 strcat(outfilename,
"_res.txt");
97 if (!
ParseCmdLine(argc, argv, threshold, matlabIndexing))
99 cout <<
"Usage: " << argv[0] <<
" <filename> [threshold] [-MATLAB]" << endl;
105 cout <<
"Error reading data to file." << endl;
123 datafile.open(filename, ifstream::in);
128 cout <<
"Cannot open file " << filename <<
" for reading" << endl;
134 while(datafile >> currdata)
136 data.push_back(currdata);
145 datafile.open(filename);
149 cout <<
"Cannot open file " << filename <<
" for writing." << endl;
153 for (vector<TPairedExtrema>::iterator p = pairs.begin(); p != pairs.end(); p++)
155 datafile << to_string((
long long)(*p).MinIndex) << endl;
156 datafile << to_string((
long long)(*p).MaxIndex) << endl;
161 bool ParseCmdLine(
int argc,
char* argv[],
float &threshold,
bool & matlabIndexing)
163 bool noErrors =
true;
166 matlabIndexing =
false;
169 for (
int counter = 2; counter < argc ; counter ++)
171 if (argv[counter][0]==
'-' && matlabIndexing ==
false)
173 if (strcmp(argv[counter],
"-MATLAB") == 0 ||
174 strcmp(argv[counter],
"-Matlab") == 0 ||
175 strcmp(argv[counter],
"-matlab") == 0 )
178 matlabIndexing =
true;
182 cout <<
"Possibly misspelled Matlab flag or negative values for threshold." << endl;
186 else if ( argv[counter][0] ==
'0')
189 threshold = (float)atof(argv[counter]);
198 cout <<
"Error. Threshold value should be >= 0. Rerun with valid threshold value or leave out to get all features.\n";
205 threshold = (float)atof(argv[counter]);
209 if (threshold == 0.0)
211 cout <<
"Cannot convert threshold value to number.\n" << endl;
214 else if (threshold < 0)
216 cout <<
"Error. Threshold value should be >= 0. Rerun with valid threshold value or leave out to get all features.\n";