Skip to content

Commit 0ccb658

Browse files
committed
sync jnifty and jsonlab to the latest github version
1 parent 70baeb6 commit 0ccb658

21 files changed

+266
-122
lines changed

barydualmesh.m

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
%
2626

2727
[enodes,eidx]=highordertet(node,elem); % compute edge-centers
28+
29+
if(size(elem,2)==3)
30+
fnodes=meshcentroid(node,elem); % compute face-centers
31+
fidx=1:
32+
newnode=[enodes;fnodes];
33+
newidx=[eidx, fidx+size(enodes,1), (1:size(elem,1))'+(size(enodes,1)+size(fnodes,1))];
34+
return;
35+
end
36+
2837
[fnodes,fidx]=elemfacecenter(node,elem); % compute face-centers
2938
c0=meshcentroid(node,elem(:,1:min(size(elem,2),4))); % compute elem-centers
3039

decodevarname.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
% decodevarname('a_') % returns a_ as it is a valid variable name
2626
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
2727
%
28-
% this file is part of EasyH5 Toolbox: https://github.com/fangq/easyh5
28+
% this file is part of EasyH5 Toolbox: https://github.com/NeuroJSON/easyh5
2929
%
30-
% License: GPLv3 or 3-clause BSD license, see https://github.com/fangq/easyh5 for details
30+
% License: GPLv3 or 3-clause BSD license, see https://github.com/NeuroJSON/easyh5 for details
3131
%
3232

3333
newname=name;

encodevarname.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
% encodevarname('a_') % returns a_ as it is a valid variable name
3333
% encodevarname('变量') % returns 'x0xE58F98__0xE9878F_'
3434
%
35-
% this file is part of EasyH5 Toolbox: https://github.com/fangq/easyh5
35+
% this file is part of EasyH5 Toolbox: https://github.com/NeuroJSON/easyh5
3636
%
37-
% License: GPLv3 or 3-clause BSD license, see https://github.com/fangq/easyh5 for details
37+
% License: GPLv3 or 3-clause BSD license, see https://github.com/NeuroJSON/easyh5 for details
3838
%
3939

4040
if(~isvarname(str(1)))

filterjsonmmap.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
% str='{"arr":[[1,2],"a",{"c":2}],"obj":{"k":"test"}}';
2424
% [dat, mmap]=loadjson(str);
2525
% savejson('',mmap)
26-
% newmmap=filterjsonmmap(mmap,{'arr.[1]', 'obj.k'});
26+
% newmmap=filterjsonmmap(mmap,{'arr[1]', 'obj.k'});
2727
% savejson('',newmmap)
2828
%
2929
% license:

getfromjsonpath.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
% obj: if the specified element exist, obj returns the result
1515
%
1616
% example:
17-
% getfromjsonpath(struct('a',[1,2,3]), '$.a.[1]') % returns 2
17+
% getfromjsonpath(struct('a',[1,2,3]), '$.a[1]') % returns 2
1818
%
1919
% license:
2020
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
@@ -23,6 +23,7 @@
2323
%
2424

2525
obj=root;
26+
jsonpath=regexprep(jsonpath,'([^.])(\[\d+\])','$1.$2');
2627
[pat,paths]=regexp(jsonpath,'\.*([^\s\.]+)\.*','match','tokens');
2728
if(~isempty(pat) && ~isempty(paths))
2829
for i=1:length(paths)

highordertet.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
if(order>=3 || order<=1)
3232
error('currently this function only supports order=2');
3333
end
34-
[edges,idx,newelem]=uniqedges(elem(:,1:4));
34+
[edges,idx,newelem]=uniqedges(elem(:,1:min(size(elem,2),4)));
3535
newnode=node(edges',1:3);
3636
newnode=reshape(newnode',[3,2,size(edges,1)]);
3737
newnode=squeeze(mean(permute(newnode,[3 2 1]),2));

jdatadecode.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
% jsondecode for MATLAB R2016b or later)
88
%
99
% This function implements the JData Specification Draft 3 (Jun. 2020)
10-
% see http://github.com/fangq/jdata for details
10+
% see http://github.com/NeuroJSON/jdata for details
1111
%
1212
% authors:Qianqian Fang (q.fang <at> neu.edu)
1313
%

jdataencode.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
% jdata=jdataencode(data, 'Param1',value1, 'Param2',value2,...)
77
%
88
% Annotate a MATLAB struct or cell array into a JData-compliant data
9-
% structure as defined in the JData spec: http://github.com/fangq/jdata.
9+
% structure as defined in the JData spec: http://github.com/NeuroJSON/jdata.
1010
% This encoded form servers as an intermediate format that allows unambiguous
1111
% storage, exchange of complex data structures and easy-to-serialize by
1212
% json encoders such as savejson and jsonencode (MATLAB R2016b or newer)
1313
%
1414
% This function implements the JData Specification Draft 3 (Jun. 2020)
15-
% see http://github.com/fangq/jdata for details
15+
% see http://github.com/NeuroJSON/jdata for details
1616
%
1717
% author: Qianqian Fang (q.fang <at> neu.edu)
1818
%
@@ -139,12 +139,14 @@
139139
newitem=cell2mat(newitem);
140140
catch
141141
end
142-
else % a single struct
142+
elseif(num==1) % a single struct
143143
names=fieldnames(item);
144144
newitem=struct;
145145
for i=1:length(names)
146146
newitem.(names{i})=obj2jd(item.(names{i}),varargin{:});
147147
end
148+
else
149+
newitem=item;
148150
end
149151

150152
%%-------------------------------------------------------------------------

jdatahash.m

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function key = jdatahash(data, algorithm, varargin)
2+
%
3+
% key = jdatahash(data)
4+
% or
5+
% key = jdatahash(data, algorithm)
6+
% key = jdatahash(data, algorithm, 'param1', value1, ...)
7+
%
8+
% computing the hash key for a string or a numeric array (data elements
9+
% are serialized in the row-major order first)
10+
%
11+
% author: Qianqian Fang (q.fang <at> neu.edu)
12+
%
13+
% input:
14+
% data: a string or a numeric array
15+
% algorithm: a string denoting the data hashing algorithm (case
16+
% insensitive); default is 'sha-256'; supported options include
17+
%
18+
% for both MATLAB/Octave: 'sha-256' (default), 'sha-1' ,'sha-384', 'sha-512', 'md2', 'md5'
19+
% Octave-only: 'md4'
20+
%
21+
% examples:
22+
% sha256key = jdatahash('neurojson')
23+
% md5key = jdatahash('reusable data', 'md5')
24+
%
25+
% license:
26+
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
27+
%
28+
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
29+
%
30+
31+
if(nargin < 2)
32+
algorithm = 'sha-256';
33+
end
34+
35+
if (ischar(data))
36+
data = uint8(data);
37+
end
38+
39+
opt=varargin2struct(varargin{:});
40+
41+
if(jsonopt('rowmajor', 1, opt))
42+
data = permute(data, ndims(data):-1:1);
43+
end
44+
45+
if(isoctavemesh && exist('hash'))
46+
algorithm(algorithm=='-')=[];
47+
key = hash(algorithm, char(typecast(data(:).', 'uint8')));
48+
else
49+
md = java.security.MessageDigest.getInstance(algorithm);
50+
key = sprintf('%2.2x', typecast(md.digest(typecast(data(:), 'uint8')), 'uint8')');
51+
end

jload.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
end
7878
header=jsondecode(jsonstr(1:pos+1));
7979
else
80-
header=loadfun(filename,'ObjectID',1, varargin{:});
80+
try
81+
header=loadfun(filename,'ObjectID',1, 'MaxBuffer', 65536, varargin{:});
82+
catch
83+
header=loadfun(filename,'ObjectID',1, varargin{:});
84+
end
8185
end
8286

8387
allvar=fieldnames(header.WorkspaceHeader);

jsonget.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
% str='[[1,2],"a",{"c":2}]{"k":"test"}';
2525
% [dat, mmap]=loadjson(str);
2626
% savejson('',dat,'filename','mydata.json','compact',1);
27-
% json=jsonget(str,mmap,'$.[0]','$.[2].c')
28-
% json=jsonget('mydata.json',mmap,'$.[0]','$.[2].c')
27+
% json=jsonget(str,mmap,'$[0]','$[2].c')
28+
% json=jsonget('mydata.json',mmap,'$[0]','$[2].c')
2929
%
3030
% license:
3131
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
@@ -63,7 +63,7 @@
6363

6464
if(isstruct(fname) || iscell(fname) || isa(fname,'table') || isa(fname,'containers.Map'))
6565
for i=1:length(keylist)
66-
json{end+1}=getobjfrompath(fname,keylist{i});
66+
json{end+1}=getfromjsonpath(fname,keylist{i});
6767
end
6868
if(length(json)==1)
6969
json=json{1};

jsonset.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
% % display mmap entries
3232
% savejson('',mmap)
3333
% % replace value using mmap
34-
% json=jsonset(str,mmap,'$.arr.[2].c','5')
34+
% json=jsonset(str,mmap,'$.arr[2].c','5')
3535
% % save same json string to file (must set savebinary 1)
3636
% savejson('',d,'filename','file.json','compact',1,'savebinary',1);
3737
% % fast write to file
38-
% json=jsonset('file.json',mmap,'$.arr.[2].c','5')
38+
% json=jsonset('file.json',mmap,'$.arr[2].c','5')
3939
%
4040
% license:
4141
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

loadbj.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
% of the stream, and length is the JSON object string length.
7979
% For more details, please see the help section of loadjson.m
8080
%
81+
% The format of the mmap table retruned from this function
82+
% follows the JSON-Mmap Specification Draft 1 [3] defined by the
83+
% NeuroJSON project, see https://neurojson.org/jsonmmap/draft1/
84+
%
8185
% examples:
8286
% obj=struct('string','value','array',[1 2 3]);
8387
% ubjdata=savebj('obj',obj);
@@ -91,9 +95,11 @@
9195
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
9296
%
9397

98+
opt=varargin2struct(varargin{:});
99+
94100
if(length(fname)<4096 && exist(fname,'file'))
95101
fid = fopen(fname,'rb');
96-
string = fread(fid,inf,'uint8=>char')';
102+
string = fread(fid,jsonopt('MaxBuffer',inf,opt),'uint8=>char')';
97103
fclose(fid);
98104
elseif(regexp(fname, '^\s*[\[\{SCHiUIulmLMhdDTFZN]'))
99105
string=fname;
@@ -105,7 +111,6 @@
105111
inputlen = length(string);
106112
inputstr = string;
107113

108-
opt=varargin2struct(varargin{:});
109114
opt.simplifycell=jsonopt('SimplifyCell',1,opt);
110115
opt.simplifycellarray=jsonopt('SimplifyCellArray',0,opt);
111116
opt.usemap=jsonopt('UseMap',0,opt);
@@ -276,7 +281,7 @@
276281
if cc ~= ']'
277282
while 1
278283
if(nargout>2)
279-
varargin{1}.jsonpath_=[origpath '.' sprintf('[%d]',length(object))];
284+
varargin{1}.jsonpath_=[origpath sprintf('[%d]',length(object))];
280285
mmap{end+1}={varargin{1}.jsonpath_, pos};
281286
[val, pos, newmmap] = parse_value(inputstr, pos, [], varargin{:});
282287
mmap{end}{2}=[mmap{end}{2}, pos-mmap{end}{2}];

loadjd.m

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
%
1313
% input:
1414
% inputfile: the input hierarchical container data file, supporting:
15-
% *.json,.jnii,.jdt,.jmsh,.jnirs: JSON/JData based data files, see http://neurojson.org/jdata/draft2
16-
% *.bjd,.bnii,.jdb,.bmsh,.bnirs: binary JData (BJData) files, see http://neurojson.org/bjdata/draft2
15+
% *.json,.jnii,.jdt,.jmsh,.jnirs,.jbids: JSON/JData based data files, see https://neurojson.org/jdata/draft2
16+
% *.bjd,.bnii,.jdb,.bmsh,.bnirs: binary JData (BJData) files, see https://neurojson.org/bjdata/draft2
1717
% *.ubj: UBJSON-encoded files, see http://ubjson.org
1818
% *.msgpack: MessagePack-encoded files, see http://msgpack.org
1919
% *.h5,.hdf5,.snirf: HDF5 files, see https://www.hdfgroup.org/
2020
% options: (optional) for JSON/JData files, these are optional 'param',value pairs
2121
% supported by loadjson.m; for BJData/UBJSON/MessagePack files, these are
2222
% options supported by loadbj.m; for HDF5 files, these are options
23-
% supported by loadh5.m (part of EasyH5 toolbox, http://github.com/fangq/easyh5/)
23+
% supported by loadh5.m (part of EasyH5 toolbox, http://github.com/NeuroJSON/easyh5/)
2424
%
2525
% output:
2626
% data: a structure (array) or cell (array) storing the hierarchical data
@@ -43,19 +43,19 @@
4343
error('you must provide file name');
4444
end
4545

46-
if(regexpi(filename,'\.json$|\.jnii$\.jdt$\.jdat$|\.jmsh$|\.jnirs$'))
46+
if(regexpi(filename,'\.json$|\.jnii$|\.jdt$|\.jdat$|\.jmsh$|\.jnirs|\.jbids$'))
4747
[varargout{1:nargout}]=loadjson(filename,varargin{:});
48-
elseif(regexpi(filename,'\.bjd$|\.bnii$\.jdb$\.jbat$|\.bmsh$|\.bnirs$'))
48+
elseif(regexpi(filename,'\.bjd$|\.bnii$|\.jdb$|\.jbat$|\.bmsh$|\.bnirs$'))
4949
[varargout{1:nargout}]=loadbj(filename,varargin{:});
5050
elseif(regexpi(filename,'\.ubj$'))
5151
[varargout{1:nargout}]=loadubjson(filename,varargin{:});
5252
elseif(regexpi(filename,'\.msgpack$'))
5353
[varargout{1:nargout}]=loadmsgpack(filename,varargin{:});
5454
elseif(regexpi(filename,'\.h5$|\.hdf5$|\.snirf$'))
5555
if(~exist('loadh5','file'))
56-
error('you must first install EasyH5 from http://github.com/fangq/easyh5/');
56+
error('you must first install EasyH5 from http://github.com/NeuroJSON/easyh5/');
5757
end
5858
[varargout{1:nargout}]=loadh5(filename,varargin{:});
5959
else
60-
error('file suffix must be one of .json,.jnii,.jdt,.jmsh,.jnirs,.bjd,.bnii,.jdb,.bmsh,.bnirs,.ubj,.msgpack,.h5,.hdf5,.snirf');
60+
error('file suffix must be one of .json,.jnii,.jdt,.jmsh,.jnirs,.jbids,.bjd,.bnii,.jdb,.bmsh,.bnirs,.ubj,.msgpack,.h5,.hdf5,.snirf');
6161
end

loadjson.m

+18-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
% matlab data structure with optional memory-map (mmap) table
99
%
1010
% authors:Qianqian Fang (q.fang <at> neu.edu)
11-
% created on 2011/09/09, including previous works from
11+
% created on 2011/09/09, including previous works from
1212
%
1313
% Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
1414
% created on 2009/11/02
@@ -81,15 +81,19 @@
8181
% dat: a cell array, where {...} blocks are converted into cell arrays,
8282
% and [...] are converted to arrays
8383
% mmap: (optional) a cell array as memory-mapping table in the form of
84-
% {{jsonpath1,[start,length,<whitespace>]},
85-
% {jsonpath2,[start,length,<whitespace>]}, ...}
84+
% {{jsonpath1,[start,length,<whitespace_pre>]},
85+
% {jsonpath2,[start,length,<whitespace_pre>]}, ...}
8686
% where jsonpath_i is a string in the JSONPath [1,2] format, and
8787
% "start" is an integer referring to the offset from the begining
8888
% of the stream, and "length" is the JSON object string length.
89-
% An optional 3rd integer "whitespace" may appear to record the
90-
% preceding whitespace length in case expansion of the data
89+
% An optional 3rd integer "whitespace_pre" may appear to record
90+
% the preceding whitespace length in case expansion of the data
9191
% record is needed when using the mmap.
9292
%
93+
% The format of the mmap table retruned from this function
94+
% follows the JSON-Mmap Specification Draft 1 [3] defined by the
95+
% NeuroJSON project, see https://neurojson.org/jsonmmap/draft1/
96+
%
9397
% Memory-mapping table (mmap) is useful when fast reading/writing
9498
% specific data records inside a large JSON file without needing
9599
% to load/parse/overwrite the entire file.
@@ -101,10 +105,10 @@
101105
% In the mmap jsonpath key, a '$' denotes the root object, a '.'
102106
% denotes a child of the preceding element; '.key' points to the
103107
% value segment of the child named "key" of the preceding
104-
% object; '.[i]' denotes the (i+1)th member of the preceding
108+
% object; '[i]' denotes the (i+1)th member of the preceding
105109
% element, which must be an array. For example, a key
106110
%
107-
% $.obj1.obj2.[0].obj3
111+
% $.obj1.obj2[0].obj3
108112
%
109113
% defines the memory-map of the "value" section in the below
110114
% hierarchy:
@@ -134,6 +138,7 @@
134138
%
135139
% [1] https://goessner.net/articles/JsonPath/
136140
% [2] http://jsonpath.herokuapp.com/
141+
% [3] https://neurojson.org/jsonmmap/draft1/
137142
%
138143
% examples:
139144
% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
@@ -335,7 +340,7 @@
335340
pos=endpos;
336341
pos=parse_char(inputstr, pos, ']');
337342
if(pbar>0)
338-
waitbar(pos/length(inStr),pbar,'loading ...');
343+
waitbar(pos/length(inputstr),pbar,'loading ...');
339344
end
340345
return;
341346
end
@@ -363,7 +368,7 @@
363368
while 1
364369
varargin{1}.arraydepth_=arraydepth+1;
365370
if(nargout>3)
366-
varargin{1}.jsonpath_=[origpath '.' sprintf('[%d]',length(object))];
371+
varargin{1}.jsonpath_=[origpath sprintf('[%d]',length(object))];
367372
mmap{end+1}={varargin{1}.jsonpath_, [pos, 0, w2]};
368373
[val, pos, index_esc, newmmap] = parse_value(inputstr, pos, esc, index_esc,varargin{:});
369374
mmap{end}{2}(2)=pos-mmap{end}{2}(1);
@@ -382,8 +387,8 @@
382387
end
383388

384389
if(varargin{1}.simplifycell)
385-
if(iscell(object) && ~isempty(object) && (isnumeric(object{1}) || isstruct(object{1})) )
386-
if(all(cellfun(@(e) isequal(size(object{1}), size(e)) , object(2:end))))
390+
if(iscell(object) && ~isempty(object) && (all(cellfun(@isnumeric, object)) || all(cellfun(@isstruct, object))))
391+
if(all(cellfun(@(e) isequal(size(object{1}), size(e)), object(2:end))))
387392
try
388393
oldobj=object;
389394
if(iscell(object) && length(object)>1 && ndims(object{1})>=2)
@@ -392,7 +397,7 @@
392397
object=cat(catdim,object{:});
393398
object=permute(object,ndims(object):-1:1);
394399
else
395-
object=cell2mat(object')';
400+
object=cell2mat(object.').';
396401
end
397402
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && varargin{1}.simplifycellarray==0)
398403
object=oldobj;
@@ -402,7 +407,7 @@
402407
end
403408
end
404409
if(~iscell(object) && size(object,1)>1 && ndims(object)==2)
405-
object=object';
410+
object=object.';
406411
end
407412
end
408413
pos=parse_char(inputstr, pos, ']');

0 commit comments

Comments
 (0)