00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __OPENEDF_H
00026 #define __OPENEDF_H
00027
00028 #include <stdio.h>
00029
00030 #include <nsnet.h>
00031
00032 #define MAXCHANNELS 32
00033 #define BYTESPERSAMPLE 2
00034 #define MAXHEADERLEN ((MAXCHANNELS+1) * 256)
00035
00036 #pragma pack(1)
00037
00038 struct EDFPackedHeader {
00039 char dataFormat[8];
00040 char localPatient[80];
00041 char localRecorder[80];
00042 char recordingStartDate[8];
00043 char recordingStartTime[8];
00044 char headerRecordBytes[8];
00045 char manufacturerID[44];
00046 char dataRecordCount[8];
00047 char dataRecordSeconds[8];
00048 char dataRecordChannels[4];
00049 };
00050
00051 struct EDFPackedChannelHeader {
00052 char label[16];
00053 char transducer[80];
00054 char dimUnit[8];
00055 char physMin[8];
00056 char physMax[8];
00057 char digiMin[8];
00058 char digiMax[8];
00059 char prefiltering[80];
00060 char sampleCount[8];
00061 char reserved[32];
00062 };
00063
00064 #pragma pack(4)
00065
00066 struct EDFDecodedHeader {
00067 int headerRecordBytes;
00068 int dataRecordCount;
00069 int dataRecordChannels;
00070 char dataFormat[9];
00071 char localPatient[81];
00072 char localRecorder[81];
00073 char recordingStartDate[9];
00074 char recordingStartTime[9];
00075 char manufacturerID[45];
00076 double dataRecordSeconds;
00077 };
00078
00079 struct EDFDecodedChannelHeader {
00080 int sampleCount;
00081 double physMin, physMax;
00082 double digiMin, digiMax;
00083 char label[17];
00084 char transducer[81];
00085 char dimUnit[9];
00086 char prefiltering[81];
00087 char reserved[33];
00088 };
00089
00090 struct EDFDecodedConfig {
00091 struct EDFDecodedHeader hdr;
00092 struct EDFDecodedChannelHeader chan[MAXCHANNELS];
00093 };
00094
00095 struct EDFInputIterator {
00096 struct EDFDecodedConfig cfg;
00097 int dataRecordNum;
00098 int sampleNum;
00099 char *dataRecord;
00100 };
00101
00102 struct EDFInputIterator *newEDFInputIterator(const struct EDFDecodedConfig *cfg);
00103 int stepEDFInputIterator(struct EDFInputIterator *edfi);
00104 int fetchSamples(const struct EDFInputIterator *edfi, short *samples, FILE *fp);
00105 void freeEDFInputIterator(struct EDFInputIterator *edfi);
00106
00107 int EDFUnpackInt(const char *inp, int fieldLen);
00108 double EDFUnpackDouble(const char *inp, int fieldLen);
00109 const char *EDFUnpackString(const char *inp, int fieldLen);
00110
00111 int EDFEncodePacket(char *target, const struct EDFDecodedConfig *cfg);
00112
00113 int writeEDF(int fd, const struct EDFDecodedConfig *cfg);
00114 int readEDF(int fd, struct EDFDecodedConfig *cfg);
00115 int writeEDFString(const struct EDFDecodedConfig *cfg, char *buf, int *buflen);
00116 int readEDFString(struct EDFDecodedConfig *cfg, const char *buf, int len);
00117
00118 int setEDFHeaderBytes(struct EDFDecodedConfig *cfg);
00119 int getDataRecordChunkSize(const struct EDFDecodedConfig *cfg);
00120
00121 double getSamplesPerSecond(const struct EDFDecodedConfig *cfg, int whichChan);
00122 double getSecondsPerSample(const struct EDFDecodedConfig *cfg, int whichChan);
00123
00124
00125 int isValidREDF(const struct EDFDecodedConfig *cfg);
00126 int makeREDFConfig(struct EDFDecodedConfig *result, const struct EDFDecodedConfig *source);
00127
00128
00129 const char *getLastError(void);
00130
00131 const char *getDMY(void);
00132 const char *getHMS(void);
00133
00134 #endif
00135