Skip to content

Commit

Permalink
Further cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markmikkelsen committed Mar 14, 2023
1 parent 31fb73e commit 674d1fe
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 49 deletions.
10 changes: 9 additions & 1 deletion CheckTargets.m
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -25,24 +28,29 @@ 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'
if all(strcmp(MRS_struct.p.target, {'EtOH', 'GABA', 'GSH'}))
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
Expand Down
9 changes: 6 additions & 3 deletions CoRegStandAlone/CoReg.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion CoRegStandAlone/CoRegStandAlone.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
6 changes: 4 additions & 2 deletions CoRegStandAlone/Seg.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion DiscernDataType.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion GERead.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
12 changes: 8 additions & 4 deletions GannetCoRegister.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
% 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

% First check if SPM12 is installed and on the search path
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

Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions GannetFit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -551,7 +552,7 @@

otherwise

error('Fitting %s not recognised',target{jj});
error('Metabolite ''%s'' not recognized.', target{jj});

end

Expand Down
7 changes: 4 additions & 3 deletions GannetFitPhantom.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -281,7 +282,7 @@

otherwise

error('Fitting %s not recognised',target{jj});
error('Metabolite ''%s'' not recognized.', target{jj});

end

Expand Down
10 changes: 4 additions & 6 deletions GannetLoad.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions GannetQuantify.m
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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

% ******
Expand Down
11 changes: 7 additions & 4 deletions GannetSegment.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
% 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

% First check if SPM12 is installed and on the search path
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

Expand Down
3 changes: 2 additions & 1 deletion GannetVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion NIfTIMRSRead.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions PRIAM/read_cpx.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions PaperPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function PaperPlot(MRS_struct, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin == 0
fprintf('\n');
error('MATLAB:minrhs','Not enough input arguments.');
end

Expand Down
11 changes: 6 additions & 5 deletions PhilipsRawRead.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions SDATread.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions SDATreadMEGA.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 674d1fe

Please sign in to comment.