|
42 | 42 | % arrays; setting to 3 will return to a 2D cell |
43 | 43 | % array of 1D vectors; setting to 4 will return a |
44 | 44 | % 3D cell array. |
| 45 | +% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar. |
| 46 | +% |
45 | 47 | % output: |
46 | 48 | % dat: a cell array, where {...} blocks are converted into cell arrays, |
47 | 49 | % and [...] are converted to arrays |
|
76 | 78 | index_esc = 1; len_esc = length(esc); |
77 | 79 |
|
78 | 80 | opt=varargin2struct(varargin{:}); |
| 81 | + |
| 82 | +if(jsonopt('ShowProgress',0,opt)==1) |
| 83 | + opt.progressbar_=waitbar(0,'loading ...'); |
| 84 | +end |
79 | 85 | jsoncount=1; |
80 | 86 | while pos <= len |
81 | 87 | switch(next_char) |
|
101 | 107 | data=jcell2array(data); |
102 | 108 | end |
103 | 109 | end |
104 | | - |
| 110 | +if(isfield(opt,'progressbar_')) |
| 111 | + close(opt.progressbar_); |
| 112 | +end |
105 | 113 |
|
106 | 114 | %% |
107 | 115 | function newdata=jcell2array(data) |
|
206 | 214 | object = cell(0, 1); |
207 | 215 | dim2=[]; |
208 | 216 | arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:}); |
| 217 | + pbar=jsonopt('progressbar_',-1,varargin{:}); |
| 218 | + |
209 | 219 | if next_char ~= ']' |
210 | 220 | if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:})) |
211 | 221 | [endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos); |
|
246 | 256 | object=reshape(obj,dim2,numel(obj)/dim2)'; |
247 | 257 | pos=endpos; |
248 | 258 | parse_char(']'); |
| 259 | + if(pbar>0) |
| 260 | + waitbar(pos/length(inStr),pbar,'loading ...'); |
| 261 | + end |
249 | 262 | return; |
250 | 263 | end |
251 | 264 | end |
|
284 | 297 | end |
285 | 298 | end |
286 | 299 | parse_char(']'); |
287 | | - |
| 300 | + |
| 301 | + if(pbar>0) |
| 302 | + waitbar(pos/length(inStr),pbar,'loading ...'); |
| 303 | + end |
288 | 304 | %%------------------------------------------------------------------------- |
289 | 305 |
|
290 | 306 | function parse_char(c) |
@@ -400,7 +416,12 @@ function parse_char(c) |
400 | 416 | function val = parse_value(varargin) |
401 | 417 | global pos inStr len |
402 | 418 | 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 | + |
404 | 425 | switch(inStr(pos)) |
405 | 426 | case '"' |
406 | 427 | val = parseStr(varargin{:}); |
|
0 commit comments