diff --git a/CheckTargets.m b/CheckTargets.m index 3f3ae7a..efee9c1 100644 --- a/CheckTargets.m +++ b/CheckTargets.m @@ -1,22 +1,25 @@ function CheckTargets(MRS_struct) filepath = fullfile(fileparts(which(mfilename('fullpath'))), 'GannetPreInitialise.m'); -msg = 'Incorrect targets entered in GannetPreInitialise.m. Check spelling, allowable options and order of targets.'; +msg = 'Incorrect targets entered in GannetPreInitialise.m. Check spelling, allowable options, and order of targets.'; msg = hyperlink(['matlab: opentoline(''' filepath ''', 4, 0)'], 'Incorrect targets entered in GannetPreInitialise.m', msg); switch num2str(length(MRS_struct.p.target)) case '1' if any(strcmp(MRS_struct.p.target, {'GABA', 'Glx', 'GABAGlx', 'GSH', 'Lac', 'EtOH'})) if MRS_struct.p.phantom && strcmp(MRS_struct.p.target, 'GABAGlx') + fprintf('\n'); error(msg); end if MRS_struct.p.HERMES msg = 'MRS_struct.p.HERMES is set to 1 in GannetPreInitialise.m. Add a second target metabolite or set flag to 0.'; msg = hyperlink(['matlab: opentoline(''' filepath ''', 4, 0)'], 'Add a second target metabolite', msg); msg = hyperlink(['matlab: opentoline(''' filepath ''', 33, 0)'], 'set flag to 0', msg); + fprintf('\n'); error(msg); end else + fprintf('\n'); error(msg); end case '2' @@ -25,14 +28,17 @@ function CheckTargets(MRS_struct) all(strcmp(MRS_struct.p.target, {'Glx', 'GSH'})) ... all(strcmp(MRS_struct.p.target, {'Lac', 'GSH'}))]) if MRS_struct.p.phantom && any(strcmp(MRS_struct.p.target, 'GABAGlx')) + fprintf('\n'); error(msg); end if ~MRS_struct.p.HERMES msg = 'Two target metabolites detected. MRS_struct.p.HERMES must be set to 1 in GannetPreInitialise.m.'; msg = hyperlink(['matlab: opentoline(''' filepath ''', 33, 0)'], 'MRS_struct.p.HERMES must be set to 1', msg); + fprintf('\n'); error(msg); end else + fprintf('\n'); error(msg); end case '3' @@ -40,9 +46,11 @@ function CheckTargets(MRS_struct) if ~MRS_struct.p.HERMES msg = 'Three target metabolites detected. MRS_struct.p.HERMES must be set to 1 in GannetPreInitialise.m.'; msg = hyperlink(['matlab: opentoline(''' filepath ''', 33, 0)'], 'MRS_struct.p.HERMES must be set to 1', msg); + fprintf('\n'); error(msg); end else + fprintf('\n'); error(msg); end end diff --git a/CoRegStandAlone/CoReg.m b/CoRegStandAlone/CoReg.m index a86b55b..d135798 100755 --- a/CoRegStandAlone/CoReg.m +++ b/CoRegStandAlone/CoReg.m @@ -17,17 +17,20 @@ spm_version = fileparts(which('spm')); if isempty(spm_version) msg = 'SPM not found! Please install SPM12 and make sure it is in your search path.'; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); elseif strcmpi(spm_version(end-3:end),'spm8') msg = ['SPM8 detected. Gannet no longer supports SPM8. ' ... 'Please install SPM12 and make sure it is in your search path.']; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); end if MRS_struct.ii ~= length(struc) - error('The number of NIfTI files does not match the number of MRS files processed by CoRegStandAlone.'); + fprintf('\n'); + error('The number of structural image files does not match the number of MRS files.'); end numscans = numel(MRS_struct.metabfile); diff --git a/CoRegStandAlone/CoRegStandAlone.m b/CoRegStandAlone/CoRegStandAlone.m index 30054e1..fd09a4f 100755 --- a/CoRegStandAlone/CoRegStandAlone.m +++ b/CoRegStandAlone/CoRegStandAlone.m @@ -44,7 +44,8 @@ % already exists in the output directory if nargin == 0 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/CoRegStandAlone/Seg.m b/CoRegStandAlone/Seg.m index 46169ba..6283441 100755 --- a/CoRegStandAlone/Seg.m +++ b/CoRegStandAlone/Seg.m @@ -26,12 +26,14 @@ spm_version = fileparts(which('spm')); if isempty(spm_version) msg = 'SPM not found! Please install SPM12 and make sure it is in your search path.'; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); elseif strcmpi(spm_version(end-3:end),'spm8') msg = ['SPM8 detected. Gannet no longer supports SPM8. ' ... 'Please install SPM12 and make sure it is in your search path.']; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); end diff --git a/DiscernDataType.m b/DiscernDataType.m index 71615d4..9a27e50 100644 --- a/DiscernDataType.m +++ b/DiscernDataType.m @@ -22,7 +22,7 @@ case '.sdat' MRS_struct.p.vendor = 'Philips'; otherwise - error('Unrecognized file type! Extension should be .7, .dat, .data, .dcm, .gz, .ima, .nii, .raw, .rda, or, .sdat.'); + error('Unrecognized file type! Extension must be .7, .dat, .data, .dcm, .gz, .ima, .nii, .raw, .rda, or, .sdat.'); end end diff --git a/GERead.m b/GERead.m index e40b0e3..ebcc1fc 100644 --- a/GERead.m +++ b/GERead.m @@ -325,7 +325,7 @@ MRS_struct.p.nrows_water(ii) = refframes; if totalframes ~= (dataframes + refframes + 1) * nechoes % RTN 2017 - error('# of totalframes not same as (dataframes + refframes + 1) * nechoes'); + error('Number of totalframes does not equal (dataframes + refframes + 1) * nechoes'); end ShapeData = reshape(raw_data, [2 MRS_struct.p.npoints(ii) totalframes nreceivers]); diff --git a/GannetCoRegister.m b/GannetCoRegister.m index eaba451..2251b81 100644 --- a/GannetCoRegister.m +++ b/GannetCoRegister.m @@ -3,10 +3,11 @@ % Coregistration of MRS voxel volumes to imaging datasets, based on headers. if nargin < 2 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end -MRS_struct.version.coreg = '230313'; +MRS_struct.version.coreg = '230314'; warning('off'); % temporarily suppress warning messages @@ -14,12 +15,14 @@ spm_version = fileparts(which('spm')); if isempty(spm_version) msg = 'SPM not found! Please install SPM12 and make sure it is in your search path.'; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); elseif strcmpi(spm_version(end-3:end), 'spm8') msg = ['SPM8 detected. Gannet no longer supports SPM8. ' ... 'Please install SPM12 and make sure it is in your search path.']; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); end @@ -32,6 +35,7 @@ struc = GetFullPath(struc); if MRS_struct.p.numScans ~= length(struc) + fprintf('\n'); error('The number of structural image files does not match the number of MRS files processed by GannetLoad.'); end diff --git a/GannetFit.m b/GannetFit.m index c9c21a8..ed0733b 100644 --- a/GannetFit.m +++ b/GannetFit.m @@ -3,10 +3,11 @@ % Signal fitting in the frequency domain using nonlinear least-squares optimization if nargin == 0 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end -MRS_struct.version.fit = '230313'; +MRS_struct.version.fit = '230314'; if MRS_struct.p.PRIAM vox = MRS_struct.p.vox; @@ -551,7 +552,7 @@ otherwise - error('Fitting %s not recognised',target{jj}); + error('Metabolite ''%s'' not recognized.', target{jj}); end diff --git a/GannetFitPhantom.m b/GannetFitPhantom.m index a4d8618..46e8ae7 100644 --- a/GannetFitPhantom.m +++ b/GannetFitPhantom.m @@ -3,10 +3,11 @@ % Updates by MM 2018-2020 if nargin == 0 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end -MRS_struct.version.fit_phantom = '230125'; +MRS_struct.version.fit_phantom = '230314'; if MRS_struct.p.PRIAM vox = MRS_struct.p.vox; @@ -281,7 +282,7 @@ otherwise - error('Fitting %s not recognised',target{jj}); + error('Metabolite ''%s'' not recognized.', target{jj}); end diff --git a/GannetLoad.m b/GannetLoad.m index 4417dcc..6331e91 100644 --- a/GannetLoad.m +++ b/GannetLoad.m @@ -14,11 +14,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if nargin == 0 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end MRS_struct.version.Gannet = '3.3.1'; -MRS_struct.version.load = '230313'; +MRS_struct.version.load = '230314'; VersionCheck(0, MRS_struct.version.Gannet); ToolboxCheck; @@ -465,10 +466,7 @@ AllFramesFTrealign = AllFramesFT; MRS_struct.out.reject{ii} = zeros(1,size(AllFramesFT,2)); otherwise - filepath = fullfile(fileparts(which(mfilename('fullpath'))), 'GannetPreInitialise.m'); - msg = 'FPC parameter in GannetPreInitialise.m not recognized. Check spelling.'; - msg = hyperlink(['matlab: opentoline(''' filepath ''', 22, 0)'], 'FPC parameter in GannetPreInitialise.m not recognized', msg); - error(msg); + error('Alignment method in GannetPreInitialise.m not recognized. Check spelling.'); end MRS_struct.spec.AllFramesFT = AllFramesFT; diff --git a/GannetQuantify.m b/GannetQuantify.m index efcbd77..15b981d 100644 --- a/GannetQuantify.m +++ b/GannetQuantify.m @@ -1,10 +1,11 @@ function MRS_struct = GannetQuantify(MRS_struct) if nargin == 0 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end -MRS_struct.version.quantify = '230302'; +MRS_struct.version.quantify = '230314'; if MRS_struct.p.PRIAM vox = MRS_struct.p.vox; @@ -16,8 +17,8 @@ % Check if there are water files, otherwise exit if ~strcmp(MRS_struct.p.reference, 'H2O') - warning('No water reference files found in input structure ''%s''. GannetQuantify.m requires water references. Exiting...\n', inputname(1)); - return + fprintf('\n'); + error('No water reference files found in input structure ''%s''. GannetQuantify.m requires water references to run. Exiting...', inputname(1)); end % ****** diff --git a/GannetSegment.m b/GannetSegment.m index dc20c5c..5452f4f 100644 --- a/GannetSegment.m +++ b/GannetSegment.m @@ -8,10 +8,11 @@ % are loaded and used for the voxel segmentation if nargin == 0 - error('MATLAB:minrhs','Not enough input arguments.'); + fprintf('\n'); + error('MATLAB:minrhs', 'Not enough input arguments.'); end -MRS_struct.version.segment = '230302'; +MRS_struct.version.segment = '230314'; warning('off'); % temporarily suppress warning messages @@ -19,12 +20,14 @@ spm_version = fileparts(which('spm')); if isempty(spm_version) msg = 'SPM not found! Please install SPM12 and make sure it is in your search path.'; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); elseif strcmpi(spm_version(end-3:end), 'spm8') msg = ['SPM8 detected. Gannet no longer supports SPM8. ' ... 'Please install SPM12 and make sure it is in your search path.']; - msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg); + msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12/', 'SPM12', msg); + fprintf('\n'); error(msg); end diff --git a/GannetVersion.m b/GannetVersion.m index 0f30066..73c9e77 100644 --- a/GannetVersion.m +++ b/GannetVersion.m @@ -4,7 +4,8 @@ loadFile = which('GannetLoad'); fileID = fopen(loadFile, 'rt'); if fileID == -1 - error('Can''t read %s.', loadFile); + fclose(fileID); + error('Cannot read %s.', loadFile); end str = fread(fileID, Inf, '*uchar'); fclose(fileID); diff --git a/NIfTIMRSRead.m b/NIfTIMRSRead.m index 5172db7..cacf5eb 100644 --- a/NIfTIMRSRead.m +++ b/NIfTIMRSRead.m @@ -363,7 +363,8 @@ else - error(sprintf('\nData are not single-voxel data. Exiting...')); + fprintf('\n'); + error('Data are not single-voxel data. Exiting...'); end diff --git a/PRIAM/read_cpx.m b/PRIAM/read_cpx.m index dec4c02..63a1694 100755 --- a/PRIAM/read_cpx.m +++ b/PRIAM/read_cpx.m @@ -508,12 +508,13 @@ info.filename = filename; % Open LAB file and read all hexadecimal labels labfid = fopen(labname,'r'); -if labfid==-1, - error( sprintf('Cannot open %s for reading', labname) ); +if labfid == -1 + fclose(labfid); + error('Cannot open %s for reading', labname); end % Read all hexadecimal labels -[unparsed_labels, readsize] = fread (labfid,[16 Inf], 'uint32=>uint32'); +unparsed_labels = fread (labfid, [16 Inf], 'uint32=>uint32'); info.nLabels = size(unparsed_labels,2); fclose(labfid); diff --git a/PaperPlot.m b/PaperPlot.m index d439067..b1c46a2 100644 --- a/PaperPlot.m +++ b/PaperPlot.m @@ -63,6 +63,7 @@ function PaperPlot(MRS_struct, varargin) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if nargin == 0 + fprintf('\n'); error('MATLAB:minrhs','Not enough input arguments.'); end diff --git a/PhilipsRawRead.m b/PhilipsRawRead.m index acfdabe..0e64fd6 100644 --- a/PhilipsRawRead.m +++ b/PhilipsRawRead.m @@ -729,7 +729,8 @@ fid = fopen([rawpath filesep 'rec_spectra_txt' filesep savefile1 '.txt'],'w'); if fid == -1 - disp(['cant open file: ' savefile1]) + fclose(fid); + disp(['Cannot open file: ' savefile1]) continue end for p=1:npoints @@ -1601,12 +1602,12 @@ info.filename = filename; % Open LAB file and read all hexadecimal labels labfid = fopen(labname,'r'); -if labfid==-1, - error( sprintf('Cannot open %s for reading', labname) ); +if labfid == -1 + error('Cannot open %s for reading', labname); end % Read all hexadecimal labels -[unparsed_labels, readsize] = fread (labfid,[16 Inf], 'uint32=>uint32'); +unparsed_labels = fread (labfid, [16 Inf], 'uint32=>uint32'); info.nLabels = size(unparsed_labels,2); fclose(labfid); @@ -2228,7 +2229,7 @@ function write_sdat_spar(data, fname_p, fname_out, fname_out_spar, averages, np) end % Check that the file has been open in ieee-le machineformat -[filename, permission, machineformat] = fopen(fid); +[~, ~, machineformat] = fopen(fid); if ~strcmp(machineformat, 'ieee-le') error('Use FOPEN with ieee-le precision'); end diff --git a/SDATread.m b/SDATread.m index acac636..81bd3d2 100644 --- a/SDATread.m +++ b/SDATread.m @@ -3,8 +3,8 @@ % Open file to read reference scan data. fid = fopen(filename, 'rb', 'ieee-le'); if fid == -1 - sprintf('Unable to locate file %s', filename); - return + fclose(fid); + error('Unable to locate file %s', filename); end % Set up a structure to take the data: diff --git a/SDATreadMEGA.m b/SDATreadMEGA.m index 6551f06..1713ed3 100644 --- a/SDATreadMEGA.m +++ b/SDATreadMEGA.m @@ -3,8 +3,8 @@ % Open file to read reference scan data. fid = fopen(filename, 'rb', 'ieee-le'); if fid == -1 - sprintf('Unable to locate file %s', filename); - return + fclose(fid); + error('Unable to locate file %s', filename); end % Set up a structure to take the data: diff --git a/ToolboxCheck.m b/ToolboxCheck.m index cf10753..06c32c4 100644 --- a/ToolboxCheck.m +++ b/ToolboxCheck.m @@ -20,8 +20,10 @@ for ii = 1:length(missing) msg = [msg missing{ii} '\n']; end + msg(end-1:end) = []; msg = hyperlink('https://www.mathworks.com/matlabcentral/answers/101885-how-do-i-install-additional-toolboxes-into-an-existing-installation-of-matlab', ... 'see instructions', msg); + fprintf('\n'); error(sprintf(msg)); end diff --git a/UpdateGannet.m b/UpdateGannet.m index 6b9ef0a..a879733 100644 --- a/UpdateGannet.m +++ b/UpdateGannet.m @@ -6,7 +6,7 @@ try java.net.InetAddress.getByName('www.google.com'); catch - error('No internet connection. Can''t run UpdateGannet.'); + error('No internet connection. Cannot run UpdateGannet.'); end % First, check if a new version of Gannet is available; exit otherwise diff --git a/VersionCheck.m b/VersionCheck.m index e813002..d460e66 100644 --- a/VersionCheck.m +++ b/VersionCheck.m @@ -16,7 +16,8 @@ loadFile = which('GannetLoad'); fileID = fopen(loadFile, 'rt'); if fileID == -1 - error('Can''t read %s.', loadFile); + fclose(fileID); + error('Cannot read %s.', loadFile); end str = fread(fileID, Inf, '*uchar'); fclose(fileID);