Created
October 9, 2013 12:48
-
-
Save regedarek/6900727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "ruby.h" | |
| #include "edflib.h" | |
| static VALUE EdfConverter; | |
| char *path; | |
| /* edf file description */ | |
| struct edf_hdr_struct hdr; | |
| /* a handle (identifier) used to distinguish the different files */ | |
| int hdl; | |
| /* buffer for seeking signals */ | |
| double *buf; | |
| void output(){ | |
| printf("number of datarecords in the file: %lli\n", hdr.datarecords_in_file); | |
| printf("signalcount is: %d\n", hdr.edfsignals); | |
| for (int i=0; i<hdr.edfsignals; i++){ | |
| printf("Signal %d\n", i); | |
| printf("label: %s\n", hdr.signalparam[i].label); | |
| printf("samples in file: %lli\n", hdr.signalparam[i].smp_in_file); | |
| printf("samples in datarecord: %i\n", hdr.signalparam[i].smp_in_datarecord); | |
| printf("physical maximum: %f\n", hdr.signalparam[i].phys_max); | |
| printf("physical minimum: %f\n", hdr.signalparam[i].phys_min); | |
| printf("digital maximum: %i\n", hdr.signalparam[i].dig_max); | |
| printf("digital minimum: %i\n", hdr.signalparam[i].dig_min); | |
| printf("physical dimension: %s\n", hdr.signalparam[i].physdimension); | |
| printf("samplefrequency: %f\n\n", ((double)hdr.signalparam[i].smp_in_datarecord / (double)hdr.datarecord_duration) * EDFLIB_TIME_DIMENSION); | |
| } | |
| } | |
| void setVariables(){ | |
| path = (char *)"ecg_2_10_sec.edf"; /* init with default path*/ | |
| } | |
| int openFile(){ | |
| if(edfopen_file_readonly(path, &hdr, EDFLIB_READ_ALL_ANNOTATIONS)){ | |
| switch(hdr.filetype){ | |
| case EDFLIB_MALLOC_ERROR : printf("\nmalloc error\n\n"); | |
| break; | |
| case EDFLIB_NO_SUCH_FILE_OR_DIRECTORY : printf("\ncan not open file, no such file or directory\n\n"); | |
| break; | |
| case EDFLIB_FILE_CONTAINS_FORMAT_ERRORS : printf("\nthe file is not EDF(+) or BDF(+) compliant\n" | |
| "(it contains format errors)\n\n"); | |
| break; | |
| case EDFLIB_MAXFILES_REACHED : printf("\nto many files opened\n\n"); | |
| break; | |
| case EDFLIB_FILE_READ_ERROR : printf("\na read error occurred\n\n"); | |
| break; | |
| case EDFLIB_FILE_ALREADY_OPENED : printf("\nfile has already been opened\n\n"); | |
| break; | |
| default : printf("\nunknown error\n\n"); | |
| break; | |
| } | |
| return(1); | |
| }else return (0); | |
| } | |
| VALUE run_output(VALUE rb_self){ | |
| setVariables(); | |
| if(openFile()){ | |
| /* ERROR */ | |
| }else{ | |
| output(); | |
| } | |
| return rb_self; | |
| } | |
| void Init_edfconverter(){ | |
| EdfConverter = rb_define_class("EdfConverter", rb_cObject); | |
| rb_define_method(EdfConverter, "run", run_output, 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment