Skip to content

Commit

Permalink
use Octave styled comment, NeuroJSON/jnifti#7
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 5, 2022
1 parent b89f80c commit b7bcb2b
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 476 deletions.
36 changes: 18 additions & 18 deletions loadnifti.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
function varargout = loadnifti (varargin)
%
% jnii=loadnifti(filename)
% or
% nii=loadnifti(filename,option)
%
% Read a NIfTI-1/2 (*.nii/.nii.gz) or Analyze 7.5 (*.hdr/*.img/.hdr.gz/.img.gz)
% image file.
%
% author: Qianqian Fang (q.fang <at> neu.edu)
%
% Please run `help nii2jnii` to see the input output outputs.
% This function is an alias to nii2jnii
%
%
% this file is part of JNIfTI specification: https://github.com/fangq/jnifti
%
% License: Apache 2.0, see https://github.com/fangq/jnifti for details
%
#
# jnii=loadnifti(filename)
# or
# nii=loadnifti(filename,option)
#
# Read a NIfTI-1/2 (*.nii/.nii.gz) or Analyze 7.5 (*.hdr/*.img/.hdr.gz/.img.gz)
# image file.
#
# author: Qianqian Fang (q.fang <at> neu.edu)
#
# Please run `help nii2jnii` to see the input output outputs.
# This function is an alias to nii2jnii
#
#
# this file is part of JNIfTI specification: https://github.com/fangq/jnifti
#
# License: Apache 2.0, see https://github.com/fangq/jnifti for details
#

[varargout{1:nargout}] = nii2jnii(varargin{:});
84 changes: 42 additions & 42 deletions memmapstream.m
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
function outstruct = memmapstream(bytes, format, varargin)
%
% outstruct=memmapstream(bytes, format)
%
% Map a byte-array (in char array or uint8/int8 array) into a structure
% using a dictionary (format is compatible with memmapfile in MATLAB)
%
% This function is compatible with both MATLAB and GNU Octave.
%
% author: Qianqian Fang (q.fang <at> neu.edu)
%
% input:
% bytes: a char, int8 or uint8 vector or array
% format: a 3-column cell array in the format compatible with the
% 'Format' parameter of memmapfile in MATLAB. It has the
% following structure
%
% column 1: data type string, it can be one of the following
% 'int8','int16','int32','int64',
% 'uint8','uint16','uint32','uint64',
% 'single','double','logical'
% column 2: an integer vector denoting the size of the data
% column 3: a string denoting the fieldname in the output struct
%
% For example format={'int8',[1,8],'key'; 'float',[1,1],'value'}
% reads the first 8 bytes from 'bytes' as the first subfield
% 'key' and the following 4 bytes as the floating point 'value'
% subfield.
%
% output:
% outstruct: a structure containing the required field
%
% example:
% bytestream=['Andy' 5 'JT'];
% format={'uint8', [1,4], 'name',
% 'uint8', [1,1], 'age',
% 'uint8', [1,2], 'school'};
% data=memmapstream(bytestream,format);
%
% this file is part of JNIfTI specification: https://github.com/fangq/jnifti
%
% License: Apache 2.0, see https://github.com/fangq/jnifti for details
%
#
# outstruct=memmapstream(bytes, format)
#
# Map a byte-array (in char array or uint8/int8 array) into a structure
# using a dictionary (format is compatible with memmapfile in MATLAB)
#
# This function is compatible with both MATLAB and GNU Octave.
#
# author: Qianqian Fang (q.fang <at> neu.edu)
#
# input:
# bytes: a char, int8 or uint8 vector or array
# format: a 3-column cell array in the format compatible with the
# 'Format' parameter of memmapfile in MATLAB. It has the
# following structure
#
# column 1: data type string, it can be one of the following
# 'int8','int16','int32','int64',
# 'uint8','uint16','uint32','uint64',
# 'single','double','logical'
# column 2: an integer vector denoting the size of the data
# column 3: a string denoting the fieldname in the output struct
#
# For example format={'int8',[1,8],'key'; 'float',[1,1],'value'}
# reads the first 8 bytes from 'bytes' as the first subfield
# 'key' and the following 4 bytes as the floating point 'value'
# subfield.
#
# output:
# outstruct: a structure containing the required field
#
# example:
# bytestream=['Andy' 5 'JT'];
# format={'uint8', [1,4], 'name',
# 'uint8', [1,1], 'age',
# 'uint8', [1,2], 'school'};
# data=memmapstream(bytestream,format);
#
# this file is part of JNIfTI specification: https://github.com/fangq/jnifti
#
# License: Apache 2.0, see https://github.com/fangq/jnifti for details
#

if (nargin < 2)
error('must provide bytes and format as inputs');
Expand Down
40 changes: 20 additions & 20 deletions nifticreate.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
function header = nifticreate(img, format)
%
% header=nifticreate(img)
% or
% header=nifticreate(img,format)
%
% Create a default NIfTI header
%
% author: Qianqian Fang (q.fang <at> neu.edu)
%
% input:
% img: the image data matching the header
% format: can only be 'nifti1'. can be ignored
%
% output:
% header: a struct that is byte-wise compatible with NIfTI-1
%
% this file is part of JNIfTI specification: https://github.com/fangq/jnifti
%
% License: Apache 2.0, see https://github.com/fangq/jnifti for details
%
#
# header=nifticreate(img)
# or
# header=nifticreate(img,format)
#
# Create a default NIfTI header
#
# author: Qianqian Fang (q.fang <at> neu.edu)
#
# input:
# img: the image data matching the header
# format: can only be 'nifti1'. can be ignored
#
# output:
# header: a struct that is byte-wise compatible with NIfTI-1
#
# this file is part of JNIfTI specification: https://github.com/fangq/jnifti
#
# License: Apache 2.0, see https://github.com/fangq/jnifti for details
#

if (nargin < 2)
format = 'nifti1';
Expand Down
68 changes: 34 additions & 34 deletions niftiinfo.m
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
%% Copyright (C) 2019 Qianqian Fang <[email protected]>
%%
%% This program is free software; you can redistribute it and/or modify it under
%% the terms of the GNU General Public License as published by the Free Software
%% Foundation; either version 3 of the License, or (at your option) any later
%% version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
%% details.
%%
%% You should have received a copy of the GNU General Public License along with
%% this program; if not, see <http://www.gnu.org/licenses/>.
## Copyright (C) 2019 Qianqian Fang <q.fang@neu.edu>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @deftypefn {Function File} {} niftiinfo (@var{filename})
%% Read the metadata from a NIfTI-1/2 and Analyze7.5 formatted image file
%%
%% Parsing the metadata in a NIfTI-1/2 file or a two-part NIfTI
%% or Analyze7.5 header file specified by @var{filename}. The
%% accepted file suffixes include .nii, .nii.gz, .hdr, and .hdr.gz.
%%
%% @seealso{niftiread, niftiwrite}
%% @end deftypefn
## -*- texinfo -*-
## @deftypefn {Function File} {} niftiinfo (@var{filename})
## Read the metadata from a NIfTI-1/2 and Analyze7.5 formatted image file
##
## Parsing the metadata in a NIfTI-1/2 file or a two-part NIfTI
## or Analyze7.5 header file specified by @var{filename}. The
## accepted file suffixes include .nii, .nii.gz, .hdr, and .hdr.gz.
##
## @seealso{niftiread, niftiwrite}
## @end deftypefn

function nii = niftiinfo (filename, varargin)

Expand Down Expand Up @@ -101,14 +101,14 @@

endfunction;

% !demo
% ! %% Reading a
% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
% ! gunzip ('minimal.nii.gz');
% ! header=niftiinfo('minimal.nii');
# !demo
# ! ## Reading a
# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
# ! gunzip ('minimal.nii.gz');
# ! header=niftiinfo('minimal.nii');

% !test
% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
% ! gunzip ('minimal.nii.gz');
% ! header=niftiinfo('minimal.nii');
% ! assert (header.ImageSize,[64 64 10]);
# !test
# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
# ! gunzip ('minimal.nii.gz');
# ! header=niftiinfo('minimal.nii');
# ! assert (header.ImageSize,[64 64 10]);
72 changes: 36 additions & 36 deletions niftiread.m
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
%% Copyright (C) 2019 Qianqian Fang <[email protected]>
%%
%% This program is free software; you can redistribute it and/or modify it under
%% the terms of the GNU General Public License as published by the Free Software
%% Foundation; either version 3 of the License, or (at your option) any later
%% version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
%% details.
%%
%% You should have received a copy of the GNU General Public License along with
%% this program; if not, see <http://www.gnu.org/licenses/>.
## Copyright (C) 2019 Qianqian Fang <q.fang@neu.edu>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @deftypefn {Function File} {} niftiread (@var{filename})
%% @deftypefnx {Function File} {} niftiread (@var{headerfile}, @var{imagefile})
%% @deftypefnx {Function File} {} niftiread (@var{info})
%% Read image data from a NIfTI-1/2 and Analyze7.5 formatted image file
%%
%% Loading a NIfTI-1/2 file specified by @var{filename}, or a two-part NIfTI
%% or Analyze7.5 files using @var{headerfile} and @var{imagefile}. The
%% accepted file suffixes include .nii, .nii.gz, .hdr, .hdr.gz, .img, img.gz
%%
%% @seealso{niftiinfo, niftiwrite}
%% @end deftypefn
## -*- texinfo -*-
## @deftypefn {Function File} {} niftiread (@var{filename})
## @deftypefnx {Function File} {} niftiread (@var{headerfile}, @var{imagefile})
## @deftypefnx {Function File} {} niftiread (@var{info})
## Read image data from a NIfTI-1/2 and Analyze7.5 formatted image file
##
## Loading a NIfTI-1/2 file specified by @var{filename}, or a two-part NIfTI
## or Analyze7.5 files using @var{headerfile} and @var{imagefile}. The
## accepted file suffixes include .nii, .nii.gz, .hdr, .hdr.gz, .img, img.gz
##
## @seealso{niftiinfo, niftiwrite}
## @end deftypefn

function img = niftiread (filename, varargin)

Expand All @@ -42,14 +42,14 @@

endfunction;

% !demo
% ! %% Reading a
% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
% ! gunzip ('minimal.nii.gz');
% ! img=niftiread('minimal.nii');
# !demo
# ! ## Reading a
# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
# ! gunzip ('minimal.nii.gz');
# ! img=niftiread('minimal.nii');

% !test
% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
% ! gunzip ('minimal.nii.gz');
% ! img=niftiread('minimal.nii');
% ! assert (size(img),[64 64 10]);
# !test
# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz')
# ! gunzip ('minimal.nii.gz');
# ! img=niftiread('minimal.nii');
# ! assert (size(img),[64 64 10]);
Loading

0 comments on commit b7bcb2b

Please sign in to comment.