-
Notifications
You must be signed in to change notification settings - Fork 2
/
dsloadfieldsavestate.m
executable file
·195 lines (193 loc) · 6.28 KB
/
dsloadfieldsavestate.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
%function [currds savestate]=dsloadfield(dfnam,currpath,currds,savestate)
%we want this to be a script instead of a function so we don't create duplicates of the ds variable.
%currpath references the parent directory, and currds/savestate reference the parents as well.
% ds=struct();
% savestate=struct();
% nams=cleandir(currpath);
% for(i=1:numel(nams))
% dfnam=nams(i).name;
if('.'==cfnam{1}(1))
%warp seems to generate random nfs file handles
return;
end
for(dslf_idx=1:numel(cfnam))
dfnam=cfnam{dslf_idx};
fpath=[currpath '/' dfnam];
if(exist(fpath,'dir'))
%'got dir'
% if(~all(dfnam(end-1:end)=='[]'))
%struct case
% [tmpds tmpsavestate]=dsload_rec(fpath);
% savestate=setfield(savestate, dfnam, tmpsavestate);
% ds=setfield(ds, dfnam, tmpds);
% else
%cell case
if(dshassuffix(fnam,'img'))
isimg=1;
else
isimg=0;
end
if(dshassuffix(fnam,'html'))
ishtml=1;
else
ishtml=0;
end
if(dshassuffix(fnam,'txt'))
istxt=1;
else
istxt=0;
end
if(dshassuffix(fnam,'fig'))
return;
end
%files=cleandir(fpath);
%nfiles=numel(files);
%idxlist=zeros(nfiles,1);
%for(i=1:nfiles)
% dotpos=find(files(i).name=='.');
% idxlist(i)=str2num(files(i).name(1:(dotpos(1)-1)));
%end
%cellsavest=getfield(savestate,sdfnam);
%tmpcell=cell(size(cellsavest));
%sdfnam=dfnam;%(1:(end-2));
%if(isfield(currds,sdfnam))
% tmpcell2=getfield(currds,sdfnam);
% if(numel(tmpcell)>numel(tmpcell2))
% tmpcell(1:numel(tmpcell2))=tmpcell2;
% else
% tmpcell=tmpcell2;
% end
%end
%if(isfield(savestate,sdfnam)&&~isempty(getfield(savestate,sdfnam)))
% cellsavest2=getfield(savestate,sdfnam);
% cellsavest2=cellsavest2{2};
% cellsavest=zeros(max(max(idxlist),size(cellsavest2,1));
% if(numel(cellsavest)>numel(cellsavest))
% cellsavest(1:numel(cellsavest2))=cellsavest2;
% else
% cellsavest=cellsavest2;
% end
%else
% cellsavest=zeros(max(idxlist),1);
%end
%if(~isempty(brakidx))
% mybrakidx=intersect(brakidx,idxlist);
% mybrakidx=mybrakidx(:)';
%else
% mybrakidx=idxlist(:)';
%end
dslf_cols=cleandir(fpath);
dslf_cols=cellfun(@(x) str2num(x(1:find(x=='.'))),{dslf_cols.name});
if(~isempty(brakidx{2}))
dslf_brakidx{2}=sort(intersect(dslf_cols,brakidx{2}),'descend')
else
dslf_brakidx{2}=sort(dslf_cols,'descend');
end
% for(dslf_k=1:2)
% if(isempty(brakidx{dslf_k}))
% brakidx{dssf_k}=1:size(cellsavest,dssf_k);
% end
% end
%cellsavest=zeros(max(dslf_brakidx{1}),max(dslf_brakidx{2}));
%tic
if(isimg||ishtml||istxt)
cellsavest(dslf_brakidx{2})=true;
else
cellsavest=[];
for(dslf_i=dslf_brakidx{2}(:)')
%dslf_i
%fpath2=[fpath '/' num2str(dslf_i)];
dslf_filnam=[fpath '/' num2str(dslf_i) '.mat'];
%tic
%dslf_cols=cleandir(fpath2);
%toc
contents=[];
try
tic
load(dslf_filnam,'contents');
toc
catch
end
if(isempty(contents))
%it turns out whos loads the whole archive, so this is really
%slow. it isn't used any more; here only for backwards
%compatibility.
%tic
%dslf_vars=whos('-file',dslf_filnam);
%toc
%dslf_rows=cellfun(@(x) str2num(x(5:end)),{dslf_vars.name});
dslf_rows=1;
else
dslf_rows=contents;
end
clear contents;
if(~isempty(brakidx{1}))
dslf_brakidx{1}=sort(intersect(dslf_rows,brakidx{1}),'descend')
else
dslf_brakidx{1}=sort(dslf_rows,'descend');
end
%tic
%dslf_files=cleandir(fpath2);
%toc
%dslf_files={dslf_files.name};
for(dslf_j=dslf_brakidx{1}(:)')
cellsavest(dslf_j,dslf_i)=true;
%if(strcmp(task,'load'))
%if(isimg)
% cellsavest(dslf_i,dslf_j)=ismember(dslf_j,dslf_cols);%(exist([fpath2 '/' num2str(dslf_j) '.jpg'],'file')>0);
%elseif(ishtml)
% cellsavest(dslf_i,dslf_j)=ismember([ num2str(dslf_j) '.html'],dslf_files);%(exist([fpath2 '/' num2str(dslf_j) '.html'],'file')>0);
%else
%[fpath2 '/' num2str(dslf_j) '.mat']
% cellsavest(dslf_i,dslf_j)=ismember([ num2str(dslf_j) '.mat'],dslf_files);%(exist([fpath2 '/' num2str(dslf_j) '.mat'],'file')>0);
%disp('got data')
%keyboard;
%tmpcell{dslf_i,dslf_j}=data;
%end
%end
%cellsavest(i,j)=1;
end
end
end
%toc
% if(strcmp(task,'load'))
%currds=setfield(currds,dfnam,tmpcell);
% end
savestate=setfield(savestate,fnam,{1,cellsavest});
% end
else
%if(dshassuffix(dfnam,'html'))
%if(strcmp(task,'load'))
% data=fileread([currpath '/' dfnam '.html']);
%end
% vnam=dfnam;%(:,1:end-5);
if(dshassuffix(dfnam,'img'))
if(dshassuffix(dfnam(1:end-4),'fig'))
return;
end
%if(strcmp(task,'load'))
% data=imread([currpath '/' dfnam '.jpg']);
%end
%vnam=dfnam;%(:,1:end-4);
%ds=setfield(ds,vnam,data);
%elseif(dshassuffix(dfnam,'fig'))
%continue;
% return
%else
%if(strcmp(task,'load'))
% load([currpath '/' dfnam '.jpg');
%end
% vnam=dfnam;%(:,1:end-4);
%if(strcmp(vnam,'binneighs'))
%keyboard;
%end
%ds=setfield(ds,vnam,data);
%end
%if(strcmp(task,'load'))
% currds=setfield(currds,vnam,data);
end
savestate=setfield(savestate,fnam,true);
end
end
%keyboard;
%end