Imported Upstream version 1.12
Fabian Klötzl
6 years ago
0 | CC = gcc | |
1 | CFLAGS = -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE | |
2 | LDLIBS = -lm | |
3 | ||
4 | programs = sine_generator sweep_generator test_edflib test_generator | |
5 | ||
6 | all: $(programs) | |
7 | ||
8 | $(programs): edflib.o | |
9 | ||
10 | clean: | |
11 | $(RM) *.o $(programs) *.[be]df |
0 | # EDFlib | |
1 | ||
2 | EDFlib is a programming library for C/C++ for reading and writing EDF+ and BDF+ files. | |
3 | It also reads "old style" EDF and BDF files. | |
4 | EDF means European Data Format. BDF is the 24-bits version of EDF. | |
5 | ||
6 | ||
7 | ## Usage | |
8 | ||
9 | The library consists of only two files: `edflib.h` and `edflib.c`. | |
10 | ||
11 | In order to use EDFlib, copy these two files to your project. | |
12 | Include the file `edflib.h` in every source file from where you want to access the library. | |
13 | ||
14 | Don't forget to tell your compiler that it must compile and link `edflib.c` (add it to | |
15 | your makefile or buildscript). `edflib.c` needs to be compiled with the options | |
16 | `-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE`. | |
17 | ||
18 | For example: | |
19 | ||
20 | `gcc -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE test_edflib.c edflib.c -lm -o test_edflib` | |
21 | ||
22 | Compilation has been tested using GCC on Linux, Mingw-w64 on Windows, and LLVM GCC on OS X (Yosemite). | |
23 | ||
24 | To understand how to use the library, read the comments in `edflib.h`. | |
25 | ||
26 | ||
27 | ## Examples | |
28 | ||
29 | To build the examples: `make` | |
30 | ||
31 | Each "generator" example creates an EDF+ or BDF+ file with sample signals. | |
32 | ||
33 | `test_generator` shows how to use most of the functions provided by the library and generates an | |
34 | EDF+ or BDF+ testfile with several sample signals. | |
35 | ||
36 | `sine_generator` creates a BDF+ file containing the signal "sine", a 1 Hz sinoidal waveform with a | |
37 | sample frequency of 2048 Hz. | |
38 | ||
39 | `sweep_generator` creates a linear or logarithmic sweep through a range of frequencies in EDF+ or | |
40 | BDF+ format. | |
41 | ||
42 | Use EDFbrowser to view these files: http://www.teuniz.net/edfbrowser/ | |
43 | ||
44 | `test_edflib <filename> <signalnumber>` will print the properties of the EDF/BDF header, the | |
45 | annotations, and the values of 200 samples of the chosen signal. For example, running | |
46 | `test_generator` will produce the file `test_generator.edf`. Running `test_edflib test_generator.edf 6` | |
47 | will show the header and first 200 samples of the "noise" signal: | |
48 | `75 6 27 77 37 30 35 96 62 69 34 15 51 56 69 68 80 45 ...` | |
49 | ||
50 | ||
51 | ## License | |
52 | ||
53 | Copyright (c) 2009, 2010, 2011, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen | |
54 | All rights reserved. | |
55 | ||
56 | email: teuniz@gmail.com | |
57 | ||
58 | Redistribution and use in source and binary forms, with or without | |
59 | modification, are permitted provided that the following conditions are met: | |
60 | * Redistributions of source code must retain the above copyright | |
61 | notice, this list of conditions and the following disclaimer. | |
62 | * Redistributions in binary form must reproduce the above copyright | |
63 | notice, this list of conditions and the following disclaimer in the | |
64 | documentation and/or other materials provided with the distribution. | |
65 | ||
66 | THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
67 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
68 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
69 | DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
70 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
71 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
72 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
73 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
74 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
75 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
0 | ||
1 | Copyright (c) 2009, 2010, 2011, 2013, 2014, 2015 Teunis van Beelen | |
2 | All rights reserved. | |
3 | ||
4 | email: teuniz@gmail.com | |
5 | ||
6 | Redistribution and use in source and binary forms, with or without | |
7 | modification, are permitted provided that the following conditions are met: | |
8 | * Redistributions of source code must retain the above copyright | |
9 | notice, this list of conditions and the following disclaimer. | |
10 | * Redistributions in binary form must reproduce the above copyright | |
11 | notice, this list of conditions and the following disclaimer in the | |
12 | documentation and/or other materials provided with the distribution. | |
13 | ||
14 | THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
15 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
17 | DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
18 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | ||
25 | ||
26 | ||
27 | ||
28 | EDFlib is a programming library for C/C++ for reading and writing EDF+ and BDF+ files. | |
29 | It also reads "old style" EDF and BDF files. | |
30 | EDF means European Data Format. BDF is the 24-bits version of EDF. | |
31 | ||
32 | The library consists of only two files: edflib.h and edflib.c. | |
33 | The file main.c can be used to compile a program that demonstrates the working and | |
34 | capabilities of the library. Use it as follows: | |
35 | ||
36 | test_edflib <filename> <signalnumber> | |
37 | ||
38 | The program will print the properties of the EDF/BDF-header, the annotations and | |
39 | the values of 200 samples of the chosen signal. | |
40 | ||
41 | The file sine.c is another programming example. It will create a BDF+ file containing | |
42 | the signal "sine", a 1 Hz sinoidal waveform with a samplefrequency of 2048 Hz. | |
43 | ||
44 | The file test_generator.c shows how to use most of the functions provided by the library. | |
45 | ||
46 | To view the results use EDFbrowser: http://www.teuniz.net/edfbrowser/ | |
47 | ||
48 | ||
49 | In order to use this library in your project, copy the files edf.h and edf.c to | |
50 | your project. Include the file edflib.h in every sourcefile from where you want | |
51 | to access the library. Don't forget to tell your compiler that it must compile | |
52 | and link edflib.c (add it to your makefile or buildscript). | |
53 | edflib.c needs to be compiled with the options "-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE". | |
54 | ||
55 | For example: | |
56 | ||
57 | gcc main.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -o test_edflib | |
58 | ||
59 | gcc sine.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -lm -o sine | |
60 | ||
61 | gcc test_generator.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -lm -o testgenerator | |
62 | ||
63 | gcc sweep.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -lm -o sweep | |
64 | ||
65 | ||
66 | To understand how to use the library, read the comments in the file edflib.h. | |
67 | ||
68 | The library has been tested using the GCC compiler on Linux and Mingw-w64 on windows. | |
69 | ||
70 | ||
71 |
0 | #!/bin/sh | |
1 | # | |
2 | gcc main.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -o test_edflib | |
3 | # | |
4 | gcc sine.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -lm -o sine | |
5 | # | |
6 | gcc test_generator.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -lm -o testgenerator | |
7 | # | |
8 | gcc sweep.c edflib.c -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -Wtype-limits -g -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -lm -o sweep | |
9 | # |
0 | 0 | /* |
1 | 1 | ***************************************************************************** |
2 | 2 | * |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen | |
4 | 4 | * All rights reserved. |
5 | 5 | * |
6 | 6 | * email: teuniz@gmail.com |
38 | 38 | #include "edflib.h" |
39 | 39 | |
40 | 40 | |
41 | #define EDFLIB_VERSION 111 | |
41 | #define EDFLIB_VERSION 112 | |
42 | 42 | #define EDFLIB_MAXFILES 64 |
43 | 43 | |
44 | 44 | |
2764 | 2764 | int i, len=8, hasdot=0, dotposition=0; |
2765 | 2765 | |
2766 | 2766 | long long value=0, radix; |
2767 | ||
2768 | if((str[0] == '+') || (str[0] == '-')) | |
2769 | { | |
2770 | for(i=0; i<7; i++) | |
2771 | { | |
2772 | str[i] = str[i+1]; | |
2773 | } | |
2774 | ||
2775 | str[7] = ' '; | |
2776 | } | |
2767 | 2777 | |
2768 | 2778 | for(i=0; i<8; i++) |
2769 | 2779 | { |
4521 | 4531 | |
4522 | 4532 | for(i=0; i<sf; i++) |
4523 | 4533 | { |
4524 | value = buf[i] / bitvalue; | |
4525 | ||
4526 | value -= phys_offset; | |
4534 | value = (buf[i] / bitvalue) - phys_offset; | |
4527 | 4535 | |
4528 | 4536 | if(value>digmax) |
4529 | 4537 | { |
4661 | 4669 | |
4662 | 4670 | for(i=0; i<sf; i++) |
4663 | 4671 | { |
4664 | value = buf[i + buf_offset] / bitvalue; | |
4665 | ||
4666 | value -= phys_offset; | |
4672 | value = (buf[i + buf_offset] / bitvalue) - phys_offset; | |
4667 | 4673 | |
4668 | 4674 | if(value>digmax) |
4669 | 4675 | { |
0 | 0 | /* |
1 | 1 | ***************************************************************************** |
2 | 2 | * |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen | |
4 | 4 | * All rights reserved. |
5 | 5 | * |
6 | 6 | * email: teuniz@gmail.com |
0 | /* | |
1 | ***************************************************************************** | |
2 | * | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
4 | * All rights reserved. | |
5 | * | |
6 | * email: teuniz@gmail.com | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | * | |
27 | ***************************************************************************** | |
28 | */ | |
29 | ||
30 | ||
31 | ||
32 | ||
33 | ||
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | ||
37 | #include "edflib.h" | |
38 | ||
39 | ||
40 | ||
41 | ||
42 | ||
43 | ||
44 | int main(int argc, char *argv[]) | |
45 | { | |
46 | int i, | |
47 | hdl, | |
48 | channel, | |
49 | n; | |
50 | ||
51 | double *buf; | |
52 | ||
53 | struct edf_hdr_struct hdr; | |
54 | ||
55 | ||
56 | if(argc!=3) | |
57 | { | |
58 | printf("\nusage: test_edflib <file> <signal nr>\n\n"); | |
59 | return(1); | |
60 | } | |
61 | ||
62 | channel = atoi(argv[2]); | |
63 | if(channel<1) | |
64 | { | |
65 | printf("\nsignalnumber must be > 0\n\n"); | |
66 | return(1); | |
67 | } | |
68 | ||
69 | if(edfopen_file_readonly(argv[1], &hdr, EDFLIB_READ_ALL_ANNOTATIONS)) | |
70 | { | |
71 | switch(hdr.filetype) | |
72 | { | |
73 | case EDFLIB_MALLOC_ERROR : printf("\nmalloc error\n\n"); | |
74 | break; | |
75 | case EDFLIB_NO_SUCH_FILE_OR_DIRECTORY : printf("\ncan not open file, no such file or directory\n\n"); | |
76 | break; | |
77 | case EDFLIB_FILE_CONTAINS_FORMAT_ERRORS : printf("\nthe file is not EDF(+) or BDF(+) compliant\n" | |
78 | "(it contains format errors)\n\n"); | |
79 | break; | |
80 | case EDFLIB_MAXFILES_REACHED : printf("\nto many files opened\n\n"); | |
81 | break; | |
82 | case EDFLIB_FILE_READ_ERROR : printf("\na read error occurred\n\n"); | |
83 | break; | |
84 | case EDFLIB_FILE_ALREADY_OPENED : printf("\nfile has already been opened\n\n"); | |
85 | break; | |
86 | default : printf("\nunknown error\n\n"); | |
87 | break; | |
88 | } | |
89 | ||
90 | return(1); | |
91 | } | |
92 | ||
93 | hdl = hdr.handle; | |
94 | ||
95 | if(channel>(hdr.edfsignals)) | |
96 | { | |
97 | printf("\nerror: file has %i signals and you selected signal %i\n\n", hdr.edfsignals, channel); | |
98 | edfclose_file(hdl); | |
99 | return(1); | |
100 | } | |
101 | ||
102 | channel--; | |
103 | ||
104 | printf("\nlibrary version: %i.%02i\n", edflib_version() / 100, edflib_version() % 100); | |
105 | ||
106 | printf("\ngeneral header:\n\n"); | |
107 | ||
108 | printf("filetype: %i\n", hdr.filetype); | |
109 | printf("edfsignals: %i\n", hdr.edfsignals); | |
110 | #ifdef WIN32 | |
111 | printf("file duration: %I64d seconds\n", hdr.file_duration / EDFLIB_TIME_DIMENSION); | |
112 | #else | |
113 | printf("file duration: %lli seconds\n", hdr.file_duration / EDFLIB_TIME_DIMENSION); | |
114 | #endif | |
115 | printf("startdate: %i-%i-%i\n", hdr.startdate_day, hdr.startdate_month, hdr.startdate_year); | |
116 | printf("starttime: %i:%02i:%02i\n", hdr.starttime_hour, hdr.starttime_minute, hdr.starttime_second); | |
117 | printf("patient: %s\n", hdr.patient); | |
118 | printf("recording: %s\n", hdr.recording); | |
119 | printf("patientcode: %s\n", hdr.patientcode); | |
120 | printf("gender: %s\n", hdr.gender); | |
121 | printf("birthdate: %s\n", hdr.birthdate); | |
122 | printf("patient_name: %s\n", hdr.patient_name); | |
123 | printf("patient_additional: %s\n", hdr.patient_additional); | |
124 | printf("admincode: %s\n", hdr.admincode); | |
125 | printf("technician: %s\n", hdr.technician); | |
126 | printf("equipment: %s\n", hdr.equipment); | |
127 | printf("recording_additional: %s\n", hdr.recording_additional); | |
128 | printf("datarecord duration: %f seconds\n", ((double)hdr.datarecord_duration) / EDFLIB_TIME_DIMENSION); | |
129 | #ifdef WIN32 | |
130 | printf("number of datarecords in the file: %I64d\n", hdr.datarecords_in_file); | |
131 | printf("number of annotations in the file: %I64d\n", hdr.annotations_in_file); | |
132 | #else | |
133 | printf("number of datarecords in the file: %lli\n", hdr.datarecords_in_file); | |
134 | printf("number of annotations in the file: %lli\n", hdr.annotations_in_file); | |
135 | #endif | |
136 | ||
137 | printf("\nsignal parameters:\n\n"); | |
138 | ||
139 | printf("label: %s\n", hdr.signalparam[channel].label); | |
140 | #ifdef WIN32 | |
141 | printf("samples in file: %I64d\n", hdr.signalparam[channel].smp_in_file); | |
142 | #else | |
143 | printf("samples in file: %lli\n", hdr.signalparam[channel].smp_in_file); | |
144 | #endif | |
145 | printf("samples in datarecord: %i\n", hdr.signalparam[channel].smp_in_datarecord); | |
146 | printf("physical maximum: %f\n", hdr.signalparam[channel].phys_max); | |
147 | printf("physical minimum: %f\n", hdr.signalparam[channel].phys_min); | |
148 | printf("digital maximum: %i\n", hdr.signalparam[channel].dig_max); | |
149 | printf("digital minimum: %i\n", hdr.signalparam[channel].dig_min); | |
150 | printf("physical dimension: %s\n", hdr.signalparam[channel].physdimension); | |
151 | printf("prefilter: %s\n", hdr.signalparam[channel].prefilter); | |
152 | printf("transducer: %s\n", hdr.signalparam[channel].transducer); | |
153 | printf("samplefrequency: %f\n", ((double)hdr.signalparam[channel].smp_in_datarecord / (double)hdr.datarecord_duration) * EDFLIB_TIME_DIMENSION); | |
154 | ||
155 | struct edf_annotation_struct annot; | |
156 | ||
157 | printf("\n"); | |
158 | ||
159 | for(i=0; i<hdr.annotations_in_file; i++) | |
160 | { | |
161 | if(edf_get_annotation(hdl, i, &annot)) | |
162 | { | |
163 | printf("\nerror: edf_get_annotations()\n"); | |
164 | edfclose_file(hdl); | |
165 | return(1); | |
166 | } | |
167 | else | |
168 | { | |
169 | #ifdef WIN32 | |
170 | printf("annotation: onset is %I64d duration is %s description is %s\n", | |
171 | annot.onset / EDFLIB_TIME_DIMENSION, | |
172 | annot.duration, | |
173 | annot.annotation); | |
174 | #else | |
175 | printf("annotation: onset is %lli duration is %s description is %s\n", | |
176 | annot.onset / EDFLIB_TIME_DIMENSION, | |
177 | annot.duration, | |
178 | annot.annotation); | |
179 | #endif | |
180 | } | |
181 | } | |
182 | ||
183 | n = 200; /* read n samples from the file */ | |
184 | ||
185 | buf = (double *)malloc(sizeof(double[n])); | |
186 | if(buf==NULL) | |
187 | { | |
188 | printf("\nmalloc error\n"); | |
189 | edfclose_file(hdl); | |
190 | return(1); | |
191 | } | |
192 | ||
193 | int x=10; /* start reading x seconds from start of file */ | |
194 | ||
195 | edfseek(hdl, channel, (long long)((((double)x) / ((double)hdr.file_duration / (double)EDFLIB_TIME_DIMENSION)) * ((double)hdr.signalparam[channel].smp_in_file)), EDFSEEK_SET); | |
196 | ||
197 | n = edfread_physical_samples(hdl, channel, n, buf); | |
198 | ||
199 | if(n==(-1)) | |
200 | { | |
201 | printf("\nerror: edf_read_physical_samples()\n"); | |
202 | edfclose_file(hdl); | |
203 | free(buf); | |
204 | return(1); | |
205 | } | |
206 | ||
207 | printf("\nread %i samples, started at %i seconds from start of file:\n\n", n, x); | |
208 | ||
209 | for(i=0; i<n; i++) | |
210 | { | |
211 | printf("%.0f ", buf[i]); | |
212 | } | |
213 | ||
214 | printf("\n\n"); | |
215 | ||
216 | edfclose_file(hdl); | |
217 | ||
218 | free(buf); | |
219 | ||
220 | return(0); | |
221 | } | |
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | ||
230 | ||
231 | ||
232 | ||
233 | ||
234 | ||
235 | ||
236 | ||
237 | ||
238 | ||
239 | ||
240 | ||
241 | ||
242 | ||
243 | ||
244 | ||
245 | ||
246 | ||
247 | ||
248 | ||
249 | ||
250 |
0 | /* | |
1 | ***************************************************************************** | |
2 | * | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
4 | * All rights reserved. | |
5 | * | |
6 | * email: teuniz@gmail.com | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | * | |
27 | ***************************************************************************** | |
28 | */ | |
29 | ||
30 | ||
31 | ||
32 | ||
33 | ||
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | #include <math.h> | |
37 | ||
38 | #include "edflib.h" | |
39 | ||
40 | ||
41 | #define SMP_FREQ 2048 | |
42 | ||
43 | ||
44 | ||
45 | ||
46 | int main(int argc, char *argv[]) | |
47 | { | |
48 | int i, j, | |
49 | hdl, | |
50 | buf2[SMP_FREQ], | |
51 | chns; | |
52 | ||
53 | double buf[SMP_FREQ], | |
54 | q; | |
55 | ||
56 | ||
57 | ||
58 | chns = 2; | |
59 | ||
60 | hdl = edfopen_file_writeonly("sine.bdf", EDFLIB_FILETYPE_BDFPLUS, chns); | |
61 | ||
62 | if(hdl<0) | |
63 | { | |
64 | printf("error: edfopen_file_writeonly()\n"); | |
65 | ||
66 | return(1); | |
67 | } | |
68 | ||
69 | for(i=0; i<chns; i++) | |
70 | { | |
71 | if(edf_set_samplefrequency(hdl, i, SMP_FREQ)) | |
72 | { | |
73 | printf("error: edf_set_samplefrequency()\n"); | |
74 | ||
75 | return(1); | |
76 | } | |
77 | } | |
78 | ||
79 | for(i=0; i<chns; i++) | |
80 | { | |
81 | if(edf_set_physical_maximum(hdl, i, 3000.0)) | |
82 | { | |
83 | printf("error: edf_set_physical_maximum()\n"); | |
84 | ||
85 | return(1); | |
86 | } | |
87 | } | |
88 | ||
89 | for(i=0; i<chns; i++) | |
90 | { | |
91 | if(edf_set_digital_maximum(hdl, i, 8388607)) | |
92 | { | |
93 | printf("error: edf_set_digital_maximum()\n"); | |
94 | ||
95 | return(1); | |
96 | } | |
97 | } | |
98 | ||
99 | for(i=0; i<chns; i++) | |
100 | { | |
101 | if(edf_set_digital_minimum(hdl, i, -8388608)) | |
102 | { | |
103 | printf("error: edf_set_digital_minimum()\n"); | |
104 | ||
105 | return(1); | |
106 | } | |
107 | } | |
108 | ||
109 | for(i=0; i<chns; i++) | |
110 | { | |
111 | if(edf_set_physical_minimum(hdl, i, -3000.0)) | |
112 | { | |
113 | printf("error: edf_set_physical_minimum()\n"); | |
114 | ||
115 | return(1); | |
116 | } | |
117 | } | |
118 | ||
119 | if(edf_set_label(hdl, 0, "sine")) | |
120 | { | |
121 | printf("error: edf_set_label()\n"); | |
122 | ||
123 | return(1); | |
124 | } | |
125 | ||
126 | if(edf_set_label(hdl, 1, "ramp")) | |
127 | { | |
128 | printf("error: edf_set_label()\n"); | |
129 | ||
130 | return(1); | |
131 | } | |
132 | ||
133 | for(i=0; i<chns; i++) | |
134 | { | |
135 | if(edf_set_physical_dimension(hdl, i, "mV")) | |
136 | { | |
137 | printf("error: edf_set_physical_dimension()\n"); | |
138 | ||
139 | return(1); | |
140 | } | |
141 | } | |
142 | ||
143 | for(j=0; j<10; j++) | |
144 | { | |
145 | for(i=0; i<SMP_FREQ; i++) | |
146 | { | |
147 | q = M_PI * 2.0; | |
148 | q /= SMP_FREQ; | |
149 | q *= i; | |
150 | q = sin(q); | |
151 | q *= 3000.0; | |
152 | buf[i] = q; | |
153 | } | |
154 | ||
155 | if(edfwrite_physical_samples(hdl, buf)) | |
156 | { | |
157 | printf("error: edfwrite_physical_samples()\n"); | |
158 | ||
159 | return(1); | |
160 | } | |
161 | ||
162 | for(i=0; i<SMP_FREQ; i++) | |
163 | { | |
164 | buf[i] = -3000.0 + (i * 2.9296875); | |
165 | } | |
166 | ||
167 | if(edfwrite_physical_samples(hdl, buf)) | |
168 | { | |
169 | printf("error: edfwrite_physical_samples()\n"); | |
170 | ||
171 | return(1); | |
172 | } | |
173 | } | |
174 | ||
175 | for(j=0; j<10; j++) | |
176 | { | |
177 | for(i=0; i<SMP_FREQ; i++) | |
178 | { | |
179 | q = M_PI * 2.0; | |
180 | q /= SMP_FREQ; | |
181 | q *= i; | |
182 | q = sin(q); | |
183 | q *= 8388607.0; | |
184 | buf2[i] = q; | |
185 | } | |
186 | ||
187 | if(edfwrite_digital_samples(hdl, buf2)) | |
188 | { | |
189 | printf("error: edfwrite_digital_samples()\n"); | |
190 | ||
191 | return(1); | |
192 | } | |
193 | ||
194 | for(i=0; i<SMP_FREQ; i++) | |
195 | { | |
196 | buf2[i] = -8388608 + (i * 8192); | |
197 | } | |
198 | ||
199 | if(edfwrite_digital_samples(hdl, buf2)) | |
200 | { | |
201 | printf("error: edfwrite_digital_samples()\n"); | |
202 | ||
203 | return(1); | |
204 | } | |
205 | } | |
206 | ||
207 | edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts"); | |
208 | ||
209 | edfwrite_annotation_latin1(hdl, 200000LL, -1LL, "Recording ends"); | |
210 | ||
211 | edfclose_file(hdl); | |
212 | ||
213 | return(0); | |
214 | } | |
215 | ||
216 | ||
217 | ||
218 | ||
219 | ||
220 | ||
221 | ||
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | ||
230 | ||
231 | ||
232 | ||
233 | ||
234 |
0 | /* | |
1 | ***************************************************************************** | |
2 | * | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
4 | * All rights reserved. | |
5 | * | |
6 | * email: teuniz@gmail.com | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | * | |
27 | ***************************************************************************** | |
28 | */ | |
29 | ||
30 | ||
31 | ||
32 | ||
33 | ||
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | #include <math.h> | |
37 | ||
38 | #include "edflib.h" | |
39 | ||
40 | ||
41 | #define SMP_FREQ 2048 | |
42 | ||
43 | ||
44 | ||
45 | ||
46 | int main(int argc, char *argv[]) | |
47 | { | |
48 | int i, j, | |
49 | hdl, | |
50 | buf2[SMP_FREQ], | |
51 | chns; | |
52 | ||
53 | double buf[SMP_FREQ], | |
54 | q; | |
55 | ||
56 | ||
57 | ||
58 | chns = 2; | |
59 | ||
60 | hdl = edfopen_file_writeonly("sine.bdf", EDFLIB_FILETYPE_BDFPLUS, chns); | |
61 | ||
62 | if(hdl<0) | |
63 | { | |
64 | printf("error: edfopen_file_writeonly()\n"); | |
65 | ||
66 | return(1); | |
67 | } | |
68 | ||
69 | for(i=0; i<chns; i++) | |
70 | { | |
71 | if(edf_set_samplefrequency(hdl, i, SMP_FREQ)) | |
72 | { | |
73 | printf("error: edf_set_samplefrequency()\n"); | |
74 | ||
75 | return(1); | |
76 | } | |
77 | } | |
78 | ||
79 | for(i=0; i<chns; i++) | |
80 | { | |
81 | if(edf_set_physical_maximum(hdl, i, 3000.0)) | |
82 | { | |
83 | printf("error: edf_set_physical_maximum()\n"); | |
84 | ||
85 | return(1); | |
86 | } | |
87 | } | |
88 | ||
89 | for(i=0; i<chns; i++) | |
90 | { | |
91 | if(edf_set_digital_maximum(hdl, i, 8388607)) | |
92 | { | |
93 | printf("error: edf_set_digital_maximum()\n"); | |
94 | ||
95 | return(1); | |
96 | } | |
97 | } | |
98 | ||
99 | for(i=0; i<chns; i++) | |
100 | { | |
101 | if(edf_set_digital_minimum(hdl, i, -8388608)) | |
102 | { | |
103 | printf("error: edf_set_digital_minimum()\n"); | |
104 | ||
105 | return(1); | |
106 | } | |
107 | } | |
108 | ||
109 | for(i=0; i<chns; i++) | |
110 | { | |
111 | if(edf_set_physical_minimum(hdl, i, -3000.0)) | |
112 | { | |
113 | printf("error: edf_set_physical_minimum()\n"); | |
114 | ||
115 | return(1); | |
116 | } | |
117 | } | |
118 | ||
119 | if(edf_set_label(hdl, 0, "sine")) | |
120 | { | |
121 | printf("error: edf_set_label()\n"); | |
122 | ||
123 | return(1); | |
124 | } | |
125 | ||
126 | if(edf_set_label(hdl, 1, "ramp")) | |
127 | { | |
128 | printf("error: edf_set_label()\n"); | |
129 | ||
130 | return(1); | |
131 | } | |
132 | ||
133 | for(i=0; i<chns; i++) | |
134 | { | |
135 | if(edf_set_physical_dimension(hdl, i, "mV")) | |
136 | { | |
137 | printf("error: edf_set_physical_dimension()\n"); | |
138 | ||
139 | return(1); | |
140 | } | |
141 | } | |
142 | ||
143 | for(j=0; j<10; j++) | |
144 | { | |
145 | for(i=0; i<SMP_FREQ; i++) | |
146 | { | |
147 | q = M_PI * 2.0; | |
148 | q /= SMP_FREQ; | |
149 | q *= i; | |
150 | q = sin(q); | |
151 | q *= 3000.0; | |
152 | buf[i] = q; | |
153 | } | |
154 | ||
155 | if(edfwrite_physical_samples(hdl, buf)) | |
156 | { | |
157 | printf("error: edfwrite_physical_samples()\n"); | |
158 | ||
159 | return(1); | |
160 | } | |
161 | ||
162 | for(i=0; i<SMP_FREQ; i++) | |
163 | { | |
164 | buf[i] = -3000.0 + (i * 2.9296875); | |
165 | } | |
166 | ||
167 | if(edfwrite_physical_samples(hdl, buf)) | |
168 | { | |
169 | printf("error: edfwrite_physical_samples()\n"); | |
170 | ||
171 | return(1); | |
172 | } | |
173 | } | |
174 | ||
175 | for(j=0; j<10; j++) | |
176 | { | |
177 | for(i=0; i<SMP_FREQ; i++) | |
178 | { | |
179 | q = M_PI * 2.0; | |
180 | q /= SMP_FREQ; | |
181 | q *= i; | |
182 | q = sin(q); | |
183 | q *= 8388607.0; | |
184 | buf2[i] = q; | |
185 | } | |
186 | ||
187 | if(edfwrite_digital_samples(hdl, buf2)) | |
188 | { | |
189 | printf("error: edfwrite_digital_samples()\n"); | |
190 | ||
191 | return(1); | |
192 | } | |
193 | ||
194 | for(i=0; i<SMP_FREQ; i++) | |
195 | { | |
196 | buf2[i] = -8388608 + (i * 8192); | |
197 | } | |
198 | ||
199 | if(edfwrite_digital_samples(hdl, buf2)) | |
200 | { | |
201 | printf("error: edfwrite_digital_samples()\n"); | |
202 | ||
203 | return(1); | |
204 | } | |
205 | } | |
206 | ||
207 | edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts"); | |
208 | ||
209 | edfwrite_annotation_latin1(hdl, 200000LL, -1LL, "Recording ends"); | |
210 | ||
211 | edfclose_file(hdl); | |
212 | ||
213 | return(0); | |
214 | } | |
215 | ||
216 | ||
217 | ||
218 | ||
219 | ||
220 | ||
221 | ||
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | ||
230 | ||
231 | ||
232 | ||
233 | ||
234 |
0 | /* | |
1 | ***************************************************************************** | |
2 | * | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
4 | * All rights reserved. | |
5 | * | |
6 | * email: teuniz@gmail.com | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | * | |
27 | ***************************************************************************** | |
28 | */ | |
29 | ||
30 | ||
31 | ||
32 | #define _GNU_SOURCE | |
33 | ||
34 | ||
35 | #include <stdio.h> | |
36 | #include <stdlib.h> | |
37 | #include <math.h> | |
38 | ||
39 | #include "edflib.h" | |
40 | ||
41 | ||
42 | ||
43 | ||
44 | /* if you want to create an EDFplus file instead of BDFplus, outcomment the next line: */ | |
45 | //#define BDF_FORMAT | |
46 | ||
47 | ||
48 | ||
49 | void remove_trailing_zeros(char *); | |
50 | ||
51 | ||
52 | ||
53 | int main(int argc, char *argv[]) | |
54 | { | |
55 | int i, j, | |
56 | hdl, | |
57 | chns=1, | |
58 | smp_freq=8192, | |
59 | fileduration=300, | |
60 | linear=1; | |
61 | ||
62 | double buf[smp_freq], | |
63 | q, | |
64 | sine_1, | |
65 | startfreq=10.0, | |
66 | stopfreq=4095.0, | |
67 | freqspan, | |
68 | freq; | |
69 | ||
70 | long long samples, | |
71 | sampleswritten; | |
72 | ||
73 | char str[256]; | |
74 | ||
75 | ||
76 | ||
77 | #ifdef BDF_FORMAT | |
78 | hdl = edfopen_file_writeonly("freq_sweep.bdf", EDFLIB_FILETYPE_BDFPLUS, chns); | |
79 | #else | |
80 | hdl = edfopen_file_writeonly("freq_sweep.edf", EDFLIB_FILETYPE_EDFPLUS, chns); | |
81 | #endif | |
82 | ||
83 | if(hdl<0) | |
84 | { | |
85 | printf("error: edfopen_file_writeonly()\n"); | |
86 | ||
87 | return(1); | |
88 | } | |
89 | ||
90 | for(i=0; i<chns; i++) | |
91 | { | |
92 | if(edf_set_samplefrequency(hdl, i, smp_freq)) | |
93 | { | |
94 | printf("error: edf_set_samplefrequency()\n"); | |
95 | ||
96 | return(1); | |
97 | } | |
98 | } | |
99 | ||
100 | #ifdef BDF_FORMAT | |
101 | for(i=0; i<chns; i++) | |
102 | { | |
103 | if(edf_set_digital_maximum(hdl, i, 8388607)) | |
104 | { | |
105 | printf("error: edf_set_digital_maximum()\n"); | |
106 | ||
107 | return(1); | |
108 | } | |
109 | } | |
110 | ||
111 | for(i=0; i<chns; i++) | |
112 | { | |
113 | if(edf_set_digital_minimum(hdl, i, -8388608)) | |
114 | { | |
115 | printf("error: edf_set_digital_minimum()\n"); | |
116 | ||
117 | return(1); | |
118 | } | |
119 | } | |
120 | #else | |
121 | for(i=0; i<chns; i++) | |
122 | { | |
123 | if(edf_set_digital_maximum(hdl, i, 32767)) | |
124 | { | |
125 | printf("error: edf_set_digital_maximum()\n"); | |
126 | ||
127 | return(1); | |
128 | } | |
129 | } | |
130 | ||
131 | for(i=0; i<chns; i++) | |
132 | { | |
133 | if(edf_set_digital_minimum(hdl, i, -32768)) | |
134 | { | |
135 | printf("error: edf_set_digital_minimum()\n"); | |
136 | ||
137 | return(1); | |
138 | } | |
139 | } | |
140 | #endif | |
141 | ||
142 | for(i=0; i<chns; i++) | |
143 | { | |
144 | if(edf_set_physical_maximum(hdl, i, 400.0)) | |
145 | { | |
146 | printf("error: edf_set_physical_maximum()\n"); | |
147 | ||
148 | return(1); | |
149 | } | |
150 | } | |
151 | ||
152 | for(i=0; i<chns; i++) | |
153 | { | |
154 | if(edf_set_physical_minimum(hdl, i, -400.0)) | |
155 | { | |
156 | printf("error: edf_set_physical_minimum()\n"); | |
157 | ||
158 | return(1); | |
159 | } | |
160 | } | |
161 | ||
162 | for(i=0; i<chns; i++) | |
163 | { | |
164 | if(edf_set_physical_dimension(hdl, i, "uV")) | |
165 | { | |
166 | printf("error: edf_set_physical_dimension()\n"); | |
167 | ||
168 | return(1); | |
169 | } | |
170 | } | |
171 | ||
172 | if(edf_set_label(hdl, 0, "sweep")) | |
173 | { | |
174 | printf("error: edf_set_label()\n"); | |
175 | ||
176 | return(1); | |
177 | } | |
178 | ||
179 | if(edf_set_equipment(hdl, "Software generated file")) | |
180 | { | |
181 | printf("edf_set_equipment()\n"); | |
182 | ||
183 | return(1); | |
184 | } | |
185 | ||
186 | if(linear) | |
187 | { | |
188 | sprintf(str, "Linear frequency sweep from %fHz to %fHz", startfreq, stopfreq); | |
189 | } | |
190 | else | |
191 | { | |
192 | sprintf(str, "Logarithmic frequency sweep from %fHz to %fHz", startfreq, stopfreq); | |
193 | } | |
194 | remove_trailing_zeros(str); | |
195 | edf_set_patientname(hdl, str); | |
196 | ||
197 | edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts"); | |
198 | ||
199 | sine_1 = 0.0; | |
200 | ||
201 | sampleswritten = 0; | |
202 | ||
203 | samples = fileduration * (long long)smp_freq; | |
204 | ||
205 | freqspan = stopfreq - startfreq; | |
206 | ||
207 | for(j=0; j<fileduration; j++) | |
208 | { | |
209 | for(i=0; i<smp_freq; i++) | |
210 | { | |
211 | q = M_PI * 2.0; | |
212 | q /= (smp_freq / freq); | |
213 | sine_1 += q; | |
214 | q = sin(sine_1); | |
215 | q *= 200.0; | |
216 | buf[i] = q; | |
217 | if(linear) | |
218 | { | |
219 | freq = startfreq + (freqspan * ((double)sampleswritten / (double)samples)); | |
220 | } | |
221 | else | |
222 | { | |
223 | // freq = exp10((((double)sampleswritten / (double)samples)) * log10(stopfreq)); | |
224 | freq = exp10(((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq)); | |
225 | } | |
226 | sampleswritten++; | |
227 | } | |
228 | ||
229 | if(edfwrite_physical_samples(hdl, buf)) | |
230 | { | |
231 | printf("error: edfwrite_physical_samples()\n"); | |
232 | ||
233 | return(1); | |
234 | } | |
235 | ||
236 | if(!(j%10)) | |
237 | { | |
238 | sprintf(str, "%fHz", freq); | |
239 | remove_trailing_zeros(str); | |
240 | edfwrite_annotation_latin1(hdl, j * 10000LL, -1LL, str); | |
241 | } | |
242 | } | |
243 | ||
244 | sprintf(str, "%fHz", freq); | |
245 | remove_trailing_zeros(str); | |
246 | edfwrite_annotation_latin1(hdl, j * 10000LL, -1LL, str); | |
247 | ||
248 | edfwrite_annotation_latin1(hdl, fileduration * 10000LL, -1LL, "Recording ends"); | |
249 | ||
250 | edfclose_file(hdl); | |
251 | ||
252 | return(0); | |
253 | } | |
254 | ||
255 | ||
256 | ||
257 | void remove_trailing_zeros(char *str) | |
258 | { | |
259 | int i, j, | |
260 | len, | |
261 | numberfound, | |
262 | dotfound, | |
263 | decimalzerofound, | |
264 | trailingzerofound=1; | |
265 | ||
266 | while(trailingzerofound) | |
267 | { | |
268 | numberfound = 0; | |
269 | dotfound = 0; | |
270 | decimalzerofound = 0; | |
271 | trailingzerofound = 0; | |
272 | ||
273 | len = strlen(str); | |
274 | ||
275 | for(i=0; i<len; i++) | |
276 | { | |
277 | if((str[i] < '0') || (str[i] > '9')) | |
278 | { | |
279 | if(decimalzerofound) | |
280 | { | |
281 | if(str[i-decimalzerofound-1] == '.') | |
282 | { | |
283 | decimalzerofound++; | |
284 | } | |
285 | ||
286 | for(j=i; j<(len+1); j++) | |
287 | { | |
288 | str[j-decimalzerofound] = str[j]; | |
289 | } | |
290 | ||
291 | trailingzerofound = 1; | |
292 | ||
293 | break; | |
294 | } | |
295 | ||
296 | if(str[i] != '.') | |
297 | { | |
298 | numberfound = 0; | |
299 | dotfound = 0; | |
300 | decimalzerofound = 0; | |
301 | } | |
302 | } | |
303 | else | |
304 | { | |
305 | numberfound = 1; | |
306 | ||
307 | if(str[i] > '0') | |
308 | { | |
309 | decimalzerofound = 0; | |
310 | } | |
311 | } | |
312 | ||
313 | if((str[i] == '.') && numberfound) | |
314 | { | |
315 | dotfound = 1; | |
316 | } | |
317 | ||
318 | if((str[i] == '0') && dotfound) | |
319 | { | |
320 | decimalzerofound++; | |
321 | } | |
322 | } | |
323 | } | |
324 | ||
325 | if(decimalzerofound) | |
326 | { | |
327 | if(str[i-decimalzerofound-1] == '.') | |
328 | { | |
329 | decimalzerofound++; | |
330 | } | |
331 | ||
332 | for(j=i; j<(len+1); j++) | |
333 | { | |
334 | str[j-decimalzerofound] = str[j]; | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
339 | ||
340 | ||
341 | ||
342 | ||
343 | ||
344 | ||
345 | ||
346 | ||
347 | ||
348 | ||
349 | ||
350 | ||
351 | ||
352 | ||
353 | ||
354 |
0 | /* | |
1 | ***************************************************************************** | |
2 | * | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
4 | * All rights reserved. | |
5 | * | |
6 | * email: teuniz@gmail.com | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | * | |
27 | ***************************************************************************** | |
28 | */ | |
29 | ||
30 | ||
31 | ||
32 | #define _GNU_SOURCE | |
33 | ||
34 | ||
35 | #include <stdio.h> | |
36 | #include <stdlib.h> | |
37 | #include <math.h> | |
38 | ||
39 | #include "edflib.h" | |
40 | ||
41 | ||
42 | ||
43 | ||
44 | // Uncomment the next line to create a BSF+ file instead of EDF+: | |
45 | //#define BDF_FORMAT | |
46 | ||
47 | ||
48 | ||
49 | void remove_trailing_zeros(char *); | |
50 | ||
51 | ||
52 | ||
53 | int main(int argc, char *argv[]) | |
54 | { | |
55 | int i, j, | |
56 | hdl, | |
57 | chns=1, | |
58 | smp_freq=8192, | |
59 | fileduration=300, | |
60 | linear=0; | |
61 | ||
62 | double buf[smp_freq], | |
63 | q, | |
64 | sine_1, | |
65 | startfreq=10.0, | |
66 | stopfreq=4095.0, | |
67 | freqspan, | |
68 | freq; | |
69 | ||
70 | long long samples, | |
71 | sampleswritten; | |
72 | ||
73 | char str[256]; | |
74 | ||
75 | ||
76 | #if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__) | |
77 | #define expo __exp10 | |
78 | #else | |
79 | #define expo exp10 | |
80 | #endif | |
81 | ||
82 | ||
83 | #ifdef BDF_FORMAT | |
84 | hdl = edfopen_file_writeonly("freq_sweep.bdf", EDFLIB_FILETYPE_BDFPLUS, chns); | |
85 | #else | |
86 | hdl = edfopen_file_writeonly("freq_sweep.edf", EDFLIB_FILETYPE_EDFPLUS, chns); | |
87 | #endif | |
88 | ||
89 | if(hdl<0) | |
90 | { | |
91 | printf("error: edfopen_file_writeonly()\n"); | |
92 | ||
93 | return(1); | |
94 | } | |
95 | ||
96 | for(i=0; i<chns; i++) | |
97 | { | |
98 | if(edf_set_samplefrequency(hdl, i, smp_freq)) | |
99 | { | |
100 | printf("error: edf_set_samplefrequency()\n"); | |
101 | ||
102 | return(1); | |
103 | } | |
104 | } | |
105 | ||
106 | #ifdef BDF_FORMAT | |
107 | for(i=0; i<chns; i++) | |
108 | { | |
109 | if(edf_set_digital_maximum(hdl, i, 8388607)) | |
110 | { | |
111 | printf("error: edf_set_digital_maximum()\n"); | |
112 | ||
113 | return(1); | |
114 | } | |
115 | } | |
116 | ||
117 | for(i=0; i<chns; i++) | |
118 | { | |
119 | if(edf_set_digital_minimum(hdl, i, -8388608)) | |
120 | { | |
121 | printf("error: edf_set_digital_minimum()\n"); | |
122 | ||
123 | return(1); | |
124 | } | |
125 | } | |
126 | #else | |
127 | for(i=0; i<chns; i++) | |
128 | { | |
129 | if(edf_set_digital_maximum(hdl, i, 32767)) | |
130 | { | |
131 | printf("error: edf_set_digital_maximum()\n"); | |
132 | ||
133 | return(1); | |
134 | } | |
135 | } | |
136 | ||
137 | for(i=0; i<chns; i++) | |
138 | { | |
139 | if(edf_set_digital_minimum(hdl, i, -32768)) | |
140 | { | |
141 | printf("error: edf_set_digital_minimum()\n"); | |
142 | ||
143 | return(1); | |
144 | } | |
145 | } | |
146 | #endif | |
147 | ||
148 | for(i=0; i<chns; i++) | |
149 | { | |
150 | if(edf_set_physical_maximum(hdl, i, 400.0)) | |
151 | { | |
152 | printf("error: edf_set_physical_maximum()\n"); | |
153 | ||
154 | return(1); | |
155 | } | |
156 | } | |
157 | ||
158 | for(i=0; i<chns; i++) | |
159 | { | |
160 | if(edf_set_physical_minimum(hdl, i, -400.0)) | |
161 | { | |
162 | printf("error: edf_set_physical_minimum()\n"); | |
163 | ||
164 | return(1); | |
165 | } | |
166 | } | |
167 | ||
168 | for(i=0; i<chns; i++) | |
169 | { | |
170 | if(edf_set_physical_dimension(hdl, i, "uV")) | |
171 | { | |
172 | printf("error: edf_set_physical_dimension()\n"); | |
173 | ||
174 | return(1); | |
175 | } | |
176 | } | |
177 | ||
178 | if(edf_set_label(hdl, 0, "sweep")) | |
179 | { | |
180 | printf("error: edf_set_label()\n"); | |
181 | ||
182 | return(1); | |
183 | } | |
184 | ||
185 | if(edf_set_equipment(hdl, "Software generated file")) | |
186 | { | |
187 | printf("edf_set_equipment()\n"); | |
188 | ||
189 | return(1); | |
190 | } | |
191 | ||
192 | if(linear) | |
193 | { | |
194 | sprintf(str, "Linear frequency sweep from %fHz to %fHz", startfreq, stopfreq); | |
195 | } | |
196 | else | |
197 | { | |
198 | sprintf(str, "Logarithmic frequency sweep from %fHz to %fHz", startfreq, stopfreq); | |
199 | } | |
200 | remove_trailing_zeros(str); | |
201 | edf_set_patientname(hdl, str); | |
202 | ||
203 | edfwrite_annotation_latin1(hdl, 0LL, -1LL, "Recording starts"); | |
204 | ||
205 | sine_1 = 0.0; | |
206 | ||
207 | sampleswritten = 0; | |
208 | ||
209 | samples = fileduration * (long long)smp_freq; | |
210 | ||
211 | freqspan = stopfreq - startfreq; | |
212 | ||
213 | for(j=0; j<fileduration; j++) | |
214 | { | |
215 | for(i=0; i<smp_freq; i++) | |
216 | { | |
217 | q = M_PI * 2.0; | |
218 | q /= (smp_freq / freq); | |
219 | sine_1 += q; | |
220 | q = sin(sine_1); | |
221 | q *= 200.0; | |
222 | buf[i] = q; | |
223 | if(linear) | |
224 | { | |
225 | freq = startfreq + (freqspan * ((double)sampleswritten / (double)samples)); | |
226 | } | |
227 | else | |
228 | { | |
229 | // freq = expo((((double)sampleswritten / (double)samples)) * log10(stopfreq)); | |
230 | freq = expo(((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq)); | |
231 | } | |
232 | sampleswritten++; | |
233 | } | |
234 | ||
235 | if(edfwrite_physical_samples(hdl, buf)) | |
236 | { | |
237 | printf("error: edfwrite_physical_samples()\n"); | |
238 | ||
239 | return(1); | |
240 | } | |
241 | ||
242 | if(!(j%10)) | |
243 | { | |
244 | sprintf(str, "%fHz", freq); | |
245 | remove_trailing_zeros(str); | |
246 | edfwrite_annotation_latin1(hdl, j * 10000LL, -1LL, str); | |
247 | } | |
248 | } | |
249 | ||
250 | sprintf(str, "%fHz", freq); | |
251 | remove_trailing_zeros(str); | |
252 | edfwrite_annotation_latin1(hdl, j * 10000LL, -1LL, str); | |
253 | ||
254 | edfwrite_annotation_latin1(hdl, fileduration * 10000LL, -1LL, "Recording ends"); | |
255 | ||
256 | edfclose_file(hdl); | |
257 | ||
258 | return(0); | |
259 | } | |
260 | ||
261 | ||
262 | ||
263 | void remove_trailing_zeros(char *str) | |
264 | { | |
265 | int i, j, | |
266 | len, | |
267 | numberfound, | |
268 | dotfound, | |
269 | decimalzerofound, | |
270 | trailingzerofound=1; | |
271 | ||
272 | while(trailingzerofound) | |
273 | { | |
274 | numberfound = 0; | |
275 | dotfound = 0; | |
276 | decimalzerofound = 0; | |
277 | trailingzerofound = 0; | |
278 | ||
279 | len = strlen(str); | |
280 | ||
281 | for(i=0; i<len; i++) | |
282 | { | |
283 | if((str[i] < '0') || (str[i] > '9')) | |
284 | { | |
285 | if(decimalzerofound) | |
286 | { | |
287 | if(str[i-decimalzerofound-1] == '.') | |
288 | { | |
289 | decimalzerofound++; | |
290 | } | |
291 | ||
292 | for(j=i; j<(len+1); j++) | |
293 | { | |
294 | str[j-decimalzerofound] = str[j]; | |
295 | } | |
296 | ||
297 | trailingzerofound = 1; | |
298 | ||
299 | break; | |
300 | } | |
301 | ||
302 | if(str[i] != '.') | |
303 | { | |
304 | numberfound = 0; | |
305 | dotfound = 0; | |
306 | decimalzerofound = 0; | |
307 | } | |
308 | } | |
309 | else | |
310 | { | |
311 | numberfound = 1; | |
312 | ||
313 | if(str[i] > '0') | |
314 | { | |
315 | decimalzerofound = 0; | |
316 | } | |
317 | } | |
318 | ||
319 | if((str[i] == '.') && numberfound) | |
320 | { | |
321 | dotfound = 1; | |
322 | } | |
323 | ||
324 | if((str[i] == '0') && dotfound) | |
325 | { | |
326 | decimalzerofound++; | |
327 | } | |
328 | } | |
329 | } | |
330 | ||
331 | if(decimalzerofound) | |
332 | { | |
333 | if(str[i-decimalzerofound-1] == '.') | |
334 | { | |
335 | decimalzerofound++; | |
336 | } | |
337 | ||
338 | for(j=i; j<(len+1); j++) | |
339 | { | |
340 | str[j-decimalzerofound] = str[j]; | |
341 | } | |
342 | } | |
343 | } |
0 | /* | |
1 | ***************************************************************************** | |
2 | * | |
3 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Teunis van Beelen | |
4 | * All rights reserved. | |
5 | * | |
6 | * email: teuniz@gmail.com | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY | |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | * | |
27 | ***************************************************************************** | |
28 | */ | |
29 | ||
30 | ||
31 | ||
32 | ||
33 | ||
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | ||
37 | #include "edflib.h" | |
38 | ||
39 | ||
40 | ||
41 | ||
42 | ||
43 | ||
44 | int main(int argc, char *argv[]) | |
45 | { | |
46 | int i, | |
47 | hdl, | |
48 | channel, | |
49 | n; | |
50 | ||
51 | double *buf; | |
52 | ||
53 | struct edf_hdr_struct hdr; | |
54 | ||
55 | ||
56 | if(argc!=3) | |
57 | { | |
58 | printf("\nusage: test_edflib <file> <signal nr>\n\n"); | |
59 | return(1); | |
60 | } | |
61 | ||
62 | channel = atoi(argv[2]); | |
63 | if(channel<1) | |
64 | { | |
65 | printf("\nsignalnumber must be > 0\n\n"); | |
66 | return(1); | |
67 | } | |
68 | ||
69 | if(edfopen_file_readonly(argv[1], &hdr, EDFLIB_READ_ALL_ANNOTATIONS)) | |
70 | { | |
71 | switch(hdr.filetype) | |
72 | { | |
73 | case EDFLIB_MALLOC_ERROR : printf("\nmalloc error\n\n"); | |
74 | break; | |
75 | case EDFLIB_NO_SUCH_FILE_OR_DIRECTORY : printf("\ncan not open file, no such file or directory\n\n"); | |
76 | break; | |
77 | case EDFLIB_FILE_CONTAINS_FORMAT_ERRORS : printf("\nthe file is not EDF(+) or BDF(+) compliant\n" | |
78 | "(it contains format errors)\n\n"); | |
79 | break; | |
80 | case EDFLIB_MAXFILES_REACHED : printf("\nto many files opened\n\n"); | |
81 | break; | |
82 | case EDFLIB_FILE_READ_ERROR : printf("\na read error occurred\n\n"); | |
83 | break; | |
84 | case EDFLIB_FILE_ALREADY_OPENED : printf("\nfile has already been opened\n\n"); | |
85 | break; | |
86 | default : printf("\nunknown error\n\n"); | |
87 | break; | |
88 | } | |
89 | ||
90 | return(1); | |
91 | } | |
92 | ||
93 | hdl = hdr.handle; | |
94 | ||
95 | if(channel>(hdr.edfsignals)) | |
96 | { | |
97 | printf("\nerror: file has %i signals and you selected signal %i\n\n", hdr.edfsignals, channel); | |
98 | edfclose_file(hdl); | |
99 | return(1); | |
100 | } | |
101 | ||
102 | channel--; | |
103 | ||
104 | printf("\nlibrary version: %i.%02i\n", edflib_version() / 100, edflib_version() % 100); | |
105 | ||
106 | printf("\ngeneral header:\n\n"); | |
107 | ||
108 | printf("filetype: %i\n", hdr.filetype); | |
109 | printf("edfsignals: %i\n", hdr.edfsignals); | |
110 | #ifdef WIN32 | |
111 | printf("file duration: %I64d seconds\n", hdr.file_duration / EDFLIB_TIME_DIMENSION); | |
112 | #else | |
113 | printf("file duration: %lli seconds\n", hdr.file_duration / EDFLIB_TIME_DIMENSION); | |
114 | #endif | |
115 | printf("startdate: %i-%i-%i\n", hdr.startdate_day, hdr.startdate_month, hdr.startdate_year); | |
116 | printf("starttime: %i:%02i:%02i\n", hdr.starttime_hour, hdr.starttime_minute, hdr.starttime_second); | |
117 | printf("patient: %s\n", hdr.patient); | |
118 | printf("recording: %s\n", hdr.recording); | |
119 | printf("patientcode: %s\n", hdr.patientcode); | |
120 | printf("gender: %s\n", hdr.gender); | |
121 | printf("birthdate: %s\n", hdr.birthdate); | |
122 | printf("patient_name: %s\n", hdr.patient_name); | |
123 | printf("patient_additional: %s\n", hdr.patient_additional); | |
124 | printf("admincode: %s\n", hdr.admincode); | |
125 | printf("technician: %s\n", hdr.technician); | |
126 | printf("equipment: %s\n", hdr.equipment); | |
127 | printf("recording_additional: %s\n", hdr.recording_additional); | |
128 | printf("datarecord duration: %f seconds\n", ((double)hdr.datarecord_duration) / EDFLIB_TIME_DIMENSION); | |
129 | #ifdef WIN32 | |
130 | printf("number of datarecords in the file: %I64d\n", hdr.datarecords_in_file); | |
131 | printf("number of annotations in the file: %I64d\n", hdr.annotations_in_file); | |
132 | #else | |
133 | printf("number of datarecords in the file: %lli\n", hdr.datarecords_in_file); | |
134 | printf("number of annotations in the file: %lli\n", hdr.annotations_in_file); | |
135 | #endif | |
136 | ||
137 | printf("\nsignal parameters:\n\n"); | |
138 | ||
139 | printf("label: %s\n", hdr.signalparam[channel].label); | |
140 | #ifdef WIN32 | |
141 | printf("samples in file: %I64d\n", hdr.signalparam[channel].smp_in_file); | |
142 | #else | |
143 | printf("samples in file: %lli\n", hdr.signalparam[channel].smp_in_file); | |
144 | #endif | |
145 | printf("samples in datarecord: %i\n", hdr.signalparam[channel].smp_in_datarecord); | |
146 | printf("physical maximum: %f\n", hdr.signalparam[channel].phys_max); | |
147 | printf("physical minimum: %f\n", hdr.signalparam[channel].phys_min); | |
148 | printf("digital maximum: %i\n", hdr.signalparam[channel].dig_max); | |
149 | printf("digital minimum: %i\n", hdr.signalparam[channel].dig_min); | |
150 | printf("physical dimension: %s\n", hdr.signalparam[channel].physdimension); | |
151 | printf("prefilter: %s\n", hdr.signalparam[channel].prefilter); | |
152 | printf("transducer: %s\n", hdr.signalparam[channel].transducer); | |
153 | printf("samplefrequency: %f\n", ((double)hdr.signalparam[channel].smp_in_datarecord / (double)hdr.datarecord_duration) * EDFLIB_TIME_DIMENSION); | |
154 | ||
155 | struct edf_annotation_struct annot; | |
156 | ||
157 | printf("\n"); | |
158 | ||
159 | for(i=0; i<hdr.annotations_in_file; i++) | |
160 | { | |
161 | if(edf_get_annotation(hdl, i, &annot)) | |
162 | { | |
163 | printf("\nerror: edf_get_annotations()\n"); | |
164 | edfclose_file(hdl); | |
165 | return(1); | |
166 | } | |
167 | else | |
168 | { | |
169 | #ifdef WIN32 | |
170 | printf("annotation: onset is %I64d duration is %s description is %s\n", | |
171 | annot.onset / EDFLIB_TIME_DIMENSION, | |
172 | annot.duration, | |
173 | annot.annotation); | |
174 | #else | |
175 | printf("annotation: onset is %lli duration is %s description is %s\n", | |
176 | annot.onset / EDFLIB_TIME_DIMENSION, | |
177 | annot.duration, | |
178 | annot.annotation); | |
179 | #endif | |
180 | } | |
181 | } | |
182 | ||
183 | n = 200; /* read n samples from the file */ | |
184 | ||
185 | buf = (double *)malloc(sizeof(double[n])); | |
186 | if(buf==NULL) | |
187 | { | |
188 | printf("\nmalloc error\n"); | |
189 | edfclose_file(hdl); | |
190 | return(1); | |
191 | } | |
192 | ||
193 | int x=10; /* start reading x seconds from start of file */ | |
194 | ||
195 | edfseek(hdl, channel, (long long)((((double)x) / ((double)hdr.file_duration / (double)EDFLIB_TIME_DIMENSION)) * ((double)hdr.signalparam[channel].smp_in_file)), EDFSEEK_SET); | |
196 | ||
197 | n = edfread_physical_samples(hdl, channel, n, buf); | |
198 | ||
199 | if(n==(-1)) | |
200 | { | |
201 | printf("\nerror: edf_read_physical_samples()\n"); | |
202 | edfclose_file(hdl); | |
203 | free(buf); | |
204 | return(1); | |
205 | } | |
206 | ||
207 | printf("\nread %i samples, started at %i seconds from start of file:\n\n", n, x); | |
208 | ||
209 | for(i=0; i<n; i++) | |
210 | { | |
211 | printf("%.0f ", buf[i]); | |
212 | } | |
213 | ||
214 | printf("\n\n"); | |
215 | ||
216 | edfclose_file(hdl); | |
217 | ||
218 | free(buf); | |
219 | ||
220 | return(0); | |
221 | } | |
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | ||
230 | ||
231 | ||
232 | ||
233 | ||
234 | ||
235 | ||
236 | ||
237 | ||
238 | ||
239 | ||
240 | ||
241 | ||
242 | ||
243 | ||
244 | ||
245 | ||
246 | ||
247 | ||
248 | ||
249 | ||
250 |
68 | 68 | #define FILE_DURATION 600 |
69 | 69 | |
70 | 70 | |
71 | /* if you want to create an EDFplus file instead of BDFplus, outcomment the next line: */ | |
72 | ||
73 | ||
74 | #define BDF_FORMAT | |
75 | ||
76 | ||
71 | // Uncomment the next line to create a BDF+ file instead of EDF+: | |
72 | // #define BDF_FORMAT | |
77 | 73 | |
78 | 74 | |
79 | 75 | int main(int argc, char *argv[]) |