Skip to content

Commit

Permalink
Merge with SPM changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gllmflndn committed Nov 8, 2023
1 parent 6ce36fd commit d270f75
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 40 deletions.
4 changes: 2 additions & 2 deletions @gifti/gifti.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
this = varargin{1};

elseif isstruct(varargin{1})
f = {'faces', 'face', 'tri' 'vertices', 'vert', 'pnt', 'cdata', 'indices'};
ff = {'faces', 'faces', 'faces', 'vertices', 'vertices', 'vertices', 'cdata', 'indices'};
f = {'faces', 'face', 'tri' 'vertices', 'vert', 'pnt', 'pos', 'cdata', 'indices'};
ff = {'faces', 'faces', 'faces', 'vertices', 'vertices', 'vertices', 'vertices', 'cdata', 'indices'};
[c, ia] = intersect(f,fieldnames(varargin{1}));
if ~isempty(c)
this = gifti;
Expand Down
12 changes: 5 additions & 7 deletions @gifti/private/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env make -f
# GIfTI Makefile
#
# Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging
#
# $Id: Makefile 6704 2016-01-29 17:23:13Z guillaume $
# Copyright (C) 2008-2023 Wellcome Centre for Human Neuroimaging

include Makefile.var

SPMMEX = zstream.$(SUF) xml_parser.$(SUF) base64.$(SUF)
SPMMEX = zstream.$(MEXEXT) xml_parser.$(MEXEXT) base64.$(MEXEXT)

ifeq (mex,$(SUF))
ifeq (mex,$(MEXEXT))
export CFLAGS = $(shell $(MEX) -p CFLAGS) -std=c99
else
ifeq (windows,$(PLATFORM))
Expand All @@ -34,8 +32,8 @@ install:
tarball: all
$(TAR) cf spm_mex.tar $(SPMMEX)

%.$(SUF) : %.c
%.$(MEXEXT) : %.c
$(MEX) $< $(MEXEND)

xml_parser.$(SUF): xml_parser.c yxml.c yxml.h
xml_parser.$(MEXEXT): xml_parser.c yxml.c yxml.h
$(MEX) $< yxml.c $(MEXEND)
16 changes: 8 additions & 8 deletions @gifti/private/Makefile.var
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ MOVE = mv -f
TAR = tar
ZIP = gzip -f

ifndef SUF
ifndef MEXEXT
ifndef PLATFORM
PLATFORM = $(shell $(UNAME))
endif
##### Linux #####
ifeq (Linux,$(PLATFORM))
SUF = mexa64
MEXEXT = mexa64
endif
##### MacOS #####
ifeq (Darwin,$(PLATFORM))
SUF = mexmaci64
MEXEXT = mexmaci64
endif
##### Windows #####
ifeq (MINGW32,$(word 1,$(subst _, ,$(PLATFORM)))) # MSC
override PLATFORM = windows
ifeq (x86,$(PROCESSOR_ARCHITECTURE))
SUF = mexw32
MEXEXT = mexw32
else
SUF = mexw64
MEXEXT = mexw64
endif
MEXBIN = cmd /c "mex.bat
MEXOPTS += -DSPM_WIN32
Expand All @@ -68,19 +68,19 @@ ifndef SUF
AR = lib.exe /out:
endif
ifeq (MSYS,$(word 1,$(subst _, ,$(PLATFORM)))) # GCC
SUF = mexw64
MEXEXT = mexw64
MEXOPTS += -DSPM_WIN32
MOSUF = obj
endif
#### Octave ####
ifeq (octave,$(PLATFORM))
MEXBIN = mkoctfile
MEXOPTS = --mex
SUF = mex
MEXEXT = mex
override PLATFORM = $(shell $(UNAME))
endif
#### Otherwise ####
ifndef SUF
ifndef MEXEXT
$(error Unknowm platform $(PLATFORM))
endif
endif
Expand Down
4 changes: 4 additions & 0 deletions @gifti/private/gifti_read.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
% special case that does not require permuting
d = reshape(d,s.Dim);
else
if isa(d,'file_array')
%warning('Memory-mapped data are loaded into memory');
d = subsref(d,substruct('()',repmat({':'},1,numel(d.dim))));
end
d = permute(reshape(d,fliplr(s.Dim)),length(s.Dim):-1:1);
end
case 'ColumnMajorOrder'
Expand Down
9 changes: 6 additions & 3 deletions @gifti/private/obj_read.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
otherwise
v = sscanf(l(2:end),'%f %f %f');
if numel(v) > 3, v = v(1:3); end
M.vertices(size(M.vertices,1)+1,:) = v;
M.vertices(:,size(M.vertices,2)+1) = v;
end
case 'f'
f = sscanf(l(2:end),'%d %d %d');
Expand All @@ -64,8 +64,8 @@
end
end
i = find(f<0);
if isempty(i), f(i) = size(M.vertices,1) + f(i); end
M.faces(size(M.faces,1)+1,:) = f;
if isempty(i), f(i) = size(M.vertices,2) + f(i); end
M.faces(:,size(M.faces,2)+1) = f;
case 'o'
fprintf('Ignoring named objects.\n');
case 'g'
Expand All @@ -82,3 +82,6 @@
end

fclose(fid);

M.vertices = M.vertices';
M.faces = M.faces';
57 changes: 37 additions & 20 deletions @gifti/save.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
function save(this,filename,encoding)
function save(this,filename,encoding,ordering)
% Save GIfTI object in a GIfTI format file
% FORMAT save(this,filename,encoding)
% this - GIfTI object
% filename - name of GIfTI file to be created [Default: 'untitled.gii']
% encoding - optional argument to specify encoding format, among
% ASCII, Base64Binary, GZipBase64Binary, ExternalFileBinary.
% [Default: 'GZipBase64Binary']
% ordering - optional argument to specify array element ordering, among
% ColumnMajorOrder, RowMajorOrder
% [Default: 'ColumnMajorOrder']
%__________________________________________________________________________

% Guillaume Flandin
Expand All @@ -24,6 +27,24 @@ function save(this,filename,encoding)
end
filename = fullfile(p,[f e]);

% Check encoding
%--------------------------------------------------------------------------
if nargin < 3 || isempty(encoding), encoding = 'GZipBase64Binary'; end
switch encoding
case {'ASCII','Base64Binary','GZipBase64Binary','ExternalFileBinary'}
otherwise
error('Unknown encoding.');
end

% Check order
%--------------------------------------------------------------------------
if nargin < 4 || isempty(ordering), ordering = 'ColumnMajorOrder'; end
switch ordering
case {'ColumnMajorOrder','RowMajorOrder'}
otherwise
error('Unknown ordering.');
end

% Open file for writing
%--------------------------------------------------------------------------
fid = fopen(filename,'wt');
Expand All @@ -33,23 +54,17 @@ function save(this,filename,encoding)

% Write file
%--------------------------------------------------------------------------
if nargin < 3, encoding = 'GZipBase64Binary'; end
switch encoding
case {'ASCII','Base64Binary','GZipBase64Binary','ExternalFileBinary'}
otherwise
error('Unknown encoding.');
end
fid = save_gii(fid,this,encoding);
fid = save_gii(fid,this,encoding,ordering);

% Close file
%--------------------------------------------------------------------------
fclose(fid);


%==========================================================================
% function fid = save_gii(fid,this,encoding)
% function fid = save_gii(fid,this,encoding,ordering)
%==========================================================================
function fid = save_gii(fid,this,encoding)
function fid = save_gii(fid,this,encoding,ordering)

% Defaults for DataArray's attributes
%--------------------------------------------------------------------------
Expand Down Expand Up @@ -81,8 +96,7 @@ function save(this,filename,encoding)
for j=1:length(d)
this.data{i}.attributes.(sprintf('Dim%d',j-1)) = num2str(d(j));
end
% Enforce some conventions
this.data{i}.attributes.ArrayIndexingOrder = 'ColumnMajorOrder';
this.data{i}.attributes.ArrayIndexingOrder = ordering;
if ~isfield(this.data{i}.attributes,'DataType') || ...
isempty(this.data{i}.attributes.DataType)
warning('DataType set to default: %s', def.DataType);
Expand Down Expand Up @@ -206,7 +220,7 @@ function save(this,filename,encoding)
fprintf(fid,'%s</CoordinateSystemTransformMatrix>\n',o(2));
end

% Data (saved using MATLAB's ColumnMajorOrder)
% Data
%----------------------------------------------------------------------
fprintf(fid,'%s<Data>',o(2));
tp = getdict;
Expand All @@ -215,21 +229,24 @@ function save(this,filename,encoding)
catch
error('[GIFTI] Unknown DataType.');
end
dat = this.data{i}.data;
if isa(dat,'file_array')
dat = subsref(dat,substruct('()',repmat({':'},1,numel(dat.dim))));
end
if strcmp(this.data{i}.attributes.ArrayIndexingOrder,'RowMajorOrder')
dat = dat.';
end
switch this.data{i}.attributes.Encoding
case 'ASCII'
fprintf(fid, [tp.format ' '], this.data{i}.data);
fprintf(fid, [tp.format ' '], dat);
case 'Base64Binary'
fwrite(fid,base64('encode',typecast(this.data{i}.data(:),'uint8')),'uint8');
fprintf(fid,base64encode(typecast(dat(:),'uint8')));
% uses native machine format
case 'GZipBase64Binary'
fwrite(fid,base64('encode',zstream('C',typecast(this.data{i}.data(:),'uint8'))),'uint8');
fprintf(fid,base64encode(zstream('C',typecast(dat(:),'uint8'))));
% uses native machine format
case 'ExternalFileBinary'
extfilename = this.data{i}.attributes.ExternalFileName;
dat = this.data{i}.data;
if isa(dat,'file_array')
dat = subsref(dat,substruct('()',repmat({':'},1,numel(dat.dim))));
end
if ~def.offset
fide = fopen(extfilename,'w'); % uses native machine format
else
Expand Down

0 comments on commit d270f75

Please sign in to comment.