0001 function [mri] = mri_toolbox_defaults(command,mri);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 mriversion = '$Revision: 1.1 $';
0047 fprintf('\nMRI_TOOLBOX_DEFAULTS [v %s]\n',mriversion(11:15));
0048
0049 if version('-release') < 10,
0050 msg = printf('matlab release < version 10, mri_toolbox GUIs may fail.\n');
0051 warning(msg);
0052 end
0053
0054 if ~exist('command','var'), command = 'create'; end
0055
0056
0057 mriPath = fileparts(which('mri_toolbox'));
0058 if isempty(mriPath),
0059 msg = sprintf('Cannot find mri_toolbox on the matlab path.\nPlease use the addpath command.\n\n');
0060 error(msg);
0061 else
0062 mriPath = strcat(mriPath,filesep);
0063 end
0064
0065
0066
0067 mriPath = fileparts(which('avw_view'));
0068 if isempty(mriPath),
0069 msg = sprintf('Cannot find mri_toolbox on the matlab path.\nPlease install and use the addpath command.\n\n');
0070 warning(msg);
0071 mriPath = mriPath;
0072 else
0073 mriPath = strcat(mriPath,filesep);
0074 end
0075
0076
0077 switch command
0078 case 'create',
0079
0080 fprintf('...creating mri_toolbox defaults\n\n');
0081
0082 mri = [];
0083
0084
0085 mri.path = strcat(mriPath,'mri_example_data',filesep);
0086 mri.file = 'T1.img';
0087 mri.type = 'Analyze';
0088 mri.orient = 'auto';
0089 mri.series = 1;
0090 mri.data = [];
0091 mri.fiducials = [];
0092 mri.IEEEMachine = 'ieee-be';
0093 mri.plot = 0;
0094
0095 mri.colormap = gray(255);
0096 mri.hold = 0;
0097
0098 case 'read'
0099
0100
0101 [path,name,ext] = fileparts(strcat(mriPath,'mri_toolbox_defaults.mat'));
0102 file = fullfile(path,[name ext]);
0103 if exist(file) == 2,
0104 fprintf('...reading mri_toolbox defaults from:\n%s\n\n',file);
0105 load(file);
0106 else
0107 fprintf('...cannot locate mri_toolbox defaults - recreating defaults.\n\n');
0108 mri = mri_toolbox_defaults;
0109 end
0110
0111
0112
0113
0114 mriPathExist = exist(mri.path);
0115 if ~mriPathExist,
0116 fprintf('...mri.path does not exist - reinitializing defaults.\n');
0117 mri = mri_toolbox_defaults('create');
0118 mri_toolbox_defaults('write',mri);
0119 end
0120
0121 case 'write'
0122
0123 if ~exist('mri','var'),
0124 msg = sprintf('mri argument is essential: mri_toolbox_defaults(''write'',mri)');
0125 error(msg);
0126 end
0127
0128 [path,name,ext] = fileparts(strcat(mriPath,'mri_toolbox_defaults.mat'));
0129 file = fullfile(path,[name ext]);
0130
0131 save(file,'mri');
0132
0133 fprintf('...saved mri_toolbox defaults to:\n%s\n\n',file);
0134
0135 case 'write_other'
0136
0137 if ~exist('mri','var'),
0138 msg = sprintf('mri argument is essential: mri_toolbox_defaults(''write_other'',mri)');
0139 error(msg);
0140 end
0141
0142 [path,name,ext] = fileparts(strcat(mri.path, filesep, mri.file));
0143 ext = '.mat';
0144 file = fullfile(path,[name ext]);
0145
0146 [newfile,newpath] = uiputfile(file,'Save MRI_TOOLBOX Dataset to File:');
0147 if (newfile == 0) & (newpath == 0),
0148 fprintf('...aborting save\n\n');
0149 else
0150 [path,name,ext] = fileparts(strcat(newpath, filesep, newfile));
0151 ext = '.mat';
0152 file = fullfile(path,[name ext]);
0153 save(file,'mri');
0154 fprintf('...saved mri_toolbox parameters to:\n%s\n\n',file);
0155 recentfiles = mri_toolbox_recent(file);
0156 end
0157
0158 otherwise
0159 error('...invalid command\n\n');
0160 end
0161
0162 return