// file: $(NEDC_NFC)/class/cpp/Edf/edf_02.cc // // This file contains set methods. // // Revision History: // // 20240307 (JP): refactored code to expand set/get methods // // 20240305 (JP): removed the set_signal_dimensions method // // 20240130 (JP): updated the deidentify process by adding more steps // // 20180205 (JM): removed "pad_whitespace" functions from deidentify // // 20170103 (SL): added set_start_date method // // 20150701 (FG): apply_montage method modified to update the header labels // regarding the values parsed for the montage specified in the // parameter file // // 20150630 (FG): interpolation moved to Edf class // methods added: interpolation_average // // 20150612 (FG): added interpolation functionality // methods added: add_channel, select_channel // // 20141219 (AH): apply_montage updated to account for negative gain // // 20141216 (AH): set_signal_dimensions is updated so it only updates // the frequency for channels that their original freq. // is the same as channel 0 (EEG channels) // // local include files // #include "Edf.h" //***************************************************************************** // // public methods: set methods // //***************************************************************************** // method: set_hdr_chan_labels // // arguments: // char** labels: channel labels as a vector of strings (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel labels. Note that it // deallocates memory as needed. // bool Edf::set_hdr_chan_labels(char** labels_a, long nchans_a) { // clear existing memory // cleanup(hdr_chan_labels_d, nchans_a); // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_labels_d[i] = new char[strlen(labels_a[i] + 1)]; strcpy(hdr_chan_labels_d[i], labels_a[i]); } // exit gracefully // return true; } // method: set_hdr_chan_trans_types // // arguments: // char** ttypes: channel trans types (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel transducer types. // bool Edf::set_hdr_chan_trans_types(char** ttypes_a, long nchans_a) { // clear existing memory // cleanup(hdr_chan_trans_types_d, nchans_a); // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_trans_types_d[i] = new char[strlen(ttypes_a[i] + 1)]; strcpy(hdr_chan_trans_types_d[i], ttypes_a[i]); } // exit gracefully // return true; } // method: set_hdr_chan_phys_dim // // arguments: // char** physd: channel physical dims (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel physical dimension. // bool Edf::set_hdr_chan_phys_dim(char** physd_a, long nchans_a) { // clear existing memory // cleanup(hdr_chan_phys_dim_d, nchans_a); // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_phys_dim_d[i] = new char[strlen(physd_a[i] + 1)]; strcpy(hdr_chan_phys_dim_d[i], physd_a[i]); } // exit gracefully // return true; } // method: set_hdr_chan_phys_min // // arguments: // double* physm: channel physical minimum as a vector of double (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel physical minimum. // bool Edf::set_hdr_chan_phys_min(double* physm_a, long nchans_a) { // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_phys_min_d[i] = physm_a[i]; } // exit gracefully // return true; } // method: set_hdr_chan_phys_max // // arguments: // long* physm: channel physical maximum as a vector of double (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel physical maximum. // bool Edf::set_hdr_chan_phys_max(double* physm_a, long nchans_a) { // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_phys_max_d[i] = physm_a[i]; } // exit gracefully // return true; } // method: set_hdr_chan_dig_min // // arguments: // long* digm: channel digital minimum as a vector of long (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel digital minimum. // bool Edf::set_hdr_chan_dig_min(long* digm_a, long nchans_a) { // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_dig_min_d[i] = digm_a[i]; } // exit gracefully // return true; } // method: set_hdr_chan_dig_max // // arguments: // long* digm: channel digital maximum as a vector of long (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel digital maximum. // bool Edf::set_hdr_chan_dig_max(long* digm_a, long nchans_a) { // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_dig_max_d[i] = digm_a[i]; } // exit gracefully // return true; } // method: set_hdr_chan_prefilt // // arguments: // char** prefilt: channel filters as a vector of strings (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel prefilters. Note that it // deallocates memory as needed. // bool Edf::set_hdr_chan_prefilt(char** prefilt_a, long nchans_a) { // clear existing memory // cleanup(hdr_chan_prefilt_d, nchans_a); // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_prefilt_d[i] = new char[strlen(prefilt_a[i] + 1)]; strcpy(hdr_chan_prefilt_d[i], prefilt_a[i]); } // exit gracefully // return true; } // method: set_hdr_chan_rec_size // // arguments: // long* recsz: channel record sizes (input) // long nchans: the number of channels (input) // // return: an boolean value indicating status // // This creates space and populates the channel record size. // bool Edf::set_hdr_chan_rec_size(long* recsz_a, long nchans_a) { // loop over all labels // for (long i = 0; i < nchans_a; i++) { hdr_chan_rec_size_d[i] = recsz_a[i]; } // exit gracefully // return true; } //***************************************************************************** // // public methods: additional set methods needed for backward compatibility // //***************************************************************************** // method: set_start_time // // arguments: // char* st_time: new start time (input) // // return: a boolean value indicating status // // This method overwrites the start time for a signal. Note that the time // should be limited to 8 characters. // bool Edf::set_start_time(const char* st_time_a) { // copy the time // strcpy(hdr_ghdi_start_time_d, st_time_a); // exit gracefully // return true; } // method: set_start_date // // arguments: // char* st_date: new start date (input) // // return: a boolean value indicating status // // This method overwrites the start date for a signal. Note that the time // should be limited to 8 characters. // bool Edf::set_start_date(const char* st_date_a) { // copy the date // strcpy(hdr_ghdi_start_date_d, st_date_a); // exit gracefully // return true; } // method: set_record_duration // // arguments: // double dur: record duration in secs (input) // // return: a boolean value indicating status // bool Edf::set_record_duration(double dur_a) { // check the value // if (dur_a <= (float)0) { return false; } else { hdr_ghdi_dur_rec_d = dur_a; } // exit gracefully // return true; } // method: set_num_records // // arguments: // long num_recs: number of records (input) // // return: a boolean value indicating status // bool Edf::set_num_records(long num_recs_a) { // check the value // if (num_recs_a <= (long)0) { return false; } else { hdr_ghdi_num_recs_d = num_recs_a; } // exit gracefully // return true; } // method: set_channel_information // // arguments: // char** channel_names: channel names // char** trans_types: transducer types // char** phys_dim: channel dimensions // double* phys_min: channel minimum value // double* phys_max: channel maximum value // long* dig_min: channel digital minimum value // long* dig_max: channel digital maximum value // char* prefilt: channel prefilters // // return: a boolean value indicating status // // This method copies one signal data structure to another. // bool Edf::set_channel_information(char** channel_names_a, char** trans_types_a, char** phys_dim_a, double* phys_min_a, double* phys_max_a, long* dig_min_a, long* dig_max_a, char** prefilt_a) { // loop over all channels // for (long i = 0; i < hdr_ghdi_nsig_rec_d; i++) { // copy the data // strcpy(hdr_chan_labels_d[i], channel_names_a[i]); strcpy(hdr_chan_trans_types_d[i], trans_types_a[i]); strcpy(hdr_chan_phys_dim_d[i], phys_dim_a[i]); hdr_chan_phys_min_d[i] = phys_min_a[i]; hdr_chan_phys_max_d[i] = phys_max_a[i]; hdr_chan_dig_min_d[i] = dig_min_a[i]; hdr_chan_dig_max_d[i] = dig_max_a[i]; strcpy(hdr_chan_prefilt_d[i], prefilt_a[i]); } // exit gracefully // return true; } // method: set_montage_chans // // arguments: // long num_montage_a: the number of montage channels (input) // // return: a boolean value indicating status // // This method sets the number of channels to be computed using a montage. // bool Edf::set_montage_chans(long num_montage_a) { num_mlabels_d = num_montage_a; if (num_montage_a == 0) { return false; } else { return true; } } // method: increment_start_time // // arguments: // long num_secs: number of seconds to add to start time // // return: a boolean value indicating status // // Edf files contain a start time field. This method adds num_secs of time // to that field. Because the field is stored as a character string, // a conversion must be done. // // Note that this method is limited to a 24-hour clock. It does not // increment times into the next day. // // Note also that the number of seconds is specified as an integer. // bool Edf::increment_start_time(long num_secs_a) { // convert the current start time to secs // long hrs, mins, secs; sscanf(hdr_ghdi_start_time_d, "%2ld.%2ld.%2ld", &hrs, &mins, &secs); // increment secs and limit it to a value in the range [0,60] // secs += num_secs_a; // limit secs to [0, 60] // while (secs > 59) { secs -= 60; mins += 1; } // limit mins to [0, 60] // while (mins > 59) { mins -= 60; hrs += 1; } // limit hrs to [0, 24] // while (hrs > 24) { hrs -= 24; } // convert back to a string // sprintf(hdr_ghdi_start_time_d, "%2ld.%2ld.%2ld", hrs, mins, secs); // exit gracefully // return true; } // // end of file