-
Notifications
You must be signed in to change notification settings - Fork 2
/
dsloadfield.m
executable file
·180 lines (175 loc) · 6.53 KB
/
dsloadfield.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
function [currds savestate]=dsloadfield(fnam,currpath,currds,savestate,task,brakidx,reduceload)
dfnam=fnam;% {dslf_idx};
fpath=[currpath '/' dfnam '[]'];
if(reduceload)
global ds;
if(dsfield(ds,'sys','distproc','localdir'))
fpath(1:numel(ds.sys.outdir))=[];
%fpath=strrep(fpath,'\','\\');
fpath=strrep(fpath(2:end),'/','.');
fpath=[ds.sys.distproc.localdir fpath];
else
reduceload=0;
end
end
cellsavest=getfield(savestate,dfnam);
if(iscell(cellsavest))
if(dshassuffix(dfnam,'img'))
isimg=1;
else
isimg=0;
end
ispng=dshassuffix(dfnam,'png');
if(dshassuffix(dfnam,'html'))
ishtml=1;
else
ishtml=0;
end
if(dshassuffix(dfnam,'txt'))
istxt=1;
else
istxt=0;
end
if(dshassuffix(dfnam,'fig'))
return;
end
if(numel(cellsavest)>=2)
cellsavest=cellsavest{2};
else
currds=setfield(currds,fnam,[]);
return;
end
for(dssf_k=1:2)
if(isempty(brakidx{dssf_k}))
dslf_brakidx{dssf_k}=1:size(cellsavest,dssf_k);
else
dslf_brakidx{dssf_k}=brakidx{dssf_k};
end
if(isempty(dslf_brakidx{dssf_k}))
bkidxsz(dssf_k)=0;
else
bkidxsz(dssf_k)=max(dslf_brakidx{dssf_k});
end
end
%uncomment these lines
if(isfield(currds,dfnam))
tmpcell2=getfield(currds,dfnam);
tmpcell=cell(max(bkidxsz,max(size(cellsavest),size(tmpcell2))));
tmpcell(1:size(tmpcell2,1),1:size(tmpcell2,2))=tmpcell2;
tmpcell2=[];
%if(strcmp(task,'load'))%not force; check what's already loaded
%cellsavest=cellsavest.*cellfun(@(x) isempty(x),tmpcell,'UniformOutput',true);%doing it this way breaks transparency somehow
% keyboard;
% for(i=1:min(numel(tmpcell),numel(cellsavest)))
% cellsavest(i)=cellsavest(i).*isempty(tmpcell{i});
% end
%end
else
tmpcell=cell(size(cellsavest));
%and this one
end
dslf_brakidx_1=dslf_brakidx{1};
dslf_brakidx_1(dslf_brakidx_1>size(cellsavest,1))=[];
dslf_brakidx{2}(dslf_brakidx{2}>size(cellsavest,2))=[];
%madechanges=0;
for(dslf_i=dslf_brakidx{2}(:)')
dslf_isect=dslf_brakidx_1(cellsavest(dslf_brakidx_1,dslf_i)~=0);
if(isimg||ishtml||istxt||ispng)
if((~isempty(dslf_isect))&&(strcmp(task,'forceload')||isempty(tmpcell{1,dslf_i})))
if(isimg)
tmpcell{1,dslf_i}=imread([fpath '/' num2str(dslf_i) '.jpg']);
elseif(ispng)
tmpcell{1,dslf_i}=dsloadpng([fpath '/' num2str(dslf_i) '.png']);
elseif(ishtml)
tmpcell{1,dslf_i}=fileread([fpath '/' num2str(dslf_i) '.html']);
elseif(istxt)
dotpos3=find(dfnam=='_');
type=varnm((dotpos3(end)+1):end);
tmpcell{1,dslf_i}=fileread([fpath '/' num2str(dslf_i) type(1:(end-3))]);
end
end
else
if(strcmp(task,'load'))
%disp('summarizing')
%keyboard;
dslf_empty=[];
for(dslf_j=1:numel(dslf_isect))
dslf_empty(dslf_j)=~isempty(tmpcell{dslf_isect(dslf_j),dslf_i});
end
dslf_isect(dslf_empty==1)=[];
%keyboard;
end
dslf_vars=[];
dslf_varnq='';
dslf_inds='';
for(dslf_j=dslf_isect(:)')
%if(size(dslf_vars,2)==0)
% dslf_vars=['''data' num2str(dslf_j) ''''];
%else
dslf_vars{end+1}=['data' num2str(dslf_j) ];
%end
dslf_inds=[dslf_inds ' ' num2str(dslf_j)];
dslf_varnq=[dslf_varnq ' data' num2str(dslf_j)];
end
if(numel(dslf_vars)>0)
if(reduceload)
[mypos]=mod(dslf_j-1,numel(ds.sys.distproc.reducehosts))+1; %ismember(ds.sys.distproc.mapreducerid,ds.sys.distproc.reducehosts);
loadfnam=[fpath '~' num2str(dslf_i) '~' num2str(mypos) '.mat'];
disp(['load(' loadfnam ',' dslf_vars{:} ')']);
%while(~exist(loadfnam,'file'))%since this got transferred over ssh rather than through
%shared disk, it's not synchronized.
% pause(1);
%end
success=0;
while(~success)
try
load(loadfnam,dslf_vars{:});
catch
disp('load failed. retrying in 1 sec...');
pause(1);
continue;
end
success=1;
end
else
loadfnam=[fpath '/' num2str(dslf_i) '.mat'];
tic
load(loadfnam,dslf_vars{:});
toc
end
%tic
%if(toc>5),keyboard;end
eval(['tmpcell([' dslf_inds '],' num2str(dslf_i) ')={' dslf_varnq '};']);%in theory this could be done with struct2cell, but
%I'm not sure save() preserves field order.
clear(dslf_vars{:});
%madechanges=1;
end
end
end
%if(madechanges)
%disp('setfield');
currds=setfield(currds,dfnam,tmpcell);
%end
else
if(strcmp(task,'forceload')||~isfield(currds,dfnam)||isempty(getfield(currds,dfnam)))
disknam=dsgetdisknam(getfield(savestate,dfnam),dfnam,[currpath '/']);
if(dshassuffix(dfnam,'html')||dshassuffix(dfnam,'txt'))
data=fileread(disknam{1});%[currpath '/' dfnam '.html']);
vnam=dfnam;%(:,1:end-5);
elseif(dshassuffix(dfnam,'img'))
data=imread(disknam{1});%[currpath '/' dfnam '.jpg']);
vnam=dfnam;%(:,1:end-4);
elseif(dshassuffix(dfnam,'png'))
data=dsloadpng(disknam{1});%[currpath '/' dfnam '.jpg']);
vnam=dfnam;%(:,1:end-4);
elseif(dshassuffix(dfnam,'fig'))
return
else
load(disknam{1});%[currpath '/' dfnam '.mat']);
vnam=dfnam;%(:,1:end-4);
end
currds=setfield(currds,vnam,data);
clear data;
savestate=setfield(savestate,vnam,1);
end
end