1 function [HDR,H1,h2]=
opendicom(arg1,arg2,arg3,arg4,arg5,arg6)
2 % OPENDICOM is an auxillary
function to SOPEN
for
3 % opening of DICOM files
for reading ECG waveform data
5 % Use SOPEN instead of OPENDICOM
7 % See also: fopen, SOPEN,
14 % This program is free software; you can redistribute it and/or
15 % modify it under the terms of the GNU General Public License
16 % as published by the Free Software Foundation; either version 3
17 % of the License, or (at your option) any later version.
19 % This program is distributed in the hope that it will be useful,
20 % but WITHOUT ANY WARRANTY; without even the implied warranty of
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 % GNU General Public License
for more details.
24 % You should have received a copy of the GNU General Public License
25 % along with
this program;
if not, write to the Free Software
26 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 % $Id:
opendicom.m 2205 2009-10-27 12:18:15Z schloegl $
30 % (C) 1997-2002,2004,2009 by Alois Schloegl <a.schloegl@ieee.org>
31 % This is part of the BIOSIG-toolbox http:
35 elseif ~any(arg2==
'b');
36 arg2= [arg2,
'b']; % force binary open.
42 FILENAME=HDR.FileName;
45 fprintf(2,
'Warning OPENDICOM: the use of OPENDICOM is discouraged (OPENDICOM might disappear); please use SOPEN instead.\n');
48 DEBUG=1; %% set 1 to get more information
51 HDR.DICOM.SeriesNumber = {};
54 if any(PERMISSION==
'r'),
56 HDR.FLAG.implicite_VR = 1;
57 HDR.Endianity =
'ieee-le';
58 warning(
'Support for DICOM waveform data is very experimental');
61 HDR.FILE.FID = fopen(HDR.FileName,
'r',
'ieee-le');
62 id = fread(HDR.FILE.FID,132,
'uint8');
63 if ~all(
id' == [zeros(1,128),abs('DICM
')])
64 status = fseek(HDR.FILE.FID,0,'bof
');
66 HDR.FLAG.implicite_VR = 0;
71 [tag,c] = fread(HDR.FILE.FID,2,'uint16
');
72 while ~feof(HDR.FILE.FID);
74 if HDR.FLAG.implicite_VR %|| any(tag(1)==[8,16,32]), % implicite VR
75 LEN = fread(HDR.FILE.FID,1,'uint32
');
77 [VR,c] = fread(HDR.FILE.FID,2,'uint16
');
78 fprintf(1,'%c%c
',char(mod(VR(1),256)),char(VR(1)/256));
79 ix = ['OB
';'OW
';'OF
';'SQ
';'UT
';'UN
']*[1;256];
81 HDR.ERROR.status = -1;
82 HDR.ERROR.message = sprintf('Error OPENDICOM: %s\n
', HDR.FileName);
88 LEN = fread(HDR.FILE.FID,1,'uint32
');
91 if (LEN==hex2dec('FFFFFFFF
')),
95 %LEN = fread(HDR.FILE.FID,1,'uint32
');
99 fprintf(1,'%06x: %03i\t%08x\t%04i\n
',ftell(HDR.FILE.FID),count,TAG,LEN);
102 %[count,LEN],dec2hex(TAG),
106 elseif (TAG==hex2dec('00000002
')),
107 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
108 HDR.DICOM.TAG00000002 = char(VAL');
109 elseif (TAG==hex2dec(
'0000003a')),
110 [VAL,c] = fread(HDR.FILE.FID,1,
'uint8');
111 HDR.DICOM.TAG0000003a = VAL;
113 elseif (TAG==hex2dec(
'00020000')),
114 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
115 HDR.DICOM.GroupLength = VAL
';
116 elseif (TAG==hex2dec('00020001
')),
117 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
118 HDR.DICOM.FileMetaInformationVersion = VAL;
119 elseif (TAG==hex2dec('00020002
')),
120 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],'uint8
');
121 HDR.DICOM.MediaStorageSOPClassUID = deblank(char(VAL));
123 HDR.DICOM.MediaStorageSOPClassUID,
124 if strcmp(HDR.DICOM.MediaStorageSOPClassUID,'1.2.840.10008.5.1.4.1.1.9.1.1
')
125 % 12-lead ECG Waveform Storage
127 elseif strcmp(HDR.DICOM.MediaStorageSOPClassUID,'1.2.840.10008.5.1.4.1.1.9.1.2
')
128 % General ECG Waveform Storage
129 elseif strcmp(HDR.DICOM.MediaStorageSOPClassUID,'1.2.840.10008.5.1.4.1.1.9.1.3
')
130 % Ambulatory ECG Waveform Storage
131 elseif strcmp(HDR.DICOM.MediaStorageSOPClassUID,'1.2.840.10008.5.1.4.1.1.9.2.1
')
132 % Hemodynamic Waveform Storage
134 elseif strcmp(HDR.DICOM.MediaStorageSOPClassUID,'1.2.840.10008.5.1.4.1.1.9.3.1
')
135 % Cardiac Electrophysiology Waveform Storagee
136 elseif strcmp(HDR.DICOM.MediaStorageSOPClassUID,'1.2.840.10008.5.1.4.1.1.9.4.1
')
137 % Basic Voice Audio Waveform Storage
139 elseif (TAG==hex2dec('00020003
')),
140 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
141 HDR.DICOM.MediaStorageSOPInstanceUID = char(VAL)';
142 elseif (TAG==hex2dec(
'00020010')),
143 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
144 HDR.DICOM.TransferSyntaxUID = deblank(
char(VAL));
145 if strcmp(HDR.DICOM.TransferSyntaxUID,
'1.2.840.10008.1.2')
146 % Implicit VR Little Endian: Default Transfer Syntax
for DICOM
147 HDR.FLAG.implicite_VR = 1;
148 elseif strcmp(HDR.DICOM.TransferSyntaxUID,
'1.2.840.10008.1.2.1')
149 % Explicit VR Little Endian
150 HDR.FLAG.implicite_VR = 0;
151 elseif strcmp(HDR.DICOM.TransferSyntaxUID,
'1.2.840.10008.1.2.1.99')
152 % Deflated Explicit VR Little Endian
153 elseif strcmp(HDR.DICOM.TransferSyntaxUID,
'1.2.840.10008.1.2.2')
154 % Explicit VR Big Endian
155 % HDR.FLAG.implicite_VR = 1;
158 elseif (TAG==hex2dec(
'00020012')),
159 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
160 HDR.DICOM.ImplementationClassUID = char(VAL
');
161 elseif (TAG==hex2dec('00020013
')),
162 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
163 HDR.DICOM.ImplementationVersionName = char(VAL');
165 elseif (TAG==hex2dec(
'00080008')),
166 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
167 HDR.DICOM.ImageType = char(VAL);
168 elseif (TAG==hex2dec(
'00080012')),
169 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
170 HDR.DICOM.InstanceCreationDate = char(VAL(VAL~=abs(
'.')));
171 elseif (TAG==hex2dec(
'00080013')),
172 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
173 HDR.DICOM.InstanceCreationTime = char(VAL(VAL~=abs(
'.')));
174 elseif (TAG==hex2dec(
'00080014')),
175 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
176 HDR.DICOM.Instance_CreatorUID = char(VAL);
177 elseif (TAG==hex2dec(
'00080016')),
178 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
179 HDR.DICOM.SOP_ClassUID = char(VAL);
180 elseif (TAG==hex2dec(
'00080018')),
181 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
182 HDR.DICOM.SOP_InstanceUID = char(VAL);
184 elseif (TAG==hex2dec(
'00080020')),
185 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
186 HDR.DICOM.StudyDate = char(VAL(VAL~=abs(
'.')));
187 elseif (TAG==hex2dec(
'00080021')),
188 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
189 HDR.DICOM.SeriesDate = char(VAL(VAL~=abs(
'.')));
190 elseif (TAG==hex2dec(
'00080022')),
191 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
192 HDR.DICOM.AcquisitionDate = char(VAL(VAL~=abs(
'.')));
193 elseif (TAG==hex2dec(
'00080023')),
194 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
195 HDR.DICOM.ContentDate = char(VAL(VAL~=abs(
'.')));
196 elseif (TAG==hex2dec(
'00080024')),
197 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
198 HDR.DICOM.OverlayDate = char(VAL(VAL~=abs(
'.')));
199 elseif (TAG==hex2dec(
'00080025')),
200 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
201 HDR.DICOM.CurveDate = char(VAL(VAL~=abs(
'.')));
202 elseif (TAG==hex2dec(
'0008002A')),
203 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8=>char');
204 HDR.DICOM.AcquisitionDateTime = VAL; char(VAL(VAL~=abs(
'.')));
206 elseif (TAG==hex2dec(
'00080030')),
207 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
208 HDR.DICOM.StudyTime = char(VAL(VAL~=abs(
'.')));
209 elseif (TAG==hex2dec(
'00080031')),
210 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
211 HDR.DICOM.SeriesTime = char(VAL(VAL~=abs(
'.')));
212 elseif (TAG==hex2dec(
'00080032')),
213 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
214 HDR.DICOM.AcquisitionTime = char(VAL(VAL~=abs(
'.')));
215 elseif (TAG==hex2dec(
'00080033')),
216 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
217 HDR.DICOM.ContentTime = char(VAL(VAL~=abs(
'.')));
218 elseif (TAG==hex2dec(
'00080034')),
219 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
220 HDR.DICOM.OverlayTime = char(VAL(VAL~=abs(
'.')));
221 elseif (TAG==hex2dec(
'00080035')),
222 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
223 HDR.DICOM.CurveTime = char(VAL(VAL~=abs(
'.')));
225 elseif (TAG==hex2dec(
'00080050')),
226 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
227 HDR.DICOM.AccessionNumber = char(VAL);
228 elseif (TAG==hex2dec(
'00080060')),
229 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
230 HDR.DICOM.Modality = char(VAL);
231 elseif (TAG==hex2dec(
'00080070')),
232 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
233 HDR.DICOM.Manufacturer = char(VAL);
234 elseif (TAG==hex2dec(
'00080080')),
235 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
236 HDR.DICOM.InstitutionName = char(VAL);
237 elseif (TAG==hex2dec(
'00080081')),
238 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
239 HDR.DICOM.InstitutionAddress = char(VAL);
240 elseif (TAG==hex2dec(
'00080090')),
241 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
242 HDR.DICOM.ReferringPhysiciansName = char(VAL);
243 elseif (TAG==hex2dec(
'00081010')),
244 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
245 HDR.DICOM.StationName = char(VAL);
246 elseif (TAG==hex2dec(
'00081030')),
247 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
248 HDR.DICOM.StudyDescription = char(VAL);
249 elseif (TAG==hex2dec(
'00081040')),
250 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
251 HDR.DICOM.InstitutionalDepartmentName = char(VAL);
252 elseif (TAG==hex2dec(
'00081050')),
253 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
254 HDR.DICOM.PerformingPhysiciansName = char(VAL);
255 elseif (TAG==hex2dec(
'00081060')),
256 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
257 HDR.DICOM.f00081060 = char(VAL);
258 elseif (TAG==hex2dec(
'00081070')),
259 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
260 HDR.DICOM.f00081070 = char(VAL);
261 elseif (TAG==hex2dec(
'00081090')),
262 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
263 HDR.DICOM.ManufacturesModelName = char(VAL);
264 elseif (TAG==hex2dec(
'0008114a')),
265 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
266 HDR.DICOM.ReferenceInstantSequence = char(VAL);
267 elseif (TAG==hex2dec(
'0008114b')),
268 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
269 HDR.DICOM.ReferenceDescription = char(VAL);
271 elseif (TAG==hex2dec(
'00100010')),
272 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
273 HDR.Patient.Name = char(VAL);
274 elseif (TAG==hex2dec(
'00100020')),
275 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
277 elseif (TAG==hex2dec(
'00100030')),
278 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8=>char');
280 VAL = (VAL(VAL~=abs(
'.')));
281 VAL = (VAL(VAL~=abs(
'-')));
282 HDR.DICOM.BirthDate = VAL;
283 tmp = repmat(
',',1,10);
284 tmp([1:4,6:7,9:10])=VAL;
285 HDR.Patient.Birthday = [
str2double(tmp,
','),12,0,0];
287 elseif (TAG==hex2dec(
'00100040')),
288 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
289 HDR.Patient.Sex = deblank(
char(VAL));
291 elseif (TAG==hex2dec(
'00101010')),
292 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
293 HDR.Patient.Age = char(VAL);
294 elseif (TAG==hex2dec(
'00101020')),
295 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
297 elseif (TAG==hex2dec(
'00101030')),
298 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
301 elseif (TAG==hex2dec(
'00181000')),
302 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
303 HDR.DICOM.DeviceSerialNumber = char(VAL);
304 elseif (TAG==hex2dec(
'00181020')),
305 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
306 HDR.DICOM.SoftwareVersion = char(VAL);
307 elseif (TAG==hex2dec(
'00181061')),
308 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
309 HDR.DICOM.TriggerSource = char(VAL);
310 elseif (TAG==hex2dec(
'00181067')),
311 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
312 HDR.DICOM.ImageTriggerDelay = char(VAL);
313 elseif (TAG==hex2dec(
'00181068')),
314 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
315 HDR.DICOM.MultiplexGroupTimeOffset = char(VAL);
316 elseif (TAG==hex2dec(
'00181069')),
317 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
318 HDR.DICOM.TriggerTimeOffset = char(VAL);
319 elseif (TAG==hex2dec(
'0018106a')),
320 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
321 HDR.DICOM.SyncTrigger = char(VAL);
322 elseif (TAG==hex2dec(
'0018106c')),
323 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
324 HDR.DICOM.SyncChannel = char(VAL);
325 elseif (TAG==hex2dec(
'0018106e')),
326 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
327 HDR.DICOM.TriggerSamplePosition = char(VAL);
328 elseif (TAG==hex2dec(
'00181800')),
329 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
330 HDR.DICOM.AcqTimeSynchronized = char(VAL);
331 elseif (TAG==hex2dec(
'00181801')),
332 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
333 HDR.DICOM.TimeSource = char(VAL);
334 elseif (TAG==hex2dec(
'00181802')),
335 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
336 HDR.DICOM.TimeDistributionProtocol = char(VAL);
337 elseif (TAG==hex2dec(
'00181810')),
338 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
339 HDR.DICOM.AcqTimestamp = char(VAL);
341 elseif (TAG==hex2dec(
'0020000d')),
342 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
343 HDR.DICOM.StudyInstanceUID = char(VAL);
344 elseif (TAG==hex2dec(
'0020000e')),
345 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
346 HDR.DICOM.SeriesInstanceUID = char(VAL);
347 elseif (TAG==hex2dec(
'00200010')),
348 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
349 HDR.DICOM.StudyID = char(VAL);
350 elseif (TAG==hex2dec(
'00200011')),
351 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],
'uint8');
352 HDR.DICOM.SeriesNumber{end+1} = char(VAL);
353 elseif (TAG==hex2dec(
'00200012')),
354 [VAL,c] = fread(HDR.FILE.FID,1,
'uint8');
355 HDR.DICOM.AcquisitionNumber = char(VAL);
356 elseif (TAG==hex2dec(
'00200013')),
357 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
359 elseif (TAG==hex2dec(
'00200019')),
360 [VAL,c] = fread(HDR.FILE.FID,1,
'uint8');
361 HDR.DICOM.ItemNumber = char(VAL);
362 elseif (TAG==hex2dec(
'00200054')),
363 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
364 HDR.DICOM.TAG00200054 = VAL
';
366 elseif (TAG==hex2dec('00200200
')),
367 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],'uint8
');
368 HDR.DICOM.SychronizationFrame = char(VAL);
370 elseif (TAG==hex2dec('00280010
')),
371 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
372 HDR.DICOM.Rows = VAL;
373 elseif (TAG==hex2dec('00280011
')),
374 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
375 HDR.DICOM.Columns = VAL;
376 elseif (TAG==hex2dec('00280012
')),
377 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
378 HDR.DICOM.Planes = VAL;
379 elseif (TAG==hex2dec('00280030
')),
380 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
381 HDR.DICOM.PixelSpacing = VAL;
382 elseif (TAG==hex2dec('00280100
')),
383 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
384 HDR.DICOM.BitsAllocated = VAL;
385 elseif (TAG==hex2dec('00280101
')),
386 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
387 HDR.DICOM.BitsStored = VAL;
388 elseif (TAG==hex2dec('00280102
')),
389 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
390 HDR.DICOM.HighBit = VAL;
391 elseif (TAG==hex2dec('00280103
')),
392 [VAL,c] = fread(HDR.FILE.FID,1,'uint16
');
393 HDR.DICOM.PixelRepresentation = VAL;
395 elseif (TAG==hex2dec('003a0004
')),
396 [VAL,c] = fread(HDR.FILE.FID,[1,LEN],'uint8=>
char');
397 HDR.DICOM.WaveformOriginality = VAL;
398 elseif (TAG==hex2dec('003a0005
')), % waveform data
399 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8=>
char');
400 HDR.NS = str2double(VAL);
401 elseif (TAG==hex2dec('003a0010
')),
402 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8=>
char');
403 HDR.SPR = str2double(VAL);
404 elseif (TAG==hex2dec('003a001a
')), % waveform data
405 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8=>
char');
406 HDR.SampleRate = str2double(VAL);
408 elseif (TAG==hex2dec('003a0020
')),
409 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
410 HDR.DICOM.MultiplexGroupLabel = VAL;
411 elseif (TAG==hex2dec('003a0200
')),
412 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
413 HDR.DICOM.ChannelDefinitionSequence = VAL;
414 elseif (TAG==hex2dec('003a0202
')),
415 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
416 HDR.DICOM.ChannelNumber = VAL;
417 elseif (TAG==hex2dec('003a0203
')),
418 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
419 HDR.DICOM.ChannelLabel = char(VAL);
420 elseif (TAG==hex2dec('003a0205
')),
421 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
422 HDR.DICOM.ChannelStatus = char(VAL);
423 elseif (TAG==hex2dec('003a0208
')), % waveform data
424 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
425 HDR.DICOM.ChannelSource = VAL;
426 elseif (TAG==hex2dec('003a0209
')),
427 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
428 HDR.DICOM.ChannelSourceModifiersSequence = VAL;
429 elseif (TAG==hex2dec('003a020a
')),
430 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
431 HDR.DICOM.SourceWaveformSequence = VAL;
432 elseif (TAG==hex2dec('003a020c
')),
433 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
434 HDR.DICOM.ChannelDerivationDescription = VAL;
435 elseif (TAG==hex2dec('003a0210
')),
436 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
437 HDR.DICOM.Sensitivity = VAL;
438 elseif (TAG==hex2dec('003a0211
')),
439 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
440 HDR.DICOM.SensitivityUnits = VAL;
441 elseif (TAG==hex2dec('003a0212
')),
442 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
443 HDR.DICOM.ChannelSensitivityCorrectionFactor = char(VAL);
444 elseif (TAG==hex2dec('003a0213
')),
445 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
446 HDR.DICOM.ChannelBaseline = VAL;
447 elseif (TAG==hex2dec('003a0214
')),
448 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
449 HDR.DICOM.ChannelTimeSkew = VAL;
450 elseif (TAG==hex2dec('003a0215
')),
451 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
452 HDR.DICOM.ChannelSampleSkew = VAL;
453 elseif (TAG==hex2dec('003a0218
')),
454 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
455 HDR.DICOM.ChannelOffset = VAL;
456 elseif (TAG==hex2dec('003a021a
')),
457 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
458 HDR.SampleRate = VAL;
460 elseif (TAG==hex2dec('003a0220
')),
461 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
462 HDR.Filter.LowFreq = VAL;
463 elseif (TAG==hex2dec('003a0221
')),
464 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
465 HDR.Filter.HiFreq = VAL;
466 elseif (TAG==hex2dec('003a0222
')),
467 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
468 HDR.Filter.NotchF = VAL;
469 elseif (TAG==hex2dec('003a0223
')),
470 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
471 HDR.Filter.NotchB = VAL;
473 elseif (TAG==hex2dec('00400055
')),
474 [VAL,c] = fread(HDR.FILE.FID,LEN/2,'uint16
');
475 HDR.DICOM.AcquisitionContextModule = VAL;
476 elseif (TAG==hex2dec('00400555
')),
478 HDR.H1 = fread(HDR.FILE.FID,[1,261*HDR.NS*2],'uint8=>
char')
479 [VAL,c] = fread(HDR.FILE.FID,[HDR.NS,LEN],'int16
');
480 HDR.DICOM.AcquisitionContextSequence = VAL';
481 HDR.data = VAL(:,1:end-3)
';
482 elseif (TAG==hex2dec('0040A043
')),
483 [VAL,c] = fread(HDR.FILE.FID,LEN/2,'uint16
');
484 HDR.DICOM.WaveformAnnotationModule = VAL;
486 elseif (TAG==hex2dec('0040a0b0
')),
487 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
488 HDR.DICOM.ReferencedWaveformChannel = VAL;
489 elseif (TAG==hex2dec('0040a130
')),
490 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
491 HDR.DICOM.TemporalRangeType = VAL;
492 elseif (TAG==hex2dec('0040a132
')),
493 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
494 HDR.DICOM.ReferencedSamplePosition = VAL;
495 elseif (TAG==hex2dec('0040a138
')),
496 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
497 HDR.DICOM.ReferencedTimeOffset = VAL;
498 elseif (TAG==hex2dec('0040a13a
')),
499 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
500 HDR.DICOM.ReferencedDataTime = VAL;
501 elseif (TAG==hex2dec('0040a180
')),
502 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
503 HDR.DICOM.AnnoationGroupName = char(VAL);
504 elseif (TAG==hex2dec('0040a195
')),
505 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
506 HDR.DICOM.ConceptNameCodeSequenceModifier = VAL;
507 elseif (TAG==hex2dec('0040B020
')),
508 [VAL,c] = fread(HDR.FILE.FID,LEN/2,'uint16
');
509 HDR.DICOM.WaveformAnnotationSequence = VAL;
511 elseif (TAG==hex2dec('20201300
'))
512 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
513 %[VAL,c] = fread(HDR.FILE.FID,LEN/2,'int16
');
514 HDR.DICOM.TAG20201300=VAL';
516 elseif (TAG==hex2dec(
'20330008'))
517 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
518 %[VAL,c] = fread(HDR.FILE.FID,LEN,
'int16');
519 HDR.DICOM.TAG20330008=VAL
';
520 elseif (TAG==hex2dec('42000000
'))
521 [VAL,c] = fread(HDR.FILE.FID,LEN,'uint8
');
522 HDR.DICOM.TAG42000000=VAL';
524 elseif (TAG==hex2dec(
'54000010')), % waveform data
525 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
527 elseif (TAG==hex2dec(
'54000100')),
528 %[VAL,c] = fread(HDR.FILE.FID,[HDR.NS,110],
'int16');
529 %[VAL,c] = fread(HDR.FILE.FID,[HDR.NS,LEN/(HDR.NS)-110],
'int16');
530 [VAL,c] = fread(HDR.FILE.FID,[HDR.NS,LEN/HDR.NS],
'int16');
531 %[VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
532 HDR.DICOM.WaveFormSequence = VAL
';
533 HDR.data = VAL(:,111:end)';
534 elseif (TAG==hex2dec(
'54000110')), % channel minimum
535 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
537 elseif (TAG==hex2dec(
'54000112')), % channel maximum
538 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
540 elseif (TAG==hex2dec(
'54001004')), % waveform bits allocation
541 [HDR.bits,c] = fread(HDR.FILE.FID,LEN,
'uint8');
542 elseif (TAG==hex2dec(
'54001006')), % waveform bits allocation
543 [HDR.WaveformSampleInterpretation,c] = fread(HDR.FILE.FID,LEN,
'uint8');
544 elseif (TAG==hex2dec(
'54000100A')), % padding
545 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
546 HDR.DICOM.PaddingValue = VAL;
547 elseif (TAG==hex2dec(
'54001010')), % waveform data element
548 [VAL,c] = fread(HDR.FILE.FID,LEN/2,
'uint16');
551 elseif (TAG==hex2dec(
'7FE00010'))
552 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
553 HDR.DICOM.TAG7fe00010=VAL
';
554 elseif (TAG==hex2dec('FFFEE000
'))
556 LEN = fread(HDR.FILE.FID,1,'uint32
');
558 elseif LEN~=hex2dec('FFFFFFFF
')
559 VAL = fread(HDR.FILE.FID,[HDR.NS,LEN/24],'int16
');
561 VAL = fread(HDR.FILE.FID,1,'uint32
');
564 elseif (TAG==hex2dec(
'FFFEE0DD'))
565 %% sequence delimiter
568 [VAL,c] = fread(HDR.FILE.FID,LEN,
'uint8');
572 fprintf(1,'ignored: TAG=%08x VAL=%s\n
',TAG,char(VAL));
576 [tag,c] = fread(HDR.FILE.FID,2,'uint16
');
579 if isfield(HDR.DICOM,'StudyDate
') & isfield(HDR.DICOM,'StudyTime
'),
580 tmp = char(repmat(',
',[1,20]));
581 if length(HDR.DICOM.StudyDate)==8,
582 tmp([1:4,6:7,9:10]) = HDR.DICOM.StudyDate;
583 tmp([12:13,15:16,18:19]) = HDR.DICOM.StudyTime(1:6);
584 HDR.T0 = str2double(tmp,',
');
586 fprintf(1,'Warning OPENDICOM: StudyDate <%s> not supported\n
',HDR.DICOM.StudyDate);
589 if isfield(HDR.DICOM,'Modality
') & strncmp(HDR.DICOM.Modality,'ECG
',3)
590 tmp = char(repmat(32,[1,20]));
591 tmp([1:4,6,7,9,10]) = HDR.DICOM.ContentDate;
592 tmp([12,13,15,16,18,19]) = HDR.DICOM.ContentTime(1:6);
593 HDR.T0 = str2double(tmp);
594 HDR.TYPE = 'DICOM-ECG
';
597 fclose(HDR.FILE.FID);