Skip to content

Commit 44623f4

Browse files
committed
Improved handling of unknown codes in file header
1 parent 13e4433 commit 44623f4

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

load_datx.m

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,28 @@
174174
end
175175

176176
resolutionMap = containers.Map({0, 1, 2}, {2, 4, 8});
177-
Metadata.resolution = resolutionMap(resolutionByte);
177+
try
178+
Metadata.resolution = resolutionMap(resolutionByte);
179+
catch ME
180+
if strcmp(ME.identifier, 'MATLAB:Containers:Map:NoKey')
181+
Metadata.resolution = ['Unknown (' num2str(resolutionByte) ')'];
182+
else
183+
rethrow(ME);
184+
end
185+
end
178186

179187
Metadata.hz = header(36);
180188

181189
axesMap = containers.Map({0, 1}, {3, 1});
182-
Metadata.axes = axesMap(header(281));
190+
try
191+
Metadata.axes = axesMap(header(281));
192+
catch ME
193+
if strcmp(ME.identifier, 'MATLAB:Containers:Map:NoKey')
194+
Metadata.axes = ['Unknown (' num2str(header(281)) ')'];
195+
else
196+
rethrow(ME);
197+
end
198+
end
183199

184200
Metadata.startTime = datetime( uint64(header(262)) + 2000, header(261), ...
185201
header(260), header(257), header(258), ...
@@ -193,12 +209,28 @@
193209

194210
startConditionMap = containers.Map( {0, 1, 2}, ...
195211
{'Trigger', 'Immediately', 'Set Time'} );
196-
Metadata.startCondition = startConditionMap(header(269));
212+
try
213+
Metadata.startCondition = startConditionMap(header(269));
214+
catch ME
215+
if strcmp(ME.identifier, 'MATLAB:Containers:Map:NoKey')
216+
Metadata.startCondition = ['Unknown (' num2str(header(269)) ')'];
217+
else
218+
rethrow(ME);
219+
end
220+
end
197221

198222
stopConditionMap = containers.Map( {0, 3, 64, 128}, ...
199223
{'Memory Full', 'Low Battery', 'USB', ...
200224
'Programmed Time'} );
201-
Metadata.stopCondition = stopConditionMap(header(276));
225+
try
226+
Metadata.stopCondition = stopConditionMap(header(276));
227+
catch ME
228+
if strcmp(ME.identifier, 'MATLAB:Containers:Map:NoKey')
229+
Metadata.stopCondition = ['Unknown (' num2str(header(276)) ')'];
230+
else
231+
rethrow(ME);
232+
end
233+
end
202234
end
203235

204236

0 commit comments

Comments
 (0)