Skip to content

Commit 011589d

Browse files
author
fangq
committed
show progress bar in loadjson
git-svn-id: http://svn.code.sf.net/p/iso2mesh/code/trunk/jsonlab@452 786e58fb-9377-0410-9ff7-e4ac0ac0635c
1 parent 5c66474 commit 011589d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

loadjson.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
% arrays; setting to 3 will return to a 2D cell
4343
% array of 1D vectors; setting to 4 will return a
4444
% 3D cell array.
45+
% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
46+
%
4547
% output:
4648
% dat: a cell array, where {...} blocks are converted into cell arrays,
4749
% and [...] are converted to arrays
@@ -76,6 +78,10 @@
7678
index_esc = 1; len_esc = length(esc);
7779

7880
opt=varargin2struct(varargin{:});
81+
82+
if(jsonopt('ShowProgress',0,opt)==1)
83+
opt.progressbar_=waitbar(0,'loading ...');
84+
end
7985
jsoncount=1;
8086
while pos <= len
8187
switch(next_char)
@@ -101,7 +107,9 @@
101107
data=jcell2array(data);
102108
end
103109
end
104-
110+
if(isfield(opt,'progressbar_'))
111+
close(opt.progressbar_);
112+
end
105113

106114
%%
107115
function newdata=jcell2array(data)
@@ -206,6 +214,8 @@
206214
object = cell(0, 1);
207215
dim2=[];
208216
arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:});
217+
pbar=jsonopt('progressbar_',-1,varargin{:});
218+
209219
if next_char ~= ']'
210220
if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
211221
[endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos);
@@ -246,6 +256,9 @@
246256
object=reshape(obj,dim2,numel(obj)/dim2)';
247257
pos=endpos;
248258
parse_char(']');
259+
if(pbar>0)
260+
waitbar(pos/length(inStr),pbar,'loading ...');
261+
end
249262
return;
250263
end
251264
end
@@ -284,7 +297,10 @@
284297
end
285298
end
286299
parse_char(']');
287-
300+
301+
if(pbar>0)
302+
waitbar(pos/length(inStr),pbar,'loading ...');
303+
end
288304
%%-------------------------------------------------------------------------
289305

290306
function parse_char(c)
@@ -400,7 +416,12 @@ function parse_char(c)
400416
function val = parse_value(varargin)
401417
global pos inStr len
402418
true = 1; false = 0;
403-
419+
420+
pbar=jsonopt('progressbar_',-1,varargin{:});
421+
if(pbar>0)
422+
waitbar(pos/len,pbar,'loading ...');
423+
end
424+
404425
switch(inStr(pos))
405426
case '"'
406427
val = parseStr(varargin{:});

0 commit comments

Comments
 (0)