From b9aae03c7650860c5cd24b16b3de4e22dc103e13 Mon Sep 17 00:00:00 2001 From: Christian Gaser Date: Sun, 22 Jan 2023 23:40:24 +0100 Subject: [PATCH] Changed: Made many changes for octave compatibility. Fixed: Corrected wrong arguments in sprintf command in cat_main_updateSPM1639.m Fixed: Contrasts were sometimes not recognized in cat_spm_results_ui.m because we have to go into the analysis folder. Fixed: Clipping should be ignored for cat_vol_slice_overlay if lower and upper clipping values are equal. Fixed: Figure in cat_vol_slice_overlay_ui.m was set to unvisible. Changed paths: M CHANGES.txt M cat_io_cprintf.m M cat_io_xml.m M cat_main_reportfig.m M cat_main_reportstr.m M cat_main_updateSPM1639.m M cat_run.m M cat_spm_results_ui.m M cat_stat_check_cov_old.m M cat_surf_createCS2.m M cat_surf_results.m M cat_vbdist.c M cat_vol_approx.m M cat_vol_slice_overlay.m M compile.m M spm_cat12.m --- CHANGES.txt | 29 +++++++++++++++++++++++++++ cat_io_cprintf.m | 2 +- cat_io_xml.m | 42 +++++++++++----------------------------- cat_main_reportfig.m | 2 +- cat_main_reportstr.m | 4 ++-- cat_main_updateSPM1639.m | 2 +- cat_run.m | 12 ------------ cat_spm_results_ui.m | 3 ++- cat_stat_check_cov_old.m | 2 +- cat_surf_createCS2.m | 2 +- cat_surf_results.m | 19 +++++++++--------- cat_vbdist.c | 2 +- cat_vol_approx.m | 2 +- cat_vol_slice_overlay.m | 6 +++--- compile.m | 9 ++++++--- spm_cat12.m | 6 +++++- 16 files changed, 75 insertions(+), 69 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index dd5e316e..4d06eb0d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,33 @@ ------------------------------------------------------------------------ +r2166 | gaser | 2023-01-22 23:40:08 + +Changed paths: + M CHANGES.txt + M cat_io_cprintf.m + M cat_io_xml.m + M cat_main_reportfig.m + M cat_main_reportstr.m + M cat_main_updateSPM1639.m + M cat_run.m + M cat_spm_results_ui.m + M cat_stat_check_cov_old.m + M cat_surf_createCS2.m + M cat_surf_results.m + M cat_vbdist.c + M cat_vol_approx.m + M cat_vol_slice_overlay.m + M compile.m + M spm_cat12.m + +Changed: Made many changes for octave compatibility. +Fixed: Corrected wrong arguments in sprintf command in + cat_main_updateSPM1639.m +Fixed: Contrasts were sometimes not recognized in cat_spm_results_ui.m because + we have to go into the analysis folder. +Fixed: Clipping should be ignored for cat_vol_slice_overlay if lower and upper + clipping values are equal. +Fixed: Figure in cat_vol_slice_overlay_ui.m was set to unvisible. +------------------------------------------------------------------------ r2164 | gaser | 2023-01-14 21:46:06 Changed paths: diff --git a/cat_io_cprintf.m b/cat_io_cprintf.m index 4692aaff..658fd086 100644 --- a/cat_io_cprintf.m +++ b/cat_io_cprintf.m @@ -215,7 +215,7 @@ end % The following is for debug use only: %global docElement el debugData - if ~exist('el','var') || isempty(el), el=handle([]); end %#ok mlint short-circuit error ("used before defined") + if ~strcmpi(spm_check_version,'octave') && (~exist('el','var') || isempty(el)), el=handle([]); end %#ok mlint short-circuit error ("used before defined") if nargin<1, showDemo(majorVersion,minorVersion); return; end if isempty(style), return; end % #### begin extended styles #### diff --git a/cat_io_xml.m b/cat_io_xml.m index ff596d3b..b28c5bae 100644 --- a/cat_io_xml.m +++ b/cat_io_xml.m @@ -52,28 +52,6 @@ % ______________________________________________________________________ onlyxml = 0; - if strcmpi(spm_check_version,'octave') - pkglist = pkg('list'); - if isempty(pkglist) || all( strfind( [pkglist{:}.name] , 'io') == 0 ) - pkg install -forge io - end - pkg load io - try - % add java files - xmljava{1} = fullfile(fileparts(mfilename('fullpath')),'Octave','xercesImpl.jar'); - xmljava{2} = fullfile(fileparts(mfilename('fullpath')),'Octave','xml-apis.jar'); - % call them - for xi=1:numel(xmljava), eval(sprintf('javaaddpath("%s");',xmljava{xi})); end - % test function - xmlread; - catch e - if strcmp(e.message,'xmlread: no Java JRE or JDK detected, exiting') - onlyxml = 1; - end - end - - end - verbose = 0; @@ -188,8 +166,9 @@ try if usejava('jvm') xml_write(file,S); - elseif strcmpi(spm_check_version,'octave') && ~onlyxml - xmlwrite(file,S); + elseif strcmpi(spm_check_version,'octave') + warning off all + savexml(file,'S'); end catch %#ok<*NASGU> % can write xml file?? % This can be a warning as far as we have the mat. @@ -211,8 +190,8 @@ try if usejava('jvm') S = xml_read(file); - elseif strcmpi(spm_check_version,'octave') && ~onlyxml - S = xmlread(file); + elseif strcmpi(spm_check_version,'octave') + S = loadxml(file); end catch error('MATLAB:cat_io_xml:write+ReadErr','Can''t read XML-file ''%s'' for update!\n',file); @@ -223,8 +202,8 @@ try if usejava('jvm') S = xml_read(file); - elseif strcmpi(spm_check_version,'octave') && ~onlyxml - S = xmlread(file); + elseif strcmpi(spm_check_version,'octave') + S = loadxml(file); end catch error('MATLAB:cat_io_xml:write+ReadErr','Can''t read XML-file ''%s'' for update!\n',file); @@ -248,8 +227,9 @@ try if usejava('jvm') xml_write(file,S); - elseif strcmpi(spm_check_version,'octave') && ~onlyxml - xmlwrite(file,S); + elseif strcmpi(spm_check_version,'octave') + warning off all + savexml(file,'S'); end catch warning('MATLAB:cat_io_xml:writeErr','Can''t write XML-file ''%s''!\n',file); @@ -271,7 +251,7 @@ if usejava('jvm') S = xml_read(file); elseif strcmpi(spm_check_version,'octave') - S = xmlread(file); + S = loadxml(file); end warning on catch diff --git a/cat_main_reportfig.m b/cat_main_reportfig.m index e325b700..0153ef2a 100644 --- a/cat_main_reportfig.m +++ b/cat_main_reportfig.m @@ -970,7 +970,7 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str) % CAT atlas labeling LAB = job.extopts.LAB; NS = @(Ys,s) Ys==s | Ys==s+1; - if job.extopts.report.useoverlay>1 + if job.extopts.report.useoverlay>1 && ~strcmpi(spm_check_version,'octave') try spm_orthviews('window',hhp0,[0 2]); end V2 = VO; switch job.extopts.report.useoverlay diff --git a/cat_main_reportstr.m b/cat_main_reportstr.m index e2295c40..add70fb4 100644 --- a/cat_main_reportstr.m +++ b/cat_main_reportstr.m @@ -63,8 +63,8 @@ % red version in case of old version? % 1 line: Matlab, SPM12, CAT12 version number and GUI and experimental mode if strcmpi(spm_check_version,'octave') - str{1} = [str{1} struct('name', 'Version: OS / Octave / SPM12 / CAT12:','value',... - sprintf('%s / %s / %s / %s (%s)',qa.software.system,qa.software.version_octave,... + str{1} = [str{1} struct('name', 'Version: OS / SPM12 / CAT12:','value',... + sprintf('%s / %s / %s (%s)',qa.software.system,... qa.software.version_spm,qa.software.version_cat,catv))]; % native2unicode is working on the command line but not in the figure cub = '^3'; diff --git a/cat_main_updateSPM1639.m b/cat_main_updateSPM1639.m index 4406de66..d1999087 100644 --- a/cat_main_updateSPM1639.m +++ b/cat_main_updateSPM1639.m @@ -94,7 +94,7 @@ abs(diff(res.spmP0.hsti(1:2:3,:))) ./ max(eps,sum(res.spmP0.hsti(1:2:3,:))); ])); res.spmP0.help = [res.spmP0.help; { - sprintf('The hsti is the histogram of the T1 image for each class (prob>%0.2%%,%d buckets) ',minprob/255,hbuckets)}; + sprintf('The hsti is the histogram of the T1 image for each class (prob>%0.2f,%d buckets) ',minprob/255,hbuckets)}; 'that are combined into the average intensity difference between classes histidiff with 1 for the ideal case without overlap and 0 for high overlap. ']; if job.extopts.expertgui>1 && res.spmP0.hstidiff<0.5 cat_io_addwarning('cat_main_updateSPM:highIntOverlapBetweenClasses',... diff --git a/cat_run.m b/cat_run.m index c68749b2..3a83a13a 100644 --- a/cat_run.m +++ b/cat_run.m @@ -1006,18 +1006,6 @@ end - if strcmpi(spm_check_version,'octave') && job.extopts.regstr > 0 - warning('cat_run:noShooting','No Shooting registration possible under Octave yet. Switch to Dartel registration.') - job.extopts.regstr = 0; - if isfield(job.extopts,'regmethod') - job.extopts.regmethod = rmfield(job.extopts.regmethod,'shooting'); - else - job.extopts = rmfield(job.extopts,'shooting'); - end - job.extopts.dartel.darteltpm = cat_get_defaults('extopts.darteltpm'); - end - - %% set Dartel/Shooting templates if isfield(job.extopts,'regmethod') if isfield(job.extopts.regmethod,'dartel') diff --git a/cat_spm_results_ui.m b/cat_spm_results_ui.m index b3c30642..2c8c4684 100644 --- a/cat_spm_results_ui.m +++ b/cat_spm_results_ui.m @@ -294,8 +294,9 @@ if exist(fullfile(fileparts(fileparts(mfilename('fullpath'))),'TFCE'),'dir') [spmmatfile, sts] = spm_select(1,'^SPM\.mat$','Select SPM.mat'); swd = spm_file(spmmatfile,'fpath'); + cd(swd) warning off - load(fullfile(swd,'SPM.mat'),'SPM','xSPM'); + load('SPM.mat','SPM','xSPM'); warning on [Ic,xCon] = spm_conman(SPM,'T&F',Inf,' Select contrast(s)...','',1); diff --git a/cat_stat_check_cov_old.m b/cat_stat_check_cov_old.m index 016a5ee9..e941a1f3 100644 --- a/cat_stat_check_cov_old.m +++ b/cat_stat_check_cov_old.m @@ -1,4 +1,4 @@ -function varargout = cat_stat_check_cov(job) +function varargout = cat_stat_check_cov_old(job) %cat_stat_check_cov. To check covariance across sample. % % Images have to be in the same orientation with same voxel size diff --git a/cat_surf_createCS2.m b/cat_surf_createCS2.m index c27d4a53..4223624b 100644 --- a/cat_surf_createCS2.m +++ b/cat_surf_createCS2.m @@ -54,7 +54,7 @@ cstime = clock; if strcmpi(spm_check_version,'octave') - cat_io_addwarning('cat_surf_createCS:noSRP','Correction of surface collisions is not yet available under Octave.',2,[1 1]) + cat_io_addwarning('cat_surf_createCS2:noSRP','Correction of surface collisions is not yet available under Octave.',2,[1 1]) opt.SRP = 0; end diff --git a/cat_surf_results.m b/cat_surf_results.m index db56b762..8b39dc5c 100644 --- a/cat_surf_results.m +++ b/cat_surf_results.m @@ -127,7 +127,7 @@ end % close old figures - if ishandle(12),close(12);end;if ishandle(21),close(21);end; + if ishandle(12),close(12);end;if ishandle(22),close(22);end; % remove any existing data if exist('H','var') @@ -205,7 +205,7 @@ 'ovmin', [0.050 0.125 0.425 0.100],'ovmax', [0.525 0.125 0.425 0.100],... 'save', [0.050 0.050 0.425 0.050],'close', [0.525 0.050 0.425 0.050]); - H.figure = figure(22); + H.figure = figure(23); clf(H.figure); set(H.figure, 'MenuBar', 'none', 'Position', H.pos{1}.fig, ... @@ -1847,8 +1847,8 @@ function disphist(type) OV.reference_range = [0.2 1.0]; end -% clipping if defined -if ~isempty(H.clip) +% clipping if (meaningful) defined +if ~isempty(H.clip) && H.clip(2) ~= H.clip(3) if ~isnan(H.clip(2)) && ~isnan(H.clip(3)) OV.clip = H.clip(2:3); else @@ -1914,7 +1914,8 @@ function disphist(type) end % show MIP and keep position if window exists -OV.fig = 21; +OV.fig = 22; + if ishandle(OV.fig) cat_vol_slice_overlay(OV); else @@ -2805,19 +2806,19 @@ function select_data(obj, event_obj, P) P0{i} = Pout; H.isvol(i) = 1; H.Pvol{i} = Pvol; - H.Pvol_sel = Pvol; vol = spm_read_vols(spm_vol(Pvol)); - H.Pvol_mn{i} = min(vol(:)); - H.Pvol_mx{i} = max(vol(:)); + H.Pvol_mn{i} = min(vol(vol ~= 0)); + H.Pvol_mx{i} = max(vol(vol ~= 0)); % print warning if no SPM.mat file was found - if ~exist(fullfile(pp, 'SPM.mat'), 'file') || ~exist(fullfile(pp, 'vSPM.mat'), 'file') + if ~exist(fullfile(pp, 'SPM.mat'), 'file') && ~exist(fullfile(pp, 'vSPM.mat'), 'file') fprintf('Warning: Please ensure that %s is spatially registered to the new MNI152NLin2009cAsym template space.\n',[ff ee]); end else P0{i} = deblank(P(i,:)); end end +H.Pvol_sel = H.Pvol{1}; P0 = char(P0); info = cat_surf_info(P0,0); diff --git a/cat_vbdist.c b/cat_vbdist.c index f2a7bb46..a7be7fe1 100644 --- a/cat_vbdist.c +++ b/cat_vbdist.c @@ -150,7 +150,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* such as cat_run_job.APRGs:196 where the old call "Ymx = Ybgd./(Ybd+Ybgd);" was working but * the new version caused a treshold in an image with INF that lead to an empty brainmask * Although, this can be solved by "Ymx = min(1,Ybgd./(Ybd+Ybgd));" I do not know other - * problematic call now and this should maybe change later. + * problematic call now and this should maybe changed later. */ if (L[i]>=0.5) D[i]=0.0; else D[i]=FLT_MAX; if (L[i]>255.0) diff --git a/cat_vol_approx.m b/cat_vol_approx.m index b5c5f8e0..f428a7cb 100644 --- a/cat_vol_approx.m +++ b/cat_vol_approx.m @@ -199,7 +199,7 @@ PM{1} = (cat_vbdist(PM{1},true(size(PM{1})),[1.5 1 1]) + ... cat_vol_smooth3X(rand(PTsize)*20,2) + cat_vol_smooth3X(randn(PTsize)*20))