-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadThd.m
57 lines (54 loc) · 1.94 KB
/
readThd.m
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
classdef readThd < handle
% Class used for reading and containing thd-lifeitme data
properties
AbsoluteFileName
Title
Date
Type
Solvent
Concentration
Compound
Replicate
Info
Data
end
methods
function obj = readThd(AbsoluteFileName)
% Ask for file, if none is provided
if ~exist('AbsoluteFileName', 'var')
[File, Path] = uigetfile('*.thd', 'Please Select Data to Import');
AbsoluteFileName = fullfile(Path, File);
end
obj.AbsoluteFileName = AbsoluteFileName;
obj.readInfoFromFileName()
obj.importData()
end
function readInfoFromFileName(obj)
[~, FileName, ~] = fileparts(obj.AbsoluteFileName);
obj.Title = FileName;
[obj.Date, obj.Replicate, obj.Type, obj.Solvent, obj.Concentration, obj.Compound] = readInformationFromFileName(obj.Title);
end
function importData(obj)
% Read binary data from hdd
fid = fopen(obj.AbsoluteFileName);
BinaryData = fread(fid);
fclose(fid);
% Determine hardware
Offset = 0;
SectionLength = 16;
Idx = (Offset+1):(Offset+1)+(SectionLength-1); % converting to matlab index
Hardware = BinaryData(Idx);
Hardware = Hardware(Hardware ~= 0);
Hardware = native2unicode(Hardware);
obj.Info.Hardware = Hardware';
% Determine version
Offset = 16;
SectionLength = 6;
Idx = (Offset+1):(Offset+1)+(SectionLength-1);
Version = BinaryData(Idx);
Version = Version(Version ~= 0);
Version = native2unicode(Version);
obj.Info.Version = Version';
end
end
end