-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDBfile.m
More file actions
executable file
·73 lines (70 loc) · 2.64 KB
/
PDBfile.m
File metadata and controls
executable file
·73 lines (70 loc) · 2.64 KB
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
% PDBfile stores file details for specified events in PatientDB
classdef PDBfile < handle
properties
name char
path char
type PDBfileType
onset double
offset double
end
methods
function obj = PDBfile()
obj.type = 'unknown';
end
function [filepath, updated] = findLostFile(obj, searchPath, overwrite, ext)
% filepath = findLostFile(searchPath, overwrite)
% search for the filename at the specified path, recursively
% If overwrite == true then it will automatically update the
% field, otherwise it will prompt for confirmation.
% Search path defaults to /storage/patients/
if nargin < 2 || isempty(searchPath)
searchPath = '/storage/patients/';
end
if nargin < 3 || isempty(overwrite)
overwrite = false;
end
if nargin < 4 || isempty(ext)
if obj.type == PDBfileType.both || obj.type == PDBfileType.micros
ext = '.ns5';
else
ext = '.ns3';
end
end
updated = false;
cmd = sprintf('find %s -name "%s" 2>&1 | grep -v "Permission denied"',searchPath,[obj.name ext]);
[v,filepath] = system(cmd);
if v
disp([9 'Response was ' filepath])
error('Problem running system command');
else
filepath = strsplit(filepath,'\n');
filepath = strtrim(filepath{1}); % only keep the first result if many
filepath = fileparts(filepath);
if overwrite
obj.path = filepath;
updated = true;
else
disp([9 'Response was: ' filepath])
g = input([9 9 'Update accordingly? y/N\n'],'s');
if strcmpi(g,'y')
obj.path = filepath;
updated = true;
end
end
end
end
function fn = fullpath(obj, ext)
if nargin < 2 || isempty(ext)
switch obj.type
case {PDBfileType.both, PDBfileType.micros}
ext = 'ns5';
case {PDBfileType.macros, PDBfileType.sync}
ext = 'ns3';
otherwise
error(['Please supply an extension for ' obj.type ' files'])
end
end
fn = [obj.path filesep obj.name '.' ext];
end
end
end