-
Notifications
You must be signed in to change notification settings - Fork 2
/
dsdiskpath.m
executable file
·114 lines (114 loc) · 3.24 KB
/
dsdiskpath.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
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
function [dpath, fileexists, type,savestate]=dsdiskpath(dsvar, createdir, assumetype)
global ds;
dpath=[];
fileexists=0;
type=[];
savestate=[];
[dsvar,brakidx]=dssplitmatchstr(dsvar);
if(numel(brakidx{2})>1 || ~isempty(brakidx{1}))
error(['cannot get disk path of variable indexed as ' dsvar(1:min(numel(dsvar),100))]);
end
abspath=dsabspath(dsvar);
savestp=['ds.sys.savestate' abspath(4:end)];
fileexists=dsfield(savestp);
%sptrexist=fileexists;
if(fileexists)
savestate=eval(savestp);
end
if(~fileexists)
if(nargin>1&&createdir>0)
fpath=ds.sys.outdir;
ptr=ds.sys.root;
sptr=ds.sys.savestate;
builtnm='';
flist=regexp(abspath(5:end),'\.','split');
for(i=1:numel(flist))
if(mystrcmp(builtnm,ds.sys.currpath))
ptr=ds;
end
if(isfield(ptr,flist{i}))
builtnm=[builtnm '.' flist{i}];
if(~isfield(sptr,flist{i}))
%sptrexist=0;
if(i<numel(flist)||createdir>1)
eval(['ds.sys.savestate' builtnm '=struct()']);
fpath=[fpath '/' flist{i}];
mymkdir(fpath);
end
sptr=struct();
else
sptr=getfield(sptr,flist{i});
end
ptr=getfield(ptr,flist{i});
else
clear ptr;
break;
end
end
end
end
dotpos=find(abspath=='.');
varnm=abspath((dotpos(end)+1):end);
locdirpath=abspath;
locdirpath=locdirpath(1:(dotpos(end)));
locdirpath(locdirpath=='.')='/';
dirpath=[ds.sys.outdir locdirpath];
if(exist('assumetype','var'))
type=assumetype;
elseif(exist('ptr','var'))
type=dsgettypeforvar(ptr,varnm);
elseif(fileexists)
type=dsgettypeforvar(eval(savestp),varnm);
else
%else the file doesn't exist on disk and createdir couldn't/didn't infer it
return;
end
if(strcmp(type,'cell')&&~isempty(brakidx{2}))
dpath={};
realtype=dsgettypeforvar([],varnm);
varnm2=dsgetdisknamtype(varnm,type,dirpath);
varnm2=varnm2{1};%can only be one name for a cell
for(i=1:numel(brakidx{2}))
dpath=[dpath dsgetdisknamtype([varnm2 '/' num2str(brakidx{2}(i))],realtype,'')];
end
else
dpath=dsgetdisknamtype(varnm,type,dirpath);
end
%varfromds=dsfindvar(abspath);
end
%function [type] =gettypeforvar(var,varnm)
% if(iscell(var))
% type='cell';
% elseif(isstruct(var))
% type='struct';
% elseif(dshassuffix(varnm,'img'))
% type='img';
% elseif(dshassuffix(varnm,'fig'))
% type='fig';
% elseif(dshassuffix(varnm,'html'))
% type='html';
% elseif(dshassuffix(varnm,'txt'))
% dotpos=find(varnm=='_');
% type=varnm((dotpos(end)+1):end);
% else
% type='mat';
% end
%end
%function disknams=getdisknam(varnm,type,dirpath)
% switch(type)
% case('cell')
% disknams={[dirpath varnm '[]']};
% case('struct')
% disknams={[dirpath varnm]};
% case('img')
% disknams={[dirpath varnm '.jpg']};
% case('fig')
% disknams={[dirpath varnm '.jpg'], [dirpath varnm '.pdf']};
% case('html')
% disknams={[dirpath varnm '.html']};
% case('mat')
% disknams={[dirpath varnm '.mat']};
% otherwise
% disknam={[dirpath varnm '.' type(1:end-3)]};
% end
%end