// file: $(NEDC_NFC)/util/cpp/nedc_gen_feats/nedc_gen_feats.cc // // this is the driver program for feature extraction. // // modified: // 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_NFC_USAGE_MSG "$NEDC_NFC/util/cpp/nedc_gen_feats/nedc_gen_feats.usage" #define NEDC_NFC_HELP_MSG "$NEDC_NFC/util/cpp/nedc_gen_feats/nedc_gen_feats.help" // fe: feature extraction // // This is a driver program that reads EDF files and generates // feature files. // int main(int argc, const char** argv) { // declare local variables // long status = 0; // create a Dbgl object for local debugging // (the level of this object is set by the cmdl object during parsing) // Dbgl dbgl; // create an EDF object // Edf edf; // create a front end object // Fe fe; // initialize a Command Line object // Cmdl cmdl; cmdl.set_usage(NEDC_NFC_USAGE_MSG); cmdl.set_help(NEDC_NFC_HELP_MSG); // add options // char pfile[Cmdl::MAX_OPTVAL_SIZE]; pfile[0] = (char)NULL; cmdl.add_option("-parameters", pfile); char out_dir[Cmdl::MAX_OPTVAL_SIZE]; out_dir[0] = (char)NULL; cmdl.add_option("-odir", out_dir); char repl_dir[Cmdl::MAX_OPTVAL_SIZE]; repl_dir[0] = (char)NULL; cmdl.add_option("-rdir", repl_dir); // branch on the status of parsing, checking for usage and help messages // if ((argc == 1) || (cmdl.parse(argc, argv) == false)) { cmdl.display_usage(stdout); return (status); } else if (cmdl.get_help_status() == true) { cmdl.display_help(stdout); return (status); } // load the parameter file // if (!fe.load_parameters((char*)pfile)) { fprintf(stdout, "**> error parsing the parameter file (%s)\n", (char*)pfile); exit(1); } // allow the output directory to be overridden: // check for "-d" argument // if(out_dir[0] != (char)NULL){ fe.set_output_directory(out_dir); } // allow the replace directory to be overridden: // check for "-r" argument // if(repl_dir[0] != (char)NULL){ fe.set_repl_directory(repl_dir); } // display an informational message // 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[Edf::MAX_LSTR_LENGTH]; for (int i = cmdl.get_first_arg_pos(); i < argc; i++) { // if it is an edf file, process it // if (edf.is_edf((char*)argv[i])) { // display a status message // num_files_att++; fprintf(stdout, " %6ld: %s\n", num_files_att, (char*)argv[i]); // compute features // if (fe.compute(feat_fname, (char*)argv[i])) { num_files_proc++; fprintf(stdout, " %s\n", feat_fname); } else { fprintf(stdout, " **> nedc_gen_feats: error generating features\n"); } } // else: treat it as a file list // else { // dsiplay an informational message // fprintf(stdout, " opening list %s...\n", (char*)argv[i]); // open the list // FILE* fp = fopen(argv[i], "r"); if (fp == (FILE*)NULL) { fprintf(stdout, " **> nedc_gen_feats: error opening file list (%s)\n", argv[i]); exit(1); } // loop over all files // char edf_fname[Edf::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, " **> nedc_gen_feats: error generating features\n"); } } // 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(status); }