Skip to content

Commit 9554a44

Browse files
committed
Merge branch 'master' of github.com:fangq/jsonlab
2 parents 3c32aff + 8c8464f commit 9554a44

File tree

10 files changed

+119
-58
lines changed

10 files changed

+119
-58
lines changed

.github/workflows/run_test.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: JSONLab CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
octave_test:
7+
name: Octave tests
8+
strategy:
9+
# provided octave versions: ubuntu-20.04 = 5.2, ubuntu-22.04 = 6.4, macos-11 = 8.1, windows-2019 = 7.3
10+
matrix:
11+
os: [ubuntu-20.04, ubuntu-22.04, macos-11, windows-2019]
12+
runs-on: ${{ matrix.os }}
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
with:
21+
submodules: 'recursive'
22+
- name: Install dependencies
23+
run: |
24+
[[ "$RUNNER_OS" == "Linux" ]] && sudo apt-get update && sudo apt-get install -y octave
25+
[[ "$RUNNER_OS" == "macOS" ]] && brew install octave
26+
if [[ "$RUNNER_OS" == "Windows" ]]; then
27+
curl --retry 3 -kL http://cdimage.debian.org/mirror/gnu.org/gnu/octave/windows/octave-7.3.0-w64-64.7z --output octave_7.3.0.7z
28+
7z x octave_7.3.0.7z -ooctave -y
29+
echo "$PWD/octave/octave-7.3.0-w64-64/mingw64/bin" >> $GITHUB_PATH
30+
fi
31+
- name: Run octave test
32+
run: |
33+
octave-cli --version
34+
octave-cli --eval "addpath(pwd);cd test;run_jsonlab_test"
35+
octave-cli --eval "addpath(pwd);cd examples; demo_jsonlab_basic; jsonlab_selftest"
36+
37+
matlab_test:
38+
name: MATLAB test
39+
strategy:
40+
matrix:
41+
os: [ubuntu-20.04, macos-11, windows-2019]
42+
runs-on: ${{ matrix.os }}
43+
steps:
44+
- name: Checkout repo
45+
uses: actions/checkout@v3
46+
with:
47+
submodules: 'recursive'
48+
- name: Set up MATLAB
49+
uses: matlab-actions/setup-matlab@v1
50+
- name: Run MATLAB test
51+
uses: matlab-actions/run-command@v1
52+
with:
53+
command: addpath(pwd);cd test;run_jsonlab_test
54+
- name: Run MATLAB examples
55+
uses: matlab-actions/run-command@v1
56+
with:
57+
command: addpath(pwd);cd examples; demo_jsonlab_basic; jsonlab_selftest

README.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ To read BJData data files generated by JSONLab v2.0, you should call
138138
139139
data=loadbj('my_old_data_file.bjd','Endian','B')
140140
141-
You are strongly encouraged to convert all pre-v2.9 JSONLab generated BJD or .jamm
141+
You are strongly encouraged to convert all pre-v2.9 JSONLab generated BJD or .pmat
142142
files using the new format.
143143

144144

@@ -323,7 +323,7 @@ for reading and writing below files types:
323323
- JSON based files: ``.json`, ``.jdt`` (text JData file), ``.jmsh`` (text JMesh file),
324324
``.jnii`` (text JNIfTI file), ``.jnirs`` (text JSNIRF file)
325325
- BJData based files: ``.bjd`, ``.jdb` (binary JData file), ``.bmsh`` (binary JMesh file),
326-
``.bnii`` (binary JNIfTI file), ``.bnirs`` (binary JSNIRF file), ``.jamm`` (MATLAB session file)
326+
``.bnii`` (binary JNIfTI file), ``.bnirs`` (binary JSNIRF file), ``.pmat`` (MATLAB session file)
327327
- UBJSON based files: ``.ubj``
328328
- MessagePack based files: ``.msgpack``
329329
- HDF5 based files: ``.h5``, ``.hdf5``, ``.snirf`` (SNIRF fNIRS data files) - require `EasyH5 toolbox <https://github.com/NeuroJSON/easyh5>`_
@@ -442,20 +442,20 @@ Using ``jsave/jload`` to share workspace
442442
Starting from JSONLab v2.0, we provide a pair of functions, ``jsave/jload`` to store
443443
and retrieve variables from the current workspace, similar to the ``save/load``
444444
functions in MATLAB and Octave. The files that ``jsave/jload`` reads/writes is by
445-
default a binary JData file with a suffix ``.jamm``. The file size is comparable
445+
default a binary JData file with a suffix ``.pmat``. The file size is comparable
446446
(can be smaller if use ``lzma`` compression) to ``.mat`` files. This feature
447447
is currently experimental.
448448

449-
The main benefits of using .jamm file to share matlab variables include
449+
The main benefits of using .pmat file to share matlab variables include
450450

451-
* a ``.jamm`` file can be 50% smaller than a ``.mat`` file when using
451+
* a ``.pmat`` file can be 50% smaller than a ``.mat`` file when using
452452
``jsave(..., "compression","lzma")``; the only drawback is longer saving time.
453-
* a ``.jamm`` file can be readily read/opened among many programming environments, including
453+
* a ``.pmat`` file can be readily read/opened among many programming environments, including
454454
Python, JavaScript, Go, Java etc, where .mat file support is not generally available.
455-
Parsers of ``.jamm`` files are largely compatible with UBJSON's parsers available at
455+
Parsers of ``.pmat`` files are largely compatible with UBJSON's parsers available at
456456
http://ubjson.org/?page_id=48
457-
* a ``.jamm`` file is quasi-human-readable, one can see the internal data fields
458-
even in a command line, for example using ``strings -n 2 file.jamm | astyle``,
457+
* a ``.pmat`` file is quasi-human-readable, one can see the internal data fields
458+
even in a command line, for example using ``strings -n 2 file.pmat | astyle``,
459459
making the binary data easy to be understood, shared and reused.
460460
* ``jsave/jload`` can also use MessagePack and JSON formats as the underlying
461461
data storage format, addressing needs from a diverse set of applications.
@@ -467,10 +467,10 @@ jsave.m
467467

468468
.. code-block:: matlab
469469
470-
jsave % save the current workspace to jamdata.jamm
471-
jsave mydata.jamm
472-
jsave('mydata.jamm','vars',{'var1','var2'})
473-
jsave('mydata.jamm','compression','lzma')
470+
jsave % save the current workspace to default.pmat
471+
jsave mydata.pmat
472+
jsave('mydata.pmat','vars',{'var1','var2'})
473+
jsave('mydata.pmat','compression','lzma')
474474
jsave('mydata.json','compression','gzip')
475475
476476
----------
@@ -479,10 +479,10 @@ jload.m
479479

480480
.. code-block:: matlab
481481
482-
jload % load variables from jamdata.jamm to the current workspace
483-
jload mydata.jamm % load variables from mydata.jamm
484-
vars=jload('mydata.jamm','vars',{'var1','var2'}) % return vars.var1, vars.var2
485-
jload('mydata.jamm','simplifycell',0)
482+
jload % load variables from default.pmat to the current workspace
483+
jload mydata.pmat % load variables from mydata.pmat
484+
vars=jload('mydata.pmat','vars',{'var1','var2'}) % return vars.var1, vars.var2
485+
jload('mydata.pmat','simplifycell',0)
486486
jload('mydata.json')
487487
488488
@@ -501,7 +501,7 @@ However, we strongly recommend one to use a lightweight ``jdata`` module,
501501
developed by the same author, to perform the extra JData encoding and decoding
502502
and convert JSON data directly to convenient Python/Numpy data structures.
503503
The ``jdata`` module can also directly read/write UBJSON/Binary JData outputs
504-
from JSONLab (``.bjd, .ubj, .bnii, .bnirs, .jamm`` etc). Using binary JData
504+
from JSONLab (``.bjd, .ubj, .bnii, .bnirs, .pmat`` etc). Using binary JData
505505
files are expected to produce much smaller file sizes and faster parsing,
506506
while maintaining excellent portability and generality.
507507

@@ -547,7 +547,7 @@ Once the necessary modules are installed, one can type ``python`` (or ``python3`
547547
548548
data1=jd.loadt('myfile.json',object_pairs_hook=OrderedDict);
549549
data2=jd.loadb('myfile.ubj',object_pairs_hook=OrderedDict);
550-
data3=jd.loadb('myfile.jamm',object_pairs_hook=OrderedDict);
550+
data3=jd.loadb('myfile.pmat',object_pairs_hook=OrderedDict);
551551
552552
where ``jd.loadt()`` function loads a text-based JSON file, performs
553553
JData decoding and converts the enclosed data into Python ``dict``, ``list``

README.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ To read BJData data files generated by JSONLab v2.0, you should call
135135

136136
data=loadbj('my_old_data_file.bjd','Endian','B')
137137

138-
You are strongly encouraged to convert all pre-v2.9 JSONLab generated BJD or .jamm
138+
You are strongly encouraged to convert all pre-v2.9 JSONLab generated BJD or .pmat
139139
files using the new format.
140140

141141

@@ -291,7 +291,7 @@ for reading and writing below files types:
291291
* JSON based files: `.json`, `.jdt` (text JData file), `.jmsh` (text JMesh file), \
292292
`.jnii` (text JNIfTI file), `.jnirs` (text JSNIRF file)
293293
* BJData based files: `.bjd`, `.jdb` (binary JData file), `.bmsh` (binary JMesh file), \
294-
`.bnii` (binary JNIfTI file), `.bnirs` (binary JSNIRF file), `.jamm` (MATLAB session file)
294+
`.bnii` (binary JNIfTI file), `.bnirs` (binary JSNIRF file), `.pmat` (MATLAB session file)
295295
* UBJSON based files: `.ubj`
296296
* MessagePack based files: `.msgpack`
297297
* HDF5 based files: `.h5`, `.hdf5`, `.snirf` (SNIRF fNIRS data files) - require [https://github.com/fangq/easyh5 EasyH5 toolbox]
@@ -383,20 +383,20 @@ IV.Using `jsave/jload` to share workspace
383383
Starting from JSONLab v2.0, we provide a pair of functions, `jsave/jload` to store
384384
and retrieve variables from the current workspace, similar to the `save/load`
385385
functions in MATLAB and Octave. The files that `jsave/jload` reads/writes is by
386-
default a binary JData file with a suffix `.jamm`. The file size is comparable
386+
default a binary JData file with a suffix `.pmat`. The file size is comparable
387387
(can be smaller if use `lzma` compression) to `.mat` files. This feature
388388
is currently experimental.
389389

390-
The main benefits of using .jamm file to share matlab variables include
390+
The main benefits of using .pmat file to share matlab variables include
391391

392-
* a `.jamm` file can be 50% smaller than a `.mat` file when using \
392+
* a `.pmat` file can be 50% smaller than a `.mat` file when using \
393393
`jsave(..., "compression","lzma")`; the only drawback is longer saving time.
394-
* a `.jamm` file can be readily read/opened among many programming environments, including \
394+
* a `.pmat` file can be readily read/opened among many programming environments, including \
395395
Python, JavaScript, Go, Java etc, where `.mat` file support is not generally available. \
396-
Parsers of `.jamm` is largely compatible with UBJSON's parsers available at \
396+
Parsers of `.pmat` is largely compatible with UBJSON's parsers available at \
397397
http://ubjson.org/?page_id=48
398-
* a `.jamm` file is quasi-human-readable, one can see the internal data fields \
399-
even in a command line, for example using `strings -n 2 file.jamm | astyle`, \
398+
* a `.pmat` file is quasi-human-readable, one can see the internal data fields \
399+
even in a command line, for example using `strings -n 2 file.pmat | astyle`, \
400400
making the binary data easy to be understood, shared and reused.
401401
* `jsave/jload` can also use MessagePack and JSON formats as the underlying \
402402
data storage format, addressing needs from diverse applications. \
@@ -405,18 +405,18 @@ The main benefits of using .jamm file to share matlab variables include
405405

406406
=== jsave.m ===
407407

408-
jsave % save the current workspace to jamdata.jamm
409-
jsave mydata.jamm
410-
jsave('mydata.jamm','vars',{'var1','var2'})
411-
jsave('mydata.jamm','compression','lzma')
408+
jsave % save the current workspace to default.pmat
409+
jsave mydata.pmat
410+
jsave('mydata.pmat','vars',{'var1','var2'})
411+
jsave('mydata.pmat','compression','lzma')
412412
jsave('mydata.json','compression','gzip')
413413

414414
=== jload.m ===
415415

416-
jload % load variables from jamdata.jamm to the current workspace
417-
jload mydata.jamm % load variables from mydata.jamm
418-
vars=jload('mydata.jamm','vars',{'var1','var2'}) % return vars.var1, vars.var2
419-
jload('mydata.jamm','simplifycell',0)
416+
jload % load variables from default.pmat to the current workspace
417+
jload mydata.pmat % load variables from mydata.pmat
418+
vars=jload('mydata.pmat','vars',{'var1','var2'}) % return vars.var1, vars.var2
419+
jload('mydata.pmat','simplifycell',0)
420420
jload('mydata.json')
421421

422422
-------------------------------------------------------------------------------
@@ -434,7 +434,7 @@ However, we strongly recommend one to use a lightweight `jdata` module,
434434
developed by the same author, to perform the extra JData encoding and decoding
435435
and convert JSON data directly to convenient Python/Numpy data structures.
436436
The `jdata` module can also directly read/write UBJSON/Binary JData outputs
437-
from JSONLab (`.bjd, .ubj, .bnii, .bnirs, .jamm` etc). Using binary JData
437+
from JSONLab (`.bjd, .ubj, .bnii, .bnirs, .pmat` etc). Using binary JData
438438
files are exptected to produce much smaller file sizes and faster parsing,
439439
while maintainining excellent portability and generality.
440440

@@ -469,7 +469,7 @@ Once the necessary modules are installed, one can type `python` (or `python3`),
469469

470470
data1=jd.loadt('myfile.json',object_pairs_hook=OrderedDict);
471471
data2=jd.loadb('myfile.ubj',object_pairs_hook=OrderedDict);
472-
data3=jd.loadb('myfile.jamm',object_pairs_hook=OrderedDict);
472+
data3=jd.loadb('myfile.pmat',object_pairs_hook=OrderedDict);
473473

474474
where `jd.loadt()` function loads a text-based JSON file, performs
475475
JData decoding and converts the enclosed data into Python `dict`, `list`

encodevarname.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
if(exist('unicode2native','builtin'))
5151
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
5252
else
53-
cpos=regexp(str,'[^0-9A-Za-z_]');
53+
cpos=find(~ismember(str, ['0':'9','A':'Z','a':'z','_']));
54+
%cpos=regexp(str,'[^0-9A-Za-z_]');
5455
if(isempty(cpos))
5556
return;
5657
end

jdatadecode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
switch(lower(fext))
477477
case {'.json','.jnii','.jdt','.jdat','.jmsh','.jnirs'}
478478
newdata=loadjson(uripath, opt);
479-
case {'.bjd' ,'.bnii','.jdb','.jbat','.bmsh','.bnirs', '.jamm'}
479+
case {'.bjd' ,'.bnii','.jdb','.jbat','.bmsh','.bnirs', '.pmat'}
480480
newdata=loadbj(uripath, opt);
481481
case {'.ubj'}
482482
newdata=loadubjson(uripath, opt);

jload.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
% created on 2020/05/31
1414
%
1515
% input:
16-
% fname: (optional) input file name; if not given, load 'jamdata.jamm'
16+
% fname: (optional) input file name; if not given, load 'default.pmat'
1717
% if fname has a '.json' or '.jdt' suffix, a text-based
18-
% JSON/JData file will be expected; if the suffix is '.jamm' or
18+
% JSON/JData file will be expected; if the suffix is '.pmat' or
1919
% '.jdb', a Binary JData file will be expected.
2020
% opt: (optional) a struct to store parsing options, opt can be replaced by
2121
% a list of ('param',value) pairs - the param string is equivallent
@@ -41,10 +41,10 @@
4141
% load the variables to the current workspace ('caller')
4242
%
4343
% examples:
44-
% jload % load all variables in jamdata.jamm to the 'caller' workspace
45-
% jload mydat.jamm
46-
% jload('mydat.jamm','vars', {'v1','v2',...}) % load selected variables
47-
% varlist=jload('mydat.jamm','simplifycell',1)
44+
% jload % load all variables in default.pmat to the 'caller' workspace
45+
% jload mydat.pmat
46+
% jload('mydat.pmat','vars', {'v1','v2',...}) % load selected variables
47+
% varlist=jload('mydat.pmat','simplifycell',1)
4848
%
4949
% license:
5050
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
@@ -53,7 +53,7 @@
5353
%
5454

5555
if(nargin==0)
56-
filename=[pwd filesep 'jamdata.jamm'];
56+
filename=[pwd filesep 'default.pmat'];
5757
end
5858

5959
opt=varargin2struct(varargin{:});

jsave.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
% created on 2020/05/31
1212
%
1313
% input:
14-
% fname: (optional) output file name; if not given, save to 'jamdata.jamm'
14+
% fname: (optional) output file name; if not given, save to 'default.pmat'
1515
% if fname has a '.json' or '.jdt' suffix, a text-based
16-
% JSON/JData file will be created (slow); if the suffix is '.jamm' or
16+
% JSON/JData file will be created (slow); if the suffix is '.pmat' or
1717
% '.jdb', a Binary JData (https://github.com/NeuroJSON/bjdata/) file will be created.
1818
% opt: (optional) a struct to store parsing options, opt can be replaced by
1919
% a list of ('param',value) pairs - the param string is equivallent
@@ -34,9 +34,9 @@
3434
% varlist: a list of variables loaded
3535
%
3636
% examples:
37-
% jsave % save all variables in the 'caller' workspace to jamdata.jamm
38-
% jsave('mydat.jamm','vars', {'v1','v2',...}) % save selected variables
39-
% jsave('mydat.jamm','compression','lzma')
37+
% jsave % save all variables in the 'caller' workspace to jamdata.pmat
38+
% jsave('mydat.pmat','vars', {'v1','v2',...}) % save selected variables
39+
% jsave('mydat.pmat','compression','lzma')
4040
%
4141
% license:
4242
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
@@ -45,7 +45,7 @@
4545
%
4646

4747
if(nargin==0)
48-
filename=[pwd filesep 'jamdata.jamm'];
48+
filename=[pwd filesep 'default.pmat'];
4949
end
5050

5151
opt=varargin2struct(varargin{:});

loadbj.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
fid = fopen(fname,'rb');
102102
string = fread(fid,jsonopt('MaxBuffer',inf,opt),'uint8=>char')';
103103
fclose(fid);
104-
elseif(regexp(fname, '^\s*[\[\{SCHiUIulmLMhdDTFZN]'))
104+
elseif(length(fname) && any(fname(1)=='[{SCHiUIulmLMhdDTFZN'))
105105
string=fname;
106106
else
107107
error_pos('input file does not exist or buffer is invalid');

loadjson.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@
514514

515515
function [num, pos] = parse_number(inputstr, pos, varargin)
516516
currstr=inputstr(pos:min(pos+30,end));
517-
[num, one, err, delta] = sscanf(currstr, '%f', 1);
517+
[num, tmp, err, delta] = sscanf(currstr, '%f', 1);
518518
if ~isempty(err)
519519
pos=error_pos('Error reading number at position %d',inputstr,pos);
520520
end
@@ -529,7 +529,7 @@
529529
end
530530
varargout{3}=index_esc;
531531
if(nargout>3)
532-
varargout{4}={};
532+
varargout{4}={};
533533
end
534534
switch(inputstr(pos))
535535
case '"'
@@ -600,7 +600,7 @@
600600
object(str)=val;
601601
else
602602
object.(encodevarname(str,varargin{:}))=val;
603-
end
603+
end
604604
[cc,pos]=next_char(inputstr,pos);
605605
if cc == '}'
606606
break;

test/run_jsonlab_test.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function run_jsonlab_test(tests)
33
% run_jsonlab_test
44
% or
55
% run_jsonlab_test(tests)
6-
% run_jsonlab_test({'js','jso','bj','bjo'})
6+
% run_jsonlab_test({'js','jso','bj','bjo','jmap','bmap','bugs'})
77
%
88
% Unit testing for JSONLab JSON, BJData/UBJSON encoders and decoders
99
%
@@ -16,6 +16,9 @@ function run_jsonlab_test(tests)
1616
% 'jso': test savejson/loadjson special options
1717
% 'bj': test savebj/loadbj
1818
% 'bjo': test savebj/loadbj special options
19+
% 'jmap': test jsonmmap features in loadjson
20+
% 'bmap': test jsonmmap features in loadbj
21+
% 'bugs': test specific bug fixes
1922
%
2023
% license:
2124
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

0 commit comments

Comments
 (0)