[med-svn] [Git][med-team/edflib][master] 9 commits: New upstream version 1.24

Étienne Mollier (@emollier) gitlab at salsa.debian.org
Mon Jun 12 22:17:54 BST 2023



Étienne Mollier pushed to branch master at Debian Med / edflib


Commits:
703154e7 by Étienne Mollier at 2023-06-12T21:56:07+02:00
New upstream version 1.24
- - - - -
12a482a5 by Étienne Mollier at 2023-06-12T21:56:07+02:00
routine-update: New upstream version

- - - - -
7ca4576d by Étienne Mollier at 2023-06-12T21:56:08+02:00
Update upstream source from tag 'upstream/1.24'

Update to upstream version '1.24'
with Debian dir cd0e24c6d22c72dd73d2c68830d4152e2c2b870f
- - - - -
64271508 by Étienne Mollier at 2023-06-12T21:56:08+02:00
routine-update: Standards-Version: 4.6.2

- - - - -
4e96c0c8 by Étienne Mollier at 2023-06-12T21:56:19+02:00
Set upstream metadata fields: Bug-Database, Bug-Submit.

Changes-By: lintian-brush

- - - - -
282e0d7d by Étienne Mollier at 2023-06-12T22:02:56+02:00
d/libedf1.symbols: append new symbols.

- - - - -
ba0d8c50 by Étienne Mollier at 2023-06-12T22:50:24+02:00
addcmake.patch: conform "Forwarded" field to dep3.

- - - - -
ac6ca23c by Étienne Mollier at 2023-06-12T22:52:32+02:00
properly-check-for-exp10.patch: forwarding not-needed.

The patch depends on a addcmake.patch which was rejected upstream.

- - - - -
5e3ed9b5 by Étienne Mollier at 2023-06-12T23:01:43+02:00
ready to upload to unstable.

- - - - -


17 changed files:

- LICENSE
- README.md
- debian/changelog
- debian/control
- debian/libedf1.symbols
- debian/patches/addcmake.patch
- debian/patches/properly-check-for-exp10.patch
- debian/upstream/metadata
- edflib.c
- edflib.h
- + lib/README
- + lib/makefile
- sine_generator.c
- sweep_generator.c
- test_edflib.c
- test_generator.c
- unittest/unittest.c


Changes:

=====================================
LICENSE
=====================================
@@ -1,6 +1,6 @@
 BSD 3-Clause License
 
-Copyright (c) 2009 - 2020 Teunis van Beelen
+Copyright (c) 2009 - 2023 Teunis van Beelen
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without


=====================================
README.md
=====================================
@@ -13,7 +13,7 @@ In order to use EDFlib, copy these two files to your project.
 Include the file `edflib.h` in every source file from where you want to access the library.
 
 Don't forget to tell your compiler that it must compile and link `edflib.c` (add it to
-your makefile or buildscript). `edflib.c` needs to be compiled with the options
+your makefile or build script). `edflib.c` needs to be compiled with the options
 `-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE`.
 
 For example:
@@ -34,9 +34,9 @@ To build the examples: `make`
 Each "generator" example creates an EDF+ or BDF+ file with sample signals.
 
 `test_generator` shows how to use most of the functions provided by the library and generates an
-EDF+ or BDF+ testfile with several sample signals.
+EDF+ or BDF+ test file with several sample signals.
 
-`sine_generator` creates a BDF+ file containing the signal "sine", a 1 Hz sinoidal waveform with a
+`sine_generator` creates a BDF+ file containing the signal "sine", a 1 Hz sinusoidal waveform with a
 sample frequency of 2048 Hz.
 
 `sweep_generator` creates a linear or logarithmic sweep through a range of frequencies in EDF+ or
@@ -69,12 +69,12 @@ read the document "Coding Schemes Used with Data Converters" (PDF):
 http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sbaa042
 
 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
+In that case a file with a duration of five minutes contains 300 datarecords. The duration of a datarecord can be freely chosen 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.
+The RECOMMENDATION of a maximum datarecord size 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
+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 sampling rates
 used by modern Analog to Digital Converters.
 
 EDF header character encoding: The EDF specification says that only ASCII characters are allowed.
@@ -85,7 +85,7 @@ The description/name of an EDF+ annotation on the other hand, is encoded in UTF-
 
 ## License
 
-Copyright (c) 2009 - 2020 Teunis van Beelen
+Copyright (c) 2009 - 2023 Teunis van Beelen
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without


=====================================
debian/changelog
=====================================
@@ -1,3 +1,16 @@
+edflib (1.24-1) unstable; urgency=medium
+
+  * New upstream version
+  * Standards-Version: 4.6.2 (routine-update)
+  * Set upstream metadata fields: Bug-Database, Bug-Submit.
+    Changes-By: lintian-brush
+  * d/libedf1.symbols: append new symbols.
+  * addcmake.patch: conform "Forwarded" field to dep3.
+  * properly-check-for-exp10.patch: forwarding not-needed.
+    The patch depends on addcmake.patch which was rejected upstream.
+
+ -- Étienne Mollier <emollier at debian.org>  Mon, 12 Jun 2023 23:01:13 +0200
+
 edflib (1.23-1) unstable; urgency=medium
 
   [ Nilesh Patra ]


=====================================
debian/control
=====================================
@@ -7,7 +7,7 @@ Priority: optional
 Build-Depends: debhelper-compat (= 13),
                cmake,
                d-shlibs
-Standards-Version: 4.6.1
+Standards-Version: 4.6.2
 Vcs-Browser: https://salsa.debian.org/med-team/edflib
 Vcs-Git: https://salsa.debian.org/med-team/edflib.git
 Homepage: https://www.teuniz.net/edflib/


=====================================
debian/libedf1.symbols
=====================================
@@ -24,6 +24,7 @@ libedf.so.1 libedf1 #MINVER#
  edf_set_prefilter at Base 1.16
  edf_set_recording_additional at Base 1.16
  edf_set_samplefrequency at Base 1.16
+ edf_set_sex at Base 1.24
  edf_set_startdatetime at Base 1.16
  edf_set_subsecond_starttime at Base 1.18
  edf_set_technician at Base 1.16
@@ -42,7 +43,9 @@ libedf.so.1 libedf1 #MINVER#
  edfseek at Base 1.16
  edftell at Base 1.16
  edfwrite_annotation_latin1 at Base 1.16
+ edfwrite_annotation_latin1_hr at Base 1.24
  edfwrite_annotation_utf8 at Base 1.16
+ edfwrite_annotation_utf8_hr at Base 1.24
  edfwrite_digital_samples at Base 1.16
  edfwrite_digital_short_samples at Base 1.16
  edfwrite_physical_samples at Base 1.16


=====================================
debian/patches/addcmake.patch
=====================================
@@ -1,5 +1,6 @@
 Description: add a build system
-Forwarded: Forwarded upstream but rejected https://lists.debian.org/debian-med/2021/01/msg00106.html
+ Note upstream preferred not to include it.
+Forwarded: https://lists.debian.org/debian-med/2021/01/msg00106.html
 Author: Mathieu Malaterre <malat at debian.org>
 
 --- /dev/null


=====================================
debian/patches/properly-check-for-exp10.patch
=====================================
@@ -1,6 +1,7 @@
 From: Fabian Klötzl <fabian at kloetzl.info>
 Date: Tue, 22 Aug 2017 10:18:47 +0200
 Subject: properly check for exp10
+Forwarded: not-needed
 
 ---
  CMakeLists.txt    | 10 ++++++++++


=====================================
debian/upstream/metadata
=====================================
@@ -1,7 +1,7 @@
 ---
 Archive: GitLab
-Bug-Database: https://gitlab.com/Teuniz/EDFlib/issues
-Bug-Submit: https://gitlab.com/Teuniz/EDFlib/issues/new
+Bug-Database: https://gitlab.com/Teuniz/EDFlib/-/issues
+Bug-Submit: https://gitlab.com/Teuniz/EDFlib/-/issues/new
 Changelog: https://gitlab.com/Teuniz/EDFlib/tags
 Repository: https://gitlab.com/Teuniz/EDFlib.git
 Repository-Browse: https://gitlab.com/Teuniz/EDFlib


=====================================
edflib.c
=====================================
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
 *
-* Copyright (c) 2009 - 2022 Teunis van Beelen
+* Copyright (c) 2009 - 2023 Teunis van Beelen
 * All rights reserved.
 *
 * Email: teuniz at protonmail.com
@@ -35,7 +35,7 @@
 
 #include "edflib.h"
 
-#define EDFLIB_VERSION  (123)
+#define EDFLIB_VERSION  (124)
 #define EDFLIB_MAXFILES  (64)
 
 #if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__) || defined(__HAIKU__) || defined(__ANDROID__)
@@ -71,110 +71,118 @@
 #define EDFLIB_WRITE_MAX_ANNOTATION_LEN  (40)
 
 /* bytes in datarecord for EDF annotations, must be an integer multiple of three and two */
-#define EDFLIB_ANNOTATION_BYTES  (114)
+#define EDFLIB_ANNOTATION_BYTES  (120)
 
 /* for writing only */
 #define EDFLIB_MAX_ANNOTATION_CHANNELS  (64)
 
 #define EDFLIB_ANNOT_MEMBLOCKSZ  (1000)
 
-struct edfparamblock{
-        char   label[17];
-        char   transducer[81];
-        char   physdimension[9];
-        double phys_min;
-        double phys_max;
-        int    dig_min;
-        int    dig_max;
-        char   prefilter[81];
-        int    smp_per_record;
-        char   reserved[33];
-        double offset;
-        int    buf_offset;
-        double bitvalue;
-        int    annotation;
-        long long sample_pntr;
-      };
-
-struct edfhdrblock{
-        FILE      *file_hdl;
-        char      path[1024];
-        int       writemode;
-        char      version[32];
-        char      patient[81];
-        char      recording[81];
-        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];
-        char      plus_admincode[81];
-        char      plus_technician[81];
-        char      plus_equipment[81];
-        char      plus_recording_additional[81];
-        long long l_starttime;
-        int       startdate_day;
-        int       startdate_month;
-        int       startdate_year;
-        int       starttime_second;
-        int       starttime_minute;
-        int       starttime_hour;
-        char      reserved[45];
-        int       hdrsize;
-        int       edfsignals;
-        long long datarecords;
-        int       recordsize;
-        int       annot_ch[EDFLIB_MAXSIGNALS];
-        int       nr_annot_chns;
-        int       mapped_signals[EDFLIB_MAXSIGNALS];
-        int       edf;
-        int       edfplus;
-        int       bdf;
-        int       bdfplus;
-        int       discontinuous;
-        int       signal_write_sequence_pos;
-        long long starttime_offset;
-        double    data_record_duration;
-        long long long_data_record_duration;
-        int       annots_in_file;
-        int       annotlist_sz;
-        int       total_annot_bytes;
-        int       eq_sf;
-        char      *wrbuf;
-        int       wrbufsize;
-        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;
-        char annotation[EDFLIB_WRITE_MAX_ANNOTATION_LEN + 1];
-       } *write_annotationslist[EDFLIB_MAXFILES];
+typedef struct
+{
+  char   label[17];
+  char   transducer[81];
+  char   physdimension[9];
+  double phys_min;
+  double phys_max;
+  int    dig_min;
+  int    dig_max;
+  char   prefilter[81];
+  int    smp_per_record;
+  char   reserved[33];
+  double offset;
+  int    buf_offset;
+  double bitvalue;
+  int    annotation;
+  long long sample_pntr;
+} edfparamblock_t;
+
+typedef struct
+{
+  FILE      *file_hdl;
+  char      path[1024];
+  int       writemode;
+  char      version[32];
+  char      patient[81];
+  char      recording[81];
+  char      plus_patientcode[81];
+  char      plus_sex[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];
+  char      plus_admincode[81];
+  char      plus_technician[81];
+  char      plus_equipment[81];
+  char      plus_recording_additional[81];
+  long long l_starttime;
+  int       startdate_day;
+  int       startdate_month;
+  int       startdate_year;
+  int       starttime_second;
+  int       starttime_minute;
+  int       starttime_hour;
+  char      reserved[45];
+  int       hdrsize;
+  int       edfsignals;
+  long long datarecords;
+  int       recordsize;
+  int       annot_ch[EDFLIB_MAXSIGNALS];
+  int       nr_annot_chns;
+  int       mapped_signals[EDFLIB_MAXSIGNALS];
+  int       edf;
+  int       edfplus;
+  int       bdf;
+  int       bdfplus;
+  int       discontinuous;
+  int       signal_write_sequence_pos;
+  long long starttime_offset;
+  double    data_record_duration;
+  long long long_data_record_duration;
+  int       annots_in_file;
+  int       annotlist_sz;
+  int       total_annot_bytes;
+  int       eq_sf;
+  char      *wrbuf;
+  int       wrbufsize;
+  edfparamblock_t *edfparam;
+} edfhdrblock_t;
+
+typedef struct
+{
+  long long onset;
+  long long duration_l;
+  char duration[20];
+  char annotation[EDFLIB_MAX_ANNOTATION_LEN + 1];
+} edf_read_annotationblock_t;
+
+static edf_read_annotationblock_t *annotationslist[EDFLIB_MAXFILES];
+
+typedef struct
+{
+  long long onset;
+  long long duration;
+  char annotation[EDFLIB_WRITE_MAX_ANNOTATION_LEN + 1];
+} edf_write_annotationblock_t;
+
+static edf_write_annotationblock_t *write_annotationslist[EDFLIB_MAXFILES];
 
 static int edf_files_open=0;
 
-static struct edfhdrblock *hdrlist[EDFLIB_MAXFILES];
+static edfhdrblock_t *hdrlist[EDFLIB_MAXFILES];
 
-static struct edfhdrblock * edflib_check_edf_file(FILE *, int *);
+static edfhdrblock_t * edflib_check_edf_file(FILE *, int *);
 static int edflib_is_integer_number(char *);
 static int edflib_is_number(char *);
 static long long edflib_get_long_duration(char *);
-static int edflib_get_annotations(struct edfhdrblock *, int, int);
+static int edflib_get_annotations(edfhdrblock_t *, int, int);
 static int edflib_is_duration_number(char *);
 static int edflib_is_onset_number(char *);
 static long long edflib_get_long_time(char *);
-static int edflib_write_edf_header(struct edfhdrblock *);
+static int edflib_write_edf_header(edfhdrblock_t *);
 static void edflib_latin1_to_ascii(char *, int);
 static void edflib_latin12utf8(char *, int);
 static void edflib_remove_padding_trailing_spaces(char *);
@@ -187,12 +195,12 @@ static int edflib_sprint_int_number_nonlocalized(char *, int, int, int);
 static int edflib_snprint_ll_number_nonlocalized(char *, long long, int, int, int);
 static int edflib_fprint_int_number_nonlocalized(FILE *, int, int, int);
 static int edflib_fprint_ll_number_nonlocalized(FILE *, long long, int, int);
-static int edflib_write_tal(struct edfhdrblock *, FILE *);
+static int edflib_write_tal(edfhdrblock_t *, FILE *);
 static int edflib_strlcpy(char *, const char *, int);
 static int edflib_strlcat(char *, const char *, int);
 
 
-int edflib_is_file_used(const char *path)
+EDFLIB_API int edflib_is_file_used(const char *path)
 {
   int i;
 
@@ -208,13 +216,13 @@ int edflib_is_file_used(const char *path)
 }
 
 
-int edflib_get_number_of_open_files()
+EDFLIB_API int edflib_get_number_of_open_files()
 {
   return edf_files_open;
 }
 
 
-int edflib_get_handle(int file_number)
+EDFLIB_API int edflib_get_handle(int file_number)
 {
   int i, file_count=0;
 
@@ -230,7 +238,7 @@ int edflib_get_handle(int file_number)
 }
 
 
-int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int read_annotations_mode)
+EDFLIB_API int edfopen_file_readonly(const char *path, edflib_hdr_t *edfhdr, int read_annotations_mode)
 {
   int i, j,
       channel,
@@ -238,7 +246,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   union
   {
@@ -246,7 +254,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
     int one;
   } byte_order_test_var;
 
-  memset(edfhdr, 0, sizeof(struct edf_hdr_struct));
+  memset(edfhdr, 0, sizeof(edflib_hdr_t));
 
   /* avoid surprises! */
   if((sizeof(char)      != 1) ||
@@ -390,7 +398,15 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
   else
   {
     edflib_strlcpy(edfhdr->patientcode, hdr->plus_patientcode, 81);
-    edflib_strlcpy(edfhdr->gender, hdr->plus_gender, 16);
+    edflib_strlcpy(edfhdr->sex, hdr->plus_sex, 16);
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+    edflib_strlcpy(edfhdr->gender, hdr->plus_sex, 16);
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
     edflib_strlcpy(edfhdr->birthdate, hdr->plus_birthdate, 16);
     edfhdr->birthdate_day = hdr->plus_birthdate_day;
     edfhdr->birthdate_month = hdr->plus_birthdate_month;
@@ -458,9 +474,9 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
 }
 
 
-int edfclose_file(int handle)
+EDFLIB_API int edfclose_file(int handle)
 {
-  struct edf_write_annotationblock *annot2;
+  edf_write_annotationblock_t *annot2;
 
   int i, j, k, n, p, err,
       datrecsize,
@@ -471,7 +487,7 @@ int edfclose_file(int handle)
 
   char str[EDFLIB_ANNOTATION_BYTES * 2];
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
@@ -508,8 +524,6 @@ int edfclose_file(int handle)
 
       for(k=0; k<hdr->annots_in_file; k++)
       {
-        annot2 = write_annotationslist[handle] + k;
-
         p = edflib_fprint_ll_number_nonlocalized(hdr->file_hdl, (hdr->datarecords * hdr->long_data_record_duration + hdr->starttime_offset) / EDFLIB_TIME_DIMENSION, 0, 1);
 
         if((hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION) || (hdr->starttime_offset))
@@ -568,7 +582,7 @@ int edfclose_file(int handle)
     {
       annot2 = write_annotationslist[handle] + k;
 
-      annot2->onset += hdr->starttime_offset / 1000LL;
+      annot2->onset += hdr->starttime_offset / 10LL;
 
       p = 0;
 
@@ -592,23 +606,23 @@ int edfclose_file(int handle)
         str[p++] =  0;
       }
 
-      n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->onset / 10000LL, 0, 1, (EDFLIB_ANNOTATION_BYTES * 2) - p);
+      n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->onset / 1000000LL, 0, 1, (EDFLIB_ANNOTATION_BYTES * 2) - p);
       p += n;
-      if(annot2->onset % 10000LL)
+      if(annot2->onset % 1000000LL)
       {
         str[p++] = '.';
-        n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->onset % 10000LL, 4, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
+        n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->onset % 1000000LL, 6, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
         p += n;
       }
       if(annot2->duration>=0LL)
       {
         str[p++] = 21;
-        n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->duration / 10000LL, 0, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
+        n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->duration / 1000000LL, 0, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
         p += n;
-        if(annot2->duration % 10000LL)
+        if(annot2->duration % 1000000LL)
         {
           str[p++] = '.';
-          n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->duration % 10000LL, 4, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
+          n = edflib_snprint_ll_number_nonlocalized(str + p, annot2->duration % 1000000LL, 6, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
           p += n;
         }
       }
@@ -676,7 +690,7 @@ int edfclose_file(int handle)
 }
 
 
-long long edfseek(int handle, int edfsignal, long long offset, int whence)
+EDFLIB_API long long edfseek(int handle, int edfsignal, long long offset, int whence)
 {
   long long smp_in_file;
 
@@ -726,7 +740,7 @@ long long edfseek(int handle, int edfsignal, long long offset, int whence)
 }
 
 
-long long edftell(int handle, int edfsignal)
+EDFLIB_API long long edftell(int handle, int edfsignal)
 {
   int channel;
 
@@ -746,7 +760,7 @@ long long edftell(int handle, int edfsignal)
 }
 
 
-void edfrewind(int handle, int edfsignal)
+EDFLIB_API void edfrewind(int handle, int edfsignal)
 {
   int channel;
 
@@ -766,7 +780,7 @@ void edfrewind(int handle, int edfsignal)
 }
 
 
-int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
+EDFLIB_API int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
 {
   int bytes_per_smpl=2,
       tmp,
@@ -782,7 +796,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
             smp_per_record,
             jump;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   union {
           unsigned int one;
@@ -935,7 +949,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
 }
 
 
-int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
+EDFLIB_API int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
 {
   int bytes_per_smpl=2,
       tmp,
@@ -948,7 +962,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
             smp_per_record,
             jump;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   union {
           unsigned int one;
@@ -1100,9 +1114,9 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
 }
 
 
-int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot)
+EDFLIB_API int edf_get_annotation(int handle, int n, edflib_annotation_t *annot)
 {
-  memset(annot, 0, sizeof(struct edf_annotation_struct));
+  memset(annot, 0, sizeof(edflib_annotation_t));
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -1116,14 +1130,14 @@ int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot)
 
   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->duration, (annotationslist[handle] + n)->duration, 20);
   edflib_strlcpy(annot->annotation, (annotationslist[handle] + n)->annotation, EDFLIB_MAX_ANNOTATION_LEN + 1);
 
   return 0;
 }
 
 
-static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_error)
+static edfhdrblock_t * edflib_check_edf_file(FILE *inputfile, int *edf_error)
 {
   int i, j, p, r=0, n,
       dotposition,
@@ -1133,7 +1147,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
        scratchpad[128],
        scratchpad2[64];
 
-  struct edfhdrblock *edfhdr;
+  edfhdrblock_t *edfhdr;
 
 /***************** check header ******************************/
 
@@ -1144,7 +1158,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
     return NULL;
   }
 
-  edfhdr = (struct edfhdrblock *)calloc(1, sizeof(struct edfhdrblock));
+  edfhdr = (edfhdrblock_t *)calloc(1, sizeof(edfhdrblock_t));
   if(edfhdr==NULL)
   {
     free(edf_hdr);
@@ -1497,26 +1511,34 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
 
   if(edfhdr->edf)
   {
-    if(!strncmp(scratchpad, "EDF+C", 5))
+    if(!strncmp(scratchpad, "EDF+C                                       ", 44))
     {
       edfhdr->edfplus = 1;
+      edfhdr->discontinuous = 0;
     }
-
-    if(!strncmp(scratchpad, "EDF+D", 5))
-    {
-      edfhdr->edfplus = 1;
-      edfhdr->discontinuous = 1;
-    }
+    else if(!strncmp(scratchpad, "EDF+D                                       ", 44))
+      {
+        edfhdr->edfplus = 1;
+        edfhdr->discontinuous = 1;
+      }
+      else if(strncmp(scratchpad, "                                            ", 44))
+      {
+        *edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
+        free(edf_hdr);
+        free(edfhdr);
+        return NULL;
+      }
   }
 
   if(edfhdr->bdf)
   {
-    if(!strncmp(scratchpad, "BDF+C", 5))
+    if(!strncmp(scratchpad, "BDF+C                                       ", 44))
     {
       edfhdr->bdfplus = 1;
+      edfhdr->discontinuous = 0;
     }
 
-    if(!strncmp(scratchpad, "BDF+D", 5))
+    if(!strncmp(scratchpad, "BDF+D                                       ", 44))
     {
       edfhdr->bdfplus = 1;
       edfhdr->discontinuous = 1;
@@ -1615,7 +1637,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
     return NULL;
   }
 
-  edfhdr->edfparam = (struct edfparamblock *)calloc(1, sizeof(struct edfparamblock) * edfhdr->edfsignals);
+  edfhdr->edfparam = (edfparamblock_t *)calloc(1, sizeof(edfparamblock_t) * edfhdr->edfsignals);
   if(edfhdr->edfparam==NULL)
   {
     *edf_error = EDFLIB_MALLOC_ERROR;
@@ -2212,15 +2234,15 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
 
     if(edfhdr->patient[p]=='M')
     {
-      edflib_strlcpy(edfhdr->plus_gender, "Male", 16);
+      edflib_strlcpy(edfhdr->plus_sex, "Male", 16);
     }
     if(edfhdr->patient[p]=='F')
     {
-      edflib_strlcpy(edfhdr->plus_gender, "Female", 16);
+      edflib_strlcpy(edfhdr->plus_sex, "Female", 16);
     }
     if(edfhdr->patient[p]=='X')
     {
-      edfhdr->plus_gender[0] = 0;
+      edfhdr->plus_sex[0] = 0;
     }
     for(i=0; i<(80-p);i++)
     {
@@ -2784,13 +2806,13 @@ static long long edflib_get_long_duration(char *str)
 }
 
 
-int edflib_version(void)
+EDFLIB_API int edflib_version(void)
 {
   return EDFLIB_VERSION;
 }
 
 
-static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_annotations_mode)
+static int edflib_get_annotations(edfhdrblock_t *edfhdr, int hdl, int read_annotations_mode)
 {
   int i, j, k, p, r=0, n,
       edfsignals,
@@ -2810,22 +2832,22 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
       annots_in_tal,
       samplesize=2;
 
-  char *scratchpad,
-       *cnv_buf,
-       *time_in_txt,
-       *duration_in_txt;
+  char *scratchpad=NULL,
+       *cnv_buf=NULL,
+       *time_in_txt=NULL,
+       *duration_in_txt=NULL;
 
 
   long long data_record_duration,
             elapsedtime,
             time_tmp=0;
 
-  FILE *inputfile;
+  FILE *inputfile=NULL;
 
-  struct edfparamblock *edfparam;
+  edfparamblock_t *edfparam=NULL;
 
-  struct edf_annotationblock *new_annotation=NULL,
-                             *malloc_list;
+  edf_read_annotationblock_t *new_annotation=NULL,
+                             *malloc_list=NULL;
 
   inputfile = edfhdr->file_hdl;
   edfsignals = edfhdr->edfsignals;
@@ -2859,6 +2881,8 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
     if(max_tal_ln<edfparam[annot_ch[i]].smp_per_record * samplesize)  max_tal_ln = edfparam[annot_ch[i]].smp_per_record * samplesize;
   }
 
+  max_tal_ln += 2;
+
   if(max_tal_ln<128)  max_tal_ln = 128;
 
   scratchpad = (char *)calloc(1, max_tal_ln + 3);
@@ -3055,8 +3079,8 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
               {
                 if(edfhdr->annots_in_file >= edfhdr->annotlist_sz)
                 {
-                  malloc_list = (struct edf_annotationblock *)realloc(annotationslist[hdl],
-                                                                      sizeof(struct edf_annotationblock) * (edfhdr->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
+                  malloc_list = (edf_read_annotationblock_t *)realloc(annotationslist[hdl],
+                                                                      sizeof(edf_read_annotationblock_t) * (edfhdr->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
                   if(malloc_list==NULL)
                   {
                     free(cnv_buf);
@@ -3077,7 +3101,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
 
                 if(duration)
                 {
-                  edflib_strlcpy(new_annotation->duration, duration_in_txt, 16);
+                  edflib_strlcpy(new_annotation->duration, duration_in_txt, 20);
                   new_annotation->duration_l = edflib_get_long_time(duration_in_txt);
                 }
                 else
@@ -3388,7 +3412,7 @@ static void edflib_latin12utf8(char *latin1_str, int len)
 }
 
 
-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)
+EDFLIB_API 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)
 {
   int i, handle;
 
@@ -3468,13 +3492,13 @@ int edfopen_file_writeonly_with_params(const char *path, int filetype, int numbe
 }
 
 
-int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals)
+EDFLIB_API int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals)
 {
   int i, handle;
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   union
   {
@@ -3534,13 +3558,13 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
     return EDFLIB_NUMBER_OF_SIGNALS_INVALID;
   }
 
-  hdr = (struct edfhdrblock *)calloc(1, sizeof(struct edfhdrblock));
+  hdr = (edfhdrblock_t *)calloc(1, sizeof(edfhdrblock_t));
   if(hdr==NULL)
   {
     return EDFLIB_MALLOC_ERROR;
   }
 
-  hdr->edfparam = (struct edfparamblock *)calloc(1, sizeof(struct edfparamblock) * number_of_signals);
+  hdr->edfparam = (edfparamblock_t *)calloc(1, sizeof(edfparamblock_t) * number_of_signals);
   if(hdr->edfparam==NULL)
   {
     free(hdr);
@@ -3621,7 +3645,7 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
 }
 
 
-int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency)
+EDFLIB_API int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3643,7 +3667,7 @@ int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency)
 }
 
 
-int edf_set_number_of_annotation_signals(int handle, int annot_signals)
+EDFLIB_API int edf_set_number_of_annotation_signals(int handle, int annot_signals)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3661,7 +3685,7 @@ int edf_set_number_of_annotation_signals(int handle, int annot_signals)
 }
 
 
-int edf_set_datarecord_duration(int handle, int duration)
+EDFLIB_API int edf_set_datarecord_duration(int handle, int duration)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3694,7 +3718,7 @@ int edf_set_datarecord_duration(int handle, int duration)
 }
 
 
-int edf_set_micro_datarecord_duration(int handle, int duration)
+EDFLIB_API int edf_set_micro_datarecord_duration(int handle, int duration)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3714,7 +3738,7 @@ int edf_set_micro_datarecord_duration(int handle, int duration)
 }
 
 
-int edf_set_subsecond_starttime(int handle, int subsecond)
+EDFLIB_API int edf_set_subsecond_starttime(int handle, int subsecond)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3732,7 +3756,7 @@ int edf_set_subsecond_starttime(int handle, int subsecond)
 }
 
 
-int edfwrite_digital_short_samples(int handle, short *buf)
+EDFLIB_API int edfwrite_digital_short_samples(int handle, short *buf)
 {
   int  i,
        error,
@@ -3744,7 +3768,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3842,7 +3866,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
 }
 
 
-int edfwrite_digital_samples(int handle, int *buf)
+EDFLIB_API int edfwrite_digital_samples(int handle, int *buf)
 {
   int  i,
        error,
@@ -3854,7 +3878,7 @@ int edfwrite_digital_samples(int handle, int *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -3966,7 +3990,7 @@ int edfwrite_digital_samples(int handle, int *buf)
 }
 
 
-int edf_blockwrite_digital_samples(int handle, int *buf)
+EDFLIB_API int edf_blockwrite_digital_samples(int handle, int *buf)
 {
   int  i, j,
        error,
@@ -3979,7 +4003,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -4090,7 +4114,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
 }
 
 
-int edf_blockwrite_digital_short_samples(int handle, short *buf)
+EDFLIB_API int edf_blockwrite_digital_short_samples(int handle, short *buf)
 {
   int  i, j,
        error,
@@ -4103,7 +4127,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -4209,7 +4233,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
 }
 
 
-int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
+EDFLIB_API int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
 {
   int  j,
        error,
@@ -4218,7 +4242,7 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -4262,7 +4286,7 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
 }
 
 
-int edfwrite_physical_samples(int handle, double *buf)
+EDFLIB_API int edfwrite_physical_samples(int handle, double *buf)
 {
   int  i,
        error,
@@ -4277,7 +4301,7 @@ int edfwrite_physical_samples(int handle, double *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -4393,7 +4417,7 @@ int edfwrite_physical_samples(int handle, double *buf)
 }
 
 
-int edf_blockwrite_physical_samples(int handle, double *buf)
+EDFLIB_API int edf_blockwrite_physical_samples(int handle, double *buf)
 {
   int  i, j,
        error,
@@ -4409,7 +4433,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
 
   FILE *file;
 
-  struct edfhdrblock *hdr;
+  edfhdrblock_t *hdr;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -4524,7 +4548,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
 }
 
 
-static int edflib_write_edf_header(struct edfhdrblock *hdr)
+static int edflib_write_edf_header(edfhdrblock_t *hdr)
 {
   int i, j, p, q,
       len,
@@ -4613,8 +4637,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
   }
   else
   {
-    fputc(255, file);
-    fprintf(file, "BIOSEMI");
+    fprintf(file, "\xff" "BIOSEMI");
   }
 
   p = 0;
@@ -4657,13 +4680,13 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
     p += fprintf(file, "X ");
   }
 
-  if(hdr->plus_gender[0]=='M')
+  if(hdr->plus_sex[0]=='M')
   {
     fputc('M', file);
   }
   else
   {
-    if(hdr->plus_gender[0]=='F')
+    if(hdr->plus_sex[0]=='F')
     {
       fputc('F', file);
     }
@@ -5167,7 +5190,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
 }
 
 
-int edf_set_label(int handle, int edfsignal, const char *label)
+EDFLIB_API int edf_set_label(int handle, int edfsignal, const char *label)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5189,7 +5212,7 @@ int edf_set_label(int handle, int edfsignal, const char *label)
 }
 
 
-int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim)
+EDFLIB_API int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5211,7 +5234,7 @@ 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)
+EDFLIB_API int edf_set_physical_maximum(int handle, int edfsignal, double phys_max)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5229,7 +5252,7 @@ int edf_set_physical_maximum(int handle, int edfsignal, double phys_max)
 }
 
 
-int edf_set_physical_minimum(int handle, int edfsignal, double phys_min)
+EDFLIB_API int edf_set_physical_minimum(int handle, int edfsignal, double phys_min)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5247,7 +5270,7 @@ int edf_set_physical_minimum(int handle, int edfsignal, double phys_min)
 }
 
 
-int edf_set_digital_maximum(int handle, int edfsignal, int dig_max)
+EDFLIB_API int edf_set_digital_maximum(int handle, int edfsignal, int dig_max)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5274,7 +5297,7 @@ int edf_set_digital_maximum(int handle, int edfsignal, int dig_max)
 }
 
 
-int edf_set_digital_minimum(int handle, int edfsignal, int dig_min)
+EDFLIB_API int edf_set_digital_minimum(int handle, int edfsignal, int dig_min)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5301,7 +5324,7 @@ int edf_set_digital_minimum(int handle, int edfsignal, int dig_min)
 }
 
 
-int edf_set_patientname(int handle, const char *patientname)
+EDFLIB_API int edf_set_patientname(int handle, const char *patientname)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5321,7 +5344,7 @@ int edf_set_patientname(int handle, const char *patientname)
 }
 
 
-int edf_set_patientcode(int handle, const char *patientcode)
+EDFLIB_API int edf_set_patientcode(int handle, const char *patientcode)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5341,7 +5364,7 @@ int edf_set_patientcode(int handle, const char *patientcode)
 }
 
 
-int edf_set_gender(int handle, int gender)
+EDFLIB_API int edf_set_sex(int handle, int sex)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5351,24 +5374,30 @@ int edf_set_gender(int handle, int gender)
 
   if(hdrlist[handle]->datarecords)  return -1;
 
-  if((gender<0)||(gender>1))  return -1;
+  if((sex<0)||(sex>1))  return -1;
 
-  if(gender)
+  if(sex)
   {
-    hdrlist[handle]->plus_gender[0] = 'M';
+    hdrlist[handle]->plus_sex[0] = 'M';
   }
   else
   {
-    hdrlist[handle]->plus_gender[0] = 'F';
+    hdrlist[handle]->plus_sex[0] = 'F';
   }
 
-  hdrlist[handle]->plus_gender[1] = 0;
+  hdrlist[handle]->plus_sex[1] = 0;
 
   return 0;
 }
 
 
-int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int birthdate_day)
+EDFLIB_API int edf_set_gender(int handle, int sex)
+{
+  return edf_set_sex(handle, sex);
+}
+
+
+EDFLIB_API int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int birthdate_day)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5393,7 +5422,7 @@ 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)
+EDFLIB_API int edf_set_patient_additional(int handle, const char *patient_additional)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5413,7 +5442,7 @@ int edf_set_patient_additional(int handle, const char *patient_additional)
 }
 
 
-int edf_set_admincode(int handle, const char *admincode)
+EDFLIB_API int edf_set_admincode(int handle, const char *admincode)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5433,7 +5462,7 @@ int edf_set_admincode(int handle, const char *admincode)
 }
 
 
-int edf_set_technician(int handle, const char *technician)
+EDFLIB_API int edf_set_technician(int handle, const char *technician)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5453,7 +5482,7 @@ int edf_set_technician(int handle, const char *technician)
 }
 
 
-int edf_set_equipment(int handle, const char *equipment)
+EDFLIB_API int edf_set_equipment(int handle, const char *equipment)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5473,7 +5502,7 @@ int edf_set_equipment(int handle, const char *equipment)
 }
 
 
-int edf_set_recording_additional(int handle, const char *recording_additional)
+EDFLIB_API int edf_set_recording_additional(int handle, const char *recording_additional)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5493,8 +5522,8 @@ 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)
+EDFLIB_API 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)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5525,11 +5554,19 @@ int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, i
 }
 
 
-int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description)
+EDFLIB_API int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description)
+{
+  if(duration > 0LL)  duration *= 100LL;
+
+  return edfwrite_annotation_utf8_hr(handle, onset * 100LL, duration, description);
+}
+
+
+EDFLIB_API int edfwrite_annotation_utf8_hr(int handle, long long onset, long long duration, const char *description)
 {
   int i;
 
-  struct edf_write_annotationblock *list_annot, *malloc_list;
+  edf_write_annotationblock_t *list_annot, *malloc_list;
 
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5541,8 +5578,8 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
 
   if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz)
   {
-    malloc_list = (struct edf_write_annotationblock *)realloc(write_annotationslist[handle],
-                                                              sizeof(struct edf_write_annotationblock) * (hdrlist[handle]->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
+    malloc_list = (edf_write_annotationblock_t *)realloc(write_annotationslist[handle],
+                                                         sizeof(edf_write_annotationblock_t) * (hdrlist[handle]->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
     if(malloc_list==NULL)
     {
       return -1;
@@ -5579,9 +5616,17 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
 }
 
 
-int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description)
+EDFLIB_API int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description)
+{
+  if(duration > 0LL)  duration *= 100LL;
+
+  return edfwrite_annotation_latin1_hr(handle, onset * 100LL, duration, description);
+}
+
+
+EDFLIB_API int edfwrite_annotation_latin1_hr(int handle, long long onset, long long duration, const char *description)
 {
-  struct edf_write_annotationblock *list_annot, *malloc_list;
+  edf_write_annotationblock_t *list_annot, *malloc_list;
 
   char str[EDFLIB_WRITE_MAX_ANNOTATION_LEN + 1];
 
@@ -5595,8 +5640,8 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration,
 
   if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz)
   {
-    malloc_list = (struct edf_write_annotationblock *)realloc(write_annotationslist[handle],
-                                                              sizeof(struct edf_write_annotationblock) * (hdrlist[handle]->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
+    malloc_list = (edf_write_annotationblock_t *)realloc(write_annotationslist[handle],
+                                                         sizeof(edf_write_annotationblock_t) * (hdrlist[handle]->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
     if(malloc_list==NULL)
     {
       return -1;
@@ -5654,7 +5699,7 @@ static void edflib_remove_padding_trailing_spaces(char *str)
 }
 
 
-int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
+EDFLIB_API int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -5678,7 +5723,7 @@ int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
 }
 
 
-int edf_set_transducer(int handle, int edfsignal, const char *transducer)
+EDFLIB_API int edf_set_transducer(int handle, int edfsignal, const char *transducer)
 {
   if((handle<0)||(handle>=EDFLIB_MAXFILES))  return -1;
 
@@ -6295,7 +6340,7 @@ static int edflib_atoi_nonlocalized(const char *str)
 }
 
 
-static int edflib_write_tal(struct edfhdrblock *hdr, FILE *file)
+static int edflib_write_tal(edfhdrblock_t *hdr, FILE *file)
 {
   int p;
 


=====================================
edflib.h
=====================================
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
 *
-* Copyright (c) 2009 - 2022 Teunis van Beelen
+* Copyright (c) 2009 - 2023 Teunis van Beelen
 * All rights reserved.
 *
 * Email: teuniz at protonmail.com
@@ -54,28 +54,28 @@
  * 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
+ * In that case a file with a duration of five minutes contains 300 datarecords. The duration of a datarecord can be freely chosen 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.
+ * The RECOMMENDATION of a maximum datarecord size 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
+ * 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 sampling rates
  * 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 description of an EDF+ annotation on the other hand, is always encoded in UTF-8 (which is forward compatible with ASCII).
  *
- * The samplefrequency of a signal is calculated as follows: sf = (smp_in_datarecord * EDFLIB_TIME_DIMENSION) / datarecord_duration
+ * The sample frequency 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).
+ * EDF+ and BDF+ store the annotations in one or more signals (in order to be backwards compatible 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.
+ * This means that the annotationsignal(s) in the file are hidden.
  * 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
@@ -86,9 +86,9 @@
  * 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
+ * To avoid rounding errors, the library stores some time values in variables of type long long int.
+ * In order not to lose the sub-second precision, all time values are scaled with a scaling factor: 10000000.
+ * This will limit the time resolution 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".
  *
@@ -106,6 +106,7 @@
 
 /* compile with options "-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" */
 
+
 #ifndef EDFLIB_INCLUDED
 #define EDFLIB_INCLUDED
 
@@ -114,6 +115,47 @@
 #include <string.h>
 #include <time.h>
 
+
+/*
+ * If both EDFLIB_SO_DLL and EDFLIB_BUILD are defined: compile only EDFlib as a shared library (so, dll).
+ * When compiling on unix-like systems, add the -fvisibility=hidden to hide all symbols by
+ * default so that this macro can reveal them.
+ *
+ * If only EDFLIB_SO_DLL is defined: link with EDFlib as an external library (so, dll).
+ * EDFlib must be installed on your system (as an .so or .dll) when running your program.
+ *
+ * If both EDFLIB_SO_DLL and EDFLIB_BUILD are not defined: EDFlib will not be used as a shared library,
+ * it will be an integral part of your program instead.
+ *
+ */
+
+/*
+#define EDFLIB_SO_DLL
+#define EDFLIB_BUILD
+*/
+
+#if defined(EDFLIB_SO_DLL)
+#  if defined(EDFLIB_BUILD)
+#    if defined(_WIN32)
+#      define EDFLIB_API __declspec(dllexport)
+#    elif defined(__ELF__)
+#      define EDFLIB_API __attribute__ ((visibility ("default")))
+#    else
+#      define EDFLIB_API
+#    endif
+#  else
+#    if defined(_WIN32)
+#      define EDFLIB_API __declspec(dllimport)
+#    else
+#      define EDFLIB_API
+#    endif
+#  endif
+#else
+#  define EDFLIB_API
+#endif
+
+
+
 #define EDFLIB_TIME_DIMENSION     (10000000LL)
 #define EDFLIB_MAXSIGNALS                (640)
 #define EDFLIB_MAX_ANNOTATION_LEN        (512)
@@ -163,42 +205,50 @@
 extern "C" {
 #endif
 
-struct edf_param_struct{         /* this structure contains all the relevant EDF-signal parameters of one signal */
+typedef 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, 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 */
+  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 sample rate */
   char   physdimension[9];       /* physical dimension (uV, bpm, mA, etc.), null-terminated string */
   char   prefilter[81];          /* null-terminated string */
   char   transducer[81];         /* null-terminated string */
-      };
+} edflib_param_t;
 
-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 */
+typedef 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, if less than zero: unused or not applicable */
+        char duration[20];                              /* 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 */
-       };
+} edflib_annotation_t;
 
-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() */
+typedef 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 */
+  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 EDF+ and BDF+ */
+  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;
-  char      patient[81];                                  /* null-terminated string, contains patientfield of header, is always empty when filetype is EDFPLUS or BDFPLUS */
-  char      recording[81];                                /* null-terminated string, contains recordingfield of header, is always empty when filetype is EDFPLUS or BDFPLUS */
+  char      patient[81];                                  /* null-terminated string, contains patient field of header, is always empty when filetype is EDFPLUS or BDFPLUS */
+  char      recording[81];                                /* null-terminated string, contains recording field of header, is always empty when filetype is EDFPLUS or BDFPLUS */
   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      sex[16];                                      /* null-terminated string, is always empty when filetype is EDF or BDF */
+#if defined(__GNUC__)
+  char      gender[16] __attribute__ ((deprecated ("use sex")));      /* DEPRECATED!! use "sex" */
+#else
+  char      gender[16];  /* DEPRECATED!! use "sex" */
+#endif
   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 */
@@ -209,15 +259,15 @@ struct edf_hdr_struct{            /* this structure contains all the relevant ED
   char      technician[81];                               /* null-terminated string, is always empty when filetype is EDF or BDF */
   char      equipment[81];                                /* null-terminated string, is always empty when filetype is EDF or BDF */
   char      recording_additional[81];                     /* null-terminated string, is always empty when filetype is EDF or BDF */
-  long long datarecord_duration;                          /* duration of a datarecord expressed in units of 100 nanoSeconds */
+  long long datarecord_duration;                          /* duration of a datarecord expressed in units of 100 nanoseconds */
   long long datarecords_in_file;                          /* number of datarecords in the file */
   long long annotations_in_file;                          /* number of annotations in the file */
-  struct edf_param_struct signalparam[EDFLIB_MAXSIGNALS]; /* array of structs which contain the relevant signal parameters */
-       };
+  edflib_param_t signalparam[EDFLIB_MAXSIGNALS];             /* array of structs which contain the relevant signal parameters */
+} edflib_hdr_t;
 
 /*****************  the following functions are used to read files **************************/
 
-int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int read_annotations);
+EDFLIB_API int edfopen_file_readonly(const char *path, edflib_hdr_t *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
@@ -229,11 +279,11 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
  *                                       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
+ * returns 0 on success, in case of an error it returns -1 and an error code will be set in the member "filetype" of edflib_hdr_t
  * This function is required if you want to read a file
  */
 
-int edfread_physical_samples(int handle, int edfsignal, int n, double *buf);
+EDFLIB_API 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])
@@ -242,7 +292,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf);
  * or -1 in case of an error
  */
 
-int edfread_digital_samples(int handle, int edfsignal, int n, int *buf);
+EDFLIB_API 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])
@@ -251,7 +301,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf);
  * or -1 in case of an error
  */
 
-long long edfseek(int handle, int edfsignal, long long offset, int whence);
+EDFLIB_API 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,
@@ -260,20 +310,20 @@ long long edfseek(int handle, int edfsignal, long long offset, int whence);
  * 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);
+EDFLIB_API 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
  */
 
-void edfrewind(int handle, int edfsignal);
+EDFLIB_API 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
  */
 
-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
+EDFLIB_API int edf_get_annotation(int handle, int n, edflib_annotation_t *annot);
+/* Fills the edflib_annotation_t structure 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
@@ -281,27 +331,27 @@ int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot);
 
 /*****************  the following functions are used in read and write mode **************************/
 
-int edfclose_file(int handle);
+EDFLIB_API 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
+ * unnecessary memory usage and in case of writing it will cause a corrupted and incomplete file
  */
 
-int edflib_version(void);
+EDFLIB_API int edflib_version(void);
 /* 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);
+EDFLIB_API int edflib_is_file_used(const char *path);
 /* returns 1 if the file is used, either for reading or writing, otherwise returns 0
  */
 
-int edflib_get_number_of_open_files(void);
+EDFLIB_API int edflib_get_number_of_open_files(void);
 /* returns the number of open files, either for reading or writing
  */
 
-int edflib_get_handle(int file_number);
+EDFLIB_API int edflib_get_handle(int file_number);
 /* 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
@@ -309,7 +359,7 @@ int edflib_get_handle(int file_number);
 
 /*****************  the following functions are used to write files **************************/
 
-int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals);
+EDFLIB_API 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
@@ -324,13 +374,13 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
  * This function is required if you want to write a file (or use edfopen_file_writeonly_with_params())
  */
 
-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);
+EDFLIB_API 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
+ * Sets the sample frequency of all signals. (In reality, it sets the number of samples per datarecord which equals the sample frequency 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.
@@ -347,72 +397,72 @@ int edfopen_file_writeonly_with_params(const char *path, int filetype, int numbe
  * 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 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
+EDFLIB_API int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency);
+/* Sets the sample frequency of signal edfsignal. In reality, it sets the number of samples in a datarecord
+ * which equals the sample frequency only when the datarecords have a duration of 1 second.
+ * The effective sample frequency 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
+ * file in write mode and before the first sample write action
  */
 
-int edf_set_physical_maximum(int handle, int edfsignal, double phys_max);
+EDFLIB_API 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
+ * file in write mode and before the first sample write action
  */
 
-int edf_set_physical_minimum(int handle, int edfsignal, double phys_min);
+EDFLIB_API 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
+ * file in write mode and before the first sample write action
  */
 
-int edf_set_digital_maximum(int handle, int edfsignal, int dig_max);
+EDFLIB_API 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
+ * This function is required for every signal and can be called only after opening a file in write mode
  * and before the first sample write action
  */
 
-int edf_set_digital_minimum(int handle, int edfsignal, int dig_min);
+EDFLIB_API 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
+ * This function is required for every signal and can be called only after opening a file in write mode
  * and before the first sample write action
  */
 
-int edf_set_label(int handle, int edfsignal, const char *label);
+EDFLIB_API 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
+ * and can be called only after opening a file in write mode and before the first sample write action
  */
 
-int edf_set_prefilter(int handle, int edfsignal, const char *prefilter);
+EDFLIB_API 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
+ * This function is optional and can be called only after opening a file in write mode and before
  * the first sample write action
  */
 
-int edf_set_transducer(int handle, int edfsignal, const char *transducer);
+EDFLIB_API 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
@@ -420,48 +470,60 @@ int edf_set_transducer(int handle, int edfsignal, const char *transducer);
  * the first sample write action
  */
 
-int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim);
+EDFLIB_API 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
+ * and can be called only after opening a file in write mode 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);
+EDFLIB_API 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
+ * This function is optional and can be called only after opening a file in write mode
  * 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);
+EDFLIB_API 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
  */
 
-int edf_set_patientcode(int handle, const char *patientcode);
+EDFLIB_API 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
  */
 
-int edf_set_gender(int handle, int gender);
-/* Sets the gender. 1 is male, 0 is female.
+EDFLIB_API int edf_set_sex(int handle, int sex);
+/* Sets the sex. 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
+ */
+
+#if defined(__GNUC__)
+EDFLIB_API int edf_set_gender(int handle, int sex) __attribute__ ((deprecated ("use edf_set_sex()")));
+#else
+EDFLIB_API int edf_set_gender(int handle, int sex);
+#endif
+/* DEPRECATED!! USE edf_set_sex()
+ * Sets the sex. 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);
+EDFLIB_API 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
@@ -470,42 +532,42 @@ int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int b
  * and before the first sample write action
  */
 
-int edf_set_patient_additional(int handle, const char *patient_additional);
+EDFLIB_API 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
  */
 
-int edf_set_admincode(int handle, const char *admincode);
+EDFLIB_API 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
  */
 
-int edf_set_technician(int handle, const char *technician);
+EDFLIB_API 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
  */
 
-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.
+EDFLIB_API int edf_set_equipment(int handle, const char *equipment);
+/* Sets the name of the equipment used during the acquisition. 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);
+EDFLIB_API 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
  */
 
-int edfwrite_physical_samples(int handle, double *buf);
+EDFLIB_API 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
@@ -518,7 +580,7 @@ int edfwrite_physical_samples(int handle, double *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edf_blockwrite_physical_samples(int handle, double *buf);
+EDFLIB_API 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.
@@ -531,7 +593,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edfwrite_digital_short_samples(int handle, short *buf);
+EDFLIB_API 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.
@@ -544,7 +606,7 @@ int edfwrite_digital_short_samples(int handle, short *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edfwrite_digital_samples(int handle, int *buf);
+EDFLIB_API 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
@@ -557,7 +619,7 @@ int edfwrite_digital_samples(int handle, int *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edf_blockwrite_digital_3byte_samples(int handle, void *buf);
+EDFLIB_API 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.
@@ -570,7 +632,7 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edf_blockwrite_digital_short_samples(int handle, short *buf);
+EDFLIB_API 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.
@@ -582,7 +644,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edf_blockwrite_digital_samples(int handle, int *buf);
+EDFLIB_API 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.
@@ -594,8 +656,24 @@ int edf_blockwrite_digital_samples(int handle, int *buf);
  * Returns 0 on success, otherwise -1
  */
 
-int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description);
+EDFLIB_API int edfwrite_annotation_utf8_hr(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 1 microSecond     resolution is 0.000001 second
+ * for example: 34.071 seconds must be written as 34071000
+ * 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
+ */
+
+#if defined(__GNUC__)
+EDFLIB_API int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description) __attribute__ ((deprecated ("use edfwrite_annotation_utf8_hr()")));
+#else
+EDFLIB_API int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description);
+#endif
+/* DEPRECATED!! USE edfwrite_annotation_utf8_hr()
+ * 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
@@ -605,8 +683,24 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
  * and before closing the file
  */
 
-int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description);
+EDFLIB_API int edfwrite_annotation_latin1_hr(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 1 microSecond     resolution is 0.000001 second
+ * for example: 34.071 seconds must be written as 34071000
+ * 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
+ */
+
+#if defined(__GNUC__)
+EDFLIB_API int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description) __attribute__ ((deprecated ("use edfwrite_annotation_latin1_hr()")));
+#else
+EDFLIB_API int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description);
+#endif
+/* DEPRECATED!! USE edfwrite_annotation_latin1_hr()
+ * 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
@@ -616,7 +710,7 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration,
  * and before closing the file
  */
 
-int edf_set_datarecord_duration(int handle, int duration);
+EDFLIB_API 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
@@ -633,7 +727,7 @@ int edf_set_datarecord_duration(int handle, int duration);
  * Do not use this function if not necessary.
  */
 
-int edf_set_micro_datarecord_duration(int handle, int duration);
+EDFLIB_API 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.
@@ -648,7 +742,7 @@ int edf_set_micro_datarecord_duration(int handle, int duration);
  * 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);
+EDFLIB_API 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
@@ -659,8 +753,8 @@ int edf_set_number_of_annotation_signals(int handle, int annot_signals);
  * 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
+EDFLIB_API 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


=====================================
lib/README
=====================================
@@ -0,0 +1,18 @@
+
+This makefile creates a shared libary of EDFlib.
+
+usage:
+
+make
+
+sudo make install
+  the default install path is /usr/local/lib64 or /usr/local/lib in case of a 32bit architecture
+  the header file will go into /usr/local/include
+
+sudo make install PREFIX=/usr
+  will change the install path to /usr/lib64 or /usr/lib
+  the header file will go into /usr/include
+
+
+System requirements: GNU/Linux
+


=====================================
lib/makefile
=====================================
@@ -0,0 +1,64 @@
+#
+#
+# Author: Teunis van Beelen
+#
+# email: teuniz at protonmail.com
+#
+#
+# GNU/Linux only for now.
+#
+# https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
+#
+# nm -D libedf.so.1.2.4
+#
+# objdump -T libedf.so.1.2.4
+#
+
+CC := gcc
+CFLAGS := -O2 -fpic -fvisibility=hidden -std=gnu11 -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security \
+          -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DEDFLIB_SO_DLL -DEDFLIB_BUILD
+LDLIBS := -lc
+TARGET := libedf.so.1.2.4
+
+LBITS := $(shell getconf LONG_BIT)
+
+ifeq ($(LBITS),64)
+   LIBDIR := /lib64
+else
+   LIBDIR := /lib
+endif
+
+ifeq ($(PREFIX),)
+    PREFIX := /usr/local
+endif
+
+.PHONY: install clean
+
+objects = edflib.o
+
+all: $(TARGET)
+
+$(TARGET) : $(objects)
+	$(CC) -shared -Wl,-soname,libedf.so.1 -o $(TARGET) edflib.o $(LDLIBS)
+
+edflib.o : ../edflib.h ../edflib.c
+	$(CC) $(CFLAGS) -c ../edflib.c -o edflib.o
+
+install : all
+ifneq ($(shell id -u), 0)
+	$(error You must be root to perform this action.)
+endif
+	install -d $(DESTDIR)$(PREFIX)$(LIBDIR)/
+	install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)$(LIBDIR)/
+	install -d $(DESTDIR)$(PREFIX)/include/
+	install -m 644 ../edflib.h $(DESTDIR)$(PREFIX)/include/
+	ldconfig
+
+clean :
+	$(RM) $(TARGET) $(objects)
+
+
+
+
+
+


=====================================
sine_generator.c
=====================================
@@ -209,9 +209,9 @@ int main(void)
     }
   }
 
-  edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts");
+  edfwrite_annotation_latin1_hr(hdl, 0LL, -1LL, "Recording starts");
 
-  edfwrite_annotation_latin1(hdl, 200000LL, -1LL, "Recording ends");
+  edfwrite_annotation_latin1_hr(hdl, 20000000LL, -1LL, "Recording ends");
 
   edfclose_file(hdl);
 


=====================================
sweep_generator.c
=====================================
@@ -199,7 +199,7 @@ int main(void)
   remove_trailing_zeros(str);
   edf_set_patientname(hdl, str);
 
-  edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts");
+  edfwrite_annotation_latin1_hr(hdl, 0LL, -1LL, "Recording starts");
 
   sine_1 = 0.0;
 
@@ -252,15 +252,15 @@ int main(void)
     {
       sprintf(str, "%fHz", freq);
       remove_trailing_zeros(str);
-      edfwrite_annotation_latin1(hdl, j * 10000LL, -1LL, str);
+      edfwrite_annotation_latin1_hr(hdl, j * 1000000LL, -1LL, str);
     }
   }
 
   sprintf(str, "%fHz", freq);
   remove_trailing_zeros(str);
-  edfwrite_annotation_latin1(hdl, j * 10000LL, -1LL, str);
+  edfwrite_annotation_latin1_hr(hdl, j * 1000000LL, -1LL, str);
 
-  edfwrite_annotation_latin1(hdl, fileduration * 10000LL, -1LL, "Recording ends");
+  edfwrite_annotation_latin1_hr(hdl, fileduration * 1000000LL, -1LL, "Recording ends");
 
   edfclose_file(hdl);
 


=====================================
test_edflib.c
=====================================
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
 
   double *buf;
 
-  struct edf_hdr_struct hdr;
+  edflib_hdr_t hdr;
 
 
   if(argc!=3)
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
     {
       case EDFLIB_MALLOC_ERROR                : printf("\nmalloc error\n\n");
                                                 break;
-      case EDFLIB_NO_SUCH_FILE_OR_DIRECTORY   : printf("\ncan not open file, no such file or directory\n\n");
+      case EDFLIB_NO_SUCH_FILE_OR_DIRECTORY   : printf("\ncannot open file, no such file or directory\n\n");
                                                 break;
       case EDFLIB_FILE_CONTAINS_FORMAT_ERRORS : printf("\nthe file is not EDF(+) or BDF(+) compliant\n"
                                                        "(it contains format errors)\n\n");
@@ -122,7 +122,7 @@ int main(int argc, char *argv[])
   printf("patient: %s\n", hdr.patient);
   printf("recording: %s\n", hdr.recording);
   printf("patientcode: %s\n", hdr.patientcode);
-  printf("gender: %s\n", hdr.gender);
+  printf("sex: %s\n", hdr.sex);
   printf("birthdate: %s\n", hdr.birthdate);
   printf("patient_name: %s\n", hdr.patient_name);
   printf("patient_additional: %s\n", hdr.patient_additional);
@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
   printf("transducer: %s\n", hdr.signalparam[channel].transducer);
   printf("samplefrequency: %f\n", ((double)hdr.signalparam[channel].smp_in_datarecord / (double)hdr.datarecord_duration) * EDFLIB_TIME_DIMENSION);
 
-  struct edf_annotation_struct annot;
+  edflib_annotation_t annot;
 
   printf("\n");
 


=====================================
test_generator.c
=====================================
@@ -681,17 +681,17 @@ int main(void)
     }
   }
 
-  edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts");
+  edfwrite_annotation_latin1_hr(hdl, 0LL, -1LL, "Recording starts");
 
-  edfwrite_annotation_latin1(hdl, 2980000LL, -1LL, "Test 1");
+  edfwrite_annotation_latin1_hr(hdl, 298000000LL, -1LL, "Test 1");
 
-  edfwrite_annotation_latin1(hdl, 2940000LL + (long long)((10000.0 / SMP_FREQ) * (SMP_FREQ - 2)), -1LL, "pulse 1");
+  edfwrite_annotation_latin1_hr(hdl, 294000000LL + (long long)((1000000.0 / SMP_FREQ) * (SMP_FREQ - 2)), -1LL, "pulse 1");
 
-  edfwrite_annotation_latin1(hdl, 2950000LL + (long long)((10000.0 / SMP_FREQ_2) * (SMP_FREQ_2 - 2)), -1LL, "pulse 2");
+  edfwrite_annotation_latin1_hr(hdl, 295000000LL + (long long)((1000000.0 / SMP_FREQ_2) * (SMP_FREQ_2 - 2)), -1LL, "pulse 2");
 
-  edfwrite_annotation_latin1(hdl, 2960000LL + (long long)((10000.0 / SMP_FREQ_3) * (SMP_FREQ_3 - 2)), -1LL, "pulse 3");
+  edfwrite_annotation_latin1_hr(hdl, 296000000LL + (long long)((1000000.0 / SMP_FREQ_3) * (SMP_FREQ_3 - 2)), -1LL, "pulse 3");
 
-  edfwrite_annotation_latin1(hdl, FILE_DURATION * 10000LL, -1LL, "Recording ends");
+  edfwrite_annotation_latin1_hr(hdl, FILE_DURATION * 1000000LL, -1LL, "Recording ends");
 
   edfclose_file(hdl);
 


=====================================
unittest/unittest.c
=====================================
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2017- 2021 Teunis van Beelen
+* Copyright (C) 2017- 2023 Teunis van Beelen
 *
 * Email: teuniz at protonmail.com
 *
@@ -36,6 +36,12 @@
 
 #define  JUMP_TO_EXIT_ERROR_PROC   {line = __LINE__; goto OUT_ERROR;}
 
+#define EDFLIB_ANNOTATION_BYTES  (120)
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 
 int dblcmp(double, double);
 int dblcmp_lim(double, double, double);
@@ -70,15 +76,15 @@ int main(void)
           unsigned char four[4];
         } var;
 
-  struct edf_hdr_struct hdr;
+  edflib_hdr_t hdr;
 
-  struct edf_annotation_struct annot;
+  edflib_annotation_t annot;
 
   FILE *fp=NULL;
 
   setlocale(LC_ALL, "C");
 
-  if(edflib_version() != 123)  JUMP_TO_EXIT_ERROR_PROC
+  if(edflib_version() != 124)  JUMP_TO_EXIT_ERROR_PROC
 
   ibuf = (int *)malloc(100 * sizeof(int));
   if(ibuf == NULL)
@@ -394,7 +400,7 @@ int main(void)
 
   if(edf_set_patientcode(hdl, "01234"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(edf_set_gender(hdl, 1))  JUMP_TO_EXIT_ERROR_PROC
+  if(edf_set_sex(hdl, 1))  JUMP_TO_EXIT_ERROR_PROC
 
   if(edf_set_birthdate(hdl, 2010, 7, 4))  JUMP_TO_EXIT_ERROR_PROC
 
@@ -410,11 +416,13 @@ int main(void)
 
   if(edf_set_datarecord_duration(hdl, 13000))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(edfwrite_annotation_latin1(hdl, 0, -1, "Recording starts"))  JUMP_TO_EXIT_ERROR_PROC
+  if(edfwrite_annotation_latin1_hr(hdl, 0, -1, "Recording starts"))  JUMP_TO_EXIT_ERROR_PROC
+
+  if(edfwrite_annotation_latin1_hr(hdl, 900000, 100000, "Test 1"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(edfwrite_annotation_latin1(hdl, 9000, 1000, "Test 1"))  JUMP_TO_EXIT_ERROR_PROC
+  if(edfwrite_annotation_utf8_hr(hdl, 9123456, 1123456, "Test 2"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(edfwrite_annotation_latin1(hdl, 13000, -1, "Recording ends"))  JUMP_TO_EXIT_ERROR_PROC
+  if(edfwrite_annotation_latin1_hr(hdl, 1300000, -1, "Recording ends"))  JUMP_TO_EXIT_ERROR_PROC
 
   for(i=0; i<20; i++)
   {
@@ -645,7 +653,7 @@ int main(void)
 
   if(edf_set_patientcode(hdl, "01234"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(edf_set_gender(hdl, 1))  JUMP_TO_EXIT_ERROR_PROC
+  if(edf_set_sex(hdl, 0))  JUMP_TO_EXIT_ERROR_PROC
 
   if(edf_set_birthdate(hdl, 2010, 7, 4))  JUMP_TO_EXIT_ERROR_PROC
 
@@ -807,7 +815,8 @@ int main(void)
 
   if(strcmp(hdr.patientcode, "01234"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(strcmp(hdr.gender, "Male"))  JUMP_TO_EXIT_ERROR_PROC
+  if(strcmp(hdr.sex, "Male"))  JUMP_TO_EXIT_ERROR_PROC
+  if(strcmp(hdr.gender, "Male"))  JUMP_TO_EXIT_ERROR_PROC  /* DEPRECATED */
 
   if(strcmp(hdr.birthdate, "04 jul 2010"))  JUMP_TO_EXIT_ERROR_PROC
 
@@ -829,7 +838,7 @@ int main(void)
 
   if(hdr.datarecords_in_file != 10)  JUMP_TO_EXIT_ERROR_PROC
 
-  if(hdr.annotations_in_file != 3)  JUMP_TO_EXIT_ERROR_PROC
+  if(hdr.annotations_in_file != 4)  JUMP_TO_EXIT_ERROR_PROC
 
   if(strcmp(hdr.signalparam[0].label, "trace1          "))  JUMP_TO_EXIT_ERROR_PROC
 
@@ -885,7 +894,7 @@ int main(void)
 
   if(annot.onset != 9000000)  JUMP_TO_EXIT_ERROR_PROC
 
-  if(strcmp(annot.duration, "0.1000"))  JUMP_TO_EXIT_ERROR_PROC
+  if(strcmp(annot.duration, "0.100000"))  JUMP_TO_EXIT_ERROR_PROC
 
   if(annot.duration_l != 1000000LL)  JUMP_TO_EXIT_ERROR_PROC
 
@@ -893,6 +902,16 @@ int main(void)
 
   if(edf_get_annotation(hdl, 2, &annot))  JUMP_TO_EXIT_ERROR_PROC
 
+  if(annot.onset != 91234560)  JUMP_TO_EXIT_ERROR_PROC
+
+  if(strcmp(annot.duration, "1.123456"))  JUMP_TO_EXIT_ERROR_PROC
+
+  if(annot.duration_l != 11234560LL)  JUMP_TO_EXIT_ERROR_PROC
+
+  if(strcmp(annot.annotation, "Test 2"))  JUMP_TO_EXIT_ERROR_PROC
+
+  if(edf_get_annotation(hdl, 3, &annot))  JUMP_TO_EXIT_ERROR_PROC
+
   if(annot.onset != 13000000)  JUMP_TO_EXIT_ERROR_PROC
 
   if(strcmp(annot.duration, ""))  JUMP_TO_EXIT_ERROR_PROC
@@ -1581,9 +1600,12 @@ int main(void)
   fseek(fp, 0xad, SEEK_SET);
 
   fputc('.', fp);
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x803, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x815, SEEK_SET);
+#endif
   fwrite("0.12", 4, 1, fp);
 
   fclose(fp);
@@ -1597,9 +1619,12 @@ int main(void)
   fp = fopen("test.edf", "r+b");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x803, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x815, SEEK_SET);
+#endif
   fwrite("0.131", 5, 1, fp);
 
   fclose(fp);
@@ -1613,13 +1638,19 @@ int main(void)
   fp = fopen("test.edf", "r+b");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x803, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x815, SEEK_SET);
+#endif
   fwrite("0.130", 5, 1, fp);
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x802, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x814, SEEK_SET);
+#endif
   fputc('0', fp);
 
   fclose(fp);
@@ -1633,9 +1664,12 @@ int main(void)
   fp = fopen("test.edf", "r+b");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x802, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x814, SEEK_SET);
+#endif
   fputc('-', fp);
 
   fclose(fp);
@@ -1649,13 +1683,19 @@ int main(void)
   fp = fopen("test.edf", "r+b");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x802, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x814, SEEK_SET);
+#endif
   fputc('+', fp);
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x750, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x75e, SEEK_SET);
+#endif
   fputc(0, fp);
 
   fclose(fp);
@@ -1669,9 +1709,12 @@ int main(void)
   fp = fopen("test.edf", "r+b");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x750, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x75e, SEEK_SET);
+#endif
   fputc(0x14, fp);
 
   fputc(1, fp);
@@ -1687,9 +1730,12 @@ int main(void)
   fp = fopen("test.edf", "r+b");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x751, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x75f, SEEK_SET);
+#endif
   fputc(0, fp);
 
   fclose(fp);
@@ -1867,9 +1913,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x7ac, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x7be, SEEK_SET);
+#endif
   if(fread(str, 40, 1, fp) != 1)
   {
     fclose(fp);
@@ -1920,9 +1969,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x7d4, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x7e6, SEEK_SET);
+#endif
   if(fread(str, 46, 1, fp) != 1)
   {
     fclose(fp);
@@ -1961,9 +2013,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x958, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x97c, SEEK_SET);
+#endif
   if(fread(str, 40, 1, fp) != 1)
   {
     fclose(fp);
@@ -2002,9 +2057,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0x980, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0x9a4, SEEK_SET);
+#endif
   if(fread(str, 46, 1, fp) != 1)
   {
     fclose(fp);
@@ -2055,9 +2113,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0xb04, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0xb3a, SEEK_SET);
+#endif
   if(fread(str, 40, 1, fp) != 1)
   {
     fclose(fp);
@@ -2096,9 +2157,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0xb2c, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0xb62, SEEK_SET);
+#endif
   if(fread(str, 46, 1, fp) != 1)
   {
     fclose(fp);
@@ -2149,9 +2213,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0xcb0, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0xcf8, SEEK_SET);
+#endif
   if(fread(str, 40, 1, fp) != 1)
   {
     fclose(fp);
@@ -2190,9 +2257,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0xcd8, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0xd20, SEEK_SET);
+#endif
   if(fread(str, 46, 1, fp) != 1)
   {
     fclose(fp);
@@ -2243,9 +2313,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0xe5c, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0xeb6, SEEK_SET);
+#endif
   if(fread(str, 40, 1, fp) != 1)
   {
     fclose(fp);
@@ -2284,9 +2357,12 @@ int main(void)
   fp = fopen("test.edf", "rb");
 
   if(fp == NULL)  JUMP_TO_EXIT_ERROR_PROC
-
+#if (EDFLIB_ANNOTATION_BYTES == 114)
   fseek(fp, 0xe84, SEEK_SET);
-
+#endif
+#if (EDFLIB_ANNOTATION_BYTES == 120)
+  fseek(fp, 0xede, SEEK_SET);
+#endif
   if(fread(str, 46, 1, fp) != 1)
   {
     fclose(fp);
@@ -2362,7 +2438,7 @@ int main(void)
 
   if(strcmp(hdr.patientcode, "01234"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(strcmp(hdr.gender, "Male"))  JUMP_TO_EXIT_ERROR_PROC
+  if(strcmp(hdr.sex, "Female"))  JUMP_TO_EXIT_ERROR_PROC
 
   if(strcmp(hdr.birthdate, "04 jul 2010"))  JUMP_TO_EXIT_ERROR_PROC
 
@@ -2440,7 +2516,7 @@ int main(void)
 
   if(annot.onset != 6000000)  JUMP_TO_EXIT_ERROR_PROC
 
-  if(strcmp(annot.duration, "0.2000"))  JUMP_TO_EXIT_ERROR_PROC
+  if(strcmp(annot.duration, "0.200000"))  JUMP_TO_EXIT_ERROR_PROC
 
   if(annot.duration_l != 2000000LL)  JUMP_TO_EXIT_ERROR_PROC
 
@@ -3239,7 +3315,7 @@ int main(void)
     }
     else
     {
-     if(edfwrite_annotation_utf8(hdl, l_tmp, -1LL, str_korea))  JUMP_TO_EXIT_ERROR_PROC
+     if(edfwrite_annotation_utf8_hr(hdl, l_tmp * 100LL, -1LL, str_korea))  JUMP_TO_EXIT_ERROR_PROC
     }
   }
 
@@ -3259,7 +3335,7 @@ int main(void)
 
   if(edf_set_patientcode(hdl, "Brv"))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(edf_set_gender(hdl, 1))  JUMP_TO_EXIT_ERROR_PROC
+  if(edf_set_gender(hdl, 1))  JUMP_TO_EXIT_ERROR_PROC  /* DEPRECATED */
 
   if(edf_set_birthdate(hdl, 2005, 7, 4))  JUMP_TO_EXIT_ERROR_PROC
 
@@ -3319,7 +3395,8 @@ int main(void)
 
   if(strncmp(hdr.patientcode, "Bravo", 5))  JUMP_TO_EXIT_ERROR_PROC
 
-  if(strncmp(hdr.gender, "Male", 4))  JUMP_TO_EXIT_ERROR_PROC
+  if(strncmp(hdr.sex, "Male", 4))  JUMP_TO_EXIT_ERROR_PROC
+  if(strncmp(hdr.gender, "Male", 4))  JUMP_TO_EXIT_ERROR_PROC  /* DEPRECATED */
 
   if(strncmp(hdr.birthdate, "04 jul 2005", 11))  JUMP_TO_EXIT_ERROR_PROC
 



View it on GitLab: https://salsa.debian.org/med-team/edflib/-/compare/ba030b79cac879597c1e2212938a653649169b2e...5e3ed9b5d3abf3cda80f2ab3bd7f2478d37ee01a

-- 
View it on GitLab: https://salsa.debian.org/med-team/edflib/-/compare/ba030b79cac879597c1e2212938a653649169b2e...5e3ed9b5d3abf3cda80f2ab3bd7f2478d37ee01a
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20230612/33c1b746/attachment-0001.htm>


More information about the debian-med-commit mailing list