From 76e3679c4fa3c0c032be23eb9b5083ef0fb32d55 Mon Sep 17 00:00:00 2001 From: Teuniz Date: Wed, 8 Feb 2023 21:22:28 +0100 Subject: [PATCH] Add Qt6 compatibility. --- about_dialog.cpp | 4 +- about_dialog.h | 2 +- connection.cpp | 2 +- connection.h | 2 +- decode_dialog.cpp | 2 +- decode_dialog.h | 13 +- dsremote.pro | 25 +- edflib.c | 2148 ++++++++++---------------------------- edflib.h | 915 ++++++++-------- global.h | 4 +- interface.cpp | 2 +- lan_connect_thread.cpp | 2 +- lan_connect_thread.h | 2 +- main.cpp | 64 +- mainwindow.cpp | 4 +- mainwindow.h | 40 +- mainwindow_constr.cpp | 16 +- playback_dialog.cpp | 2 +- playback_dialog.h | 13 +- qt_headers.h | 143 +++ read_settings_thread.cpp | 2 +- read_settings_thread.h | 2 +- save_data.cpp | 6 +- save_data_thread.cpp | 2 +- save_data_thread.h | 2 +- screen_thread.cpp | 4 +- screen_thread.h | 2 +- serial_decoder.cpp | 2 +- settings_dialog.cpp | 8 +- settings_dialog.h | 14 +- signalcurve.cpp | 27 +- signalcurve.h | 2 +- tdial.cpp | 15 +- tdial.h | 2 +- timer_handlers.cpp | 2 +- tled.cpp | 4 +- tled.h | 2 +- tmc_dev.c | 10 +- tmc_dev.h | 2 +- tmc_lan.c | 2 +- tmc_lan.h | 2 +- utils.c | 559 +++++----- utils.h | 31 +- wave_dialog.cpp | 2 +- wave_dialog.h | 10 +- wave_view.cpp | 18 +- wave_view.h | 13 +- 47 files changed, 1666 insertions(+), 2486 deletions(-) create mode 100644 qt_headers.h diff --git a/about_dialog.cpp b/about_dialog.cpp index 4357998..8252205 100644 --- a/about_dialog.cpp +++ b/about_dialog.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -57,7 +57,7 @@ UI_Aboutwindow::UI_Aboutwindow() textedit1->setPlainText( "\n " PROGRAM_NAME " " PROGRAM_VERSION "\n" "\n This program is made by Teunis van Beelen.\n" - "\n Copyright (C) 2015 - 2021 Teunis van Beelen.\n" + "\n Copyright (C) 2015 - 2023 Teunis van Beelen.\n" "\n Email: teuniz@protonmail.com\n" "\n Disclaimer:\n" " Despite this software is intend to be useful, there is no warranty, use this software at your own risk!\n"); diff --git a/about_dialog.h b/about_dialog.h index 2e1d36d..3095b92 100644 --- a/about_dialog.h +++ b/about_dialog.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/connection.cpp b/connection.cpp index aeb2080..7807fa3 100644 --- a/connection.cpp +++ b/connection.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/connection.h b/connection.h index 77ce996..3735ae0 100644 --- a/connection.h +++ b/connection.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/decode_dialog.cpp b/decode_dialog.cpp index 5060e94..5f1ce8b 100644 --- a/decode_dialog.cpp +++ b/decode_dialog.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/decode_dialog.h b/decode_dialog.h index 1a7e112..8e0bd17 100644 --- a/decode_dialog.h +++ b/decode_dialog.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -30,16 +30,7 @@ #define UI_DECODE_DIALOG_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "qt_headers.h" #include #include diff --git a/dsremote.pro b/dsremote.pro index 2f88490..ac00e60 100644 --- a/dsremote.pro +++ b/dsremote.pro @@ -2,11 +2,11 @@ contains(QT_MAJOR_VERSION, 4) { LIST = 0 1 2 3 4 5 6 -for(a, LIST):contains(QT_MINOR_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1") +for(a, LIST):contains(QT_MINOR_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1 or Qt6 version >= 6.4.1") contains(QT_MINOR_VERSION, 7) { LIST = 0 - for(a, LIST):contains(QT_PATCH_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1") + for(a, LIST):contains(QT_PATCH_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1 or Qt6 version >= 6.4.1") } } @@ -14,11 +14,23 @@ contains(QT_MINOR_VERSION, 7) { contains(QT_MAJOR_VERSION, 5) { LIST = 0 1 2 3 4 5 6 7 8 -for(a, LIST):contains(QT_MINOR_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1") +for(a, LIST):contains(QT_MINOR_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1 or Qt6 version >= 6.4.1") contains(QT_MINOR_VERSION, 9) { LIST = 0 - for(a, LIST):contains(QT_PATCH_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1") + for(a, LIST):contains(QT_PATCH_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1 or Qt6 version >= 6.4.1") +} +} + + +contains(QT_MAJOR_VERSION, 6) { + +LIST = 0 1 2 3 +for(a, LIST):contains(QT_MINOR_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1 or Qt6 version >= 6.4.1") + +contains(QT_MINOR_VERSION, 4) { + LIST = 0 + for(a, LIST):contains(QT_PATCH_VERSION, $$a):error("This project needs Qt4 version >= 4.7.1 or Qt5 version >= 5.9.1 or Qt6 version >= 6.4.1") } } @@ -36,11 +48,14 @@ CONFIG += largefile QT += widgets QT += network -QMAKE_CXXFLAGS += -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -Wfatal-errors +QMAKE_CXXFLAGS += -Wextra -Wshadow -Wformat -Wformat-nonliteral -Wformat-security -Wtype-limits -Wfatal-errors -Wdeprecated-declarations + +QMAKE_CFLAGS += -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -Wfatal-errors -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE OBJECTS_DIR = ./objects MOC_DIR = ./moc +HEADERS += qt_headers.h HEADERS += global.h HEADERS += mainwindow.h HEADERS += about_dialog.h diff --git a/edflib.c b/edflib.c index d68f98f..8e5e443 100644 --- a/edflib.c +++ b/edflib.c @@ -1,7 +1,7 @@ /* ***************************************************************************** * -* Copyright (c) 2009 - 2021 Teunis van Beelen +* Copyright (c) 2009 - 2023 Teunis van Beelen * All rights reserved. * * Email: teuniz@protonmail.com @@ -31,22 +31,14 @@ ***************************************************************************** */ - - - /* compile with options "-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" */ - - - #include "edflib.h" - -#define EDFLIB_VERSION (119) +#define EDFLIB_VERSION (123) #define EDFLIB_MAXFILES (64) - -#if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__) || defined(__HAIKU__) +#if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__) || defined(__HAIKU__) || defined(__ANDROID__) #define fopeno fopen @@ -58,7 +50,6 @@ #endif - #ifdef _WIN32 #ifndef __MINGW32__ @@ -76,8 +67,6 @@ #endif - - /* max size of annotationtext */ #define EDFLIB_WRITE_MAX_ANNOTATION_LEN (40) @@ -89,7 +78,6 @@ #define EDFLIB_ANNOT_MEMBLOCKSZ (1000) - struct edfparamblock{ char label[17]; char transducer[81]; @@ -118,6 +106,9 @@ struct edfhdrblock{ char plus_patientcode[81]; char plus_gender[16]; char plus_birthdate[16]; + int plus_birthdate_day; + int plus_birthdate_month; + int plus_birthdate_year; char plus_patient_name[81]; char plus_patient_additional[81]; char plus_startdate[16]; @@ -158,14 +149,13 @@ struct edfhdrblock{ struct edfparamblock *edfparam; }; - static struct edf_annotationblock{ long long onset; + long long duration_l; char duration[16]; char annotation[EDFLIB_MAX_ANNOTATION_LEN + 1]; } *annotationslist[EDFLIB_MAXFILES]; - static struct edf_write_annotationblock{ long long onset; long long duration; @@ -176,7 +166,6 @@ static int edf_files_open=0; static struct edfhdrblock *hdrlist[EDFLIB_MAXFILES]; - static struct edfhdrblock * edflib_check_edf_file(FILE *, int *); static int edflib_is_integer_number(char *); static int edflib_is_number(char *); @@ -203,8 +192,6 @@ static int edflib_strlcpy(char *, const char *, int); static int edflib_strlcat(char *, const char *, int); - - int edflib_is_file_used(const char *path) { int i; @@ -213,10 +200,7 @@ int edflib_is_file_used(const char *path) { if(hdrlist[i]!=NULL) { - if(!(strcmp(path, hdrlist[i]->path))) - { - return 1; - } + if(!(strcmp(path, hdrlist[i]->path))) return 1; } } @@ -238,10 +222,7 @@ int edflib_get_handle(int file_number) { if(hdrlist[i]!=NULL) { - if(file_count++ == file_number) - { - return i; - } + if(file_count++ == file_number) return i; } } @@ -259,23 +240,46 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r struct edfhdrblock *hdr; - - if(read_annotations_mode<0) + union { - edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE; - - return -1; - } - - if(read_annotations_mode>2) - { - edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE; - - return -1; - } + char four[4]; + int one; + } byte_order_test_var; memset(edfhdr, 0, sizeof(struct edf_hdr_struct)); + /* avoid surprises! */ + if((sizeof(char) != 1) || + (sizeof(short) != 2) || + (sizeof(int) != 4) || + (sizeof(long long) != 8) || + (sizeof(float) != 4) || + (sizeof(double) != 8)) + { + edfhdr->filetype = EDFLIB_ARCH_ERROR; + + return -1; + } + + /* check endianness! */ + byte_order_test_var.one = 0x03020100; + if((byte_order_test_var.four[0] != 0) || + (byte_order_test_var.four[1] != 1) || + (byte_order_test_var.four[2] != 2) || + (byte_order_test_var.four[3] != 3)) + { + edfhdr->filetype = EDFLIB_ARCH_ERROR; + + return -1; + } + + if((read_annotations_mode<0)||(read_annotations_mode>2)) + { + edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE; + + return -1; + } + if(edf_files_open>=EDFLIB_MAXFILES) { edfhdr->filetype = EDFLIB_MAXFILES_REACHED; @@ -326,8 +330,6 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r return -1; } - hdr->writemode = 0; - for(i=0; ipatient, hdr->patient, 81); edflib_strlcpy(edfhdr->recording, hdr->recording, 81); - edfhdr->patientcode[0] = 0; - edfhdr->gender[0] = 0; - edfhdr->birthdate[0] = 0; - edfhdr->patient_name[0] = 0; - edfhdr->patient_additional[0] = 0; - edfhdr->admincode[0] = 0; - edfhdr->technician[0] = 0; - edfhdr->equipment[0] = 0; - edfhdr->recording_additional[0] = 0; } else { - edfhdr->patient[0] = 0; - edfhdr->recording[0] = 0; edflib_strlcpy(edfhdr->patientcode, hdr->plus_patientcode, 81); edflib_strlcpy(edfhdr->gender, hdr->plus_gender, 16); edflib_strlcpy(edfhdr->birthdate, hdr->plus_birthdate, 16); + edfhdr->birthdate_day = hdr->plus_birthdate_day; + edfhdr->birthdate_month = hdr->plus_birthdate_month; + edfhdr->birthdate_year = hdr->plus_birthdate_year; edflib_strlcpy(edfhdr->patient_name, hdr->plus_patient_name, 81); edflib_strlcpy(edfhdr->patient_additional, hdr->plus_patient_additional, 81); edflib_strlcpy(edfhdr->admincode, hdr->plus_admincode, 81); @@ -480,20 +474,9 @@ int edfclose_file(int handle) struct edfhdrblock *hdr; - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } - - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; hdr = hdrlist[handle]; @@ -699,36 +682,15 @@ long long edfseek(int handle, int edfsignal, long long offset, int whence) int channel; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(edfsignal<0) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->writemode) return -1; - if(edfsignal<0) - { - return -1; - } - - if(hdrlist[handle]->writemode) - { - return -1; - } - - if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) - { - return -1; - } + if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1; channel = hdrlist[handle]->mapped_signals[edfsignal]; @@ -768,36 +730,15 @@ long long edftell(int handle, int edfsignal) { int channel; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(edfsignal<0) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->writemode) return -1; - if(edfsignal<0) - { - return -1; - } - - if(hdrlist[handle]->writemode) - { - return -1; - } - - if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) - { - return -1; - } + if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1; channel = hdrlist[handle]->mapped_signals[edfsignal]; @@ -809,36 +750,15 @@ void edfrewind(int handle, int edfsignal) { int channel; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return; - if(handle<0) - { - return; - } + if(hdrlist[handle]==NULL) return; - if(handle>=EDFLIB_MAXFILES) - { - return; - } + if(edfsignal<0) return; - if(hdrlist[handle]==NULL) - { - return; - } + if(hdrlist[handle]->writemode) return; - if(edfsignal<0) - { - return; - } - - if(hdrlist[handle]->writemode) - { - return; - } - - if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) - { - return; - } + if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return; channel = hdrlist[handle]->mapped_signals[edfsignal]; @@ -874,48 +794,21 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf) FILE *file; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(edfsignal<0) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->writemode) return -1; - if(edfsignal<0) - { - return -1; - } - - if(hdrlist[handle]->writemode) - { - return -1; - } - - if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) - { - return -1; - } + if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1; channel = hdrlist[handle]->mapped_signals[edfsignal]; - if(n<0LL) - { - return -1; - } + if(n<0LL) return -1; - if(n==0LL) - { - return 0LL; - } + if(n==0LL) return 0LL; hdr = hdrlist[handle]; @@ -935,15 +828,9 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf) { n = smp_in_file - hdr->edfparam[channel].sample_pntr; - if(n==0) - { - return 0LL; - } + if(n==0) return 0LL; - if(n<0) - { - return -1; - } + if(n<0) return -1; } file = hdr->file_hdl; @@ -985,6 +872,15 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf) } var.four[1] = tmp; + if(var.two_signed[0] > hdr->edfparam[channel].dig_max) + { + var.two_signed[0] = hdr->edfparam[channel].dig_max; + } + else if(var.two_signed[0] < hdr->edfparam[channel].dig_min) + { + var.two_signed[0] = hdr->edfparam[channel].dig_min; + } + buf[i] = phys_bitvalue * (phys_offset + (double)var.two_signed[0]); sample_pntr++; @@ -1006,10 +902,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf) var.four[0] = fgetc(file); var.four[1] = fgetc(file); tmp = fgetc(file); - if(tmp==EOF) - { - return -1; - } + if(tmp==EOF) return -1; var.four[2] = tmp; if(var.four[2]&0x80) @@ -1021,6 +914,15 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf) var.four[3] = 0x00; } + if(var.one_signed > hdr->edfparam[channel].dig_max) + { + var.one_signed = hdr->edfparam[channel].dig_max; + } + else if(var.one_signed < hdr->edfparam[channel].dig_min) + { + var.one_signed = hdr->edfparam[channel].dig_min; + } + buf[i] = phys_bitvalue * (phys_offset + (double)var.one_signed); sample_pntr++; @@ -1058,48 +960,21 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf) FILE *file; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(edfsignal<0) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->writemode) return -1; - if(edfsignal<0) - { - return -1; - } - - if(hdrlist[handle]->writemode) - { - return -1; - } - - if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) - { - return -1; - } + if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1; channel = hdrlist[handle]->mapped_signals[edfsignal]; - if(n<0LL) - { - return -1; - } + if(n<0LL) return -1; - if(n==0LL) - { - return 0LL; - } + if(n==0LL) return 0LL; hdr = hdrlist[handle]; @@ -1159,12 +1034,18 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf) var.four[0] = fgetc(file); tmp = fgetc(file); - if(tmp==EOF) - { - return -1; - } + if(tmp==EOF) return -1; var.four[1] = tmp; + if(var.two_signed[0] > hdr->edfparam[channel].dig_max) + { + var.two_signed[0] = hdr->edfparam[channel].dig_max; + } + else if(var.two_signed[0] < hdr->edfparam[channel].dig_min) + { + var.two_signed[0] = hdr->edfparam[channel].dig_min; + } + buf[i] = var.two_signed[0]; sample_pntr++; @@ -1186,10 +1067,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf) var.four[0] = fgetc(file); var.four[1] = fgetc(file); tmp = fgetc(file); - if(tmp==EOF) - { - return -1; - } + if(tmp==EOF) return -1; var.four[2] = tmp; if(var.four[2]&0x80) @@ -1201,6 +1079,15 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf) var.four[3] = 0x00; } + if(var.one_signed > hdr->edfparam[channel].dig_max) + { + var.one_signed = hdr->edfparam[channel].dig_max; + } + else if(var.one_signed < hdr->edfparam[channel].dig_min) + { + var.one_signed = hdr->edfparam[channel].dig_min; + } + buf[i] = var.one_signed; sample_pntr++; @@ -1217,37 +1104,18 @@ int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot) { memset(annot, 0, sizeof(struct edf_annotation_struct)); - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]->writemode) - { - return -1; - } + if(n<0) return -1; - if(n<0) - { - return -1; - } - - if(n>=hdrlist[handle]->annots_in_file) - { - return -1; - } + if(n>=hdrlist[handle]->annots_in_file) return -1; annot->onset = (annotationslist[handle] + n)->onset; + annot->duration_l = (annotationslist[handle] + n)->duration_l; edflib_strlcpy(annot->duration, (annotationslist[handle] + n)->duration, 16); edflib_strlcpy(annot->annotation, (annotationslist[handle] + n)->annotation, EDFLIB_MAX_ANNOTATION_LEN + 1); @@ -1424,7 +1292,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro scratchpad[5] = 0; scratchpad[8] = 0; - if((edflib_atof_nonlocalized(scratchpad)<1)||(edflib_atof_nonlocalized(scratchpad)>31)) + if((edflib_atoi_nonlocalized(scratchpad)<1)||(edflib_atoi_nonlocalized(scratchpad)>31)) { strncpy(scratchpad, edf_hdr + 168, 8); scratchpad[8] = 0; @@ -1434,7 +1302,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - if((edflib_atof_nonlocalized(scratchpad+3)<1)||(edflib_atof_nonlocalized(scratchpad+3)>12)) + if((edflib_atoi_nonlocalized(scratchpad+3)<1)||(edflib_atoi_nonlocalized(scratchpad+3)>12)) { strncpy(scratchpad, edf_hdr + 168, 8); scratchpad[8] = 0; @@ -1444,9 +1312,9 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - edfhdr->startdate_day = edflib_atof_nonlocalized(scratchpad); - edfhdr->startdate_month = edflib_atof_nonlocalized(scratchpad + 3); - edfhdr->startdate_year = edflib_atof_nonlocalized(scratchpad + 6); + edfhdr->startdate_day = edflib_atoi_nonlocalized(scratchpad); + edfhdr->startdate_month = edflib_atoi_nonlocalized(scratchpad + 3); + edfhdr->startdate_year = edflib_atoi_nonlocalized(scratchpad + 6); if(edfhdr->startdate_year>84) { edfhdr->startdate_year += 1900; @@ -1497,7 +1365,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro scratchpad[5] = 0; scratchpad[8] = 0; - if(edflib_atof_nonlocalized(scratchpad)>23) + if(edflib_atoi_nonlocalized(scratchpad)>23) { strncpy(scratchpad, edf_hdr + 176, 8); scratchpad[8] = 0; @@ -1507,7 +1375,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - if(edflib_atof_nonlocalized(scratchpad+3)>59) + if(edflib_atoi_nonlocalized(scratchpad+3)>59) { strncpy(scratchpad, edf_hdr + 176, 8); scratchpad[8] = 0; @@ -1517,7 +1385,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - if(edflib_atof_nonlocalized(scratchpad+6)>59) + if(edflib_atoi_nonlocalized(scratchpad+6)>59) { strncpy(scratchpad, edf_hdr + 176, 8); scratchpad[8] = 0; @@ -1527,13 +1395,13 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - edfhdr->starttime_hour = edflib_atof_nonlocalized(scratchpad); - edfhdr->starttime_minute = edflib_atof_nonlocalized(scratchpad + 3); - edfhdr->starttime_second = edflib_atof_nonlocalized(scratchpad + 6); + edfhdr->starttime_hour = edflib_atoi_nonlocalized(scratchpad); + edfhdr->starttime_minute = edflib_atoi_nonlocalized(scratchpad + 3); + edfhdr->starttime_second = edflib_atoi_nonlocalized(scratchpad + 6); - edfhdr->l_starttime = 3600 * edflib_atof_nonlocalized(scratchpad); - edfhdr->l_starttime += 60 * edflib_atof_nonlocalized(scratchpad + 3); - edfhdr->l_starttime += edflib_atof_nonlocalized(scratchpad + 6); + edfhdr->l_starttime = 3600 * edflib_atoi_nonlocalized(scratchpad); + edfhdr->l_starttime += 60 * edflib_atoi_nonlocalized(scratchpad + 3); + edfhdr->l_starttime += edflib_atoi_nonlocalized(scratchpad + 6); edfhdr->l_starttime *= EDFLIB_TIME_DIMENSION; @@ -1559,7 +1427,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro free(edfhdr); return NULL; } - edfhdr->edfsignals = edflib_atof_nonlocalized(scratchpad); + edfhdr->edfsignals = edflib_atoi_nonlocalized(scratchpad); if(edfhdr->edfsignals<1) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; @@ -1600,7 +1468,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - n = edflib_atof_nonlocalized(scratchpad); + n = edflib_atoi_nonlocalized(scratchpad); if((edfhdr->edfsignals * 256 + 256)!=n) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; @@ -1682,7 +1550,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - edfhdr->datarecords = edflib_atof_nonlocalized(scratchpad); + edfhdr->datarecords = edflib_atoi_nonlocalized(scratchpad); if(edfhdr->datarecords<1) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; @@ -1978,12 +1846,12 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - n = edflib_atof_nonlocalized(scratchpad); + n = edflib_atoi_nonlocalized(scratchpad); if(edfhdr->edfplus) { if(edfhdr->edfparam[i].annotation) { - if(n!=-32768) + if(n!=-0x8000) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -1997,7 +1865,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro { if(edfhdr->edfparam[i].annotation) { - if(n!=-8388608) + if(n!=-0x800000) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2009,7 +1877,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro } if(edfhdr->edf) { - if((n>32767)||(n<-32768)) + if((n>0x7fff)||(n<-0x8000)) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2020,7 +1888,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro } if(edfhdr->bdf) { - if((n>8388607)||(n<-8388608)) + if((n>0x7fffff)||(n<-0x800000)) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2060,12 +1928,12 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - n = edflib_atof_nonlocalized(scratchpad); + n = edflib_atoi_nonlocalized(scratchpad); if(edfhdr->edfplus) { if(edfhdr->edfparam[i].annotation) { - if(n!=32767) + if(n!=0x7fff) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2079,7 +1947,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro { if(edfhdr->edfparam[i].annotation) { - if(n!=8388607) + if(n!=0x7fffff) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2091,7 +1959,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro } if(edfhdr->edf) { - if((n>32767)||(n<-32768)) + if((n>0x7fff)||(n<-0x8000)) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2102,7 +1970,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro } else { - if((n>8388607)||(n<-8388608)) + if((n>0x7fffff)||(n<-0x800000)) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2190,7 +2058,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - n = edflib_atof_nonlocalized(scratchpad); + n = edflib_atoi_nonlocalized(scratchpad); if(n<1) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; @@ -2296,7 +2164,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro if((scratchpad2[8]<48)||(scratchpad2[8]>57)) error = 1; if((scratchpad2[9]<48)||(scratchpad2[9]>57)) error = 1; if((scratchpad2[10]<48)||(scratchpad2[10]>57)) error = 1; - if((edflib_atof_nonlocalized(scratchpad2)<1)||(edflib_atof_nonlocalized(scratchpad2)>31)) error = 1; + if((edflib_atoi_nonlocalized(scratchpad2)<1)||(edflib_atoi_nonlocalized(scratchpad2)>31)) error = 1; if(strcmp(scratchpad2 + 3, "JAN")) if(strcmp(scratchpad2 + 3, "FEB")) if(strcmp(scratchpad2 + 3, "MAR")) @@ -2322,7 +2190,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro } p = 0; - if(edfhdr->patient[p]=='X') + if((edfhdr->patient[p]=='X') && (edfhdr->patient[p+1]==' ')) { edfhdr->plus_patientcode[0] = 0; p += 2; @@ -2366,6 +2234,9 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro if(edfhdr->patient[p]=='X') { edfhdr->plus_birthdate[0] = 0; + edfhdr->plus_birthdate_day = 0; + edfhdr->plus_birthdate_month = 0; + edfhdr->plus_birthdate_year = 0; p += 2; } else @@ -2385,6 +2256,60 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro edfhdr->plus_birthdate[6] = ' '; edfhdr->plus_birthdate[11] = 0; p += i + 1; + edfhdr->plus_birthdate_day = edflib_atoi_nonlocalized(edfhdr->plus_birthdate); + if(!strncmp(edfhdr->plus_birthdate + 3, "jan", 3)) + { + edfhdr->plus_birthdate_month = 1; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "feb", 3)) + { + edfhdr->plus_birthdate_month = 2; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "mar", 3)) + { + edfhdr->plus_birthdate_month = 3; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "apr", 3)) + { + edfhdr->plus_birthdate_month = 4; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "may", 3)) + { + edfhdr->plus_birthdate_month = 5; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "jun", 3)) + { + edfhdr->plus_birthdate_month = 6; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "jul", 3)) + { + edfhdr->plus_birthdate_month = 7; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "aug", 3)) + { + edfhdr->plus_birthdate_month = 8; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "sep", 3)) + { + edfhdr->plus_birthdate_month = 9; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "oct", 3)) + { + edfhdr->plus_birthdate_month = 10; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "nov", 3)) + { + edfhdr->plus_birthdate_month = 11; + } + else if(!strncmp(edfhdr->plus_birthdate + 3, "dec", 3)) + { + edfhdr->plus_birthdate_month = 12; + } + else + { + edfhdr->plus_birthdate_month = 0; + } + edfhdr->plus_birthdate_year = edflib_atoi_nonlocalized(edfhdr->plus_birthdate + 7); } for(i=0; i<(80-p);i++) @@ -2437,7 +2362,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro if((scratchpad2[8]<48)||(scratchpad2[8]>57)) error = 1; if((scratchpad2[9]<48)||(scratchpad2[9]>57)) error = 1; if((scratchpad2[10]<48)||(scratchpad2[10]>57)) error = 1; - if((edflib_atof_nonlocalized(scratchpad2)<1)||(edflib_atof_nonlocalized(scratchpad2)>31)) error = 1; + if((edflib_atoi_nonlocalized(scratchpad2)<1)||(edflib_atoi_nonlocalized(scratchpad2)>31)) error = 1; r = 0; if(!strcmp(scratchpad2 + 3, "JAN")) r = 1; else if(!strcmp(scratchpad2 + 3, "FEB")) r = 2; @@ -2492,9 +2417,9 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro scratchpad[5] = 0; scratchpad[8] = 0; - if(edflib_atof_nonlocalized(scratchpad)!=edflib_atof_nonlocalized(scratchpad2)) error = 1; - if(edflib_atof_nonlocalized(scratchpad+3)!=r) error = 1; - if(edflib_atof_nonlocalized(scratchpad+6)!=edflib_atof_nonlocalized(scratchpad2+9)) error = 1; + if(edflib_atoi_nonlocalized(scratchpad)!=edflib_atoi_nonlocalized(scratchpad2)) error = 1; + if(edflib_atoi_nonlocalized(scratchpad+3)!=r) error = 1; + if(edflib_atoi_nonlocalized(scratchpad+6)!=edflib_atoi_nonlocalized(scratchpad2+9)) error = 1; if(error) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; @@ -2504,7 +2429,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro return NULL; } - if(edfhdr->startdate_year != edflib_atof_nonlocalized(scratchpad2 + 7)) + if(edfhdr->startdate_year != edflib_atoi_nonlocalized(scratchpad2 + 7)) { *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS; free(edf_hdr); @@ -2531,7 +2456,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro edfhdr->plus_startdate[11] = 0; p += i + 1; - if(edfhdr->recording[p]=='X') + if((edfhdr->recording[p]=='X') && (edfhdr->recording[p+1]==' ')) { edfhdr->plus_admincode[0] = 0; p += 2; @@ -2551,7 +2476,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro p += i + 1; } - if(edfhdr->recording[p]=='X') + if((edfhdr->recording[p]=='X') && (edfhdr->recording[p+1]==' ')) { edfhdr->plus_technician[0] = 0; p += 2; @@ -2571,7 +2496,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro p += i + 1; } - if(edfhdr->recording[p]=='X') + if((edfhdr->recording[p]=='X') && (edfhdr->recording[p+1]==' ')) { edfhdr->plus_equipment[0] = 0; p += 2; @@ -3150,8 +3075,16 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_ new_annotation->annotation[0] = 0; - if(duration) edflib_strlcpy(new_annotation->duration, duration_in_txt, 16); - else new_annotation->duration[0] = 0; + if(duration) + { + edflib_strlcpy(new_annotation->duration, duration_in_txt, 16); + new_annotation->duration_l = edflib_get_long_time(duration_in_txt); + } + else + { + new_annotation->duration[0] = 0; + new_annotation->duration_l = -EDFLIB_TIME_DIMENSION; + } for(j=0; je.zY.i....|....<...-....\'u.....>...?AAAAAAECEEEEIIIIDNOOOOOxOUUUUYtsaaaaaaeceeeeiiiidnooooo:0uuuuyty"; + for(i=0; i=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(edfsignal<0) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(edfsignal<0) - { - return -1; - } + if(edfsignal>=hdrlist[handle]->edfsignals) return -1; - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } + if(samplefrequency<1) return -1; - if(samplefrequency<1) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; hdrlist[handle]->edfparam[edfsignal].smp_per_record = samplefrequency; @@ -3816,35 +3645,15 @@ int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency) int edf_set_number_of_annotation_signals(int handle, int annot_signals) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(hdrlist[handle]->datarecords) - { - return -1; - } - - if((annot_signals < 1) || (annot_signals > EDFLIB_MAX_ANNOTATION_CHANNELS)) - { - return -1; - } + if((annot_signals < 1) || (annot_signals > EDFLIB_MAX_ANNOTATION_CHANNELS)) return -1; hdrlist[handle]->nr_annot_chns = annot_signals; @@ -3854,35 +3663,15 @@ int edf_set_number_of_annotation_signals(int handle, int annot_signals) int edf_set_datarecord_duration(int handle, int duration) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(hdrlist[handle]->datarecords) - { - return -1; - } - - if((duration < 100) || (duration > 6000000)) - { - return -1; - } + if((duration < 100) || (duration > 6000000)) return -1; hdrlist[handle]->long_data_record_duration = (long long)duration * 100LL; @@ -3907,35 +3696,15 @@ int edf_set_datarecord_duration(int handle, int duration) int edf_set_micro_datarecord_duration(int handle, int duration) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(hdrlist[handle]->datarecords) - { - return -1; - } - - if((duration < 1) || (duration > 9999)) - { - return -1; - } + if((duration < 1) || (duration > 9999)) return -1; hdrlist[handle]->long_data_record_duration = (long long)duration * 10LL; @@ -3947,35 +3716,15 @@ int edf_set_micro_datarecord_duration(int handle, int duration) int edf_set_subsecond_starttime(int handle, int subsecond) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(hdrlist[handle]->datarecords) - { - return -1; - } - - if((subsecond < 0) || (subsecond > 9999999)) - { - return -1; - } + if((subsecond < 0) || (subsecond > 9999999)) return -1; hdrlist[handle]->starttime_offset = (long long)subsecond; @@ -3997,36 +3746,15 @@ int edfwrite_digital_short_samples(int handle, short *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } - - if(hdrlist[handle]->bdf == 1) - { - return -1; - } + if(hdrlist[handle]->bdf == 1) return -1; hdr = hdrlist[handle]; @@ -4040,10 +3768,7 @@ int edfwrite_digital_short_samples(int handle, short *buf) { error = edflib_write_edf_header(hdr); - if(error) - { - return error; - } + if(error) return error; } } @@ -4055,26 +3780,17 @@ int edfwrite_digital_short_samples(int handle, short *buf) if(hdr->edf) { - if((digmax != 32767) || (digmin != -32768)) + if((digmax != 0x7fff) || (digmin != -0x8000)) { for(i=0; idigmax) - { - buf[i] = digmax; - } + if(buf[i]>digmax) buf[i] = digmax; - if(buf[i]wrbuf = (char *)malloc(sf * 3); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 3; } @@ -4098,15 +3811,9 @@ int edfwrite_digital_short_samples(int handle, short *buf) { value = buf[i]; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 3] = value & 0xff; @@ -4115,10 +3822,7 @@ int edfwrite_digital_short_samples(int handle, short *buf) hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1; } hdr->signal_write_sequence_pos++; @@ -4127,10 +3831,7 @@ int edfwrite_digital_short_samples(int handle, short *buf) { hdr->signal_write_sequence_pos = 0; - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -4155,31 +3856,13 @@ int edfwrite_digital_samples(int handle, int *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } - - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; hdr = hdrlist[handle]; @@ -4193,10 +3876,7 @@ int edfwrite_digital_samples(int handle, int *buf) { error = edflib_write_edf_header(hdr); - if(error) - { - return error; - } + if(error) return error; } } @@ -4216,10 +3896,7 @@ int edfwrite_digital_samples(int handle, int *buf) hdr->wrbuf = (char *)malloc(sf * 2); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 2; } @@ -4228,25 +3905,16 @@ int edfwrite_digital_samples(int handle, int *buf) { value = buf[i]; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 2] = value & 0xff; hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1; } else // BDF { @@ -4258,10 +3926,7 @@ int edfwrite_digital_samples(int handle, int *buf) hdr->wrbuf = (char *)malloc(sf * 3); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 3; } @@ -4270,15 +3935,9 @@ int edfwrite_digital_samples(int handle, int *buf) { value = buf[i]; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 3] = value & 0xff; @@ -4287,10 +3946,7 @@ int edfwrite_digital_samples(int handle, int *buf) hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1; } hdr->signal_write_sequence_pos++; @@ -4299,10 +3955,7 @@ int edfwrite_digital_samples(int handle, int *buf) { hdr->signal_write_sequence_pos = 0; - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -4328,36 +3981,15 @@ int edf_blockwrite_digital_samples(int handle, int *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->signal_write_sequence_pos) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } + if(hdrlist[handle]->signal_write_sequence_pos) return -1; hdr = hdrlist[handle]; @@ -4369,10 +4001,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf) { error = edflib_write_edf_header(hdr); - if(error) - { - return error; - } + if(error) return error; } buf_offset = 0; @@ -4395,10 +4024,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf) hdr->wrbuf = (char *)malloc(sf * 2); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 2; } @@ -4407,25 +4033,16 @@ int edf_blockwrite_digital_samples(int handle, int *buf) { value = buf[i + buf_offset]; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 2] = value & 0xff; hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1; } else // BDF { @@ -4437,10 +4054,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf) hdr->wrbuf = (char *)malloc(sf * 3); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 3; } @@ -4449,15 +4063,9 @@ int edf_blockwrite_digital_samples(int handle, int *buf) { value = buf[i + buf_offset]; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 3] = value & 0xff; @@ -4466,19 +4074,13 @@ int edf_blockwrite_digital_samples(int handle, int *buf) hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1; } buf_offset += sf; } - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -4503,41 +4105,17 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->signal_write_sequence_pos) return -1; - if(hdrlist[handle]->signal_write_sequence_pos) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } - - if(hdrlist[handle]->bdf == 1) - { - return -1; - } + if(hdrlist[handle]->bdf == 1) return -1; hdr = hdrlist[handle]; @@ -4567,7 +4145,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf) if(hdr->edf) { - if((digmax != 32767) || (digmin != -32768)) + if((digmax != 0x7fff) || (digmin != -0x8000)) { for(i=0; iwrbuf = (char *)malloc(sf * 3); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 3; } @@ -4610,15 +4182,9 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf) { value = buf[i + buf_offset]; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 3] = value & 0xff; @@ -4627,19 +4193,13 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf) hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1; } buf_offset += sf; } - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -4660,41 +4220,17 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->signal_write_sequence_pos) return -1; - if(hdrlist[handle]->signal_write_sequence_pos) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } - - if(hdrlist[handle]->bdf != 1) - { - return -1; - } + if(hdrlist[handle]->bdf != 1) return -1; hdr = hdrlist[handle]; @@ -4706,10 +4242,7 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf) { error = edflib_write_edf_header(hdr); - if(error) - { - return error; - } + if(error) return error; } for(j=0; jedfparam[j].smp_per_record; } - if(fwrite(buf, total_samples * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(buf, total_samples * 3, 1, file) != 1) return -1; - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -4752,31 +4279,13 @@ int edfwrite_physical_samples(int handle, double *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } - - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; hdr = hdrlist[handle]; @@ -4790,10 +4299,7 @@ int edfwrite_physical_samples(int handle, double *buf) { error = edflib_write_edf_header(hdr); - if(error) - { - return error; - } + if(error) return error; } } @@ -4817,10 +4323,7 @@ int edfwrite_physical_samples(int handle, double *buf) hdr->wrbuf = (char *)malloc(sf * 2); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 2; } @@ -4829,25 +4332,16 @@ int edfwrite_physical_samples(int handle, double *buf) { value = (buf[i] / bitvalue) - phys_offset; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 2] = value & 0xff; hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1; } else // BDF { @@ -4859,10 +4353,7 @@ int edfwrite_physical_samples(int handle, double *buf) hdr->wrbuf = (char *)malloc(sf * 3); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 3; } @@ -4871,15 +4362,9 @@ int edfwrite_physical_samples(int handle, double *buf) { value = (buf[i] / bitvalue) - phys_offset; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 3] = value & 0xff; @@ -4888,10 +4373,7 @@ int edfwrite_physical_samples(int handle, double *buf) hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1; } hdr->signal_write_sequence_pos++; @@ -4900,10 +4382,7 @@ int edfwrite_physical_samples(int handle, double *buf) { hdr->signal_write_sequence_pos = 0; - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -4932,36 +4411,15 @@ int edf_blockwrite_physical_samples(int handle, double *buf) struct edfhdrblock *hdr; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(hdrlist[handle]->edfsignals == 0) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->signal_write_sequence_pos) - { - return -1; - } - - if(hdrlist[handle]->edfsignals == 0) - { - return -1; - } + if(hdrlist[handle]->signal_write_sequence_pos) return -1; hdr = hdrlist[handle]; @@ -4973,10 +4431,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf) { error = edflib_write_edf_header(hdr); - if(error) - { - return error; - } + if(error) return error; } buf_offset = 0; @@ -5003,10 +4458,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf) hdr->wrbuf = (char *)malloc(sf * 2); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 2; } @@ -5015,25 +4467,16 @@ int edf_blockwrite_physical_samples(int handle, double *buf) { value = (buf[i + buf_offset] / bitvalue) - phys_offset; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 2] = value & 0xff; hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1; } else // BDF { @@ -5045,10 +4488,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf) hdr->wrbuf = (char *)malloc(sf * 3); - if(hdr->wrbuf == NULL) - { - return -1; - } + if(hdr->wrbuf == NULL) return -1; hdr->wrbufsize = sf * 3; } @@ -5057,15 +4497,9 @@ int edf_blockwrite_physical_samples(int handle, double *buf) { value = (buf[i + buf_offset] / bitvalue) - phys_offset; - if(value>digmax) - { - value = digmax; - } + if(value>digmax) value = digmax; - if(valuewrbuf[i * 3] = value & 0xff; @@ -5074,19 +4508,13 @@ int edf_blockwrite_physical_samples(int handle, double *buf) hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff; } - if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) - { - return -1; - } + if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1; } buf_offset += sf; } - if(edflib_write_tal(hdr, file)) - { - return -1; - } + if(edflib_write_tal(hdr, file)) return -1; hdr->datarecords++; @@ -5111,20 +4539,13 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr) FILE *file; - file = hdr->file_hdl; edfsignals = hdr->edfsignals; - if(edfsignals<0) - { - return EDFLIB_NO_SIGNALS; - } + if(edfsignals<0) return EDFLIB_NO_SIGNALS; - if(edfsignals>EDFLIB_MAXSIGNALS) - { - return EDFLIB_TOO_MANY_SIGNALS; - } + if(edfsignals>EDFLIB_MAXSIGNALS) return EDFLIB_TOO_MANY_SIGNALS; hdr->eq_sf = 1; @@ -5134,25 +4555,13 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr) for(i=0; iedfparam[i].smp_per_record<1) - { - return EDFLIB_NO_SAMPLES_IN_RECORD; - } + if(hdr->edfparam[i].smp_per_record<1) return EDFLIB_NO_SAMPLES_IN_RECORD; - if(hdr->edfparam[i].dig_max==hdr->edfparam[i].dig_min) - { - return EDFLIB_DIGMIN_IS_DIGMAX; - } + if(hdr->edfparam[i].dig_max==hdr->edfparam[i].dig_min) return EDFLIB_DIGMIN_IS_DIGMAX; - if(hdr->edfparam[i].dig_maxedfparam[i].dig_min) - { - return EDFLIB_DIGMAX_LOWER_THAN_DIGMIN; - } + if(hdr->edfparam[i].dig_maxedfparam[i].dig_min) return EDFLIB_DIGMAX_LOWER_THAN_DIGMIN; - if(hdr->edfparam[i].phys_max==hdr->edfparam[i].phys_min) - { - return EDFLIB_PHYSMIN_IS_PHYSMAX; - } + if(hdr->edfparam[i].phys_max==hdr->edfparam[i].phys_min) return EDFLIB_PHYSMIN_IS_PHYSMAX; hdr->recordsize += hdr->edfparam[i].smp_per_record; @@ -5278,7 +4687,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr) fputc(hdr->plus_birthdate[0], file); fputc(hdr->plus_birthdate[1], file); fputc('-', file); - q = edflib_atof_nonlocalized(&(hdr->plus_birthdate[3])); + q = edflib_atoi_nonlocalized(&(hdr->plus_birthdate[3])); switch(q) { case 1: fprintf(file, "JAN"); break; @@ -5760,40 +5169,15 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr) int edf_set_label(int handle, int edfsignal, const char *label) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } - - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; strncpy(hdrlist[handle]->edfparam[edfsignal].label, label, 16); @@ -5807,40 +5191,15 @@ int edf_set_label(int handle, int edfsignal, const char *label) int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } - - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; strncpy(hdrlist[handle]->edfparam[edfsignal].physdimension, phys_dim, 8); @@ -5854,40 +5213,15 @@ int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim) int edf_set_physical_maximum(int handle, int edfsignal, double phys_max) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } - - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; hdrlist[handle]->edfparam[edfsignal].phys_max = phys_max; @@ -5897,40 +5231,15 @@ int edf_set_physical_maximum(int handle, int edfsignal, double phys_max) int edf_set_physical_minimum(int handle, int edfsignal, double phys_min) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } - - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; hdrlist[handle]->edfparam[edfsignal].phys_min = phys_min; @@ -5940,54 +5249,23 @@ int edf_set_physical_minimum(int handle, int edfsignal, double phys_min) int edf_set_digital_maximum(int handle, int edfsignal, int dig_max) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } - - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; if(hdrlist[handle]->edf) { - if(dig_max > 32767) - { - return -1; - } + if(dig_max > 0x7fff) return -1; } else { - if(dig_max > 8388607) - { - return -1; - } - } - - if(hdrlist[handle]->datarecords) - { - return -1; + if(dig_max > 0x7fffff) return -1; } hdrlist[handle]->edfparam[edfsignal].dig_max = dig_max; @@ -5998,54 +5276,23 @@ int edf_set_digital_maximum(int handle, int edfsignal, int dig_max) int edf_set_digital_minimum(int handle, int edfsignal, int dig_min) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } - - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; if(hdrlist[handle]->edf) { - if(dig_min < (-32768)) - { - return -1; - } + if(dig_min < (-0x8000)) return -1; } else { - if(dig_min < (-8388608)) - { - return -1; - } - } - - if(hdrlist[handle]->datarecords) - { - return -1; + if(dig_min < (-0x800000)) return -1; } hdrlist[handle]->edfparam[edfsignal].dig_min = dig_min; @@ -6056,30 +5303,13 @@ int edf_set_digital_minimum(int handle, int edfsignal, int dig_min) int edf_set_patientname(int handle, const char *patientname) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_patient_name, patientname, 80); @@ -6093,30 +5323,13 @@ int edf_set_patientname(int handle, const char *patientname) int edf_set_patientcode(int handle, const char *patientcode) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_patientcode, patientcode, 80); @@ -6130,35 +5343,15 @@ int edf_set_patientcode(int handle, const char *patientcode) int edf_set_gender(int handle, int gender) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(hdrlist[handle]->datarecords) - { - return -1; - } - - if((gender<0)||(gender>1)) - { - return -1; - } + if((gender<0)||(gender>1)) return -1; if(gender) { @@ -6177,30 +5370,13 @@ int edf_set_gender(int handle, int gender) int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int birthdate_day) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; if((birthdate_year<1800) || (birthdate_year>3000) || (birthdate_month<1) || (birthdate_month>12) || @@ -6219,30 +5395,13 @@ int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int b int edf_set_patient_additional(int handle, const char *patient_additional) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_patient_additional, patient_additional, 80); @@ -6256,30 +5415,13 @@ int edf_set_patient_additional(int handle, const char *patient_additional) int edf_set_admincode(int handle, const char *admincode) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_admincode, admincode, 80); @@ -6293,30 +5435,13 @@ int edf_set_admincode(int handle, const char *admincode) int edf_set_technician(int handle, const char *technician) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_technician, technician, 80); @@ -6330,30 +5455,13 @@ int edf_set_technician(int handle, const char *technician) int edf_set_equipment(int handle, const char *equipment) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_equipment, equipment, 80); @@ -6367,30 +5475,13 @@ int edf_set_equipment(int handle, const char *equipment) int edf_set_recording_additional(int handle, const char *recording_additional) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->plus_recording_additional, recording_additional, 80); @@ -6405,30 +5496,13 @@ int edf_set_recording_additional(int handle, const char *recording_additional) int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, int startdate_day, int starttime_hour, int starttime_minute, int starttime_second) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; if((startdate_year<1985) || (startdate_year>2084) || (startdate_month<1) || (startdate_month>12) || @@ -6457,31 +5531,13 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co struct edf_write_annotationblock *list_annot, *malloc_list; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } - - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(onset<0LL) - { - return -1; - } + if(onset<0LL) return -1; if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz) { @@ -6529,31 +5585,13 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration, char str[EDFLIB_WRITE_MAX_ANNOTATION_LEN + 1]; + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle<0) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } - - if(!(hdrlist[handle]->writemode)) - { - return -1; - } - - if(onset<0LL) - { - return -1; - } + if(onset<0LL) return -1; if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz) { @@ -6618,40 +5656,17 @@ static void edflib_remove_padding_trailing_spaces(char *str) int edf_set_prefilter(int handle, int edfsignal, const char *prefilter) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->edfparam[edfsignal].prefilter, prefilter, 80); @@ -6665,40 +5680,17 @@ int edf_set_prefilter(int handle, int edfsignal, const char *prefilter) int edf_set_transducer(int handle, int edfsignal, const char *transducer) { - if(handle<0) - { - return -1; - } + if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1; - if(handle>=EDFLIB_MAXFILES) - { - return -1; - } + if(hdrlist[handle]==NULL) return -1; - if(hdrlist[handle]==NULL) - { - return -1; - } + if(!hdrlist[handle]->writemode) return -1; - if(!(hdrlist[handle]->writemode)) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; - if(edfsignal<0) - { - return -1; - } + if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1; - if(edfsignal>=hdrlist[handle]->edfsignals) - { - return -1; - } - - if(hdrlist[handle]->datarecords) - { - return -1; - } + if(hdrlist[handle]->datarecords) return -1; strncpy(hdrlist[handle]->edfparam[edfsignal].transducer, transducer, 80); diff --git a/edflib.h b/edflib.h index 88fe802..47c9b49 100644 --- a/edflib.h +++ b/edflib.h @@ -1,7 +1,7 @@ /* ***************************************************************************** * -* Copyright (c) 2009 - 2021 Teunis van Beelen +* Copyright (c) 2009 - 2023 Teunis van Beelen * All rights reserved. * * Email: teuniz@protonmail.com @@ -31,23 +31,89 @@ ***************************************************************************** */ +/**************************************************************************** + * + * For more info about the EDF and EDF+ format, visit: http://edfplus.info/specs/ + * + * For more info about the BDF and BDF+ format, visit: http://www.teuniz.net/edfbrowser/bdfplus%20format%20description.html + * + * note: In EDF, the resolution (or sensitivity) (e.g. uV/bit) and offset are stored using four parameters: + * digital maximum and minimum, and physical maximum and minimum. + * Here, digital means the raw data coming from a sensor or ADC. Physical means the units like uV. + * The resolution in units per least significant bit is calculated as follows: + * + * units per bit = (physical max - physical min) / (digital max - digital min) + * + * The digital offset is calculated as follows: + * + * offset = (physical max / units per bit) - digital max + * + * For a better explanation about the relation between digital data and physical data, + * read the document "Coding Schemes Used with Data Converters" (PDF): + * + * https://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sbaa042 + * + * note: An EDF file usually contains multiple so-called datarecords. One datarecord usually has a duration of one second (this is the default but it is not mandatory!). + * In that case a file with a duration of five minutes contains 300 datarecords. The duration of a datarecord can be freely choosen but, if possible, use values from + * 0.1 to 1 second for easier handling. Just make sure that the total size of one datarecord, expressed in bytes, does not exceed 10MByte (15MBytes for BDF(+)). + * + * The RECOMMENDATION of a maximum datarecordsize of 61440 bytes in the EDF and EDF+ specification was useful in the time people were still using DOS as their main operating system. + * Using DOS and fast (near) pointers (16-bit pointers), the maximum allocatable block of memory was 64KByte. + * This is not a concern anymore so the maximum datarecord size now is limited to 10MByte for EDF(+) and 15MByte for BDF(+). This helps to accommodate for higher samplingrates + * used by modern Analog to Digital Converters. + * + * EDF header character encoding: The EDF specification says that only (printable) ASCII characters are allowed. + * When writing the header info, EDFlib will assume you are using Latin1 encoding and it will automatically convert + * characters with accents, umlauts, tilde, etc. to their "normal" equivalent without the accent/umlaut/tilde/etc. + * in order to create a valid EDF file. + * The description of an EDF+ annotation on the other hand, is always encoded in UTF-8 (which is foreward compatible with ASCII). + * + * The samplefrequency of a signal is calculated as follows: sf = (smp_in_datarecord * EDFLIB_TIME_DIMENSION) / datarecord_duration + * + * Annotation signals + * ================== + * + * EDF+ and BDF+ store the annotations in one or more signals (in order to be backwards compatibel with EDF and BDF). + * The numbering of the signals in the file is zero based (starts at 0). Signals used for annotations are skipped by EDFlib. + * This means that the annotationsignal(s) in the file are hided. + * Use the function edf_get_annotation() to get the annotations. + * + * So, when a file contains 5 signals and the third signal is an annotations signal, the library will + * report that there are only 4 signals in the file. + * The library will "map" the signal numbers as follows: 0->0, 1->1, 2->3, 3->4. + * This way you don't need to worry about which signals are annotationsignals, the library will take care of it. + * + * How the library stores time values + * ================================== + * + * To avoid rounding errors, the library stores some timevalues in variables of type long long int. + * In order not to lose the subsecond precision, all timevalues are scaled with a scaling factor: 10000000. + * This will limit the timeresolution to 100 nanoSeconds. To calculate the amount of seconds, divide + * the timevalue by 10000000 or use the macro EDFLIB_TIME_DIMENSION which is declared in edflib.h. + * The following variables use this scaling when you open a file in read mode: "file_duration", "starttime_subsecond" and "onset". + * + * EDFlib and thread-safety + * ======================== + * The following functions are always MT-unsafe: + * edfopen_file_readonly() (race condition) + * edfclose_file() (race condition) + * edflib_get_handle() (race condition) + * + * When writing to or reading from the same file, all EDFlib functions are MT-unsafe (race condition). + * + */ /* compile with options "-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" */ - - #ifndef EDFLIB_INCLUDED #define EDFLIB_INCLUDED - #include #include #include #include - - #define EDFLIB_TIME_DIMENSION (10000000LL) #define EDFLIB_MAXSIGNALS (640) #define EDFLIB_MAX_ANNOTATION_LEN (512) @@ -56,10 +122,8 @@ #define EDFSEEK_CUR (1) #define EDFSEEK_END (2) - - -/* the following defines are used in the member "filetype" of the edf_hdr_struct */ -/* and as return value for the function edfopen_file_readonly() */ +/* the following defines are used in the member "filetype" of the edf_hdr_struct + and as return value for the function edfopen_file_readonly() */ #define EDFLIB_FILETYPE_EDF (0) #define EDFLIB_FILETYPE_EDFPLUS (1) #define EDFLIB_FILETYPE_BDF (2) @@ -69,7 +133,7 @@ /* when this error occurs, try to open the file with EDFbrowser, it will give you full details about the cause of the error. */ -#define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS -3 +#define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS (-3) #define EDFLIB_MAXFILES_REACHED (-4) #define EDFLIB_FILE_READ_ERROR (-5) @@ -79,6 +143,7 @@ #define EDFLIB_NUMBER_OF_SIGNALS_INVALID (-9) #define EDFLIB_FILE_IS_DISCONTINUOUS (-10) #define EDFLIB_INVALID_READ_ANNOTS_VALUE (-11) +#define EDFLIB_ARCH_ERROR (-12) /* values for annotations */ #define EDFLIB_DO_NOT_READ_ANNOTATIONS (0) @@ -94,85 +159,39 @@ #define EDFLIB_PHYSMIN_IS_PHYSMAX (-25) #define EDFLIB_DATARECORD_SIZE_TOO_BIG (-26) - - - #ifdef __cplusplus extern "C" { #endif - - -/* For more info about the EDF and EDF+ format, visit: http://edfplus.info/specs/ */ - -/* For more info about the BDF and BDF+ format, visit: http://www.teuniz.net/edfbrowser/bdfplus%20format%20description.html */ - -/* - * note: In EDF, the sensitivity (e.g. uV/bit) and offset are stored using four parameters: - * digital maximum and minimum, and physical maximum and minimum. - * Here, digital means the raw data coming from a sensor or ADC. Physical means the units like uV. - * The sensitivity in units/bit is calculated as follows: - * - * units per bit = (physical max - physical min) / (digital max - digital min) - * - * The digital offset is calculated as follows: - * - * offset = (physical max / units per bit) - digital max - * - * For a better explanation about the relation between digital data and physical data, - * read the document "Coding Schemes Used with Data Converters" (PDF): - * - * http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sbaa042 - * - * note: An EDF file usually contains multiple so-called datarecords. One datarecord usually has a duration of one second (this is the default but it is not mandatory!). - * In that case a file with a duration of five minutes contains 300 datarecords. The duration of a datarecord can be freely choosen but, if possible, use values from - * 0.1 to 1 second for easier handling. Just make sure that the total size of one datarecord, expressed in bytes, does not exceed 10MByte (15MBytes for BDF(+)). - * - * The RECOMMENDATION of a maximum datarecordsize of 61440 bytes in the EDF and EDF+ specification was usefull in the time people were still using DOS as their main operating system. - * Using DOS and fast (near) pointers (16-bit pointers), the maximum allocatable block of memory was 64KByte. - * This is not a concern anymore so the maximum datarecord size now is limited to 10MByte for EDF(+) and 15MByte for BDF(+). This helps to accommodate for higher samplingrates - * used by modern Analog to Digital Converters. - * - * EDF header character encoding: The EDF specification says that only (printable) ASCII characters are allowed. - * When writing the header info, EDFlib will assume you are using Latin1 encoding and it will automatically convert - * characters with accents, umlauts, tilde, etc. to their "normal" equivalent without the accent/umlaut/tilde/etc. - * in order to create a valid EDF file. - * - * The description/name of an EDF+ annotation on the other hand, is encoded in UTF-8. - * - */ - - struct edf_param_struct{ /* this structure contains all the relevant EDF-signal parameters of one signal */ char label[17]; /* label (name) of the signal, null-terminated string */ long long smp_in_file; /* number of samples of this signal in the file */ double phys_max; /* physical maximum, usually the maximum input of the ADC */ double phys_min; /* physical minimum, usually the minimum input of the ADC */ - int dig_max; /* digital maximum, usually the maximum output of the ADC, can not not be higher than 32767 for EDF or 8388607 for BDF */ - int dig_min; /* digital minimum, usually the minimum output of the ADC, can not not be lower than -32768 for EDF or -8388608 for BDF */ + int dig_max; /* digital maximum, usually the maximum output of the ADC, cannot not be higher than 32767 for EDF or 8388607 for BDF */ + int dig_min; /* digital minimum, usually the minimum output of the ADC, cannot not be lower than -32768 for EDF or -8388608 for BDF */ int smp_in_datarecord; /* number of samples of this signal in a datarecord, if the datarecord has a duration of one second (default), then it equals the samplerate */ char physdimension[9]; /* physical dimension (uV, bpm, mA, etc.), null-terminated string */ char prefilter[81]; /* null-terminated string */ char transducer[81]; /* null-terminated string */ }; - struct edf_annotation_struct{ /* this structure is used for annotations */ long long onset; /* onset time of the event, expressed in units of 100 nanoSeconds and relative to the start of the file */ + long long duration_l; /* duration time, expressed in units of 100 nanoSeconds, a value of -10000000 means unused (duration not present) */ char duration[16]; /* duration time, this is a null-terminated ASCII text-string */ char annotation[EDFLIB_MAX_ANNOTATION_LEN + 1]; /* description of the event in UTF-8, this is a null terminated string */ }; - -struct edf_hdr_struct{ /* this structure contains all the relevant EDF header info and will be filled when calling the function edf_open_file_readonly() */ - int handle; /* a handle (identifier) used to distinguish the different files */ - int filetype; /* 0: EDF, 1: EDFplus, 2: BDF, 3: BDFplus, a negative number means an error */ - int edfsignals; /* number of EDF signals in the file, annotation channels are NOT included */ - long long file_duration; /* duration of the file expressed in units of 100 nanoSeconds */ +struct edf_hdr_struct{ /* this structure contains all the relevant EDF header info and will be filled when calling the function edf_open_file_readonly() */ + int handle; /* a handle (identifier) used to distinguish the different files */ + int filetype; /* 0: EDF, 1: EDF+, 2: BDF, 3: BDF+, a negative number means an error */ + int edfsignals; /* number of EDF signals in the file, annotation channels are NOT included */ + long long file_duration; /* duration of the file expressed in units of 100 nanoSeconds */ int startdate_day; int startdate_month; int startdate_year; - long long starttime_subsecond; /* starttime offset expressed in units of 100 nanoSeconds. Is always less than 10000000 (one second). Only used by EDFplus and BDFplus */ + long long starttime_subsecond; /* starttime offset expressed in units of 100 nanoSeconds. Is always less than 10000000 (one second). Only used by EDF+ and BDF+ */ int starttime_second; int starttime_minute; int starttime_hour; @@ -181,6 +200,9 @@ struct edf_hdr_struct{ /* this structure contains all the re char patientcode[81]; /* null-terminated string, is always empty when filetype is EDF or BDF */ char gender[16]; /* null-terminated string, is always empty when filetype is EDF or BDF */ char birthdate[16]; /* null-terminated string, is always empty when filetype is EDF or BDF */ + int birthdate_day; /* 1 - 31 */ + int birthdate_month; /* 1 - 12 */ + int birthdate_year; char patient_name[81]; /* null-terminated string, is always empty when filetype is EDF or BDF */ char patient_additional[81]; /* null-terminated string, is always empty when filetype is EDF or BDF */ char admincode[81]; /* null-terminated string, is always empty when filetype is EDF or BDF */ @@ -193,509 +215,460 @@ struct edf_hdr_struct{ /* this structure contains all the re struct edf_param_struct signalparam[EDFLIB_MAXSIGNALS]; /* array of structs which contain the relevant signal parameters */ }; - - - /***************** the following functions are used to read files **************************/ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int read_annotations); +/* opens an existing file for reading + * path is a null-terminated string containing the path to the file + * hdr is a pointer to an edf_hdr_struct, all fields in this struct will be overwritten + * the edf_hdr_struct will be filled with all the relevant header- and signalinfo/parameters -/* opens an existing file for reading */ -/* path is a null-terminated string containing the path to the file */ -/* hdr is a pointer to an edf_hdr_struct, all fields in this struct will be overwritten */ -/* the edf_hdr_struct will be filled with all the relevant header- and signalinfo/parameters */ - -/* read_annotations must have one of the following values: */ -/* EDFLIB_DO_NOT_READ_ANNOTATIONS annotations will not be read (this saves time when opening a very large EDFplus or BDFplus file */ -/* EDFLIB_READ_ANNOTATIONS annotations will be read immediately, stops when an annotation has */ -/* been found which contains the description "Recording ends" */ -/* EDFLIB_READ_ALL_ANNOTATIONS all annotations will be read immediately */ - -/* returns 0 on success, in case of an error it returns -1 and an errorcode will be set in the member "filetype" of struct edf_hdr_struct */ -/* This function is required if you want to read a file */ - + * read_annotations must have one of the following values: + * EDFLIB_DO_NOT_READ_ANNOTATIONS annotations will not be read (this saves time when opening a very large EDF+ or BDF+ file + * EDFLIB_READ_ANNOTATIONS annotations will be read immediately, stops when an annotation has + * been found which contains the description "Recording ends" + * EDFLIB_READ_ALL_ANNOTATIONS all annotations will be read immediately + * returns 0 on success, in case of an error it returns -1 and an errorcode will be set in the member "filetype" of struct edf_hdr_struct + * This function is required if you want to read a file + */ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf); - -/* reads n samples from edfsignal, starting from the current sample position indicator, into buf (edfsignal starts at 0) */ -/* the values are converted to their physical values e.g. microVolts, beats per minute, etc. */ -/* bufsize should be equal to or bigger than sizeof(double[n]) */ -/* the sample position indicator will be increased with the amount of samples read */ -/* returns the amount of samples read (this can be less than n or zero!) */ -/* or -1 in case of an error */ - +/* reads n samples from edfsignal, starting from the current sample position indicator, into buf (edfsignal starts at 0) + * the values are converted to their physical values e.g. microVolts, beats per minute, etc. + * bufsize should be equal to or bigger than sizeof(double[n]) + * the sample position indicator will be increased with the amount of samples read + * returns the amount of samples read (this can be less than n or zero!) + * or -1 in case of an error + */ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf); - -/* reads n samples from edfsignal, starting from the current sample position indicator, into buf (edfsignal starts at 0) */ -/* the values are the "raw" digital values */ -/* bufsize should be equal to or bigger than sizeof(int[n]) */ -/* the sample position indicator will be increased with the amount of samples read */ -/* returns the amount of samples read (this can be less than n or zero!) */ -/* or -1 in case of an error */ - +/* reads n samples from edfsignal, starting from the current sample position indicator, into buf (edfsignal starts at 0) + * the values are the "raw" digital values + * bufsize should be equal to or bigger than sizeof(int[n]) + * the sample position indicator will be increased with the amount of samples read + * returns the amount of samples read (this can be less than n or zero!) + * or -1 in case of an error + */ long long edfseek(int handle, int edfsignal, long long offset, int whence); - -/* The edfseek() function sets the sample position indicator for the edfsignal pointed to by edfsignal. */ -/* The new position, measured in samples, is obtained by adding offset samples to the position specified by whence. */ -/* If whence is set to EDFSEEK_SET, EDFSEEK_CUR, or EDFSEEK_END, the offset is relative to the start of the file, */ -/* the current position indicator, or end-of-file, respectively. */ -/* Returns the current offset. Otherwise, -1 is returned. */ -/* note that every signal has it's own independent sample position indicator and edfseek() affects only one of them */ - +/* The edfseek() function sets the sample position indicator for the edfsignal pointed to by edfsignal. + * The new position, measured in samples, is obtained by adding offset samples to the position specified by whence. + * If whence is set to EDFSEEK_SET, EDFSEEK_CUR, or EDFSEEK_END, the offset is relative to the start of the file, + * the current position indicator, or end-of-file, respectively. + * Returns the current offset. Otherwise, -1 is returned. + * note that every signal has it's own independent sample position indicator and edfseek() affects only one of them + */ long long edftell(int handle, int edfsignal); - -/* The edftell() function obtains the current value of the sample position indicator for the edfsignal pointed to by edfsignal. */ -/* Returns the current offset. Otherwise, -1 is returned */ -/* note that every signal has it's own independent sample position indicator and edftell() affects only one of them */ - +/* The edftell() function obtains the current value of the sample position indicator for the edfsignal pointed to by edfsignal. + * Returns the current offset. Otherwise, -1 is returned + * note that every signal has it's own independent sample position indicator and edftell() affects only one of them + */ void edfrewind(int handle, int edfsignal); - -/* The edfrewind() function sets the sample position indicator for the edfsignal pointed to by edfsignal to the beginning of the file. */ -/* It is equivalent to: (void) edfseek(int handle, int edfsignal, 0LL, EDFSEEK_SET) */ -/* note that every signal has it's own independent sample position indicator and edfrewind() affects only one of them */ - +/* The edfrewind() function sets the sample position indicator for the edfsignal pointed to by edfsignal to the beginning of the file. + * It is equivalent to: (void) edfseek(int handle, int edfsignal, 0LL, EDFSEEK_SET) + * note that every signal has it's own independent sample position indicator and edfrewind() affects only one of them + */ int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot); +/* Fills the edf_annotation_struct with the annotation n, returns 0 on success, otherwise -1 + * The string that describes the annotation/event is encoded in UTF-8 + * To obtain the number of annotations in a file, check edf_hdr_struct -> annotations_in_file. + * returns 0 on success or -1 in case of an error + */ -/* Fills the edf_annotation_struct with the annotation n, returns 0 on success, otherwise -1 */ -/* The string that describes the annotation/event is encoded in UTF-8 */ -/* To obtain the number of annotations in a file, check edf_hdr_struct -> annotations_in_file. */ -/* returns 0 on success or -1 in case of an error */ - -/* -Notes: - -Annotationsignals -================= - -EDFplus and BDFplus store the annotations in one or more signals (in order to be backwards compatibel with EDF and BDF). -The counting of the signals in the file starts at 0. Signals used for annotations are skipped by EDFlib. -This means that the annotationsignal(s) in the file are hided. -Use the function edf_get_annotation() to get the annotations. - -So, when a file contains 5 signals and the third signal is used to store the annotations, the library will -report that there are only 4 signals in the file. -The library will "map" the signalnumbers as follows: 0->0, 1->1, 2->3, 3->4. -This way you don't need to worry about which signals are annotationsignals, the library will take care of it. - -How the library stores time-values -================================== - -To avoid rounding errors, the library stores some timevalues in variables of type long long int. -In order not to loose the subsecond precision, all timevalues have been multiplied by 10000000. -This will limit the timeresolution to 100 nanoSeconds. To calculate the amount of seconds, divide -the timevalue by 10000000 or use the macro EDFLIB_TIME_DIMENSION which is declared in edflib.h. -The following variables do use this when you open a file in read mode: "file_duration", "starttime_subsecond" and "onset". -*/ - -/***************** the following functions are used to read or write files **************************/ +/***************** the following functions are used in read and write mode **************************/ int edfclose_file(int handle); - -/* closes (and in case of writing, finalizes) the file */ -/* returns -1 in case of an error, 0 on success */ -/* this function MUST be called when you are finished reading or writing */ -/* This function is required after reading or writing. Failing to do so will cause */ -/* unnessecary memory usage and in case of writing it will cause a corrupted and incomplete file */ - +/* closes (and in case of writing, finalizes) the file + * returns -1 in case of an error, 0 on success + * this function MUST be called when you are finished reading or writing + * This function is required after reading or writing. Failing to do so will cause + * unnessecary memory usage and in case of writing it will cause a corrupted and incomplete file + */ int edflib_version(void); - -/* Returns the version number of this library, multiplied by hundred. if version is "1.00" than it will return 100 */ - +/* Returns the version number of this library, multiplied by hundred. if version is "1.00" than it will return 100 + */ int edflib_is_file_used(const char *path); - -/* returns 1 if the file is used, either for reading or writing */ -/* otherwise returns 0 */ - +/* returns 1 if the file is used, either for reading or writing, otherwise returns 0 + */ int edflib_get_number_of_open_files(void); - -/* returns the number of open files, either for reading or writing */ - +/* returns the number of open files, either for reading or writing + */ int edflib_get_handle(int file_number); - -/* returns the handle of an opened file, either for reading or writing */ -/* file_number starts with 0 */ -/* returns -1 if the file is not opened */ - +/* returns the handle of an opened file, either for reading or writing + * file_number is zero based (starts with 0) + * returns -1 if the file is not opened + */ /***************** the following functions are used to write files **************************/ - int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals); +/* opens an new file for writing. warning, an already existing file with the same name will be silently overwritten without advance warning! + * path is a null-terminated string containing the path and name of the file + * filetype must be EDFLIB_FILETYPE_EDFPLUS or EDFLIB_FILETYPE_BDFPLUS + * returns a handle on success, you need this handle for the other functions + * in case of an error it returns a negative number corresponding to one of the following values: + * EDFLIB_MALLOC_ERROR + * EDFLIB_NO_SUCH_FILE_OR_DIRECTORY + * EDFLIB_MAXFILES_REACHED + * EDFLIB_FILE_ALREADY_OPENED + * EDFLIB_NUMBER_OF_SIGNALS_INVALID + * EDFLIB_ARCH_ERROR + * This function is required if you want to write a file (or use edfopen_file_writeonly_with_params()) + */ -/* opens an new file for writing. warning, an already existing file with the same name will be silently overwritten without advance warning!! */ -/* path is a null-terminated string containing the path and name of the file */ -/* filetype must be EDFLIB_FILETYPE_EDFPLUS or EDFLIB_FILETYPE_BDFPLUS */ -/* returns a handle on success, you need this handle for the other functions */ -/* in case of an error it returns a negative number corresponding to one of the following values: */ -/* EDFLIB_MALLOC_ERROR */ -/* EDFLIB_NO_SUCH_FILE_OR_DIRECTORY */ -/* EDFLIB_MAXFILES_REACHED */ -/* EDFLIB_FILE_ALREADY_OPENED */ -/* EDFLIB_NUMBER_OF_SIGNALS_INVALID */ -/* This function is required if you want to write a file */ - +int edfopen_file_writeonly_with_params(const char *path, int filetype, int number_of_signals, int samplefrequency, double phys_max_min, const char *phys_dim); +/* this is a convenience function that can create a new EDF file and initializes the most important parameters. + * it assumes that all signals are sharing the same parameters (you can still change them though). + * warning, an already existing file with the same name will be silently overwritten without advance warning! + * path is a null-terminated string containing the path and name of the file + * filetype must be EDFLIB_FILETYPE_EDFPLUS or EDFLIB_FILETYPE_BDFPLUS + * Sets the samplefrequency of all signals. (In reality, it sets the number of samples per datarecord which equals the samplefrequency only when + * the datarecords have a duration of 1 second) + * Sets the physical maximum of all signals to phys_max_min. + * Sets the physical minimum of all signals to -phys_max_min. + * Sets the physical dimension (unit) of all signals ("uV", "BPM", "mA", "Degr.", etc.). + * phys_dim is a pointer to a NULL-terminated ASCII-string containing the physical dimension of the signals + * returns a handle on success, you need this handle for the other functions + * in case of an error it returns a negative number corresponding to one of the following values: + * EDFLIB_MALLOC_ERROR + * EDFLIB_NO_SUCH_FILE_OR_DIRECTORY + * EDFLIB_MAXFILES_REACHED + * EDFLIB_FILE_ALREADY_OPENED + * EDFLIB_NUMBER_OF_SIGNALS_INVALID + * EDFLIB_ARCH_ERROR + * This function is required if you want to write a file (or use edfopen_file_writeonly()) + */ int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency); - -/* Sets the samplefrequency of signal edfsignal. (In reallity, it sets the number of samples in a datarecord.) */ -/* Returns 0 on success, otherwise -1 */ -/* This function is required for every signal and can be called only after opening a */ -/* file in writemode and before the first sample write action */ - +/* Sets the samplefrequency of signal edfsignal. In reality, it sets the number of samples in a datarecord + * which equals the samplefrequency only when the datarecords have a duration of 1 second. + * The effective samplefrequency is: samplefrequency / datarecord duration + * Returns 0 on success, otherwise -1 + * This function is required for every signal and can be called only after opening a + * file in writemode and before the first sample write action + */ int edf_set_physical_maximum(int handle, int edfsignal, double phys_max); - -/* Sets the maximum physical value of signal edfsignal. (the value of the input of the ADC when the output equals the value of "digital maximum") */ -/* It is the highest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level */ -/* Must be un-equal to physical minimum */ -/* Returns 0 on success, otherwise -1 */ -/* This function is required for every signal and can be called only after opening a */ -/* file in writemode and before the first sample write action */ - +/* Sets the maximum physical value of signal edfsignal. (the value of the input of the ADC when the output equals the value of "digital maximum") + * It is the highest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level + * Must be un-equal to physical minimum + * Returns 0 on success, otherwise -1 + * This function is required for every signal and can be called only after opening a + * file in writemode and before the first sample write action + */ int edf_set_physical_minimum(int handle, int edfsignal, double phys_min); - -/* Sets the minimum physical value of signal edfsignal. (the value of the input of the ADC when the output equals the value of "digital minimum") */ -/* It is the lowest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level */ -/* Usually this will be (-(phys_max)) */ -/* Must be un-equal to physical maximum */ -/* Returns 0 on success, otherwise -1 */ -/* This function is required for every signal and can be called only after opening a */ -/* file in writemode and before the first sample write action */ - +/* Sets the minimum physical value of signal edfsignal. (the value of the input of the ADC when the output equals the value of "digital minimum") + * It is the lowest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level + * Usually this will be (-(phys_max)) + * Must be un-equal to physical maximum + * Returns 0 on success, otherwise -1 + * This function is required for every signal and can be called only after opening a + * file in writemode and before the first sample write action + */ int edf_set_digital_maximum(int handle, int edfsignal, int dig_max); - -/* Sets the maximum digital value of signal edfsignal. The maximum value is 32767 for EDF+ and 8388607 for BDF+ */ -/* It is the highest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level */ -/* Usually it's the extreme output of the ADC */ -/* Must be higher than digital minimum */ -/* Returns 0 on success, otherwise -1 */ -/* This function is required for every signal and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the maximum digital value of signal edfsignal. The maximum value is 32767 for EDF+ and 8388607 for BDF+ + * It is the highest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level + * Usually it's the extreme output of the ADC + * Must be higher than digital minimum + * Returns 0 on success, otherwise -1 + * This function is required for every signal and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_digital_minimum(int handle, int edfsignal, int dig_min); - -/* Sets the minimum digital value of signal edfsignal. The minimum value is -32768 for EDF+ and -8388608 for BDF+ */ -/* It is the lowest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level */ -/* Usually it's the extreme output of the ADC */ -/* Usually this will be (-(dig_max + 1)) */ -/* Must be lower than digital maximum */ -/* Returns 0 on success, otherwise -1 */ -/* This function is required for every signal and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the minimum digital value of signal edfsignal. The minimum value is -32768 for EDF+ and -8388608 for BDF+ + * It is the lowest value that the equipment is able to record. It does not necessarily mean the signal recorded reaches this level + * Usually it's the extreme output of the ADC + * Usually this will be (-(dig_max + 1)) + * Must be lower than digital maximum + * Returns 0 on success, otherwise -1 + * This function is required for every signal and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_label(int handle, int edfsignal, const char *label); - -/* Sets the label (name) of signal edfsignal. ("FP1", "SaO2", etc.) */ -/* label is a pointer to a NULL-terminated ASCII-string containing the label (name) of the signal edfsignal */ -/* Returns 0 on success, otherwise -1 */ -/* This function is recommended for every signal when you want to write a file */ -/* and can be called only after opening a file in writemode and before the first sample write action */ - +/* Sets the label (name) of signal edfsignal. ("FP1", "SaO2", etc.) + * label is a pointer to a NULL-terminated ASCII-string containing the label (name) of the signal edfsignal + * Returns 0 on success, otherwise -1 + * This function is recommended for every signal when you want to write a file + * and can be called only after opening a file in writemode and before the first sample write action + */ int edf_set_prefilter(int handle, int edfsignal, const char *prefilter); - -/* Sets the prefilter of signal edfsignal ("HP:0.1Hz", "LP:75Hz N:50Hz", etc.). */ -/* prefilter is a pointer to a NULL-terminated ASCII-string containing the prefilter text of the signal edfsignal */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode and before */ -/* the first sample write action */ - +/* Sets the prefilter of signal edfsignal ("HP:0.1Hz", "LP:75Hz N:50Hz", etc.). + * prefilter is a pointer to a NULL-terminated ASCII-string containing the prefilter text of the signal edfsignal + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode and before + * the first sample write action + */ int edf_set_transducer(int handle, int edfsignal, const char *transducer); - -/* Sets the transducer of signal edfsignal ("AgAgCl cup electrodes", etc.). */ -/* transducer is a pointer to a NULL-terminated ASCII-string containing the transducer text of the signal edfsignal */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode and before */ -/* the first sample write action */ - +/* Sets the transducer of signal edfsignal ("AgAgCl cup electrodes", etc.). + * transducer is a pointer to a NULL-terminated ASCII-string containing the transducer text of the signal edfsignal + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode and before + * the first sample write action + */ int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim); - -/* Sets the physical dimension (unit) of signal edfsignal. ("uV", "BPM", "mA", "Degr.", etc.) */ -/* phys_dim is a pointer to a NULL-terminated ASCII-string containing the physical dimension of the signal edfsignal */ -/* Returns 0 on success, otherwise -1 */ -/* This function is recommended for every signal when you want to write a file */ -/* and can be called only after opening a file in writemode and before the first sample write action */ - +/* Sets the physical dimension (unit) of signal edfsignal. ("uV", "BPM", "mA", "Degr.", etc.) + * phys_dim is a pointer to a NULL-terminated ASCII-string containing the physical dimension of the signal edfsignal + * Returns 0 on success, otherwise -1 + * This function is recommended for every signal when you want to write a file + * and can be called only after opening a file in writemode and before the first sample write action + */ int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, int startdate_day, int starttime_hour, int starttime_minute, int starttime_second); - -/* Sets the startdate and starttime. */ -/* year: 1985 - 2084, month: 1 - 12, day: 1 - 31 */ -/* hour: 0 - 23, minute: 0 - 59, second: 0 - 59 */ -/* If not called, the library will use the system date and time at runtime */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ -/* Note: for anonymization purposes, the consensus is to use 1985-01-01 00:00:00 for the startdate and starttime. */ - +/* Sets the startdate and starttime. + * year: 1985 - 2084, month: 1 - 12, day: 1 - 31 + * hour: 0 - 23, minute: 0 - 59, second: 0 - 59 + * If not called, the library will use the system date and time at runtime + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + * Note: for anonymization purposes, the consensus is to use 1985-01-01 00:00:00 for the startdate and starttime. + */ int edf_set_patientname(int handle, const char *patientname); - -/* Sets the patientname. patientname is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the patientname. patientname is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_patientcode(int handle, const char *patientcode); - -/* Sets the patientcode. patientcode is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the patientcode. patientcode is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_gender(int handle, int gender); - -/* Sets the gender. 1 is male, 0 is female. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - - +/* Sets the gender. 1 is male, 0 is female. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int birthdate_day); - -/* Sets the birthdate. */ -/* year: 1800 - 3000, month: 1 - 12, day: 1 - 31 */ -/* This function is optional */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the birthdate. + * year: 1800 - 3000, month: 1 - 12, day: 1 - 31 + * This function is optional + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_patient_additional(int handle, const char *patient_additional); - -/* Sets the additional patientinfo. patient_additional is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the additional patientinfo. patient_additional is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_admincode(int handle, const char *admincode); - -/* Sets the admincode. admincode is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the admincode. admincode is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_technician(int handle, const char *technician); - -/* Sets the technicians name. technician is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the technicians name. technician is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_equipment(int handle, const char *equipment); - -/* Sets the name of the equipment used during the aquisition. equipment is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the name of the equipment used during the aquisition. equipment is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edf_set_recording_additional(int handle, const char *recording_additional); - -/* Sets the additional recordinginfo. recording_additional is a pointer to a null-terminated ASCII-string. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ - +/* Sets the additional recordinginfo. recording_additional is a pointer to a null-terminated ASCII-string. + * Returns 0 on success, otherwise -1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + */ int edfwrite_physical_samples(int handle, double *buf); - -/* Writes n physical samples (uV, mA, Ohm) from *buf belonging to one signal */ -/* where n is the samplefrequency of that signal. */ -/* The physical samples will be converted to digital samples using the */ -/* values of physical maximum, physical minimum, digital maximum and digital minimum */ -/* The number of samples written is equal to the samplefrequency of the signal */ -/* Size of buf should be equal to or bigger than sizeof(double[samplefrequency]) */ -/* Call this function for every signal in the file. The order is important! */ -/* When there are 4 signals in the file, the order of calling this function */ -/* must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes n physical samples (uV, mA, Ohm) from *buf belonging to one signal + * where n is the samplefrequency of that signal. + * The physical samples will be converted to digital samples using the + * values of physical maximum, physical minimum, digital maximum and digital minimum + * The number of samples written is equal to the samplefrequency of the signal + * Size of buf should be equal to or bigger than sizeof(double[samplefrequency]) + * Call this function for every signal in the file. The order is important! + * When there are 4 signals in the file, the order of calling this function + * must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. + * Returns 0 on success, otherwise -1 + */ int edf_blockwrite_physical_samples(int handle, double *buf); - -/* Writes physical samples (uV, mA, Ohm) from *buf */ -/* buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. */ -/* where n is the samplefrequency of that signal. */ -/* buf must be filled with samples from all signals, starting with signal 0, 1, 2, etc. */ -/* one block equals one second */ -/* The physical samples will be converted to digital samples using the */ -/* values of physical maximum, physical minimum, digital maximum and digital minimum */ -/* The number of samples written is equal to the sum of the samplefrequencies of all signals */ -/* Size of buf should be equal to or bigger than sizeof(double) multiplied by the sum of the samplefrequencies of all signals */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes physical samples (uV, mA, Ohm) from *buf + * buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. + * where n is the samplefrequency of that signal. + * buf must be filled with samples from all signals, starting with signal 0, 1, 2, etc. + * one block equals one second + * The physical samples will be converted to digital samples using the + * values of physical maximum, physical minimum, digital maximum and digital minimum + * The number of samples written is equal to the sum of the samplefrequencies of all signals + * Size of buf should be equal to or bigger than sizeof(double) multiplied by the sum of the samplefrequencies of all signals + * Returns 0 on success, otherwise -1 + */ int edfwrite_digital_short_samples(int handle, short *buf); - -/* Writes n "raw" digital samples from *buf belonging to one signal */ -/* where n is the samplefrequency of that signal. */ -/* The samples will be written to the file without any conversion. */ -/* Because the size of a short is 16-bit, do not use this function with BDF (24-bit) */ -/* The number of samples written is equal to the samplefrequency of the signal */ -/* Size of buf should be equal to or bigger than sizeof(short[samplefrequency]) */ -/* Call this function for every signal in the file. The order is important! */ -/* When there are 4 signals in the file, the order of calling this function */ -/* must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes n "raw" digital samples from *buf belonging to one signal + * where n is the samplefrequency of that signal. + * The samples will be written to the file without any conversion. + * Because the size of a short is 16-bit, do not use this function with BDF (24-bit) + * The number of samples written is equal to the samplefrequency of the signal + * Size of buf should be equal to or bigger than sizeof(short[samplefrequency]) + * Call this function for every signal in the file. The order is important! + * When there are 4 signals in the file, the order of calling this function + * must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. + * Returns 0 on success, otherwise -1 + */ int edfwrite_digital_samples(int handle, int *buf); - -/* Writes n "raw" digital samples from *buf belonging to one signal */ -/* where n is the samplefrequency of that signal. */ -/* The 16 (or 24 in case of BDF) least significant bits of the sample will be written to the */ -/* file without any conversion. */ -/* The number of samples written is equal to the samplefrequency of the signal */ -/* Size of buf should be equal to or bigger than sizeof(int[samplefrequency]) */ -/* Call this function for every signal in the file. The order is important! */ -/* When there are 4 signals in the file, the order of calling this function */ -/* must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes n "raw" digital samples from *buf belonging to one signal + * where n is the samplefrequency of that signal. + * The 16 (or 24 in case of BDF) least significant bits of the sample will be written to the + * file without any conversion. + * The number of samples written is equal to the samplefrequency of the signal + * Size of buf should be equal to or bigger than sizeof(int[samplefrequency]) + * Call this function for every signal in the file. The order is important! + * When there are 4 signals in the file, the order of calling this function + * must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. + * Returns 0 on success, otherwise -1 + */ int edf_blockwrite_digital_3byte_samples(int handle, void *buf); - -/* Writes "raw" digital samples from *buf. */ -/* buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. */ -/* where n is the samplefrequency of that signal. */ -/* One block equals one second. One sample equals 3 bytes, order is little endian (least significant byte first) */ -/* Encoding is second's complement, most significant bit of most significant byte is the sign-bit */ -/* The samples will be written to the file without any conversion. */ -/* Because the size of a 3-byte sample is 24-bit, this function can only be used when writing a BDF file */ -/* The number of samples written is equal to the sum of the samplefrequencies of all signals. */ -/* Size of buf should be equal to or bigger than: the sum of the samplefrequencies of all signals x 3 bytes */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes "raw" digital samples from *buf. + * buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. + * where n is the samplefrequency of that signal. + * One block equals one second. One sample equals 3 bytes, order is little endian (least significant byte first) + * Encoding is second's complement, most significant bit of most significant byte is the sign-bit + * The samples will be written to the file without any conversion. + * Because the size of a 3-byte sample is 24-bit, this function can only be used when writing a BDF file + * The number of samples written is equal to the sum of the samplefrequencies of all signals. + * Size of buf should be equal to or bigger than: the sum of the samplefrequencies of all signals x 3 bytes + * Returns 0 on success, otherwise -1 + */ int edf_blockwrite_digital_short_samples(int handle, short *buf); - -/* Writes "raw" digital samples from *buf. */ -/* buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. */ -/* where n is the samplefrequency of that signal. */ -/* One block equals one second. */ -/* The samples will be written to the file without any conversion. */ -/* Because the size of a short is 16-bit, do not use this function with BDF (24-bit) */ -/* The number of samples written is equal to the sum of the samplefrequencies of all signals. */ -/* Size of buf should be equal to or bigger than sizeof(short) multiplied by the sum of the samplefrequencies of all signals */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes "raw" digital samples from *buf. + * buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. + * where n is the samplefrequency of that signal. + * One block equals one second. + * The samples will be written to the file without any conversion. + * Because the size of a short is 16-bit, do not use this function with BDF (24-bit) + * The number of samples written is equal to the sum of the samplefrequencies of all signals. + * Size of buf should be equal to or bigger than sizeof(short) multiplied by the sum of the samplefrequencies of all signals + * Returns 0 on success, otherwise -1 + */ int edf_blockwrite_digital_samples(int handle, int *buf); - -/* Writes "raw" digital samples from *buf. */ -/* buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. */ -/* where n is the samplefrequency of that signal. */ -/* One block equals one second. */ -/* The 16 (or 24 in case of BDF) least significant bits of the sample will be written to the */ -/* file without any conversion. */ -/* The number of samples written is equal to the sum of the samplefrequencies of all signals. */ -/* Size of buf should be equal to or bigger than sizeof(int) multiplied by the sum of the samplefrequencies of all signals */ -/* Returns 0 on success, otherwise -1 */ - +/* Writes "raw" digital samples from *buf. + * buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. + * where n is the samplefrequency of that signal. + * One block equals one second. + * The 16 (or 24 in case of BDF) least significant bits of the sample will be written to the + * file without any conversion. + * The number of samples written is equal to the sum of the samplefrequencies of all signals. + * Size of buf should be equal to or bigger than sizeof(int) multiplied by the sum of the samplefrequencies of all signals + * Returns 0 on success, otherwise -1 + */ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description); - -/* writes an annotation/event to the file */ -/* onset is relative to the start of the file */ -/* onset and duration are in units of 100 microSeconds! resolution is 0.0001 second! */ -/* for example: 34.071 seconds must be written as 340710 */ -/* if duration is unknown or not applicable: set a negative number (-1) */ -/* description is a null-terminated UTF8-string containing the text that describes the event */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before closing the file */ - +/* writes an annotation/event to the file + * onset is relative to the start of the file + * onset and duration are in units of 100 microSeconds! resolution is 0.0001 second! + * for example: 34.071 seconds must be written as 340710 + * if duration is unknown or not applicable: set a negative number (-1) + * description is a null-terminated UTF8-string containing the text that describes the event + * This function is optional and can be called only after opening a file in writemode + * and before closing the file + */ int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description); - -/* writes an annotation/event to the file */ -/* onset is relative to the start of the file */ -/* onset and duration are in units of 100 microSeconds! resolution is 0.0001 second! */ -/* for example: 34.071 seconds must be written as 340710 */ -/* if duration is unknown or not applicable: set a negative number (-1) */ -/* description is a null-terminated Latin1-string containing the text that describes the event */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before closing the file */ - +/* writes an annotation/event to the file + * onset is relative to the start of the file + * onset and duration are in units of 100 microSeconds! resolution is 0.0001 second! + * for example: 34.071 seconds must be written as 340710 + * if duration is unknown or not applicable: set a negative number (-1) + * description is a null-terminated Latin1-string containing the text that describes the event + * This function is optional and can be called only after opening a file in writemode + * and before closing the file + */ int edf_set_datarecord_duration(int handle, int duration); - -/* Sets the datarecord duration. The default value is 1 second. */ -/* ATTENTION: the argument "duration" is expressed in units of 10 microSeconds! */ -/* So, if you want to set the datarecord duration to 0.1 second, you must give */ -/* the argument "duration" a value of "10000". */ -/* This function is optional, normally you don't need to change the default value. */ -/* The datarecord duration must be in the range 0.001 to 60 seconds. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is NOT REQUIRED but can be called after opening a */ -/* file in writemode and before the first sample write action. */ -/* This function can be used when you want to use a samplerate */ -/* which is not an integer. For example, if you want to use a samplerate of 0.5 Hz, */ -/* set the samplefrequency to 5 Hz and the datarecord duration to 10 seconds, */ -/* or set the samplefrequency to 1 Hz and the datarecord duration to 2 seconds. */ -/* Do not use this function if not necessary. */ - +/* Sets the datarecord duration. The default value is 1 second. + * ATTENTION: the argument "duration" is expressed in units of 10 microSeconds! + * So, if you want to set the datarecord duration to 0.1 second, you must give + * the argument "duration" a value of "10000". + * This function is optional, normally you don't need to change the default value. + * The datarecord duration must be in the range 0.001 to 60 seconds. + * Returns 0 on success, otherwise -1 + * This function is NOT REQUIRED but can be called after opening a + * file in writemode and before the first sample write action. + * This function can be used when you want to use a samplerate + * which is not an integer. For example, if you want to use a samplerate of 0.5 Hz, + * set the samplefrequency to 5 Hz and the datarecord duration to 10 seconds, + * or set the samplefrequency to 1 Hz and the datarecord duration to 2 seconds. + * Do not use this function if not necessary. + */ int edf_set_micro_datarecord_duration(int handle, int duration); - -/* Sets the datarecord duration to a very small value. */ -/* ATTENTION: the argument "duration" is expressed in units of 1 microSecond! */ -/* This function is optional, normally you don't need to change the default value. */ -/* The datarecord duration must be in the range 1 to 9999 micro-seconds. */ -/* Returns 0 on success, otherwise -1 */ -/* This function is NOT REQUIRED but can be called after opening a */ -/* file in writemode and before the first sample write action. */ -/* This function can be used when you want to use a very high samplerate. */ -/* For example, if you want to use a samplerate of 5 GHz, */ -/* set the samplefrequency to 5000 Hz and the datarecord duration to 1 micro-second. */ -/* Do not use this function if not necessary. */ -/* This function was added to accommodate for high speed ADC's e.g. Digital Sampling Oscilloscopes */ - +/* Sets the datarecord duration to a very small value. + * ATTENTION: the argument "duration" is expressed in units of 1 microSecond! + * This function is optional, normally you don't need to change the default value. + * The datarecord duration must be in the range 1 to 9999 micro-seconds. + * Returns 0 on success, otherwise -1 + * This function is NOT REQUIRED but can be called after opening a + * file in writemode and before the first sample write action. + * This function can be used when you want to use a very high samplerate. + * For example, if you want to use a samplerate of 5 GHz, + * set the samplefrequency to 5000 Hz and the datarecord duration to 1 micro-second. + * Do not use this function if not necessary. + * This function was added to accommodate for high speed ADC's e.g. Digital Sampling Oscilloscopes + */ int edf_set_number_of_annotation_signals(int handle, int annot_signals); - -/* Sets the number of annotation signals. The default value is 1 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ -/* Normally you don't need to change the default value. Only when the number of annotations */ -/* you want to write is higher than the number of datarecords in the recording, you can use */ -/* this function to increase the storage space for annotations */ -/* Minimum is 1, maximum is 64 */ -/* Returns 0 on success, otherwise -1 */ - +/* Sets the number of annotation signals. The default value is 1 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + * Normally you don't need to change the default value. Only when the number of annotations + * you want to write is higher than the number of datarecords in the recording, you can use + * this function to increase the storage space for annotations + * Minimum is 1, maximum is 64 + * Returns 0 on success, otherwise -1 + */ int edf_set_subsecond_starttime(int handle, int subsecond); -/* Sets the subsecond starttime expressed in units of 100 nanoSeconds */ -/* Valid range is 0 to 9999999 inclusive. Default is 0 */ -/* This function is optional and can be called only after opening a file in writemode */ -/* and before the first sample write action */ -/* Returns 0 on success, otherwise -1 */ -/* It is strongly recommended to use a maximum resolution of no more than 100 micro-Seconds. */ -/* e.g. use 1234000 to set a starttime offset of 0.1234 seconds (instead of 1234567) */ -/* in other words, leave the last 3 digits at zero */ +/* Sets the subsecond starttime expressed in units of 100 nanoSeconds + * Valid range is 0 to 9999999 inclusive. Default is 0 + * This function is optional and can be called only after opening a file in writemode + * and before the first sample write action + * Returns 0 on success, otherwise -1 + * It is strongly recommended to use a maximum resolution of no more than 100 micro-Seconds. + * e.g. use 1234000 to set a starttime offset of 0.1234 seconds (instead of 1234567) + * in other words, leave the last 3 digits at zero + */ #ifdef __cplusplus } /* extern "C" */ diff --git a/global.h b/global.h index e133185..deeb767 100644 --- a/global.h +++ b/global.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -35,7 +35,7 @@ #define PROGRAM_NAME "DSRemote" -#define PROGRAM_VERSION "0.37_2105301226" +#define PROGRAM_VERSION "0.38_2302082035" #define MAX_PATHLEN (1024) diff --git a/interface.cpp b/interface.cpp index d8456ef..8ab6b8c 100644 --- a/interface.cpp +++ b/interface.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/lan_connect_thread.cpp b/lan_connect_thread.cpp index a0c9ab2..6ba0a1a 100644 --- a/lan_connect_thread.cpp +++ b/lan_connect_thread.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/lan_connect_thread.h b/lan_connect_thread.h index 05cb0dd..653306c 100644 --- a/lan_connect_thread.h +++ b/lan_connect_thread.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/main.cpp b/main.cpp index 0e7f323..1ba9e92 100644 --- a/main.cpp +++ b/main.cpp @@ -9,18 +9,74 @@ int main(int argc, char *argv[]) { - QApplication app(argc, argv); +#if !defined(__GNUC__) +#error "Wrong compiler or platform!" +#endif -// app.setAttribute(Qt::AA_DontUseNativeMenuBar); +#if CHAR_BIT != 8 +#error "unsupported char size" +#endif + +#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ +#error "system is not little endian!" +#endif + + char str[512]={""}; + + union + { + char four[4]; + int one; + } byte_order_test_var; + + /* avoid surprises! */ + if((sizeof(char) != 1) || + (sizeof(short) != 2) || + (sizeof(int) != 4) || + (sizeof(long) != 8) || + (sizeof(long long) != 8) || + (sizeof(float) != 4) || + (sizeof(double) != 8)) + { + fprintf(stderr, "Wrong compiler or platform!\n"); + return EXIT_FAILURE; + } + + /* check endianness! */ + byte_order_test_var.one = 0x03020100; + if((byte_order_test_var.four[0] != 0) || + (byte_order_test_var.four[1] != 1) || + (byte_order_test_var.four[2] != 2) || + (byte_order_test_var.four[3] != 3)) + { + fprintf(stderr, "Wrong compiler or platform!\n"); + return EXIT_FAILURE; + } + + QApplication app(argc, argv); #if QT_VERSION >= 0x050000 qApp->setStyle(QStyleFactory::create("Fusion")); #endif qApp->setStyleSheet("QLabel, QMessageBox { messagebox-text-interaction-flags: 5; }"); - class UI_Mainwindow MainWindow; + UI_Mainwindow *MainWindow = new UI_Mainwindow; + if(MainWindow == NULL) + { + snprintf(str, 512, "Malloc error.\nFile: %s line: %i", __FILE__, __LINE__); - return app.exec(); + fprintf(stderr, "%s\n", str); + + QMessageBox::critical(NULL, "Error", str); + + return EXIT_FAILURE; + } + + int ret = app.exec(); + + delete MainWindow; + + return ret; } diff --git a/mainwindow.cpp b/mainwindow.cpp index 445dc18..4504758 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -85,7 +85,7 @@ void UI_Mainwindow::open_connection() { strlcpy(dev_str, "/dev/usbtmc0", 256); - settings.setValue("connection/device", dev_str); + settings.setValue("connection/device", QString(dev_str)); } device = tmc_open_usb(dev_str); diff --git a/mainwindow.h b/mainwindow.h index 6a0b146..26641dc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -30,43 +30,6 @@ #define UI_VIEW_MAINFORM_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -78,6 +41,7 @@ #include #include +#include "qt_headers.h" #include "global.h" #include "about_dialog.h" #include "utils.h" diff --git a/mainwindow_constr.cpp b/mainwindow_constr.cpp index e7e28c1..debe9ea 100644 --- a/mainwindow_constr.cpp +++ b/mainwindow_constr.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -188,7 +188,11 @@ UI_Mainwindow::UI_Mainwindow() devicemenu->setTitle("Device"); devicemenu->addAction("Connect", this, SLOT(open_connection())); devicemenu->addAction("Disconnect", this, SLOT(close_connection())); +#if QT_VERSION < 0x060000 devicemenu->addAction("Exit", this, SLOT(close()), QKeySequence::Quit); +#else + devicemenu->addAction("Exit", QKeySequence::Quit, this, SLOT(close())); +#endif menubar->addMenu(devicemenu); settingsmenu = new QMenu(this); @@ -495,7 +499,11 @@ UI_Mainwindow::UI_Mainwindow() addAction(chan_scale_plus_act); chan_scale_plus_all_channels_act = new QAction(this); +#if QT_VERSION < 0x060000 chan_scale_plus_all_channels_act->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Minus)); +#else + chan_scale_plus_all_channels_act->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_Minus)); +#endif connect(chan_scale_plus_all_channels_act, SIGNAL(triggered()), this, SLOT(chan_scale_plus_all())); addAction(chan_scale_plus_all_channels_act); @@ -505,7 +513,11 @@ UI_Mainwindow::UI_Mainwindow() addAction(chan_scale_minus_act); chan_scale_minus_all_channels_act = new QAction(this); +#if QT_VERSION < 0x060000 chan_scale_minus_all_channels_act->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Plus)); +#else + chan_scale_minus_all_channels_act->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_Plus)); +#endif connect(chan_scale_minus_all_channels_act, SIGNAL(triggered()), this, SLOT(chan_scale_minus_all())); addAction(chan_scale_minus_all_channels_act); @@ -655,7 +667,7 @@ UI_Mainwindow::~UI_Mainwindow() { QSettings settings; - settings.setValue("path/savedir", recent_savedir); + settings.setValue("path/savedir", QString(recent_savedir)); delete scrn_thread; delete appfont; diff --git a/playback_dialog.cpp b/playback_dialog.cpp index 2da52e7..0c14233 100644 --- a/playback_dialog.cpp +++ b/playback_dialog.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2017 - 2021 Teunis van Beelen +* Copyright (C) 2017 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/playback_dialog.h b/playback_dialog.h index fcd9752..7fe3575 100644 --- a/playback_dialog.h +++ b/playback_dialog.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2017 - 2021 Teunis van Beelen +* Copyright (C) 2017 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -30,16 +30,7 @@ #define UI_PLAYBACK_DIALOG_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "qt_headers.h" #include #include diff --git a/qt_headers.h b/qt_headers.h new file mode 100644 index 0000000..73b9ce5 --- /dev/null +++ b/qt_headers.h @@ -0,0 +1,143 @@ +/* +*************************************************************************** +* +* author: Teunis van Beelen +* +* email: teuniz@protonmail.com +* +*************************************************************************** +*/ + +#ifndef QT_HEADERS_INCLUDE_H +#define QT_HEADERS_INCLUDE_H + +#include +#include +#include +#if QT_VERSION < 0x060000 +#include +#endif +#if QT_VERSION >= 0x050000 +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if QT_VERSION >= 0x050200 +#include +#endif + +#endif + + + + + + diff --git a/read_settings_thread.cpp b/read_settings_thread.cpp index 79269d6..37cf176 100644 --- a/read_settings_thread.cpp +++ b/read_settings_thread.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/read_settings_thread.h b/read_settings_thread.h index db42f8b..9191f7e 100644 --- a/read_settings_thread.h +++ b/read_settings_thread.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/save_data.cpp b/save_data.cpp index ff2baa0..44ab41c 100644 --- a/save_data.cpp +++ b/save_data.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -135,7 +135,7 @@ void UI_Mainwindow::save_screenshot() if(devparms.modelserie == 1) { painter.begin(&screenXpm); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) painter.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif @@ -150,7 +150,7 @@ void UI_Mainwindow::save_screenshot() else if(devparms.modelserie == 6) { painter.begin(&screenXpm); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) painter.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif diff --git a/save_data_thread.cpp b/save_data_thread.cpp index 58b929b..a555315 100644 --- a/save_data_thread.cpp +++ b/save_data_thread.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/save_data_thread.h b/save_data_thread.h index cecff0d..663920c 100644 --- a/save_data_thread.h +++ b/save_data_thread.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/screen_thread.cpp b/screen_thread.cpp index d76e076..8ed0e5a 100644 --- a/screen_thread.cpp +++ b/screen_thread.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -779,7 +779,7 @@ void screen_thread::run() if(n < 0) { - printf("Can not read from device.\n"); + printf("Can not read from device. (n is %i)\n", n); line = __LINE__; goto OUT_ERROR; } diff --git a/screen_thread.h b/screen_thread.h index 2355308..3c43004 100644 --- a/screen_thread.h +++ b/screen_thread.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/serial_decoder.cpp b/serial_decoder.cpp index cc8e285..0e64fef 100644 --- a/serial_decoder.cpp +++ b/serial_decoder.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/settings_dialog.cpp b/settings_dialog.cpp index 2228343..4a94a47 100644 --- a/settings_dialog.cpp +++ b/settings_dialog.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -277,17 +277,17 @@ void UI_settings_window::applyButtonClicked() mainwindow->devparms.connectiontype = 1; } - settings.setValue("connection/device", dev_str); + settings.setValue("connection/device", QString(dev_str)); snprintf(dev_str, 256, "%i.%i.%i.%i", ipSpinbox1->value(), ipSpinbox2->value(), ipSpinbox3->value(), ipSpinbox4->value()); - settings.setValue("connection/ip", dev_str); + settings.setValue("connection/ip", QString(dev_str)); strncpy(mainwindow->devparms.hostname, HostLineEdit->text().toLatin1().data(), 63); mainwindow->devparms.hostname[63] = 0; - settings.setValue("connection/hostname", mainwindow->devparms.hostname); + settings.setValue("connection/hostname", QString(mainwindow->devparms.hostname)); if(invScrShtCheckbox->checkState() == Qt::Checked) { diff --git a/settings_dialog.h b/settings_dialog.h index 817ebed..c16af66 100644 --- a/settings_dialog.h +++ b/settings_dialog.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -33,17 +33,7 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "qt_headers.h" #include #include diff --git a/signalcurve.cpp b/signalcurve.cpp index fd1dcc9..d0e7651 100644 --- a/signalcurve.cpp +++ b/signalcurve.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2010 - 2021 Teunis van Beelen +* Copyright (C) 2010 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -142,7 +142,7 @@ void SignalCurve::paintEvent(QPaintEvent *) if(updates_enabled == false) return; QPainter paint(this); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) paint.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif @@ -172,7 +172,7 @@ int SignalCurve::print_to_image(const char *path) QPixmap pixmap(w_p, h_p); QPainter paint(&pixmap); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) paint.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif @@ -1676,10 +1676,13 @@ void SignalCurve::mousePressEvent(QMouseEvent *press_event) w = width() - (2 * bordersize); h = height() - (2 * bordersize); - +#if QT_VERSION < 0x060000 m_x = press_event->x() - bordersize; m_y = press_event->y() - bordersize; - +#else + m_x = press_event->position().x() - bordersize; + m_y = press_event->position().y() - bordersize; +#endif if(devparms == NULL) { return; @@ -1811,10 +1814,13 @@ void SignalCurve::mouseReleaseEvent(QMouseEvent *release_event) w = width() - (2 * bordersize); h = height() - (2 * bordersize); - +#if QT_VERSION < 0x060000 mouse_x = release_event->x() - bordersize; mouse_y = release_event->y() - bordersize; - +#else + mouse_x = release_event->position().x() - bordersize; + mouse_y = release_event->position().y() - bordersize; +#endif if(devparms == NULL) { return; @@ -2075,10 +2081,13 @@ void SignalCurve::mouseMoveEvent(QMouseEvent *move_event) { return; } - +#if QT_VERSION < 0x060000 mouse_x = move_event->x() - bordersize; mouse_y = move_event->y() - bordersize; - +#else + mouse_x = move_event->position().x() - bordersize; + mouse_y = move_event->position().y() - bordersize; +#endif if(devparms == NULL) { return; diff --git a/signalcurve.h b/signalcurve.h index 5de3c52..5a21a82 100644 --- a/signalcurve.h +++ b/signalcurve.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/tdial.cpp b/tdial.cpp index d98a3de..e5ee16c 100644 --- a/tdial.cpp +++ b/tdial.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -58,7 +58,7 @@ void TDial::paintEvent(QPaintEvent *) double r1, r2, r3, r4, dtmp; QPainter p(this); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) p.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif @@ -162,8 +162,11 @@ void TDial::mousePressEvent(QMouseEvent *press_event) { slider_down = true; setMouseTracking(true); - +#if QT_VERSION < 0x060000 mouse_grad_old = polar_to_degr(press_event->x() - (width() / 2), press_event->y() - (height() / 2)); +#else + mouse_grad_old = polar_to_degr(press_event->position().x() - (width() / 2), press_event->position().y() - (height() / 2)); +#endif } press_event->accept(); @@ -190,9 +193,11 @@ void TDial::mouseMoveEvent(QMouseEvent *move_event) gr_diff; if(slider_down == false) return; - +#if QT_VERSION < 0x060000 gr_new = polar_to_degr(move_event->x() - (width() / 2), move_event->y() - (height() / 2)); - +#else + gr_new = polar_to_degr(move_event->position().x() - (width() / 2), move_event->position().y() - (height() / 2)); +#endif gr_diff = gr_new - mouse_grad_old; mouse_grad_old = gr_new; diff --git a/tdial.h b/tdial.h index d0c7909..9cb0356 100644 --- a/tdial.h +++ b/tdial.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/timer_handlers.cpp b/timer_handlers.cpp index 953c16f..98d7b0c 100644 --- a/timer_handlers.cpp +++ b/timer_handlers.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/tled.cpp b/tled.cpp index 336fd10..312d2a5 100644 --- a/tled.cpp +++ b/tled.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2014 - 2021 Teunis van Beelen +* Copyright (C) 2014 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -43,7 +43,7 @@ TLed::TLed(QWidget *p) : QWidget(p) void TLed::paintEvent(QPaintEvent *) { QPainter paint(this); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) paint.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif drawLed(&paint); diff --git a/tled.h b/tled.h index f19b480..dc32ca2 100644 --- a/tled.h +++ b/tled.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2014 - 2021 Teunis van Beelen +* Copyright (C) 2014 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/tmc_dev.c b/tmc_dev.c index fbb9070..45835cc 100644 --- a/tmc_dev.c +++ b/tmc_dev.c @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -238,7 +238,7 @@ int tmcdev_read(struct tmcdev *dev) dev->buf[0] = 0; - return -1; + return -2; } dev->hdrbuf[size] = 0; @@ -265,7 +265,7 @@ int tmcdev_read(struct tmcdev *dev) { blockhdr[31] = 0; - return -1; + return -3; } blockhdr[len + 2] = 0; @@ -279,7 +279,7 @@ int tmcdev_read(struct tmcdev *dev) { blockhdr[31] = 0; - return -1; + return -4; } size += read_size; @@ -291,7 +291,7 @@ int tmcdev_read(struct tmcdev *dev) { blockhdr[31] = 0; - return -1; + return -5; } dev->buf = dev->hdrbuf + len + 2; diff --git a/tmc_dev.h b/tmc_dev.h index 27aaae8..a439879 100644 --- a/tmc_dev.h +++ b/tmc_dev.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/tmc_lan.c b/tmc_lan.c index 275b3b0..c1af518 100644 --- a/tmc_lan.c +++ b/tmc_lan.c @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/tmc_lan.h b/tmc_lan.h index 8b7ccd7..92df0be 100644 --- a/tmc_lan.h +++ b/tmc_lan.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2015 - 2021 Teunis van Beelen +* Copyright (C) 2015 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/utils.c b/utils.c index dbb44b1..9542797 100644 --- a/utils.c +++ b/utils.c @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2009 - 2021 Teunis van Beelen +* Copyright (C) 2009 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -34,8 +34,134 @@ #define FLT_ROUNDS 1 +/* size is size of destination */ +/* dest points to src2 relative to src1 */ +void get_relative_path_from_absolut_paths(char *dest, const char *src1, const char *src2, int size) +{ + int i, len1, len2, len_min, delim_shared=0, delim1=0, delim2=0; - /* removes extension including the dot */ + if(size < 1) return; + + dest[0] = 0; + + len1 = strlen(src1); + + len2 = strlen(src2); + + len_min = (len1 > len2) ? len2 : len1; + + if(!len_min) return; + + for(i=0; i= 0) && dir) + { + cut = delim_pos3 - delim_pos1; + + for(j=delim_pos1; j<(len-cut+1); j++) + { + path[j] = path[j+cut]; + } + + len = strlen(path); + + i = 0; + + dots = 0; + + dir = 0; + + continue; + } + + dots = 0; + } + else + { + dots = 3; + + letter++; + } + } +} + + +/* removes extension including the dot */ void remove_extension_from_filename(char *str) { int i, len; @@ -64,7 +190,7 @@ void remove_extension_from_filename(char *str) } - /* sz is size of destination, returns length of filename */ +/* sz is size of destination, returns length of filename */ int get_filename_from_path(char *dest, const char *src, int sz) { int i, len; @@ -115,8 +241,8 @@ int get_filename_from_path(char *dest, const char *src, int sz) } - /* sz is size of destination, returns length of directory */ - /* last character of destination is not a slash! */ +/* sz is size of destination, returns length of directory */ +/* last character of destination is not a slash! */ int get_directory_from_path(char *dest, const char *src, int sz) { int i, len; @@ -200,6 +326,8 @@ void remove_trailing_spaces(char *str) len = strlen(str); + if(!len) return; + for(i=(len-1); i>=0; i--) { if(str[i]!=' ') break; @@ -265,6 +393,8 @@ void trim_spaces(char *str) len = strlen(str); + if(!len) return; + for(i=(len-1); i>=0; i--) { if(str[i]!=' ') break; @@ -274,7 +404,7 @@ void trim_spaces(char *str) } - +/* removes trailing zero's from one or more occurrences of a decimal fraction in a string */ void remove_trailing_zeros(char *str) { int i, j, @@ -448,13 +578,14 @@ void utf8_to_latin1(char *utf8_str) } - +/* max string length: 4096 characters! */ void latin1_to_utf8(char *latin1_str, int len) { int i, j; - unsigned char *str, tmp_str[1024]; + unsigned char *str, tmp_str[4096]; + if(len > 4096) len = 4096; str = (unsigned char *)latin1_str; @@ -498,11 +629,26 @@ void latin1_to_utf8(char *latin1_str, int len) } +void sanitize_ascii(char *s) +{ + for( ; *s; s++) + { + if((*s < 32) || (*s > 126)) + { + *s = '.'; + } + } +} + void latin1_to_ascii(char *str, int len) { + /* ISO 8859-1 except for characters 0x80 to 0x9f which are taken from the extension CP-1252 */ + int i, value; + const char conv_table[]=".E.,F\".++^.Se.zY.i....|....<...-....\'u.....>...?AAAAAAECEEEEIIIIDNOOOOOxOUUUUYtsaaaaaaeceeeeiiiidnooooo:0uuuuyty"; + for(i=0; i 0.999999e12 && ltmp < 0.999999e15) + if(ftmp > 0.999999e12 && ftmp < 0.999999e15) { - ltmp = ltmp / 1e12; + ftmp = ftmp / 1e12; suffix = 'T'; } - else if(ltmp > 0.999999e9) + else if(ftmp > 0.999999e9) { - ltmp = ltmp / 1e9; + ftmp = ftmp / 1e9; suffix = 'G'; } - else if(ltmp > 0.999999e6) + else if(ftmp > 0.999999e6) { - ltmp = ltmp / 1e6; + ftmp = ftmp / 1e6; suffix = 'M'; } - else if(ltmp > 0.999999e3) + else if(ftmp > 0.999999e3) { - ltmp /= 1e3; + ftmp /= 1e3; suffix = 'K'; } - else if(ltmp > 0.999999e-3 && ltmp < 0.999999) + else if(ftmp > 0.999999e-3 && ftmp < 0.999999) { - ltmp *= 1e3; + ftmp *= 1e3; suffix = 'm'; } - else if( ltmp > 0.999999e-6 && ltmp < 0.999999e-3) + else if( ftmp > 0.999999e-6 && ftmp < 0.999999e-3) { - ltmp *= 1e6; + ftmp *= 1e6; suffix = 'u'; } - else if(ltmp > 0.999999e-9 && ltmp < 0.999999e-6) + else if(ftmp > 0.999999e-9 && ftmp < 0.999999e-6) { - ltmp *= 1e9; + ftmp *= 1e9; suffix = 'n'; } - else if(ltmp > 0.999999e-12 && ltmp < 0.999999e-9) + else if(ftmp > 0.999999e-12 && ftmp < 0.999999e-9) { - ltmp *= 1e12; + ftmp *= 1e12; suffix = 'p'; } - if(value >= 0) - { - switch(decimals) - { - case 0: return snprintf(dest, sz, "%.0f%c", ltmp, suffix); - break; - case 1: return snprintf(dest, sz, "%.1f%c", ltmp, suffix); - break; - case 2: return snprintf(dest, sz, "%.2f%c", ltmp, suffix); - break; - case 3: return snprintf(dest, sz, "%.3f%c", ltmp, suffix); - break; - case 4: return snprintf(dest, sz, "%.4f%c", ltmp, suffix); - break; - case 5: return snprintf(dest, sz, "%.5f%c", ltmp, suffix); - break; - case 6: return snprintf(dest, sz, "%.6f%c", ltmp, suffix); - break; - default: return snprintf(dest, sz, "%.3f%c", ltmp, suffix); - break; - } - } + if((decimals < 0) || (decimals > 6)) decimals = 3; - if(value < 0) - { - switch(decimals) - { - case 0: return snprintf(dest, sz, "%.0f%c", ltmp * -1, suffix); - break; - case 1: return snprintf(dest, sz, "%.1f%c", ltmp * -1, suffix); - break; - case 2: return snprintf(dest, sz, "%.2f%c", ltmp * -1, suffix); - break; - default: return snprintf(dest, sz, "%.3f%c", ltmp * -1, suffix); - break; - } - } + if(value < 0) ftmp *=-1; - strlcpy(dest, "0", sz); - - return 1; + return snprintf(dest, sz, "%.*f%c", decimals, ftmp, suffix); } @@ -2097,11 +2036,11 @@ int dblcmp(double val1, double val2) { long double diff = (long double)val1 - (long double)val2; - if(diff > 1e-13) + if(diff > 1e-13l) { return 1; } - else if(-diff > 1e-13) + else if(-diff > 1e-13l) { return -1; } @@ -2317,6 +2256,53 @@ int strlcat(char *dst, const char *src, int sz) #endif +void remove_leading_chars(char *str, int n) +{ + int i, len; + + if(str == NULL) return; + + if(n < 1) return; + + len = strlen(str); + + if(n >= len) + { + str[0] = 0; + + return; + } + + for(i=0; i<(len-n); i++) + { + str[i] = str[i + n]; + } + + str[i] = 0; +} + + +void remove_trailing_chars(char *str, int n) +{ + int len; + + if(str == NULL) return; + + if(n < 1) return; + + len = strlen(str); + + if(n >= len) + { + str[0] = 0; + + return; + } + + str[len - n] = 0; +} + + void str_insert_substr(char *str, int pos, int len, const char *substr, int subpos, int sublen) { int i, slen; @@ -2456,10 +2442,47 @@ int convert_non_ascii_to_hex(char *dest, const char *src, int destlen) } - - - - +/* returns greatest common divisor */ +int t_gcd(int a, int b) +{ + if(!a) + { + return b; + } + + while(b) + { + if(a > b) + { + a = a - b; + } + else + { + b = b - a; + } + } + + return a; +} + + +/* returns least common multiple */ +int t_lcm(int a, int b) +{ + return ((a * b) / t_gcd(a, b)); +} + + +void ascii_toupper(char *p) +{ + for(; *p; p++) + { + if((*p >= 'a') && (*p <= 'z')) + { + *p -= 32; + } + } +} diff --git a/utils.h b/utils.h index 915e12b..69186b9 100644 --- a/utils.h +++ b/utils.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2009 - 2021 Teunis van Beelen +* Copyright (C) 2009 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -45,8 +45,11 @@ extern "C" { void remove_trailing_spaces(char *); void remove_leading_spaces(char *); void trim_spaces(char *); +/* removes trailing zero's from one or more occurrences of a decimal fraction in a string */ void remove_trailing_zeros(char *); void convert_trailing_zeros_to_spaces(char *); +void remove_leading_chars(char *, int); +void remove_trailing_chars(char *, int); /* Inserts a copy of substr into str. The substring is the portion of substr that begins at */ /* the character position subpos and spans sublen characters (or until the end of substr */ @@ -59,12 +62,31 @@ void str_insert_substr(char *str, int pos, int len, const char *substr, int subp /* Returns the number of substrings replaced. */ int str_replace_substr(char *str, int len, int n, const char *dest_substr, const char *src_substr); +/* converts non-readable non-ascii characters in "<0xhh>" */ +/* arguments: destination string, source string, maximum destination length including the terminating null byte */ +int convert_non_ascii_to_hex(char *, const char *, int); + void remove_extension_from_filename(char *); /* removes extension including the dot */ int get_filename_from_path(char *dest, const char *src, int size); /* size is size of destination, returns length of filename */ int get_directory_from_path(char *dest, const char *src, int size); /* size is size of destination, returns length of directory */ +void get_relative_path_from_absolut_paths(char *dest, const char *src1, const char *src2, int size); /* size is size of destination, dest points to src2 relative to src1 */ +void sanitize_path(char *path); /* removes double dot entries */ +void sanitize_ascii(char *); /* replaces all non-ascii characters with a dot */ +/* replaces all control chars (decimal values < 32 and decimal value == 127 (DEL)) */ +/* works also with UTF-8 and Latin-1 */ +void str_replace_ctrl_chars(char *, char); +void ascii_toupper(char *); void latin1_to_ascii(char *, int); void latin1_to_utf8(char *, int); void utf8_to_latin1(char *); +int utf8_strlen(const char *); /* returns the number of utf8 characters in the string */ +int utf8_idx(const char *, int); /* returns the byte offset of the nth utf8 character */ +/* limits the length in bytes of the string while avoiding creating an illegal utf8 character at the end of the string */ +/* returns the new byte length */ +int utf8_set_byte_len(char *, int); +/* limits the length in utf8 chars of the string */ +/* returns the new utf8 char length */ +int utf8_set_char_len(char *, int); int antoi(const char *, int); int atoi_nonlocalized(const char *); double atof_nonlocalized(const char *); @@ -85,8 +107,8 @@ int fprint_int_number_nonlocalized(FILE *, int, int, int); int fprint_ll_number_nonlocalized(FILE *, long long, int, int); /* returns 1 in case the string is not a number */ -int is_integer_number(char *); -int is_number(char *); +int is_integer_number(const char *); +int is_number(const char *); int round_125_cat(double); /* returns 10, 20 or 50, depending on the value */ @@ -111,6 +133,9 @@ int dblcmp(double, double); /* returns 0 when equal */ int base64_dec(const void *, void *, int); +int t_gcd(int, int); /* returns greatest common divisor */ +int t_lcm(int, int); /* returns least common multiple */ + /* sz is size of destination, returns length of string in dest. * This is different than the official BSD implementation! * From the BSD man-page: diff --git a/wave_dialog.cpp b/wave_dialog.cpp index 90b68fc..4852b17 100644 --- a/wave_dialog.cpp +++ b/wave_dialog.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * diff --git a/wave_dialog.h b/wave_dialog.h index b44632a..04106f1 100644 --- a/wave_dialog.h +++ b/wave_dialog.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -33,13 +33,7 @@ -#include -#include -#include -#include -#include -#include -#include +#include "qt_headers.h" #include "mainwindow.h" #include "global.h" diff --git a/wave_view.cpp b/wave_view.cpp index bd15bf7..5670063 100644 --- a/wave_view.cpp +++ b/wave_view.cpp @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -91,7 +91,7 @@ void WaveCurve::paintEvent(QPaintEvent *) } QPainter paint(this); -#if QT_VERSION >= 0x050000 +#if (QT_VERSION >= 0x050000) && (QT_VERSION < 0x060000) paint.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif @@ -882,10 +882,13 @@ void WaveCurve::mouseReleaseEvent(QMouseEvent *release_event) { w = width() - (2 * bordersize); h = height() - (2 * bordersize); - +#if QT_VERSION < 0x060000 mouse_x = release_event->x() - bordersize; mouse_y = release_event->y() - bordersize; - +#else + mouse_x = release_event->position().x() - bordersize; + mouse_y = release_event->position().y() - bordersize; +#endif if(devparms == NULL) { return; @@ -904,10 +907,13 @@ void WaveCurve::mouseMoveEvent(QMouseEvent *move_event) { return; } - +#if QT_VERSION < 0x060000 mouse_x = move_event->x() - bordersize; mouse_y = move_event->y() - bordersize; - +#else + mouse_x = move_event->position().x() - bordersize; + mouse_y = move_event->position().y() - bordersize; +#endif if(devparms == NULL) { return; diff --git a/wave_view.h b/wave_view.h index 03b087f..6c3f77a 100644 --- a/wave_view.h +++ b/wave_view.h @@ -3,7 +3,7 @@ * * Author: Teunis van Beelen * -* Copyright (C) 2016 - 2021 Teunis van Beelen +* Copyright (C) 2016 - 2023 Teunis van Beelen * * Email: teuniz@protonmail.com * @@ -31,16 +31,7 @@ #define WAVECURVE_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "qt_headers.h" #include #include