Skip to content

Commit 91728a2

Browse files
authored
Merge pull request #252 from holgern/fix_decimal_precision_pminmax
apply patch for decimal precision min/max values
2 parents 3bbcdc0 + b1fa71d commit 91728a2

File tree

2 files changed

+37
-56
lines changed

2 files changed

+37
-56
lines changed

pyedflib/_extensions/c/edflib.c

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,21 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
277277
return -1;
278278
}
279279

280-
if(check_file_size<0)
281-
{
282-
edfhdr->filetype = EDFLIB_INVALID_CHECK_SIZE_VALUE;
280+
if(check_file_size<0)
281+
{
282+
edfhdr->filetype = EDFLIB_INVALID_CHECK_SIZE_VALUE;
283283

284284

285-
return -1;
286-
}
285+
return -1;
286+
}
287287

288-
if(check_file_size>2)
289-
{
290-
edfhdr->filetype = EDFLIB_INVALID_CHECK_SIZE_VALUE;
288+
if(check_file_size>2)
289+
{
290+
edfhdr->filetype = EDFLIB_INVALID_CHECK_SIZE_VALUE;
291291

292292
return -1;
293293
}
294-
294+
295295
memset(edfhdr, 0, sizeof(struct edf_hdr_struct));
296296

297297
if(edf_files_open>=EDFLIB_MAXFILES)
@@ -329,7 +329,7 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
329329
fclose(file);
330330
edflib_repair_file_size(path, hdr);
331331
free(hdr->edfparam);
332-
free(hdr);
332+
free(hdr);
333333
file = fopeno(path, "rb");
334334
hdr = edflib_check_edf_file(file, &edf_error, EDFLIB_CHECK_FILE_SIZE);
335335
}
@@ -2622,7 +2622,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
26222622
edfhdr->hdrsize = edfhdr->edfsignals * 256 + 256;
26232623

26242624
if (check_file_size != EDFLIB_DO_NOT_CHECK_FILE_SIZE)
2625-
{
2625+
{
26262626
fseeko(inputfile, 0LL, SEEK_END);
26272627
if(ftello(inputfile)<(edfhdr->recordsize * edfhdr->datarecords + edfhdr->hdrsize))
26282628
{
@@ -2834,7 +2834,7 @@ static long long edflib_get_long_duration(char *str)
28342834
}
28352835
str[7] = ' ';
28362836
}
2837-
2837+
28382838
for(i=0; i<8; i++)
28392839
{
28402840
if(str[i]==' ')
@@ -3789,24 +3789,24 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
37893789
{
37903790
hdr->edf = 1;
37913791
hdr->edfplus = 1;
3792-
hdr->nr_annot_chns = 1;
3793-
3792+
hdr->nr_annot_chns = 1;
3793+
37943794
}
3795-
3795+
37963796
if(filetype==EDFLIB_FILETYPE_EDF)
37973797
{
37983798
hdr->edf = 1;
37993799
hdr->edfplus = 0;
38003800
hdr->nr_annot_chns = 0;
38013801
}
3802-
3802+
38033803
if(filetype==EDFLIB_FILETYPE_BDFPLUS)
38043804
{
38053805
hdr->bdf = 1;
38063806
hdr->bdfplus = 1;
3807-
hdr->nr_annot_chns = 1;
3807+
hdr->nr_annot_chns = 1;
38083808
}
3809-
3809+
38103810
if(filetype==EDFLIB_FILETYPE_BDF)
38113811
{
38123812
hdr->bdf = 1;
@@ -5198,24 +5198,24 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
51985198
{
51995199
return EDFLIB_NO_SAMPLES_IN_RECORD ;
52005200
}
5201-
5201+
52025202
if(hdr->edfparam[i].dig_max==hdr->edfparam[i].dig_min)
52035203
{
52045204
return EDFLIB_DIGMIN_IS_DIGMAX;
52055205
}
5206-
5206+
52075207
if(hdr->edfparam[i].dig_max<hdr->edfparam[i].dig_min)
52085208
{
52095209
return EDFLIB_DIGMAX_LOWER_THAN_DIGMIN;
52105210
}
5211-
5211+
52125212
if(hdr->edfparam[i].phys_max==hdr->edfparam[i].phys_min)
52135213
{
52145214
return EDFLIB_PHYSMIN_IS_PHYSMAX;
52155215
}
5216-
5216+
52175217
hdr->recordsize += hdr->edfparam[i].smp_per_record;
5218-
5218+
52195219
}
52205220
if(i > 0)
52215221
{
@@ -5225,7 +5225,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
52255225
}
52265226
}
52275227
}
5228-
5228+
52295229

52305230
if(hdr->edf)
52315231
{
@@ -5827,7 +5827,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
58275827
{
58285828
fputc(' ', file);
58295829
}
5830-
5830+
58315831
return 0;
58325832
}
58335833

@@ -7090,6 +7090,15 @@ static int edflib_snprint_number_nonlocalized(char *dest, double val, int sz)
70907090

70917091
if(sz < 1) return 0;
70927092

7093+
if(val < 0.0)
7094+
{
7095+
val -= 1e-12;
7096+
}
7097+
else
7098+
{
7099+
val += 1e-12;
7100+
}
7101+
70937102
q = (int)val;
70947103

70957104
var = val - q;
@@ -7100,7 +7109,7 @@ static int edflib_snprint_number_nonlocalized(char *dest, double val, int sz)
71007109

71017110
if(q < 0)
71027111
{
7103-
q = -q;
7112+
base = -base;
71047113
}
71057114
}
71067115

@@ -7154,7 +7163,7 @@ static int edflib_snprint_number_nonlocalized(char *dest, double val, int sz)
71547163

71557164
if(q < 0)
71567165
{
7157-
q = -q;
7166+
base = -base;
71587167
}
71597168

71607169
if(!q)
@@ -7447,31 +7456,3 @@ static int edflib_strlcat(char *dst, const char *src, int sz)
74477456

74487457
return (dstlen + srclen);
74497458
}
7450-
7451-
7452-
7453-
7454-
7455-
7456-
7457-
7458-
7459-
7460-
7461-
7462-
7463-
7464-
7465-
7466-
7467-
7468-
7469-
7470-
7471-
7472-
7473-
7474-
7475-
7476-
7477-

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
MAJOR = 0
2424
MINOR = 1
25-
MICRO = 36
25+
MICRO = 37
2626
ISRELEASED = True
2727
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
2828

0 commit comments

Comments
 (0)