Skip to content

Commit 9980f9b

Browse files
committed
[jnifty] update to the latest jnifty v0.8, add saveh5 from easyh5
1 parent 486a77a commit 9980f9b

12 files changed

+539
-47
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: jsonlab
2-
Version: 2.9.8
3-
Date: 2024-25-03
2+
Version: 3.0.0
3+
Date: 2025-23-03
44
Title: A JSON/UBJSON/MessagePack encoder/decoder for MATLAB/Octave
55
Author: Qianqian Fang <[email protected]>
66
Maintainer: Qianqian Fang <[email protected]>

gzipdecode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%
77
% Decompressing a GZIP-compressed byte-stream to recover the original data
88
% This function depends on JVM in MATLAB or, can optionally use the ZMat
9-
% toolbox (http://github.com/NeuroJSON/zmat)
9+
% toolbox (https://github.com/NeuroJSON/zmat)
1010
%
1111
% Copyright (c) 2012, Kota Yamaguchi
1212
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities

gzipencode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
% Compress a string or numerical array using the GZIP-compression
88
%
99
% This function depends on JVM in MATLAB or, can optionally use the ZMat
10-
% toolbox (http://github.com/NeuroJSON/zmat)
10+
% toolbox (https://github.com/NeuroJSON/zmat)
1111
%
1212
% Copyright (c) 2012, Kota Yamaguchi
1313
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities

loadjnifti.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
% jnii=loadjnifti(inputfile, 'Param1',value1, 'Param2',value2,...)
66
%
77
% Load a standard NIFTI-1/2 file or text or binary JNIfTI file with
8-
% format defined in JNIfTI specification: https://github.com/NeuroJSON/jnifti
8+
% format defined in JNIfTI specification: https://github.com/NeuroJSON/jnifty
99
%
1010
% author: Qianqian Fang (q.fang <at> neu.edu)
1111
%
@@ -33,17 +33,17 @@
3333
% savejnifti(jnii, 'magic10.jnii')
3434
% newjnii=loadjnifti('magic10.jnii');
3535
%
36-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
36+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
3737
%
38-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
38+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
3939
%
4040

4141
if (nargin < 1)
4242
error('you must provide data and output file name');
4343
end
4444

4545
if (~exist('savejson', 'file'))
46-
error('you must first install JSONLab from http://github.com/NeuroJSON/jsonlab/');
46+
error('you must first install JSONLab from https://github.com/NeuroJSON/jsonlab/');
4747
end
4848

4949
if (regexp(filename, '\.nii$'))

loadnifti.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
% This function is an alias to nii2jnii
1414
%
1515
%
16-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
16+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
1717
%
18-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
18+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
1919
%
2020

2121
[varargout{1:nargout}] = nii2jnii(varargin{:});

memmapstream.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
% 'uint8', [1,2], 'school'};
3838
% data=memmapstream(bytestream,format);
3939
%
40-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
40+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
4141
%
42-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
42+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
4343
%
4444

4545
if (nargin < 2)

nii2jnii.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
%
88
% A fast and portable NIFTI-1/2 and Analyze7.5 file parser and converter
99
% to the text and binary JNIfTI formats defined in JNIfTI specification:
10-
% https://github.com/NeuroJSON/jnifti
10+
% https://github.com/NeuroJSON/jnifty
1111
%
1212
% This function is compatible with both MATLAB and GNU Octave.
1313
% It accepts .nii, .nii.gz, .hdr/.img and .hdr.gz/.img.gz input files
@@ -51,23 +51,24 @@
5151
% magic: must be 'ni1\0' or 'n+1\0'
5252
%
5353
% For the detailed nii header, please see
54-
% https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h
54+
% https://nifti.nimh.nih.gov/nifti-1/
5555
%
5656
% dependency:
5757
% No external dependency if reading .nii/.hdr/.img files;
5858
%
59-
% To load gzipped input files (.nii.gz/.hdr.gz/.img.gz), one must
60-
% install the ZMat Toolbox (http://github.com/NeuroJSON/zmat) and
61-
% JSONLab Toolbox (http://github.com/NeuroJSON/jsonlab);
59+
% To load gzipped input files (.nii.gz/.hdr.gz/.img.gz), one may
60+
% install the ZMat Toolbox (https://github.com/NeuroJSON/zmat) and
61+
% JSONLab Toolbox (https://github.com/NeuroJSON/jsonlab), although
62+
% it is optional.
6263
%
6364
% To save files into the text/binary JNIfTI formatted files, one
64-
% need to install JSONLab (http://github.com/NeuroJSON/jsonlab).
65+
% need to install JSONLab (https://github.com/NeuroJSON/jsonlab).
6566
%
6667
% this file was initially developed for the MCX project: https://github.com/fangq/mcx/blob/master/utils/mcxloadnii.m
6768
%
68-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
69+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
6970
%
70-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
71+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
7172
%
7273

7374
hdrfile = filename;
@@ -95,7 +96,7 @@
9596

9697
if (regexp(hdrfile, '\.[Gg][Zz]$'))
9798
if (~exist('gzipdecode', 'file'))
98-
error('To process zipped files, you must install gzipdecode.m from the JSONLab toolbox: http://github.com/NeuroJSON/jsonlab');
99+
error('To process zipped files, you must install gzipdecode.m from the JSONLab toolbox: https://github.com/NeuroJSON/jsonlab');
99100
end
100101
gzdata = gzipdecode(input);
101102
else
@@ -294,7 +295,7 @@
294295

295296
if (nargout == 0 && strcmp(format, 'nii') == 0 && strcmp(format, 'jnii') == 0)
296297
if (~exist('savejson', 'file'))
297-
error('you must first install JSONLab from http://github.com/NeuroJSON/jsonlab/');
298+
error('you must first install JSONLab from https://github.com/NeuroJSON/jsonlab/');
298299
end
299300
if (regexp(format, '\.jnii$'))
300301
savejson('', nii, 'FileName', format, varargin{:});

niicodemap.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
%
1010
% input:
1111
% name: a header name as a string, currently support the below nii
12-
% headers: 'intent_code', 'slice_code', 'datatype', 'qform',
13-
% 'sform' and 'xyzt_units' and their corresponding JNIfTI
12+
% headers: 'intent_code', 'slice_code', 'datatype', 'qform_code',
13+
% 'sform_code' and 'xyzt_units' and their corresponding JNIfTI
1414
% headers:
1515
% 'Intent','SliceType','DataType','QForm','SForm','Unit'
1616
% value:the current header value, if it is a code, newval will
@@ -30,9 +30,9 @@
3030
%
3131
% this file was initially developed for the MCX project: https://github.com/fangq/mcx/blob/master/utils/mcxloadnii.m
3232
%
33-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
33+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
3434
%
35-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
35+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
3636
%
3737

3838
% code to name look-up-table
@@ -42,14 +42,18 @@
4242
return
4343
end
4444

45-
lut.intent_code = containers.Map([0, 2:24 1001:1011 2001:2005], ...
45+
lut.intent_code = containers.Map([0, 2:24 1001:1011 2001:2005 2006:2009 2016:2018], ...
4646
{'', 'corr', 'ttest', 'ftest', 'zscore', 'chi2', 'beta', ...
4747
'binomial', 'gamma', 'poisson', 'normal', 'ncftest', ...
4848
'ncchi2', 'logistic', 'laplace', 'uniform', 'ncttest', ...
4949
'weibull', 'chi', 'invgauss', 'extval', 'pvalue', ...
5050
'logpvalue', 'log10pvalue', 'estimate', 'label', 'neuronames', ...
5151
'matrix', 'symmatrix', 'dispvec', 'vector', 'point', 'triangle', ...
52-
'quaternion', 'unitless', 'tseries', 'elem', 'rgb', 'rgba', 'shape'});
52+
'quaternion', 'unitless', 'tseries', 'elem', 'rgb', 'rgba', 'shape', ...
53+
'fsl_fnirt_displacement_field', 'fsl_cubic_spline_coefficients', ...
54+
'fsl_dct_coefficients', 'fsl_quadratic_spline_coefficients', ...
55+
'fsl_topup_cubic_spline_coefficients', 'fsl_topup_quadratic_spline_coefficients', ...
56+
'fsl_topup_field'});
5357

5458
lut.slice_code = containers.Map(0:6, {'', 'seq+', 'seq-', 'alt+', 'alt-', 'alt2+', 'alt-'});
5559

@@ -61,10 +65,10 @@
6165
lut.xyzt_units = containers.Map([0:3 8 16 24 32 40 48], ...
6266
{'', 'm', 'mm', 'um', 's', 'ms', 'us', 'hz', 'ppm', 'rad'});
6367

64-
lut.qform = containers.Map(0:4, {'', 'scanner', 'aligned', 'talairach', 'mni'});
68+
lut.qform_code = containers.Map(0:5, {'', 'scanner_anat', 'aligned_anat', 'talairach', 'mni_152', 'template_other'});
6569

6670
lut.unit = lut.xyzt_units;
67-
lut.sform = lut.qform;
71+
lut.sform_code = lut.qform_code;
6872
lut.slicetype = lut.slice_code;
6973
lut.intent = lut.intent_code;
7074

@@ -74,9 +78,9 @@
7478
tul.slice_code = containers.Map(values(lut.slice_code), keys(lut.slice_code));
7579
tul.datatype = containers.Map(values(lut.datatype), keys(lut.datatype));
7680
tul.xyzt_units = containers.Map(values(lut.xyzt_units), keys(lut.xyzt_units));
77-
tul.qform = containers.Map(values(lut.qform), keys(lut.qform));
81+
tul.qform_code = containers.Map(values(lut.qform_code), keys(lut.qform_code));
7882

79-
tul.sform = tul.qform;
83+
tul.sform_code = tul.qform_code;
8084
tul.slicetype = tul.slice_code;
8185
tul.intent = tul.intent_code;
8286
tul.unit = tul.xyzt_units;

niiformat.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
% column 2: an integer vector denoting the size of the data
2323
% column 3: a string denoting the fieldname in the output struct
2424
%
25-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
25+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
2626
%
27-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
27+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
2828
%
2929

3030
header.nifti1 = { ...

niiheader2jnii.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
end
4343
nii.NIFTIHeader.Description = deblank(char(nii0.hdr.descrip));
4444
nii.NIFTIHeader.AuxFile = deblank(char(nii0.hdr.aux_file));
45-
nii.NIFTIHeader.QForm = nii0.hdr.qform_code;
46-
nii.NIFTIHeader.SForm = nii0.hdr.sform_code;
45+
nii.NIFTIHeader.QForm = niicodemap('qform_code', nii0.hdr.qform_code);
46+
nii.NIFTIHeader.SForm = niicodemap('sform_code', nii0.hdr.sform_code);
4747
nii.NIFTIHeader.Quatern.b = nii0.hdr.quatern_b;
4848
nii.NIFTIHeader.Quatern.c = nii0.hdr.quatern_c;
4949
nii.NIFTIHeader.Quatern.d = nii0.hdr.quatern_d;

octavezmat.m

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
% unzipdata = octavezmat(zipdata, info)
77
%
88
% Compress or decompress zlib and gzip memory buffers using zip/unzip/gzip/gunzip on Octave
9-
% in case ZMat toolbox (http://github.com/NeuroJSON/zmat) was not installed (ZMat is much faster)
9+
% in case ZMat toolbox (https://github.com/NeuroJSON/zmat) was not installed (ZMat is much faster)
1010
%
1111
% Author: Qianqian Fang (q.fang <at> neu.edu)
1212
%
@@ -59,7 +59,7 @@
5959
nowarning = getvarfrom({'caller', 'base'}, 'NO_ZMAT');
6060

6161
if (isempty(nowarning) || nowarning == 0)
62-
warning('You are recommended to install ZMat (http://github.com/NeuroJSON/zmat) get much faster speed in Octave');
62+
warning('You are recommended to install ZMat (https://github.com/NeuroJSON/zmat) get much faster speed in Octave');
6363
end
6464

6565
if (nargin < 1)
@@ -102,16 +102,26 @@
102102
tmpfile = [fname suff.(zipmethod)];
103103
end
104104

105-
fd = fopen(tmpfile, 'wb');
105+
writeflag = 'wb';
106+
107+
if (iscompress && strcmp(zipmethod, 'gzip'))
108+
writeflag = [writeflag, 'z'];
109+
end
110+
111+
fd = fopen(tmpfile, writeflag);
106112
if (~fd)
107113
error('unable to create temporary file');
108114
end
109115

110116
fwrite(fd, typecast(data(:), 'uint8'), 'uint8');
111117
fclose(fd);
112118

113-
if (iscompress)
114-
outputfile = [fname suff.(zipmethod)];
119+
if (strcmp(zipmethod, 'gzip'))
120+
outputfile = tmpfile;
121+
else
122+
if (iscompress)
123+
outputfile = [fname suff.(zipmethod)];
124+
end
115125
end
116126

117127
if (~iscompress)
@@ -122,22 +132,24 @@
122132
else
123133
outputfile = outputfile{1};
124134
end
125-
elseif (strcmp(zipmethod, 'gzip'))
126-
gunzip(tmpfile);
127135
end
128136
else
129137
if (strcmp(zipmethod, 'zlib'))
130138
zip(outputfile, tmpfile);
131-
elseif (strcmp(zipmethod, 'gzip'))
132-
gzip(tmpfile);
133139
end
134140
end
135141

136-
if (exist(tmpfile, 'file'))
142+
if (strcmp(zipmethod, 'zlib') && exist(tmpfile, 'file'))
137143
delete(tmpfile);
138144
end
139145

140-
fd = fopen(outputfile, 'rb');
146+
readflag = 'rb';
147+
148+
if (~iscompress && strcmp(zipmethod, 'gzip'))
149+
readflag = [readflag, 'z'];
150+
end
151+
152+
fd = fopen(outputfile, readflag);
141153
if (~fd)
142154
error('failed to unzip buffer');
143155
end

0 commit comments

Comments
 (0)