File: biosig.i

package info (click to toggle)
biosig4c%2B%2B 1.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,220 kB
  • sloc: ansic: 41,218; cpp: 8,946; sh: 4,365; makefile: 1,758; python: 87; awk: 73; php: 40; perl: 36; java: 14; ruby: 7
file content (304 lines) | stat: -rw-r--r-- 10,556 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
%
% $Id$
% Copyright (C) 2008,2009 Alois Schloegl <a.schloegl@ieee.org>
% This file is part of the "BioSig for C/C++" repository 
% (biosig4c++) at http://biosig.sf.net/ 


    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 3
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    
 */


// swig.i

%module biosig
%{
#include "../biosig.h"
%}


%include <inttypes.i>


typedef int64_t gdf_time; 	/* gdf time is represented in 64 bits */

typedef int64_t nrec_t; 	/* type for number of records */


	/* list of file formats */
enum FileFormat {
	noFile, unknown,
	ABF, ACQ, ACR_NEMA, AIFC, AIFF, AINF, alpha, ARFF, 
	ASCII_IBI, ASCII, AU, ASF, ATES, ATF, AVI, Axona,
	BCI2000, BDF, BESA, BIN, BKR, BLSC, BMP, BNI, BSCS,
	BrainVision, BrainVisionVAmp, BrainVisionMarker, BZ2,
	CDF, CFS, CFWB, CNT, CTF, DICOM, DEMG,
	EBS, EDF, EEG1100, EEProbe, EEProbe2, EEProbeAvr, EGI,
	EGIS, ELF, EMBLA, ePrime, ET_MEG, ETG4000, EVENT, EXIF,
	FAMOS, FEF, FITS, FLAC, GDF, GDF1,
	GIF, GTF, GZIP, HDF, HL7aECG, HEKA, 
	ISHNE, ITX, JPEG, JSON, Lexicor,
	Matlab, MFER, MIDI, MIT, MM, MSI, MSVCLIB, MS_LNK, 
	native, NeuroLoggerHEX, NetCDF, NEURON, NEX1, NIFTI, 
	OGG, OpenXDF,
	PBMA, PBMN, PDF, PDP, Persyst, PGMA, PGMB,
	PLEXON, PNG, PNM, POLY5, PPMA, PPMB, PS,
	RDF, RIFF,
	SASXPT, SCP_ECG, SIGIF, Sigma, SMA, SND, SQLite, 
	SPSS, STATA, SVG, SXI, SYNERGY,
	TIFF, TMS32, TMSiLOG, TRC, UNIPRO, VRML, VTK,
	WAV, WG1, WinEEG, WMF, XML, XPM,
	Z, ZIP, ZIP2, 
};


typedef struct CHANNEL_STRUCT {
	double 		PhysMin;		/* physical minimum */
	double 		PhysMax;		/* physical maximum */
	double 		DigMin;			/* digital minimum */
	double	 	DigMax;			/* digital maximum */
	double		Cal;			/* gain factor */
	double		Off;			/* bias */

	char		OnOff;
	char		Label[MAX_LENGTH_LABEL+1]; 		/* Label of channel */
	uint16_t	LeadIdCode;				/* Lead identification code */
	char 		Transducer[MAX_LENGTH_TRANSDUCER+1];	/* transducer e.g. EEG: Ag-AgCl electrodes */
//	char 		PhysDim[MAX_LENGTH_PHYSDIM+1] ;		/* physical dimension */
			/*PhysDim is now obsolete - use function PhysDim3(PhysDimCode) instead */
	uint16_t	PhysDimCode;		/* code for physical dimension */
	/* char* 	PreFilt;		// pre-filtering */

	float 		TOffset;		/* time delay of sampling */
	float 		LowPass;		/* lowpass filter */
	float 		HighPass;		/* high pass */
	float 		Notch;			/* notch filter */
	float 		XYZ[3];			/* sensor position */
//	float 		Orientation[3];		// sensor direction
//	float 		Area;			// area of sensor (e.g. for MEG)

	union {
        /* context specific channel information */
	float 		Impedance;   		/* Electrode Impedance in Ohm, defined only if PhysDim = _Volt */
	float 		fZ;	   		/* ICG probe frequency, defined only if PhysDim = _Ohm */
	};

	uint16_t 	GDFTYP;			/* data type */
	uint32_t 	SPR;			/* samples per record (block) */
} CHANNEL_TYPE;



/*
	This structure defines the general (fixed) header  
*/
typedef struct {
	float 		VERSION;	/* GDF version number */ 
	const char* 	FileName;
	enum FileFormat TYPE; 		/* type of file format */
	
	struct {
		size_t 			size[2]; /* size {rows, columns} of data block	 */
		biosig_data_type* 	block; 	 /* data block */
	} data;

	uint8_t 	IPaddr[16]; 	/* IP address of recording device (if applicable) */
	double 		SampleRate;	/* Sampling rate */
	int64_t  	NRec;		/* number of records/blocks -1 indicates length is unknown. */	
	gdf_time 	T0; 		/* starttime of recording */
	uint32_t 	HeadLen;	/* length of header in bytes */
	uint32_t 	SPR;		/* samples per block (when different sampling rates are used, this is the LCM(CHANNEL[..].SPR) */
	uint32_t  	LOC[4];		/* location of recording according to RFC1876 */
	uint16_t 	NS;		/* number of channels */
	int16_t 	tzmin; 		/* time zone (minutes of difference to UTC */

#ifdef CHOLMOD_H
	cholmod_sparse  *Calib;                  /* re-referencing matrix */
#endif 	
	CHANNEL_TYPE 	*rerefCHANNEL;  

	/* Patient specific information */
	struct {
		gdf_time 	Birthday; 	/* Birthday of Patient */
		// 		Age;		/* the age is HDR.T0 - HDR.Patient.Birthday, even if T0 and Birthday are not known */ 		
		uint16_t	Headsize[3]; 	/* circumference, nasion-inion, left-right mastoid in millimeter;  */
		char		Name[MAX_LENGTH_NAME+1]; /* because for privacy protection it is by default not supported, support is turned on with FLAG.ANONYMOUS */
//		char*		Name;	/* because for privacy protection it is by default not supported, support is turned on with FLAG.ANONYMOUS */
		char		Id[MAX_LENGTH_PID+1];	/* patient identification, identification code as used in hospital  */
		uint8_t		Weight;		/* weight in kilograms [kg] 0:unkown, 255: overflow  */
		uint8_t		Height;		/* height in centimeter [cm] 0:unkown, 255: overflow  */
		//		BMI;		/* the body-mass index = weight[kg]/height[m]^2 */
		/* Patient classification */
		int	 	Sex;		/* 0:Unknown, 1: Male, 2: Female  */
		int		Handedness;	/* 0:Unknown, 1: Right, 2: Left, 3: Equal */
		int		Smoking;	/* 0:Unknown, 1: NO, 2: YES */
		int		AlcoholAbuse;	/* 0:Unknown, 1: NO, 2: YES */
		int		DrugAbuse;	/* 0:Unknown, 1: NO, 2: YES */
		int		Medication;	/* 0:Unknown, 1: NO, 2: YES */
		struct {
			int 	Visual;		/* 0:Unknown, 1: NO, 2: YES, 3: Corrected */
			int 	Heart;		/* 0:Unknown, 1: NO, 2: YES, 3: Pacemaker */
		} Impairment;
	} Patient; 
	
	struct {
		char		Recording[MAX_LENGTH_RID+1]; 	/* HL7, EDF, GDF, BDF replaces HDR.AS.RID */
		char 		Technician;
		char* 		Hospital; 	
		uint64_t 	Equipment; 	/* identifies this software */
		struct {
			/* see 
				SCP: section1, tag14, 
				MFER: tag23:  "Manufacturer^model^version number^serial number"
				GDF: tag3:  "Manufacturer\0model\0version\0number\0serial number\0"
			*/	
//			char	_field[MAX_LENGTH_MANUF+1];	/* buffer */
			char*	Name;  
			char*	Model;
			char*	Version;
			char*	SerialNumber;
		} Manufacturer;  
	} ID;

	/* position of electrodes; see also HDR.CHANNEL[k].XYZ */
	struct {
		float		REF[3];	/* XYZ position of reference electrode */
		float		GND[3];	/* XYZ position of ground electrode */
	} ELEC;

	/*	EVENTTABLE */
	struct {
		double  	SampleRate;	/* for converting POS and DUR into seconds  */
		uint16_t 	*TYP;	/* defined at ../biosig4matlab/doc/eventcodes.txt */
		uint32_t 	*POS;	/* starting position [in samples] */
		uint32_t 	*DUR;	/* duration [in samples] */
		uint16_t 	*CHN;	/* channel number; 0: all channels  */
#if (BIOSIG_VERSION >= 10500)
		gdf_time        *TimeStamp ATT_ALI;  /* store time stamps */
#endif
		char		**CodeDesc;	/* describtion of "free text"/"user specific" events (encoded with TYP=0..255 */
		uint32_t  	N;	/* number of events */
		uint16_t	LenCodeDesc;	/* length of CodeDesc Table */
	} EVENT; 

	struct {	/* flags */
		char		OVERFLOWDETECTION; 	/* overflow & saturation detection 0: OFF, !=0 ON */
		char		UCAL; 		/* UnCalibration  0: scaling  !=0: NO scaling - raw data return  */
		char		ANONYMOUS; 	/* 1: anonymous mode, no personal names are processed */ 
		char		ROW_BASED_CHANNELS;	/* 0: column-based data [default]; 1: row-based data */ 
		char		TARGETSEGMENT; /* in multi-segment files (like Nihon-Khoden, EEG1100), it is used to select a segment */ 
	} FLAG; 

	CHANNEL_TYPE *CHANNEL;
	  
	struct {	/* File specific data  */
#ifdef ZLIB_H
		gzFile		gzFID;
#endif
#ifdef _BZLIB_H
//		BZFILE*		bzFID;
#endif
		FILE* 		FID;		/* file handle  */
		size_t 		POS;		/* current reading/writing position [in blocks] */
//		int		Des;		/* file descriptor */
		uint8_t		OPEN; 		/* 0: closed, 1:read, 2: write */
		uint8_t		LittleEndian;
		uint8_t		COMPRESSION;   /* 0: no compression 9: best compression */
//		int		DES;		/* descriptor for streams */
	} FILE; 

	/*	internal variables (not public)  */
	struct {
		const char*	B4C_ERRMSG;	/* error message */
//		char 		PID[MAX_LENGTH_PID+1];	/* use HDR.Patient.Id instead */
//		char* 		RID;		/* recording identification */ 
//		uint32_t 	spb;		/* total samples per block */
//		uint32_t 	bpb;  		/* total bytes per block */
//		uint32_t 	bpb8;  		/* total bits per block */
		uint8_t*	Header; 
//		uint8_t*	rawEventData;
//		uint8_t*	rawdata; 	/* raw data block */
//		char		flag_collapsed_rawdata; /*0 if rawdata contain obsolete channels, too. 	*/
//		nrec_t		first;		/* first block loaded in buffer - this is equivalent to hdr->FILE.POS */
//		nrec_t		length;		/* number of block(s) loaded in buffer */
		uint8_t*	auxBUF;		/* auxillary buffer - used for storing EVENT.CodeDesc, MIT FMT infor */
		char*		bci2000;
//		uint32_t	SegSel[5];	/* segment selection in a hirachical data formats, e.g. sweeps in HEKA/PatchMaster format */
		enum B4C_ERROR	B4C_ERRNUM;	/* error code */
//		char		flag_collapsed_rawdata; /* 0 if rawdata contain obsolete channels, too. 	*/
	} AS;
	
	void *aECG;
	
} HDRTYPE;

HDRTYPE* constructHDR(const unsigned NS, const unsigned N_EVENT);
void 	 destructHDR(HDRTYPE* hdr);
HDRTYPE* sopen(const char* FileName, const char* MODE, HDRTYPE* hdr);
int 	sclose(HDRTYPE* hdr);
size_t	sread(biosig_data_type* data, size_t start, size_t length, HDRTYPE* hdr);
size_t  swrite(const biosig_data_type *data, size_t nelem, HDRTYPE* hdr);
int	seof(HDRTYPE* hdr);
void	srewind(HDRTYPE* hdr);
int 	sseek(HDRTYPE* hdr, long int offset, int whence);
long int stell(HDRTYPE* hdr);
int 	serror2(HDRTYPE* hdr);
int	hdr2ascii(HDRTYPE* hdr, FILE *fid, int verbosity);

int RerefCHANNEL(HDRTYPE *hdr, void *ReRef, char rrtype);
const char* GetFileTypeString(enum FileFormat FMT);

uint16_t PhysDimCode(char* PhysDim0);
char* 	PhysDim3(uint16_t PhysDimCode);

/*
HDRTYPE* sopen(char *filename);
%{
	HDRTYPE* sopen(char *filename)
	{
		HDRTYPE *hdr = constructHDR(0,0);
		hdr = sopen(filename, "r", hdr);
		return hdr;
        }
%}


int sclose(HDRTYPE *hdr);
%{
	int sclose(HDRTYPE *hdr)
	{
		sclose(hdr);
		destructHDR(hdr);
		return 0;
        }
%}
*/

void serror();
%{
	void _serror() {
		fprintf(stderr,"Use of SERROR is deprecated - use serror2(HDR) instead"); 	
		serror();
	}	
%}

void hdr2ascii(HDRTYPE* hdr, int verbosity);
%{
	void hdr2ascii(HDRTYPE* hdr, int verbosity)
	{
		hdr2ascii(hdr, stdout, verbosity);
        }
%}