|
565 | 565 | if (~isnumeric(item) && ~islogical(item) && ~ischar(item))
|
566 | 566 | error('input is not an array');
|
567 | 567 | end
|
568 |
| -ws = varargin{1}.whitespaces_; |
| 568 | +opt=varargin{1}; |
| 569 | +ws = opt.whitespaces_; |
569 | 570 | padding1 = repmat(ws.tab, 1, level);
|
570 | 571 | padding0 = repmat(ws.tab, 1, level + 1);
|
571 | 572 | nl = ws.newline;
|
572 | 573 | sep = ws.sep;
|
573 | 574 |
|
574 |
| -dozip = varargin{1}.compression; |
575 |
| -zipsize = varargin{1}.compressarraysize; |
576 |
| -format = varargin{1}.formatversion; |
577 |
| -isnest = varargin{1}.nestarray; |
| 575 | +dozip = opt.compression; |
| 576 | +zipsize = opt.compressarraysize; |
| 577 | +format = opt.formatversion; |
| 578 | +isnest = opt.nestarray; |
578 | 579 |
|
579 |
| -if (~varargin{1}.nosubstruct_ && (((isnest == 0) && length(size(item)) > 2) || issparse(item) || ~isreal(item) || ... |
580 |
| - (isempty(item) && any(size(item))) || varargin{1}.arraytostruct || (~isempty(dozip) && numel(item) > zipsize))) |
| 580 | +if (~opt.nosubstruct_ && (((isnest == 0) && length(size(item)) > 2) || issparse(item) || ~isreal(item) || ... |
| 581 | + (isempty(item) && any(size(item))) || opt.arraytostruct || (~isempty(dozip) && numel(item) > zipsize))) |
581 | 582 | if (isempty(name))
|
582 | 583 | txt = sprintf('%s{%s%s"_ArrayType_":"%s",%s%s"_ArraySize_":%s,%s', ...
|
583 | 584 | padding1, nl, padding0, class(item), nl, padding0, regexprep(mat2str(size(item)), '\s+', ','), nl);
|
584 | 585 | else
|
585 | 586 | txt = sprintf('%s"%s":{%s%s"_ArrayType_":"%s",%s%s"_ArraySize_":%s,%s', ...
|
586 |
| - padding1, decodevarname(name, varargin{1}.unpackhex), nl, padding0, class(item), nl, padding0, regexprep(mat2str(size(item)), '\s+', ','), nl); |
| 587 | + padding1, decodevarname(name, opt.unpackhex), nl, padding0, class(item), nl, padding0, regexprep(mat2str(size(item)), '\s+', ','), nl); |
587 | 588 | end
|
588 | 589 | else
|
589 | 590 | numtxt = matdata2json(item, level + 1, varargin{:});
|
590 | 591 | if (isempty(name))
|
591 | 592 | txt = sprintf('%s%s', padding1, numtxt);
|
592 | 593 | else
|
593 | 594 | if (numel(item) == 1 && varargin{1}.singletarray == 0)
|
594 |
| - txt = sprintf('%s"%s":%s', padding1, decodevarname(name, varargin{1}.unpackhex), numtxt); |
| 595 | + txt = sprintf('%s"%s":%s', padding1, decodevarname(name, opt.unpackhex), numtxt); |
595 | 596 | else
|
596 |
| - txt = sprintf('%s"%s":%s', padding1, decodevarname(name, varargin{1}.unpackhex), numtxt); |
| 597 | + txt = sprintf('%s"%s":%s', padding1, decodevarname(name, opt.unpackhex), numtxt); |
597 | 598 | end
|
598 | 599 | end
|
599 | 600 | return
|
|
659 | 660 | end
|
660 | 661 | txt = sprintf(dataformat, txt, padding0, '"_ArrayZipSize_":', regexprep(mat2str(size(fulldata)), '\s+', ','), sep);
|
661 | 662 | txt = sprintf(dataformat, txt, padding0, '"_ArrayZipType_":"', dozip, ['"' sep]);
|
662 |
| - compfun = str2func([dozip 'encode']); |
663 |
| - txt = sprintf(dataformat, txt, padding0, '"_ArrayZipData_":"', char(base64encode(compfun(typecast(fulldata(:), 'uint8')))), ['"' nl]); |
| 663 | + encodeparam={}; |
| 664 | + if(~isempty(regexp(dozip,'^blosc2', 'once'))) |
| 665 | + compfun=@blosc2encode; |
| 666 | + encodeparam={dozip, 'nthread', jsonopt('nthread',1,opt), 'shuffle', jsonopt('shuffle',1,opt), 'typesize', jsonopt('typesize',length(typecast(fulldata(1),'uint8')),opt)}; |
| 667 | + else |
| 668 | + compfun=str2func([dozip 'encode']); |
| 669 | + end |
| 670 | + txt = sprintf(dataformat, txt, padding0, '"_ArrayZipData_":"', char(base64encode(compfun(typecast(fulldata(:), 'uint8'),encodeparam{:}))), ['"' nl]); |
664 | 671 | else
|
665 | 672 | if (isreal(item))
|
666 | 673 | txt = sprintf(dataformat, txt, padding0, '"_ArrayData_":', ...
|
|
0 commit comments