// file: $(NEDC_NFC)/util/cpp/nedc_eeg_gen_feats/nedc_eeg_gen_feats.cc // // Revision History: // // 20240518 (JP): renamed utility // 20200520 (JP): refactored the code // 20160722 (SL): added the -replace command line option // 20160608 (JM): fixed improper error output // 20160529 (JP): updated to use a new help message format // 20160212 (SL): updated to use the Cmdl class for command line parsing // 20140223 (JP): upgraded to the new Edf feature file I/O // 20140125 (JP): revamped the parameter file parsing; made the // front end implementations more modular // 20131120 (JP): initial version // // local include files // #include #include // define the help and usage messages // #define NEDC_USAGE \ "$NEDC_NFC/util/cpp/nedc_eeg_gen_feats/nedc_eeg_gen_feats.usage" #define NEDC_HELP \ "$NEDC_NFC/util/cpp/nedc_eeg_gen_feats/nedc_eeg_gen_feats.help" // define the program options: // note that you cannot separate them by spaces // #define ARG_ODIR_NAME "odir" #define ARG_ODIR "odir,o" #define ARG_PARM_NAME "parameters" #define ARG_PARM "parameters,p" #define ARG_RDIR_NAME "rdir" #define ARG_RDIR "rdir,r" // define default parameter file // #define DEF_PARAM_FILE \ "$NEDC_NFC/util/cpp/nedc_eeg_gen_feats/feats_v00.txt" // main: nec_gen_feats // // This is a driver program that reads EDF files and generates // feature files. // int main(int argc, const char** argv) { // create the required objects // Dbgl dbgl; Cmdl cmdl(NEDC_USAGE, NEDC_HELP); Edf edf; Fe fe; // add options // cmdl.add_argument(ARG_ODIR); cmdl.add_argument(ARG_PARM); cmdl.add_argument(ARG_RDIR); // parse the command line // cmdl.parse_args(argc, argv); // check the number of arguments // if (argc == 1) { cmdl.display_usage(stdout); } // retrieve the argument values // std::string odir; cmdl.get_value(odir, ARG_ODIR_NAME); std::string parm(DEF_PARAM_FILE); cmdl.get_value(parm, ARG_PARM_NAME); std::string rdir; cmdl.get_value(rdir, ARG_RDIR_NAME); // retrieve the file list // VectorString args; if (cmdl.get_value(args, Cmdl::ARG_ARGS) == false) { fprintf(stdout, "Error: %s (line: %d) %s: error getting args\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); cmdl.display_usage(stdout); } // load the parameter file // if (!fe.load_parameters(parm.c_str())) { fprintf(stdout, "Error: %s (line: %d) %s: error parsing the parameter file (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, parm.c_str()); exit(EXIT_FAILURE); } // allow the output directory to be overridden // if(odir.size() > (long)0){ fe.set_output_directory(odir.c_str()); } // allow the replace directory to be overridden // if(rdir.size() > (long)0){ fe.set_repl_directory(rdir.c_str()); } // display an informational message // if (dbgl > Dbgl::NONE) { fprintf(stdout, "%s (line: %d) %s: parameter file = %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, parm.c_str()); fprintf(stdout, "%s (line: %d) %s: output dir = %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, odir.c_str()); fprintf(stdout, "%s (line: %d) %s: replace dir = %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, rdir.c_str()); } fprintf(stdout, "beginning argument processing...\n"); // main processing loop: loop over all input filenames // long num_files_att = 0; long num_files_proc = 0; char feat_fname[Itgl::MAX_LSTR_LENGTH]; for (int i = 0; i < (long)args.size(); i++) { // if it is an edf file, process it // if (edf.is_edf(args[i].c_str())) { // display a status message // num_files_att++; fprintf(stdout, " %6ld: %s\n", num_files_att, args[i].c_str()); // compute features // if (fe.compute(feat_fname, args[i].c_str())) { num_files_proc++; fprintf(stdout, " %s\n", feat_fname); } else { fprintf(stdout, "Error: %s (line: %d) %s: error generating features\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); } } // else: treat it as a file list // else { // dsiplay an informational message // fprintf(stdout, " opening list %s ...\n", args[i].c_str()); // open the list // FILE* fp = fopen(args[i].c_str(), "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "Error: %s (line: %d) %s: error opening file list (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, args[i].c_str()); exit(EXIT_FAILURE); } // loop over all files // char edf_fname[Itgl::MAX_LSTR_LENGTH]; while (fscanf(fp, "%s", edf_fname) == 1) { // display a status message // num_files_att++; fprintf(stdout, " %6ld: %s\n", num_files_att, edf_fname); // compute features // if (fe.compute(feat_fname, edf_fname)) { num_files_proc++; fprintf(stdout, " %s\n", feat_fname); } else { fprintf(stdout, "Error: %s (line: %d) %s: error generating features\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); } } // close the list // fclose(fp); } } // display the results // fprintf(stdout, "processed %ld out of %ld files successfully\n", num_files_proc, num_files_att); // exit gracefully // exit(EXIT_SUCCESS); } // // end of file