// file: get_1.C // #include "./process_data.h" // important definitions // #define line_format "%s%*s%f%*s" char* tags[] = { "sample_frequency", "frame_duration", "window_duration", "\0", }; //----------------------------------------------------------------------------- // function: get_parameters_C // // arguments: // float& sample_frequency: (output) sample frequency of the signals // float& frame_duration: (output) frame_duration of the signals // float& window_duration: (output) window_duration of the signals // char* param_file: (output) parameter filename // // returns: // L_TRUE if no error was encounterd //----------------------------------------------------------------------------- int get_parameters_C(float& sample_frequency, float& frame_duration, float& window_duration, char* param_file) { // open the file // FILE* fp = fopen(param_file, "r"); if (fp == NULL) {return L_FALSE;} // read the file // char buffer[MAX_STRING_LENGTH]; char param_tag[MAX_STRING_LENGTH]; float param_value; while (fgets(buffer, MAX_STRING_LENGTH-1, fp) != NULL) { // check the line - skip comments and whitespace // int index = strlen(buffer) - (int)1; int num_non_whitespace = (int)0; while (index >= (int)0) { if (isalnum(buffer[index])) {num_non_whitespace++;} index--; } if ((buffer[0] != '#') && (num_non_whitespace > (int)0)) { // convert the data into actual values // sscanf(buffer, line_format, param_tag, ¶m_value); // find the proper parameter name // int tag_index=0; while (*tags[tag_index] != NULL) { // do a partial match // if (strstr(tags[tag_index], param_tag) != NULL) { // assign the value // if (tag_index == (int)0) {sample_frequency = param_value;} else if (tag_index == (int)1) {frame_duration = param_value;} else if (tag_index == (int)2) {window_duration = param_value;} } // increment counters // tag_index++; } } } // close all files // fclose(fp); // exit gracefully // return L_TRUE; }