Home > bioelectromagnetism > mri_toolbox_defaults.m

mri_toolbox_defaults

PURPOSE ^

mri_toolbox_defaults - Create, read, write mri_toolbox defaults

SYNOPSIS ^

function [mri] = mri_toolbox_defaults(command,mri);

DESCRIPTION ^

 mri_toolbox_defaults - Create, read, write mri_toolbox defaults

 Useage:   [mri] = mri_toolbox_defaults(command,[mri])

 command  =  'create'
             'read'
             'write' or 'write_other'
 mri      =  structure returned by create|read command
             structure to write for write command

 All read and write commands are to a matlab .mat file.  The
 'write_other' command will write out a data specific archive
 that can be accessed from the recent files list.  It will be
 located in the folder where the eeg data is opened.
 
 Examples:
 mri = mri_toolbox_defaults; % create new defaults
 mri = mri_toolbox_defaults('read'); % read saved defaults
 mri_toolbox_defaults('write',mri);  % write current mri as default
 mri_toolbox_defaults('write_other',mri); % write current mri data

 The write command will write to the mri_toolbox
 installation folder.  The read command will first 
 try to find the paramater file in the mri_toolbox
 installation and otherwise recreates the defaults.

 Notes:    Handles parameter structure for the 
           mri_toolbox routines.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mri] = mri_toolbox_defaults(command,mri);
0002 
0003 % mri_toolbox_defaults - Create, read, write mri_toolbox defaults
0004 %
0005 % Useage:   [mri] = mri_toolbox_defaults(command,[mri])
0006 %
0007 % command  =  'create'
0008 %             'read'
0009 %             'write' or 'write_other'
0010 % mri      =  structure returned by create|read command
0011 %             structure to write for write command
0012 %
0013 % All read and write commands are to a matlab .mat file.  The
0014 % 'write_other' command will write out a data specific archive
0015 % that can be accessed from the recent files list.  It will be
0016 % located in the folder where the eeg data is opened.
0017 %
0018 % Examples:
0019 % mri = mri_toolbox_defaults; % create new defaults
0020 % mri = mri_toolbox_defaults('read'); % read saved defaults
0021 % mri_toolbox_defaults('write',mri);  % write current mri as default
0022 % mri_toolbox_defaults('write_other',mri); % write current mri data
0023 %
0024 % The write command will write to the mri_toolbox
0025 % installation folder.  The read command will first
0026 % try to find the paramater file in the mri_toolbox
0027 % installation and otherwise recreates the defaults.
0028 %
0029 % Notes:    Handles parameter structure for the
0030 %           mri_toolbox routines.
0031 %
0032 
0033 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0034 
0035 % Licence:  GNU GPL, no express or implied warranties
0036 % Created:  01/2002 Darren.Weber@flinders.edu.au
0037 % Modified: 02/2002 Darren.Weber@flinders.edu.au
0038 %           - adapted read/write output from .txt format
0039 %             to .mat format so it will contain data structures.
0040 %             Hence, it is no longer editable text.
0041 %           08/2002 Darren.Weber@flinders.edu.au
0042 %                   added MRI defaults
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 % try to locate the installation path
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 % try to locate the mri_toolbox installation path
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     % parameters for 'mri_open' & 'avw_view', see these for more information
0085     mri.path          = strcat(mriPath,'mri_example_data',filesep);
0086     mri.file          = 'T1.img';  % SPM T1 template
0087     mri.type          = 'Analyze'; % Analyze files
0088     mri.orient        = 'auto';
0089     mri.series        = 1;
0090     mri.data          = [];
0091     mri.fiducials     = []; % MRI fiducial points
0092     mri.IEEEMachine   = 'ieee-be'; % T1 is big endian MRI data
0093     mri.plot          = 0;
0094     
0095     mri.colormap      = gray(255);
0096     mri.hold          = 0;   % default for GUI hold checkboxes
0097     
0098 case 'read'
0099     
0100     % Look for default file
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     % verify that path to default files exists;
0112     % if not, create defaults again (I hope this will avoid
0113     % new installation problems)
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

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003