// file: $(NEDC_NFC)/class/cpp/Edf/edf_07.cc // // This file contains linear algebra methods associated with the class Edf. // // Revision History: // // 20240307 (JP): refactored code to expand set/get methods // // local include files // #include "Edf.h" //***************************************************************************** // // public methods: general purpose parsing tools // //***************************************************************************** // method: parse_line // // arguments: // long& nl: the number of labels (output) // char** labels: an array of strings containing the labels (output) // char* str: a string containing the label list (input) // char* delim: represents the string that is used as the delimiter // return: a boolean indicating status // // Note that EEG labels usually have spaces in them which can't be ignored. // // Note that the character string array labels is assumed to be // allocated, but each individual element is not defined. // bool Edf::parse_line(long& nl_a, char** labels_a, const char* str_a, const char* delim) { // declare local variables // char* tmp_ptr = (char*)str_a; char* str_end = (char*)str_a + strlen(str_a); // iterate over all characters // nl_a = 0; while (tmp_ptr < str_end) { // trim off leading whitespace // while (isspace(*tmp_ptr)) { tmp_ptr++; } // find the next comma // char* pos_c = strstr(tmp_ptr, delim); // note that if one doesn't exist, it is the end of the line. in this // case we go to the end of the line and then step back to the first // non-whitespace. // if (pos_c == (char*)NULL) { pos_c = str_end - 1; while (isspace(*pos_c)) { pos_c--; } // increment by one to be consistent with cases where we are // not at the end of the line // pos_c++; } // compute the length and create space // long label_len = pos_c - tmp_ptr; labels_a[nl_a] = new char [label_len + 1]; // copy and uppercase the string // for (long i = 0; i < label_len; i++) { labels_a[nl_a][i] = toupper(*tmp_ptr++); } labels_a[nl_a][label_len] = (char)NULL; // increment counters // nl_a++; tmp_ptr++; } // exit gracefully // return true; } //***************************************************************************** // // public methods: linear algebra methods // //***************************************************************************** // method: shift // // arguments: // VectorDouble& v: vector to be shifted (input) // long incr: shift increment (input) // // return: a boolean value indicating status // // This method shifts elements in a vector and resizes the vector. // bool Edf::shift(VectorDouble& v_a, long incr_a) { // check the direction // if (incr_a == 0) { return true; } else if (incr_a < 0) { return false; } // shift data // long new_size = v_a.size() - 1; //long loc = incr_a; for (long i = 0; i < new_size; i++) { v_a[i] = v_a[incr_a]; incr_a++; } // resize // Edf::resize(v_a, new_size, true); // exit gracefully // return true; } // // end of file