[med-svn] [edflib] 01/07: New upstream version 1.13
Andreas Tille
tille at debian.org
Tue Jan 2 20:56:29 UTC 2018
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository edflib.
commit 6533763c46fd0bc7522dedabba9c48ccec29cd33
Author: Andreas Tille <tille at debian.org>
Date: Tue Jan 2 21:23:51 2018 +0100
New upstream version 1.13
---
Makefile | 2 +-
edflib.c | 1605 +++++++++++++++++++++++++++++++++--------------------
edflib.h | 46 +-
sine_generator.c | 2 +-
sweep_generator.c | 12 +-
test_generator.c | 36 +-
6 files changed, 1065 insertions(+), 638 deletions(-)
diff --git a/Makefile b/Makefile
old mode 100755
new mode 100644
index 4dd8c4c..6368069
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC = gcc
-CFLAGS = -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE
+CFLAGS = -O2 -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE
LDLIBS = -lm
programs = sine_generator sweep_generator test_edflib test_generator
diff --git a/edflib.c b/edflib.c
index 31e65f4..f505e18 100644
--- a/edflib.c
+++ b/edflib.c
@@ -1,7 +1,7 @@
/*
*****************************************************************************
*
-* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
+* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Teunis van Beelen
* All rights reserved.
*
* email: teuniz at gmail.com
@@ -39,7 +39,7 @@
#include "edflib.h"
-#define EDFLIB_VERSION 112
+#define EDFLIB_VERSION 113
#define EDFLIB_MAXFILES 64
@@ -78,9 +78,12 @@
/* max size of annotationtext */
#define EDFLIB_WRITE_MAX_ANNOTATION_LEN 40
-/* bytes in datarecord for EDF annotations, must be a multiple of three and two */
+/* bytes in datarecord for EDF annotations, must be an integer multiple of three and two */
#define EDFLIB_ANNOTATION_BYTES 114
+/* for writing only */
+#define EDFLIB_MAX_ANNOTATION_CHANNELS 64
+
#define EDFLIB_ANNOT_MEMBLOCKSZ 1000
@@ -147,6 +150,8 @@ struct edfhdrblock{
int annotlist_sz;
int total_annot_bytes;
int eq_sf;
+ char *wrbuf;
+ int wrbufsize;
struct edfparamblock *edfparam;
};
@@ -190,14 +195,14 @@ static int edflib_sprint_int_number_nonlocalized(char *, int, int, int);
static int edflib_sprint_ll_number_nonlocalized(char *, long long, 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 *);
int edflib_is_file_used(const char *path)
{
- int i, file_used=0;
+ int i;
for(i=0; i<EDFLIB_MAXFILES; i++)
{
@@ -205,20 +210,18 @@ int edflib_is_file_used(const char *path)
{
if(!(strcmp(path, hdrlist[i]->path)))
{
- file_used = 1;
-
- break;
+ return 1;
}
}
}
- return(file_used);
+ return 0;
}
int edflib_get_number_of_open_files()
{
- return(edf_files_open);
+ return edf_files_open;
}
@@ -232,12 +235,12 @@ int edflib_get_handle(int file_number)
{
if(file_count++ == file_number)
{
- return(i);
+ return i;
}
}
}
- return(-1);
+ return -1;
}
@@ -256,14 +259,14 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
{
edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
- return(-1);
+ return -1;
}
if(read_annotations>2)
{
edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
- return(-1);
+ return -1;
}
memset(edfhdr, 0, sizeof(struct edf_hdr_struct));
@@ -272,7 +275,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
{
edfhdr->filetype = EDFLIB_MAXFILES_REACHED;
- return(-1);
+ return -1;
}
for(i=0; i<EDFLIB_MAXFILES; i++)
@@ -283,7 +286,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
{
edfhdr->filetype = EDFLIB_FILE_ALREADY_OPENED;
- return(-1);
+ return -1;
}
}
}
@@ -293,7 +296,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
{
edfhdr->filetype = EDFLIB_NO_SUCH_FILE_OR_DIRECTORY;
- return(-1);
+ return -1;
}
hdr = edflib_check_edf_file(file, &edf_error);
@@ -303,7 +306,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
fclose(file);
- return(-1);
+ return -1;
}
if(hdr->discontinuous)
@@ -315,7 +318,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
fclose(file);
- return(-1);
+ return -1;
}
hdr->writemode = 0;
@@ -409,9 +412,14 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
fclose(file);
free(hdr->edfparam);
+ hdr->edfparam = NULL;
free(hdr);
+ hdr = NULL;
+ hdrlist[edfhdr->handle] = NULL;
+ free(annotationslist[edfhdr->handle]);
+ annotationslist[edfhdr->handle] = NULL;
- return(-1);
+ return -1;
}
}
@@ -448,7 +456,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
edfhdr->signalparam[i].smp_in_datarecord = hdr->edfparam[channel].smp_per_record;
}
- return(0);
+ return 0;
}
@@ -456,7 +464,7 @@ int edfclose_file(int handle)
{
struct edf_write_annotationblock *annot2;
- int i, j, k, n, p,
+ int i, j, k, n, p, err,
datrecsize,
nmemb;
@@ -470,17 +478,17 @@ int edfclose_file(int handle)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -489,9 +497,26 @@ int edfclose_file(int handle)
{
if(hdr->datarecords == 0LL)
{
- if(edflib_write_edf_header(hdr))
+ err = edflib_write_edf_header(hdr);
+ if(err)
{
- return(-1);
+ fclose(hdr->file_hdl);
+
+ free(hdr->edfparam);
+
+ free(hdr->wrbuf);
+
+ free(hdr);
+
+ hdrlist[handle] = NULL;
+
+ free(write_annotationslist[handle]);
+
+ write_annotationslist[handle] = NULL;
+
+ edf_files_open--;
+
+ return err;
}
for(k=0; k<hdr->annots_in_file; k++)
@@ -650,13 +675,15 @@ int edfclose_file(int handle)
free(hdr->edfparam);
+ free(hdr->wrbuf);
+
free(hdr);
hdrlist[handle] = NULL;
edf_files_open--;
- return(0);
+ return 0;
}
@@ -669,32 +696,32 @@ long long edfseek(int handle, int edfsignal, long long offset, int whence)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->writemode)
{
- return(-1);
+ return -1;
}
if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
{
- return(-1);
+ return -1;
}
channel = hdrlist[handle]->mapped_signals[edfsignal];
@@ -727,7 +754,7 @@ long long edfseek(int handle, int edfsignal, long long offset, int whence)
hdrlist[handle]->edfparam[channel].sample_pntr = 0LL;
}
- return(hdrlist[handle]->edfparam[channel].sample_pntr);
+ return hdrlist[handle]->edfparam[channel].sample_pntr;
}
@@ -738,37 +765,37 @@ long long edftell(int handle, int edfsignal)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->writemode)
{
- return(-1);
+ return -1;
}
if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
{
- return(-1);
+ return -1;
}
channel = hdrlist[handle]->mapped_signals[edfsignal];
- return(hdrlist[handle]->edfparam[channel].sample_pntr);
+ return hdrlist[handle]->edfparam[channel].sample_pntr;
}
@@ -844,44 +871,44 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->writemode)
{
- return(-1);
+ return -1;
}
if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
{
- return(-1);
+ return -1;
}
channel = hdrlist[handle]->mapped_signals[edfsignal];
if(n<0LL)
{
- return(-1);
+ return -1;
}
if(n==0LL)
{
- return(0LL);
+ return 0LL;
}
hdr = hdrlist[handle];
@@ -904,12 +931,12 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
if(n==0)
{
- return(0LL);
+ return 0LL;
}
if(n<0)
{
- return(-1);
+ return -1;
}
}
@@ -948,7 +975,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
tmp = fgetc(file);
if(tmp==EOF)
{
- return(-1);
+ return -1;
}
var.four[1] = tmp;
@@ -975,7 +1002,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
tmp = fgetc(file);
if(tmp==EOF)
{
- return(-1);
+ return -1;
}
var.four[2] = tmp;
@@ -996,7 +1023,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
hdr->edfparam[channel].sample_pntr = sample_pntr;
- return(n);
+ return n;
}
@@ -1028,44 +1055,44 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->writemode)
{
- return(-1);
+ return -1;
}
if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
{
- return(-1);
+ return -1;
}
channel = hdrlist[handle]->mapped_signals[edfsignal];
if(n<0LL)
{
- return(-1);
+ return -1;
}
if(n==0LL)
{
- return(0LL);
+ return 0LL;
}
hdr = hdrlist[handle];
@@ -1088,12 +1115,12 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
if(n==0)
{
- return(0LL);
+ return 0LL;
}
if(n<0)
{
- return(-1);
+ return -1;
}
}
@@ -1128,7 +1155,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
tmp = fgetc(file);
if(tmp==EOF)
{
- return(-1);
+ return -1;
}
var.four[1] = tmp;
@@ -1155,7 +1182,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
tmp = fgetc(file);
if(tmp==EOF)
{
- return(-1);
+ return -1;
}
var.four[2] = tmp;
@@ -1176,7 +1203,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
hdr->edfparam[channel].sample_pntr = sample_pntr;
- return(n);
+ return n;
}
@@ -1186,39 +1213,39 @@ int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->writemode)
{
- return(-1);
+ return -1;
}
if(n<0)
{
- return(-1);
+ return -1;
}
if(n>=hdrlist[handle]->annots_in_file)
{
- return(-1);
+ return -1;
}
annot->onset = (annotationslist[handle] + n)->onset;
strcpy(annot->duration, (annotationslist[handle] + n)->duration);
strcpy(annot->annotation, (annotationslist[handle] + n)->annotation);
- return(0);
+ return 0;
}
@@ -1240,7 +1267,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
if(edf_hdr==NULL)
{
*edf_error = EDFLIB_MALLOC_ERROR;
- return(NULL);
+ return NULL;
}
edfhdr = (struct edfhdrblock *)calloc(1, sizeof(struct edfhdrblock));
@@ -1248,7 +1275,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
{
free(edf_hdr);
*edf_error = EDFLIB_MALLOC_ERROR;
- return(NULL);
+ return NULL;
}
rewind(inputfile);
@@ -1257,7 +1284,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_READ_ERROR;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
/**************************** VERSION ***************************************/
@@ -1274,7 +1301,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1283,7 +1310,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->bdf = 1;
@@ -1297,7 +1324,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1306,7 +1333,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->edf = 1;
@@ -1327,7 +1354,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1345,7 +1372,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1363,7 +1390,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1384,7 +1411,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
scratchpad[2] = 0;
@@ -1398,7 +1425,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if((edflib_atof_nonlocalized(scratchpad+3)<1)||(edflib_atof_nonlocalized(scratchpad+3)>12))
@@ -1408,7 +1435,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->startdate_day = edflib_atof_nonlocalized(scratchpad);
@@ -1434,7 +1461,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1457,7 +1484,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
scratchpad[2] = 0;
@@ -1471,7 +1498,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if(edflib_atof_nonlocalized(scratchpad+3)>59)
@@ -1481,7 +1508,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if(edflib_atof_nonlocalized(scratchpad+6)>59)
@@ -1491,7 +1518,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->starttime_hour = edflib_atof_nonlocalized(scratchpad);
@@ -1515,7 +1542,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1524,7 +1551,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->edfsignals = edflib_atof_nonlocalized(scratchpad);
if(edfhdr->edfsignals<1)
@@ -1532,7 +1559,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if(edfhdr->edfsignals>EDFLIB_MAXSIGNALS)
@@ -1540,7 +1567,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
/***************** NUMBER OF BYTES IN HEADER *******************************/
@@ -1555,7 +1582,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1564,7 +1591,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
n = edflib_atof_nonlocalized(scratchpad);
@@ -1573,7 +1600,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
/********************* RESERVED FIELD *************************************/
@@ -1590,7 +1617,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1637,7 +1664,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1646,7 +1673,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->datarecords = edflib_atof_nonlocalized(scratchpad);
@@ -1655,7 +1682,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
/********************* DATARECORD DURATION *************************************/
@@ -1670,7 +1697,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1679,7 +1706,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->data_record_duration = edflib_atof_nonlocalized(scratchpad);
@@ -1688,7 +1715,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->long_data_record_duration = edflib_get_long_duration(scratchpad);
@@ -1702,7 +1729,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
{
*edf_error = EDFLIB_MALLOC_ERROR;
free(edfhdr);
- return(NULL);
+ return NULL;
}
rewind(inputfile);
@@ -1711,7 +1738,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_FILE_READ_ERROR;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->edfparam = (struct edfparamblock *)calloc(1, sizeof(struct edfparamblock) * edfhdr->edfsignals);
@@ -1720,7 +1747,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
*edf_error = EDFLIB_MALLOC_ERROR;
free(edf_hdr);
free(edfhdr);
- return(NULL);
+ return NULL;
}
/**************************** LABELS *************************************/
@@ -1737,7 +1764,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
if(edfhdr->edfplus)
@@ -1767,7 +1794,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if(edfhdr->bdfplus&&(!edfhdr->nr_annot_chns))
{
@@ -1775,7 +1802,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if((edfhdr->edfsignals!=edfhdr->nr_annot_chns)||((!edfhdr->edfplus)&&(!edfhdr->bdfplus)))
{
@@ -1785,7 +1812,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1802,7 +1829,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
strncpy(edfhdr->edfparam[i].transducer, edf_hdr + 256 + (edfhdr->edfsignals * 16) + (i * 80), 80);
@@ -1820,7 +1847,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
}
@@ -1840,7 +1867,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
strncpy(edfhdr->edfparam[i].physdimension, edf_hdr + 256 + (edfhdr->edfsignals * 96) + (i * 8), 8);
@@ -1862,7 +1889,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1872,7 +1899,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->edfparam[i].phys_min = edflib_atof_nonlocalized(scratchpad);
@@ -1893,7 +1920,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1903,7 +1930,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->edfparam[i].phys_max = edflib_atof_nonlocalized(scratchpad);
@@ -1913,7 +1940,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1932,7 +1959,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -1942,7 +1969,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
n = edflib_atof_nonlocalized(scratchpad);
@@ -1956,7 +1983,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
}
@@ -1970,7 +1997,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
}
@@ -1982,7 +2009,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
if(edfhdr->bdf)
@@ -1993,7 +2020,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
edfhdr->edfparam[i].dig_min = n;
@@ -2014,7 +2041,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -2024,7 +2051,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
n = edflib_atof_nonlocalized(scratchpad);
@@ -2038,7 +2065,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
}
@@ -2052,7 +2079,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
}
@@ -2064,7 +2091,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
else
@@ -2075,7 +2102,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
edfhdr->edfparam[i].dig_max = n;
@@ -2085,7 +2112,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -2102,7 +2129,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
strncpy(edfhdr->edfparam[i].prefilter, edf_hdr + 256 + (edfhdr->edfsignals * 136) + (i * 80), 80);
@@ -2120,7 +2147,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
}
@@ -2144,7 +2171,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -2154,7 +2181,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
n = edflib_atof_nonlocalized(scratchpad);
@@ -2164,7 +2191,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->edfparam[i].smp_per_record = n;
edfhdr->recordsize += n;
@@ -2174,26 +2201,26 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
{
edfhdr->recordsize *= 3;
- if(edfhdr->recordsize > 15728640)
+ if(edfhdr->recordsize > (15 * 1024 * 1024))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
else
{
edfhdr->recordsize *= 2;
- if(edfhdr->recordsize > 10485760)
+ if(edfhdr->recordsize > (10 * 1024 * 1024))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -2210,7 +2237,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
strncpy(edfhdr->edfparam[i].reserved, edf_hdr + 256 + (edfhdr->edfsignals * 224) + (i * 32), 32);
@@ -2285,7 +2312,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
p = 0;
@@ -2447,7 +2474,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
if(edf_hdr[98]!='X')
@@ -2468,7 +2495,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
edfhdr->startdate_year = edflib_atof_nonlocalized(scratchpad2 + 7);
@@ -2479,7 +2506,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
}
@@ -2579,7 +2606,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
free(edfhdr->edfparam);
free(edfhdr);
- return(NULL);
+ return NULL;
}
n = 0;
@@ -2598,7 +2625,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edf_hdr);
- return(edfhdr);
+ return edfhdr;
}
@@ -2610,7 +2637,7 @@ static int edflib_is_integer_number(char *str)
l = strlen(str);
- if(!l) return(1);
+ if(!l) return 1;
if((str[0]=='+')||(str[0]=='-'))
{
@@ -2624,7 +2651,7 @@ static int edflib_is_integer_number(char *str)
{
if(!digit)
{
- return(1);
+ return 1;
}
hasspace++;
}
@@ -2632,21 +2659,21 @@ static int edflib_is_integer_number(char *str)
{
if((str[i]<48)||(str[i]>57))
{
- return(1);
+ return 1;
}
else
{
if(hasspace)
{
- return(1);
+ return 1;
}
digit++;
}
}
}
- if(digit) return(0);
- else return(1);
+ if(digit) return 0;
+ else return 1;
}
@@ -2657,7 +2684,7 @@ static int edflib_is_number(char *str)
l = strlen(str);
- if(!l) return(1);
+ if(!l) return 1;
if((str[0]=='+')||(str[0]=='-'))
{
@@ -2671,7 +2698,7 @@ static int edflib_is_number(char *str)
{
if((!digit)||hasexp)
{
- return(1);
+ return 1;
}
hasexp++;
hassign = 0;
@@ -2684,7 +2711,7 @@ static int edflib_is_number(char *str)
{
if(!digit)
{
- return(1);
+ return 1;
}
hasspace++;
}
@@ -2692,17 +2719,17 @@ static int edflib_is_number(char *str)
{
if(((str[i]<48)||(str[i]>57))&&str[i]!='.')
{
- return(1);
+ return 1;
}
else
{
if(hasspace)
{
- return(1);
+ return 1;
}
if(str[i]=='.')
{
- if(hasdot) return(1);
+ if(hasdot) return 1;
hasdot++;
}
else
@@ -2717,7 +2744,7 @@ static int edflib_is_number(char *str)
{
if(++i==l)
{
- return(1);
+ return 1;
}
if((str[i]=='+')||(str[i]=='-'))
@@ -2732,7 +2759,7 @@ static int edflib_is_number(char *str)
{
if(!digit)
{
- return(1);
+ return 1;
}
hasspace++;
}
@@ -2740,13 +2767,13 @@ static int edflib_is_number(char *str)
{
if((str[i]<48)||(str[i]>57))
{
- return(1);
+ return 1;
}
else
{
if(hasspace)
{
- return(1);
+ return 1;
}
digit++;
@@ -2755,8 +2782,8 @@ static int edflib_is_number(char *str)
}
}
- if(digit) return(0);
- else return(1);
+ if(digit) return 0;
+ else return 1;
}
@@ -2824,13 +2851,13 @@ static long long edflib_get_long_duration(char *str)
}
}
- return(value);
+ return value;
}
int edflib_version(void)
{
- return(EDFLIB_VERSION);
+ return EDFLIB_VERSION;
}
@@ -2893,7 +2920,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
cnv_buf = (char *)calloc(1, recordsize);
if(cnv_buf==NULL)
{
- return(1);
+ return 1;
}
max_tal_ln = 0;
@@ -2909,7 +2936,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
if(scratchpad==NULL)
{
free(cnv_buf);
- return(1);
+ return 1;
}
time_in_txt = (char *)calloc(1, max_tal_ln + 3);
@@ -2917,7 +2944,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
{
free(cnv_buf);
free(scratchpad);
- return(1);
+ return 1;
}
duration_in_txt = (char *)calloc(1, max_tal_ln + 3);
@@ -2926,7 +2953,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
free(cnv_buf);
free(scratchpad);
free(time_in_txt);
- return(1);
+ return 1;
}
if(fseeko(inputfile, (long long)((edfsignals + 1) * 256), SEEK_SET))
@@ -2935,7 +2962,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
free(scratchpad);
free(time_in_txt);
free(duration_in_txt);
- return(2);
+ return 2;
}
elapsedtime = 0;
@@ -2948,7 +2975,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
free(scratchpad);
free(time_in_txt);
free(duration_in_txt);
- return(2);
+ return 2;
}
@@ -3102,7 +3129,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
free(scratchpad);
free(time_in_txt);
free(duration_in_txt);
- return(-1);
+ return -1;
}
annotationslist[hdl] = malloc_list;
@@ -3201,7 +3228,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
free(scratchpad);
free(time_in_txt);
free(duration_in_txt);
- return(9);
+ return 9;
}
}
}
@@ -3211,7 +3238,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
free(time_in_txt);
free(duration_in_txt);
- return(0);
+ return 0;
}
@@ -3221,24 +3248,24 @@ static int edflib_is_duration_number(char *str)
l = strlen(str);
- if(!l) return(1);
+ if(!l) return 1;
- if((str[0] == '.')||(str[l-1] == '.')) return(1);
+ if((str[0] == '.')||(str[l-1] == '.')) return 1;
for(i=0; i<l; i++)
{
if(str[i]=='.')
{
- if(hasdot) return(1);
+ if(hasdot) return 1;
hasdot++;
}
else
{
- if((str[i]<48)||(str[i]>57)) return(1);
+ if((str[i]<48)||(str[i]>57)) return 1;
}
}
- return(0);
+ return 0;
}
@@ -3249,37 +3276,45 @@ static int edflib_is_onset_number(char *str)
l = strlen(str);
- if(l<2) return(1);
+ if(l<2) return 1;
- if((str[0]!='+')&&(str[0]!='-')) return(1);
+ if((str[0]!='+')&&(str[0]!='-')) return 1;
- if((str[1] == '.')||(str[l-1] == '.')) return(1);
+ if((str[1] == '.')||(str[l-1] == '.')) return 1;
for(i=1; i<l; i++)
{
if(str[i]=='.')
{
- if(hasdot) return(1);
+ if(hasdot) return 1;
hasdot++;
}
else
{
- if((str[i]<48)||(str[i]>57)) return(1);
+ if((str[i]<48)||(str[i]>57)) return 1;
}
}
- return(0);
+ return 0;
}
static long long edflib_get_long_time(char *str)
{
- int i, len, hasdot=0, dotposition=0;
+ int i, len, hasdot=0, dotposition=0, neg=0;
long long value=0, radix;
- str = str + 1;
+ if(str[0] == '+')
+ {
+ str++;
+ }
+ else if(str[0] == '-')
+ {
+ neg = 1;
+ str++;
+ }
len = strlen(str);
@@ -3322,9 +3357,9 @@ static long long edflib_get_long_time(char *str)
}
}
- if(str[-1]=='-') value = -value;
+ if(neg) value = -value;
- return(value);
+ return value;
}
@@ -3602,12 +3637,12 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
if((filetype!=EDFLIB_FILETYPE_EDFPLUS)&&(filetype!=EDFLIB_FILETYPE_BDFPLUS))
{
- return(EDFLIB_FILETYPE_ERROR);
+ return EDFLIB_FILETYPE_ERROR;
}
if(edf_files_open>=EDFLIB_MAXFILES)
{
- return(EDFLIB_MAXFILES_REACHED);
+ return EDFLIB_MAXFILES_REACHED;
}
for(i=0; i<EDFLIB_MAXFILES; i++)
@@ -3616,25 +3651,25 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
{
if(!(strcmp(path, hdrlist[i]->path)))
{
- return(EDFLIB_FILE_ALREADY_OPENED);
+ return EDFLIB_FILE_ALREADY_OPENED;
}
}
}
if(number_of_signals<0)
{
- return(EDFLIB_NUMBER_OF_SIGNALS_INVALID);
+ return EDFLIB_NUMBER_OF_SIGNALS_INVALID;
}
if(number_of_signals>EDFLIB_MAXSIGNALS)
{
- return(EDFLIB_NUMBER_OF_SIGNALS_INVALID);
+ return EDFLIB_NUMBER_OF_SIGNALS_INVALID;
}
hdr = (struct edfhdrblock *)calloc(1, sizeof(struct edfhdrblock));
if(hdr==NULL)
{
- return(EDFLIB_MALLOC_ERROR);
+ return EDFLIB_MALLOC_ERROR;
}
hdr->edfparam = (struct edfparamblock *)calloc(1, sizeof(struct edfparamblock) * number_of_signals);
@@ -3642,7 +3677,7 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
{
free(hdr);
- return(EDFLIB_MALLOC_ERROR);
+ return EDFLIB_MALLOC_ERROR;
}
hdr->writemode = 1;
@@ -3669,7 +3704,7 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
free(hdr);
- return(EDFLIB_MAXFILES_REACHED);
+ return EDFLIB_MAXFILES_REACHED;
}
write_annotationslist[handle] = NULL;
@@ -3682,10 +3717,12 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
if(file==NULL)
{
free(hdr->edfparam);
-
+ hdr->edfparam = NULL;
free(hdr);
+ hdr = NULL;
+ hdrlist[handle] = NULL;
- return(EDFLIB_NO_SUCH_FILE_OR_DIRECTORY);
+ return EDFLIB_NO_SUCH_FILE_OR_DIRECTORY;
}
hdr->file_hdl = file;
@@ -3712,7 +3749,7 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
hdr->nr_annot_chns = 1;
- return(handle);
+ return handle;
}
@@ -3720,47 +3757,47 @@ int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(samplefrequency<1)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
hdrlist[handle]->edfparam[edfsignal].smp_per_record = samplefrequency;
- return(0);
+ return 0;
}
@@ -3768,37 +3805,37 @@ int edf_set_number_of_annotation_signals(int handle, int annot_signals)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
- if((annot_signals < 1) || (annot_signals > 64))
+ if((annot_signals < 1) || (annot_signals > EDFLIB_MAX_ANNOTATION_CHANNELS))
{
- return(-1);
+ return -1;
}
hdrlist[handle]->nr_annot_chns = annot_signals;
- return(0);
+ return 0;
}
@@ -3806,32 +3843,32 @@ int edf_set_datarecord_duration(int handle, int duration)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
if((duration < 100) || (duration > 6000000))
{
- return(-1);
+ return -1;
}
hdrlist[handle]->long_data_record_duration = (long long)duration * 100LL;
@@ -3851,13 +3888,53 @@ int edf_set_datarecord_duration(int handle, int duration)
hdrlist[handle]->data_record_duration = ((double)(hdrlist[handle]->long_data_record_duration)) / EDFLIB_TIME_DIMENSION;
- return(0);
+ return 0;
+}
+
+
+int edf_set_micro_datarecord_duration(int handle, int duration)
+{
+ if(handle<0)
+ {
+ return -1;
+ }
+
+ if(handle>=EDFLIB_MAXFILES)
+ {
+ return -1;
+ }
+
+ if(hdrlist[handle]==NULL)
+ {
+ return -1;
+ }
+
+ if(!(hdrlist[handle]->writemode))
+ {
+ return -1;
+ }
+
+ if(hdrlist[handle]->datarecords)
+ {
+ return -1;
+ }
+
+ if((duration < 1) || (duration > 99))
+ {
+ return -1;
+ }
+
+ hdrlist[handle]->long_data_record_duration = (long long)duration * 10LL;
+
+ hdrlist[handle]->data_record_duration = ((double)(hdrlist[handle]->long_data_record_duration)) / EDFLIB_TIME_DIMENSION;
+
+ return 0;
}
int edfwrite_digital_short_samples(int handle, short *buf)
{
- int i, p,
+ int i,
error,
sf,
digmax,
@@ -3872,32 +3949,32 @@ int edfwrite_digital_short_samples(int handle, short *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->bdf == 1)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -3914,7 +3991,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
if(error)
{
- return(error);
+ return error;
}
}
}
@@ -3925,32 +4002,72 @@ int edfwrite_digital_short_samples(int handle, short *buf)
digmin = hdr->edfparam[edfsignal].dig_min;
- for(i=0; i<sf; i++)
+ if(hdr->edf)
{
- value = buf[i];
-
- if(value>digmax)
+ if((digmax != 32767) || (digmin != -32768))
{
- value = digmax;
+ for(i=0; i<sf; i++)
+ {
+ if(buf[i]>digmax)
+ {
+ buf[i] = digmax;
+ }
+
+ if(buf[i]<digmin)
+ {
+ buf[i] = digmin;
+ }
+ }
}
- if(value<digmin)
+ if(fwrite(buf, sf * 2, 1, file) != 1)
{
- value = digmin;
+ return -1;
}
+ }
+ else // BDF
+ {
+ if(hdr->wrbufsize < (sf * 3))
+ {
+ free(hdr->wrbuf);
- fputc((value)&0xff, file);
+ hdr->wrbufsize = 0;
- if(fputc((value>>8)&0xff, file)==EOF)
- {
- return(-1);
+ hdr->wrbuf = (char *)malloc(sf * 3);
+
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 3;
}
- if(hdr->bdf)
+ for(i=0; i<sf; i++)
{
- fputc((value>>16)&0xff, file);
+ value = buf[i];
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 3] = value & 0xff;
+
+ hdr->wrbuf[i * 3 + 1] = (value >> 8) & 0xff;
+
+ hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
+ {
+ return -1;
+ }
}
hdr->signal_write_sequence_pos++;
@@ -3959,19 +4076,9 @@ int edfwrite_digital_short_samples(int handle, short *buf)
{
hdr->signal_write_sequence_pos = 0;
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
- {
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
+ if(edflib_write_tal(hdr, file))
{
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
@@ -3979,13 +4086,13 @@ int edfwrite_digital_short_samples(int handle, short *buf)
fflush(file);
}
- return(0);
+ return 0;
}
int edfwrite_digital_samples(int handle, int *buf)
{
- int i, p,
+ int i,
error,
sf,
digmax,
@@ -4000,27 +4107,27 @@ int edfwrite_digital_samples(int handle, int *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -4037,7 +4144,7 @@ int edfwrite_digital_samples(int handle, int *buf)
if(error)
{
- return(error);
+ return error;
}
}
}
@@ -4048,30 +4155,90 @@ int edfwrite_digital_samples(int handle, int *buf)
digmin = hdr->edfparam[edfsignal].dig_min;
- for(i=0; i<sf; i++)
+ if(hdr->edf)
{
- value = buf[i];
+ if(hdr->wrbufsize < (sf * 2))
+ {
+ free(hdr->wrbuf);
- if(value>digmax)
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 2);
+
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 2;
+ }
+
+ for(i=0; i<sf; i++)
{
- value = digmax;
+ value = buf[i];
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 2] = value & 0xff;
+
+ hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(value<digmin)
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
{
- value = digmin;
+ return -1;
}
+ }
+ else // BDF
+ {
+ if(hdr->wrbufsize < (sf * 3))
+ {
+ free(hdr->wrbuf);
+
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 3);
- fputc((value)&0xff, file);
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
- if(fputc((value>>8)&0xff, file)==EOF)
+ hdr->wrbufsize = sf * 3;
+ }
+
+ for(i=0; i<sf; i++)
{
- return(-1);
+ value = buf[i];
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 3] = value & 0xff;
+
+ hdr->wrbuf[i * 3 + 1] = (value >> 8) & 0xff;
+
+ hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(hdr->bdf)
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
{
- fputc((value>>16)&0xff, file);
+ return -1;
}
}
@@ -4081,19 +4248,9 @@ int edfwrite_digital_samples(int handle, int *buf)
{
hdr->signal_write_sequence_pos = 0;
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ if(edflib_write_tal(hdr, file))
{
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
- {
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
@@ -4101,13 +4258,13 @@ int edfwrite_digital_samples(int handle, int *buf)
fflush(file);
}
- return(0);
+ return 0;
}
int edf_blockwrite_digital_samples(int handle, int *buf)
{
- int i, j, p,
+ int i, j,
error,
sf,
digmax,
@@ -4123,32 +4280,32 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->signal_write_sequence_pos)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -4163,7 +4320,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
if(error)
{
- return(error);
+ return error;
}
}
@@ -4177,62 +4334,112 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
digmin = hdr->edfparam[j].dig_min;
- for(i=0; i<sf; i++)
+ if(hdr->edf)
{
- value = buf[i + buf_offset];
+ if(hdr->wrbufsize < (sf * 2))
+ {
+ free(hdr->wrbuf);
- if(value>digmax)
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 2);
+
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 2;
+ }
+
+ for(i=0; i<sf; i++)
{
- value = digmax;
+ value = buf[i + buf_offset];
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 2] = value & 0xff;
+
+ hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(value<digmin)
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
{
- value = digmin;
+ return -1;
}
+ }
+ else // BDF
+ {
+ if(hdr->wrbufsize < (sf * 3))
+ {
+ free(hdr->wrbuf);
+
+ hdr->wrbufsize = 0;
- fputc(value&0xff, file);
+ hdr->wrbuf = (char *)malloc(sf * 3);
- if(fputc((value>>8)&0xff, file)==EOF)
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 3;
+ }
+
+ for(i=0; i<sf; i++)
{
- return(-1);
+ value = buf[i + buf_offset];
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 3] = value & 0xff;
+
+ hdr->wrbuf[i * 3 + 1] = (value >> 8) & 0xff;
+
+ hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(hdr->bdf)
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
{
- fputc((value>>16)&0xff, file);
+ return -1;
}
}
buf_offset += sf;
}
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ if(edflib_write_tal(hdr, file))
{
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
- {
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
fflush(file);
- return(0);
+ return 0;
}
int edf_blockwrite_digital_short_samples(int handle, short *buf)
{
- int i, j, p,
+ int i, j,
error,
sf,
digmax,
@@ -4248,37 +4455,37 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->signal_write_sequence_pos)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->bdf == 1)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -4293,7 +4500,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
if(error)
{
- return(error);
+ return error;
}
}
@@ -4307,62 +4514,93 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
digmin = hdr->edfparam[j].dig_min;
- for(i=0; i<sf; i++)
+ if(hdr->edf)
{
- value = buf[i + buf_offset];
-
- if(value>digmax)
+ if((digmax != 32767) || (digmin != -32768))
{
- value = digmax;
+ for(i=0; i<sf; i++)
+ {
+ if(buf[i + buf_offset] > digmax)
+ {
+ buf[i + buf_offset] = digmax;
+ }
+
+ if(buf[i + buf_offset] < digmin)
+ {
+ buf[i + buf_offset] = digmin;
+ }
+ }
}
- if(value<digmin)
+ if(fwrite(buf + buf_offset, sf * 2, 1, file) != 1)
{
- value = digmin;
+ return -1;
}
+ }
+ else // BDF
+ {
+ if(hdr->wrbufsize < (sf * 3))
+ {
+ free(hdr->wrbuf);
+
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 3);
- fputc(value&0xff, file);
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 3;
+ }
- if(fputc((value>>8)&0xff, file)==EOF)
+ for(i=0; i<sf; i++)
{
- return(-1);
+ value = buf[i + buf_offset];
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 3] = value & 0xff;
+
+ hdr->wrbuf[i * 3 + 1] = (value >> 8) & 0xff;
+
+ hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(hdr->bdf)
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
{
- fputc((value>>16)&0xff, file);
+ return -1;
}
}
buf_offset += sf;
}
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ if(edflib_write_tal(hdr, file))
{
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
- {
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
fflush(file);
- return(0);
+ return 0;
}
int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
{
- int j, p,
+ int j,
error,
edfsignals,
total_samples=0;
@@ -4374,37 +4612,37 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->signal_write_sequence_pos)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->bdf != 1)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -4419,7 +4657,7 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
if(error)
{
- return(error);
+ return error;
}
}
@@ -4430,35 +4668,25 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
if(fwrite(buf, total_samples * 3, 1, file) != 1)
{
- return(-1);
+ return -1;
}
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ if(edflib_write_tal(hdr, file))
{
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
- {
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
fflush(file);
- return(0);
+ return 0;
}
int edfwrite_physical_samples(int handle, double *buf)
{
- int i, p,
+ int i,
error,
sf,
digmax,
@@ -4474,31 +4702,29 @@ int edfwrite_physical_samples(int handle, double *buf)
struct edfhdrblock *hdr;
-
-
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -4515,7 +4741,7 @@ int edfwrite_physical_samples(int handle, double *buf)
if(error)
{
- return(error);
+ return error;
}
}
}
@@ -4530,30 +4756,90 @@ int edfwrite_physical_samples(int handle, double *buf)
phys_offset = hdr->edfparam[edfsignal].offset;
- for(i=0; i<sf; i++)
+ if(hdr->edf)
{
- value = (buf[i] / bitvalue) - phys_offset;
+ if(hdr->wrbufsize < (sf * 2))
+ {
+ free(hdr->wrbuf);
+
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 2);
+
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 2;
+ }
- if(value>digmax)
+ for(i=0; i<sf; i++)
{
- value = digmax;
+ value = (buf[i] / bitvalue) - phys_offset;
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 2] = value & 0xff;
+
+ hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(value<digmin)
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
{
- value = digmin;
+ return -1;
}
+ }
+ else // BDF
+ {
+ if(hdr->wrbufsize < (sf * 3))
+ {
+ free(hdr->wrbuf);
- fputc(value&0xff, file);
+ hdr->wrbufsize = 0;
- if(fputc((value>>8)&0xff, file)==EOF)
+ hdr->wrbuf = (char *)malloc(sf * 3);
+
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 3;
+ }
+
+ for(i=0; i<sf; i++)
{
- return(-1);
+ value = (buf[i] / bitvalue) - phys_offset;
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 3] = value & 0xff;
+
+ hdr->wrbuf[i * 3 + 1] = (value >> 8) & 0xff;
+
+ hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(hdr->bdf)
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
{
- fputc((value>>16)&0xff, file);
+ return -1;
}
}
@@ -4563,19 +4849,9 @@ int edfwrite_physical_samples(int handle, double *buf)
{
hdr->signal_write_sequence_pos = 0;
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ if(edflib_write_tal(hdr, file))
{
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
- {
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
@@ -4583,13 +4859,13 @@ int edfwrite_physical_samples(int handle, double *buf)
fflush(file);
}
- return(0);
+ return 0;
}
int edf_blockwrite_physical_samples(int handle, double *buf)
{
- int i, j, p,
+ int i, j,
error,
sf,
digmax,
@@ -4606,36 +4882,34 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
struct edfhdrblock *hdr;
-
-
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->signal_write_sequence_pos)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edfsignals == 0)
{
- return(-1);
+ return -1;
}
hdr = hdrlist[handle];
@@ -4650,7 +4924,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
if(error)
{
- return(error);
+ return error;
}
}
@@ -4668,56 +4942,106 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
phys_offset = hdr->edfparam[j].offset;
- for(i=0; i<sf; i++)
+ if(hdr->edf)
{
- value = (buf[i + buf_offset] / bitvalue) - phys_offset;
+ if(hdr->wrbufsize < (sf * 2))
+ {
+ free(hdr->wrbuf);
- if(value>digmax)
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 2);
+
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
+
+ hdr->wrbufsize = sf * 2;
+ }
+
+ for(i=0; i<sf; i++)
{
- value = digmax;
+ value = (buf[i + buf_offset] / bitvalue) - phys_offset;
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 2] = value & 0xff;
+
+ hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(value<digmin)
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
{
- value = digmin;
+ return -1;
}
+ }
+ else // BDF
+ {
+ if(hdr->wrbufsize < (sf * 3))
+ {
+ free(hdr->wrbuf);
+
+ hdr->wrbufsize = 0;
+
+ hdr->wrbuf = (char *)malloc(sf * 3);
- fputc(value&0xff, file);
+ if(hdr->wrbuf == NULL)
+ {
+ return -1;
+ }
- if(fputc((value>>8)&0xff, file)==EOF)
+ hdr->wrbufsize = sf * 3;
+ }
+
+ for(i=0; i<sf; i++)
{
- return(-1);
+ value = (buf[i + buf_offset] / bitvalue) - phys_offset;
+
+ if(value>digmax)
+ {
+ value = digmax;
+ }
+
+ if(value<digmin)
+ {
+ value = digmin;
+ }
+
+ hdr->wrbuf[i * 3] = value & 0xff;
+
+ hdr->wrbuf[i * 3 + 1] = (value >> 8) & 0xff;
+
+ hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(hdr->bdf)
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
{
- fputc((value>>16)&0xff, file);
+ return -1;
}
}
buf_offset += sf;
}
- p = edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
- if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ if(edflib_write_tal(hdr, file))
{
- fputc('.', file);
- p++;
- p += edflib_fprint_ll_number_nonlocalized(file, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
- }
- fputc(20, file);
- fputc(20, file);
- p += 2;
- for(; p<hdr->total_annot_bytes; p++)
- {
- fputc(0, file);
+ return -1;
}
hdr->datarecords++;
fflush(file);
- return(0);
+ return 0;
}
@@ -4743,38 +5067,44 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
if(edfsignals<0)
{
- return(-20);
+ return EDFLIB_NO_SIGNALS;
}
if(edfsignals>EDFLIB_MAXSIGNALS)
{
- return(-21);
+ return EDFLIB_TOO_MANY_SIGNALS;
}
hdr->eq_sf = 1;
+ hdr->recordsize = 0;
+
+ hdr->total_annot_bytes = EDFLIB_ANNOTATION_BYTES * hdr->nr_annot_chns;
+
for(i=0; i<edfsignals; i++)
{
if(hdr->edfparam[i].smp_per_record<1)
{
- return(-22);
+ return EDFLIB_NO_SAMPLES_IN_RECORD;
}
if(hdr->edfparam[i].dig_max==hdr->edfparam[i].dig_min)
{
- return(-23);
+ return EDFLIB_DIGMIN_IS_DIGMAX;
}
if(hdr->edfparam[i].dig_max<hdr->edfparam[i].dig_min)
{
- return(-24);
+ return EDFLIB_DIGMAX_LOWER_THAN_DIGMIN;
}
if(hdr->edfparam[i].phys_max==hdr->edfparam[i].phys_min)
{
- return(-25);
+ return EDFLIB_PHYSMIN_IS_PHYSMAX;
}
+ hdr->recordsize += hdr->edfparam[i].smp_per_record;
+
if(i > 0)
{
if(hdr->edfparam[i].smp_per_record != hdr->edfparam[i-1].smp_per_record)
@@ -4784,6 +5114,31 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
}
}
+ if(hdr->edf)
+ {
+ hdr->recordsize *= 2;
+
+ hdr->recordsize += hdr->total_annot_bytes;
+
+ if(hdr->recordsize > (10 * 1024 * 1024)) /* datarecord size should not exceed 10MB for EDF */
+ {
+ return EDFLIB_DATARECORD_SIZE_TOO_BIG;
+ } /* if your application gets hit by this limitation, lower the value for the datarecord duration */
+ /* using the function edf_set_datarecord_duration() */
+ }
+ else
+ {
+ hdr->recordsize *= 3;
+
+ hdr->recordsize += hdr->total_annot_bytes;
+
+ if(hdr->recordsize > (15 * 1024 * 1024)) /* datarecord size should not exceed 15MB for BDF */
+ {
+ return EDFLIB_DATARECORD_SIZE_TOO_BIG;
+ } /* if your application gets hit by this limitation, lower the value for the datarecord duration */
+ /* using the function edf_set_datarecord_duration() */
+ }
+
for(i=0; i<edfsignals; i++)
{
hdr->edfparam[i].bitvalue = (hdr->edfparam[i].phys_max - hdr->edfparam[i].phys_min) / (hdr->edfparam[i].dig_max - hdr->edfparam[i].dig_min);
@@ -5312,9 +5667,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
fputc(' ', file);
}
- hdr->total_annot_bytes = EDFLIB_ANNOTATION_BYTES * hdr->nr_annot_chns;
-
- return(0);
+ return 0;
}
@@ -5322,37 +5675,37 @@ int edf_set_label(int handle, int edfsignal, const char *label)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->edfparam[edfsignal].label, label, 16);
@@ -5361,7 +5714,7 @@ int edf_set_label(int handle, int edfsignal, const char *label)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->edfparam[edfsignal].label);
- return(0);
+ return 0;
}
@@ -5369,37 +5722,37 @@ int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->edfparam[edfsignal].physdimension, phys_dim, 8);
@@ -5408,7 +5761,7 @@ int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->edfparam[edfsignal].physdimension);
- return(0);
+ return 0;
}
@@ -5416,42 +5769,42 @@ int edf_set_physical_maximum(int handle, int edfsignal, double phys_max)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
hdrlist[handle]->edfparam[edfsignal].phys_max = phys_max;
- return(0);
+ return 0;
}
@@ -5459,42 +5812,42 @@ int edf_set_physical_minimum(int handle, int edfsignal, double phys_min)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
hdrlist[handle]->edfparam[edfsignal].phys_min = phys_min;
- return(0);
+ return 0;
}
@@ -5502,57 +5855,57 @@ int edf_set_digital_maximum(int handle, int edfsignal, int dig_max)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edf)
{
if(dig_max > 32767)
{
- return(-1);
+ return -1;
}
}
else
{
if(dig_max > 8388607)
{
- return(-1);
+ return -1;
}
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
hdrlist[handle]->edfparam[edfsignal].dig_max = dig_max;
- return(0);
+ return 0;
}
@@ -5560,57 +5913,57 @@ int edf_set_digital_minimum(int handle, int edfsignal, int dig_min)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->edf)
{
if(dig_min < (-32768))
{
- return(-1);
+ return -1;
}
}
else
{
if(dig_min < (-8388608))
{
- return(-1);
+ return -1;
}
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
hdrlist[handle]->edfparam[edfsignal].dig_min = dig_min;
- return(0);
+ return 0;
}
@@ -5618,27 +5971,27 @@ int edf_set_patientname(int handle, const char *patientname)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_patient_name, patientname, 80);
@@ -5647,7 +6000,7 @@ int edf_set_patientname(int handle, const char *patientname)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_patient_name);
- return(0);
+ return 0;
}
@@ -5655,27 +6008,27 @@ int edf_set_patientcode(int handle, const char *patientcode)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_patientcode, patientcode, 80);
@@ -5684,7 +6037,7 @@ int edf_set_patientcode(int handle, const char *patientcode)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_patientcode);
- return(0);
+ return 0;
}
@@ -5692,32 +6045,32 @@ int edf_set_gender(int handle, int gender)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
if((gender<0)||(gender>1))
{
- return(-1);
+ return -1;
}
if(gender)
@@ -5731,7 +6084,7 @@ int edf_set_gender(int handle, int gender)
hdrlist[handle]->plus_gender[1] = 0;
- return(0);
+ return 0;
}
@@ -5739,41 +6092,41 @@ int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int b
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
if((birthdate_year<1800) || (birthdate_year>3000) ||
(birthdate_month<1) || (birthdate_month>12) ||
(birthdate_day<1) || (birthdate_day>31))
{
- return(-1);
+ return -1;
}
sprintf(hdrlist[handle]->plus_birthdate, "%02i.%02i.%02i%02i", birthdate_day, birthdate_month, birthdate_year / 100, birthdate_year % 100);
hdrlist[handle]->plus_birthdate[10] = 0;
- return(0);
+ return 0;
}
@@ -5781,27 +6134,27 @@ int edf_set_patient_additional(int handle, const char *patient_additional)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_patient_additional, patient_additional, 80);
@@ -5810,7 +6163,7 @@ int edf_set_patient_additional(int handle, const char *patient_additional)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_patient_additional);
- return(0);
+ return 0;
}
@@ -5818,27 +6171,27 @@ int edf_set_admincode(int handle, const char *admincode)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_admincode, admincode, 80);
@@ -5847,7 +6200,7 @@ int edf_set_admincode(int handle, const char *admincode)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_admincode);
- return(0);
+ return 0;
}
@@ -5855,27 +6208,27 @@ int edf_set_technician(int handle, const char *technician)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_technician, technician, 80);
@@ -5884,7 +6237,7 @@ int edf_set_technician(int handle, const char *technician)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_technician);
- return(0);
+ return 0;
}
@@ -5892,27 +6245,27 @@ int edf_set_equipment(int handle, const char *equipment)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_equipment, equipment, 80);
@@ -5921,7 +6274,7 @@ int edf_set_equipment(int handle, const char *equipment)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_equipment);
- return(0);
+ return 0;
}
@@ -5929,27 +6282,27 @@ int edf_set_recording_additional(int handle, const char *recording_additional)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->plus_recording_additional, recording_additional, 80);
@@ -5958,7 +6311,7 @@ int edf_set_recording_additional(int handle, const char *recording_additional)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->plus_recording_additional);
- return(0);
+ return 0;
}
@@ -5967,27 +6320,27 @@ int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, i
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
if((startdate_year<1970) || (startdate_year>3000) ||
@@ -5997,7 +6350,7 @@ int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, i
(starttime_minute<0) || (starttime_minute>59) ||
(starttime_second<0) || (starttime_second>59))
{
- return(-1);
+ return -1;
}
hdrlist[handle]->startdate_year = startdate_year;
@@ -6007,7 +6360,7 @@ int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, i
hdrlist[handle]->starttime_minute = starttime_minute;
hdrlist[handle]->starttime_second = starttime_second;
- return(0);
+ return 0;
}
@@ -6020,27 +6373,27 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(onset<0LL)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz)
@@ -6049,7 +6402,7 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
sizeof(struct edf_write_annotationblock) * (hdrlist[handle]->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
if(malloc_list==NULL)
{
- return(-1);
+ return -1;
}
write_annotationslist[handle] = malloc_list;
@@ -6079,7 +6432,7 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
hdrlist[handle]->annots_in_file++;
- return(0);
+ return 0;
}
@@ -6092,27 +6445,27 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration,
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(onset<0LL)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz)
@@ -6121,7 +6474,7 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration,
sizeof(struct edf_write_annotationblock) * (hdrlist[handle]->annotlist_sz + EDFLIB_ANNOT_MEMBLOCKSZ));
if(malloc_list==NULL)
{
- return(-1);
+ return -1;
}
write_annotationslist[handle] = malloc_list;
@@ -6141,7 +6494,7 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration,
hdrlist[handle]->annots_in_file++;
- return(0);
+ return 0;
}
@@ -6180,37 +6533,37 @@ int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->edfparam[edfsignal].prefilter, prefilter, 80);
@@ -6219,7 +6572,7 @@ int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->edfparam[edfsignal].prefilter);
- return(0);
+ return 0;
}
@@ -6227,37 +6580,37 @@ int edf_set_transducer(int handle, int edfsignal, const char *transducer)
{
if(handle<0)
{
- return(-1);
+ return -1;
}
if(handle>=EDFLIB_MAXFILES)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]==NULL)
{
- return(-1);
+ return -1;
}
if(!(hdrlist[handle]->writemode))
{
- return(-1);
+ return -1;
}
if(edfsignal<0)
{
- return(-1);
+ return -1;
}
if(edfsignal>=hdrlist[handle]->edfsignals)
{
- return(-1);
+ return -1;
}
if(hdrlist[handle]->datarecords)
{
- return(-1);
+ return -1;
}
strncpy(hdrlist[handle]->edfparam[edfsignal].transducer, transducer, 80);
@@ -6266,7 +6619,7 @@ int edf_set_transducer(int handle, int edfsignal, const char *transducer)
edflib_remove_padding_trailing_spaces(hdrlist[handle]->edfparam[edfsignal].transducer);
- return(0);
+ return 0;
}
@@ -6336,7 +6689,7 @@ static int edflib_fprint_int_number_nonlocalized(FILE *file, int q, int minimum,
j++;
}
- return(j);
+ return j;
}
@@ -6408,7 +6761,7 @@ static int edflib_fprint_ll_number_nonlocalized(FILE *file, long long q, int min
j++;
}
- return(j);
+ return j;
}
@@ -6473,7 +6826,7 @@ static int edflib_sprint_int_number_nonlocalized(char *str, int q, int minimum,
str[j] = 0;
- return(j);
+ return j;
}
*/
@@ -6539,7 +6892,7 @@ static int edflib_sprint_ll_number_nonlocalized(char *str, long long q, int mini
str[j] = 0;
- return(j);
+ return j;
}
@@ -6599,7 +6952,7 @@ static int edflib_sprint_number_nonlocalized(char *str, double nr)
{
str[j] = 0;
- return(j);
+ return j;
}
str[j++] = '.';
@@ -6633,7 +6986,7 @@ static int edflib_sprint_number_nonlocalized(char *str, double nr)
}
}
- return(j);
+ return j;
}
@@ -6708,7 +7061,7 @@ static double edflib_atof_nonlocalized(const char *str)
value2 /= i;
}
- return(value + value2);
+ return value + value2;
}
@@ -6748,10 +7101,36 @@ static int edflib_atoi_nonlocalized(const char *str)
value += (str[i] - '0');
}
- return(value * sign);
+ return value * sign;
}
+static int edflib_write_tal(struct edfhdrblock *hdr, FILE *file)
+{
+ int p;
+
+ char str[EDFLIB_ANNOTATION_BYTES * (EDFLIB_MAX_ANNOTATION_CHANNELS + 1)];
+
+ p = edflib_sprint_ll_number_nonlocalized(str, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
+ if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+ {
+ str[p++] = '.';
+ p += edflib_sprint_ll_number_nonlocalized(str + p, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
+ }
+ str[p++] = 20;
+ str[p++] = 20;
+ for(; p<hdr->total_annot_bytes; p++)
+ {
+ str[p] = 0;
+ }
+
+ if(fwrite(str, hdr->total_annot_bytes, 1, file) != 1)
+ {
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/edflib.h b/edflib.h
index 2b28798..2250a53 100644
--- a/edflib.h
+++ b/edflib.h
@@ -1,7 +1,7 @@
/*
*****************************************************************************
*
-* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
+* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Teunis van Beelen
* All rights reserved.
*
* email: teuniz at gmail.com
@@ -63,7 +63,11 @@
#define EDFLIB_FILETYPE_BDFPLUS 3
#define EDFLIB_MALLOC_ERROR -1
#define EDFLIB_NO_SUCH_FILE_OR_DIRECTORY -2
+
+/* when this error occurs, try to open the file with EDFbrowser,
+ it will give you full details about the cause of the error. */
#define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS -3
+
#define EDFLIB_MAXFILES_REACHED -4
#define EDFLIB_FILE_READ_ERROR -5
#define EDFLIB_FILE_ALREADY_OPENED -6
@@ -78,13 +82,14 @@
#define EDFLIB_READ_ANNOTATIONS 1
#define EDFLIB_READ_ALL_ANNOTATIONS 2
-/* the following defines are possible errors returned by edfopen_file_writeonly() */
+/* the following defines are possible errors returned by the first sample write action */
#define EDFLIB_NO_SIGNALS -20
#define EDFLIB_TOO_MANY_SIGNALS -21
#define EDFLIB_NO_SAMPLES_IN_RECORD -22
#define EDFLIB_DIGMIN_IS_DIGMAX -23
#define EDFLIB_DIGMAX_LOWER_THAN_DIGMIN -24
#define EDFLIB_PHYSMIN_IS_PHYSMAX -25
+#define EDFLIB_DATARECORD_SIZE_TOO_BIG -26
@@ -98,6 +103,25 @@ extern "C" {
/* For more info about the EDF and EDF+ format, visit: http://edfplus.info/specs/ */
/* For more info about the BDF and BDF+ format, visit: http://www.teuniz.net/edfbrowser/bdfplus%20format%20description.html */
+/*
+ * note: In EDF, the sensitivity (e.g. uV/bit) and offset are stored using four parameters:
+ * digital maximum and minimum, and physical maximum and minimum.
+ * Here, digital means the raw data coming from a sensor or ADC. Physical means the units like uV.
+ * The sensitivity in units/bit is calculated as follows:
+ *
+ * units per bit = (physical max - physical min) / (digital max - digital min)
+ *
+ * The digital offset is calculated as follows:
+ *
+ * offset = (physical max / units per bit) - digital max
+ *
+ * For a better explanation about the relation between digital data and physical data,
+ * read the document "Coding Schemes Used with Data Converters" (PDF):
+ *
+ * http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sbaa042
+ *
+ */
+
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 */
@@ -371,7 +395,7 @@ int edf_set_transducer(int handle, int edfsignal, const char *transducer);
int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim);
-/* Sets the physical dimension of signal edfsignal. ("uV", "BPM", "mA", "Degr.", etc.) */
+/* 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 recommanded for every signal when you want to write a file */
@@ -600,7 +624,21 @@ int edf_set_datarecord_duration(int handle, int duration);
/* which is not an integer. For example, if you want to use a samplerate of 0.5 Hz, */
/* set the samplefrequency to 5 Hz and the datarecord duration to 10 seconds, */
/* or set the samplefrequency to 1 Hz and the datarecord duration to 2 seconds. */
-/* Do not use this function, except when absolutely necessary! */
+/* Do not use this function if not necessary. */
+
+int edf_set_micro_datarecord_duration(int handle, int duration);
+
+/* Sets the datarecord duration to a very small value. */
+/* ATTENTION: the argument "duration" is expressed in units of 1 microSecond! */
+/* This function is optional, normally you don't need to change the default value. */
+/* The datarecord duration must be in the range 1 to 99 micro-seconds. */
+/* Returns 0 on success, otherwise -1 */
+/* This function is NOT REQUIRED but can be called after opening a */
+/* file in writemode and before the first sample write action. */
+/* This function can be used when you want to use a very high samplerate. */
+/* For example, if you want to use a samplerate of 5 GHz, */
+/* set the samplefrequency to 5000 Hz and the datarecord duration to 1 micro-second. */
+/* Do not use this function if not necessary. */
int edf_set_number_of_annotation_signals(int handle, int annot_signals);
diff --git a/sine_generator.c b/sine_generator.c
index d31c18b..20e00c5 100644
--- a/sine_generator.c
+++ b/sine_generator.c
@@ -44,7 +44,7 @@
-int main(int argc, char *argv[])
+int main(void)
{
int i, j,
hdl,
diff --git a/sweep_generator.c b/sweep_generator.c
index 3d27a14..0ad2477 100644
--- a/sweep_generator.c
+++ b/sweep_generator.c
@@ -51,7 +51,7 @@ void remove_trailing_zeros(char *);
-int main(int argc, char *argv[])
+int main(void)
{
int i, j,
hdl,
@@ -211,6 +211,16 @@ int main(int argc, char *argv[])
freqspan = stopfreq - startfreq;
+ if(linear)
+ {
+ freq = startfreq + (freqspan * ((double)sampleswritten / (double)samples));
+ }
+ else
+ {
+ // freq = expo((((double)sampleswritten / (double)samples)) * log10(stopfreq));
+ freq = expo(((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq));
+ }
+
for(j=0; j<fileduration; j++)
{
for(i=0; i<smp_freq; i++)
diff --git a/test_generator.c b/test_generator.c
index affed86..9041d69 100644
--- a/test_generator.c
+++ b/test_generator.c
@@ -31,21 +31,21 @@
/*
this program generates an EDFplus or BDFplus testfile with the following signals:
- signal label/waveform amplitude f sf
- ---------------------------------------------------
- 1 squarewave 100 uV 0.1Hz 200 Hz
- 2 ramp 100 uV 1 Hz 200 Hz
- 3 pulse 1 100 uV 1 Hz 200 Hz
- 4 pulse 2 100 uV 1 Hz 256 Hz
- 5 pulse 3 100 uV 1 Hz 217 Hz
- 6 noise 100 uV - Hz 200 Hz
- 7 sine 1 Hz 100 uV 1 Hz 200 Hz
- 8 sine 8 Hz 100 uV 8 Hz 200 Hz
- 9 sine 8.1777 Hz 100 uV 8.25 Hz 200 Hz
- 10 sine 8.5 Hz 100 uV 8.5Hz 200 Hz
- 11 sine 15 Hz 100 uV 15 Hz 200 Hz
- 12 sine 17 Hz 100 uV 17 Hz 200 Hz
- 13 sine 50 Hz 100 uV 50 Hz 200 Hz
+ signal label/waveform amplitude f sf
+ ------------------------------------------------------
+ 1 squarewave 100 uV 0.1Hz 200 Hz
+ 2 ramp 100 uV 1 Hz 200 Hz
+ 3 pulse 1 100 uV 1 Hz 200 Hz
+ 4 pulse 2 100 uV 1 Hz 256 Hz
+ 5 pulse 3 100 uV 1 Hz 217 Hz
+ 6 noise 100 uV - Hz 200 Hz
+ 7 sine 1 Hz 100 uV 1 Hz 200 Hz
+ 8 sine 8 Hz + DC 100 uV 8 Hz 200 Hz
+ 9 sine 8.1777 Hz + DC 100 uV 8.25 Hz 200 Hz
+ 10 sine 8.5 Hz 100 uV 8.5Hz 200 Hz
+ 11 sine 15 Hz 100 uV 15 Hz 200 Hz
+ 12 sine 17 Hz 100 uV 17 Hz 200 Hz
+ 13 sine 50 Hz 100 uV 50 Hz 200 Hz
14 DC event 8-bits code 1 V 100 mS/bit 200 Hz
*/
@@ -73,7 +73,7 @@
// #define BDF_FORMAT
-int main(int argc, char *argv[])
+int main(void)
{
int i, j,
hdl,
@@ -323,14 +323,14 @@ int main(int argc, char *argv[])
return(1);
}
- if(edf_set_label(hdl, i++, "sine 8 Hz"))
+ if(edf_set_label(hdl, i++, "sine 8 Hz + DC"))
{
printf("error: edf_set_label()\n");
return(1);
}
- if(edf_set_label(hdl, i++, "sine 8.1777 Hz"))
+ if(edf_set_label(hdl, i++, "sine 8.1777 Hz + DC"))
{
printf("error: edf_set_label()\n");
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/edflib.git
More information about the debian-med-commit
mailing list