0001 function SetCurrentSession(varargin)
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 spikes = 'on';
0036 verbose = 'on';
0037 filename = '';
0038
0039
0040 if nargin ~= 0,
0041 if ~isastring(varargin{1},'spikes'),
0042 filename = varargin{1};
0043 varargin = {varargin{2:end}};
0044 end
0045 end
0046
0047
0048 if mod(length(varargin),2) ~= 0,
0049 error('Incorrect number of parameters (type ''help <a href="matlab:help SetCurrentSession">SetCurrentSession</a>'' for details).');
0050 end
0051
0052
0053 for i = 1:2:length(varargin),
0054 if ~ischar(varargin{i}),
0055 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help SetCurrentSession">SetCurrentSession</a>'' for details).']);
0056 end
0057 switch(lower(varargin{i})),
0058 case 'verbose',
0059 verbose = lower(varargin{i+1});
0060 if ~isastring(verbose,'on','off'),
0061 error('Incorrect value for property ''verbose'' (type ''help <a href="matlab:help SetCurrentSession">SetCurrentSession</a>'' for details).');
0062 end
0063 case 'spikes',
0064 spikes = lower(varargin{i+1});
0065 if ~isastring(spikes,'on','off'),
0066 error('Incorrect value for property ''spikes'' (type ''help <a href="matlab:help SetCurrentSession">SetCurrentSession</a>'' for details).');
0067 end
0068 otherwise,
0069 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help SetCurrentSession">SetCurrentSession</a>'' for details).']);
0070 end
0071 end
0072
0073 global DATA;
0074 separator = filesep;
0075
0076
0077 if isempty(DATA) || ~isfield(DATA,'session') || ~isfield(DATA.session,'path') || ~isfield(DATA.session,'basename'),
0078 format long g;
0079 DATA.session.basename = '';
0080 DATA.session.path = '';
0081 DATA.spikeGroups.nGroups = 0;
0082 DATA.spikeGroups.nSamples = [];
0083 DATA.spikeGroups.peakSamples = [];
0084 DATA.spikeGroups.groups = {};
0085 DATA.nChannels = [];
0086 DATA.nBits = [];
0087 DATA.rates.lfp = [];
0088 DATA.rates.wideband = [];
0089 DATA.rates.video = [];
0090 DATA.maxX = [];
0091 DATA.maxY = [];
0092 DATA.events.time = [];
0093 DATA.events.description = {};
0094 DATA.positions = [];
0095 DATA.spikes = [];
0096
0097 GlobalSettings;
0098 end
0099
0100 if isempty(filename) || (strcmp(filename,'same') && isempty(DATA.session.basename)),
0101
0102 [filename,path] = uigetfile('*.xml','Please select a parameter file for this session');
0103 if filename == 0,return; end
0104 filename = [path filename];
0105 end
0106
0107 if strcmp(filename,'same'),
0108
0109 path = DATA.session.path;
0110 basename = DATA.session.basename;
0111 else
0112
0113 [path,basename] = fileparts(filename);
0114 if isempty(path),
0115 path = pwd;
0116 else
0117 if ~exist(path),
0118 error(['Directory ''' path ''' does not exist.']);
0119 end
0120
0121 here = pwd;
0122 cd(path);
0123 path = pwd;
0124 cd(here);
0125 end
0126 end
0127
0128 if strcmp(verbose,'on'), disp(['Loading session files for ' basename]); end
0129
0130
0131 if strcmp(basename,DATA.session.basename) & strcmp(path,DATA.session.path) & ~strcmp(filename,'same'),
0132 disp(['... session files already loaded, skipping - type SetCurrentSession(''same'') to force reload']);
0133 disp('Done');
0134 return
0135 end
0136
0137
0138 DATA = LoadParameters([path separator basename '.xml']);
0139 if strcmp(verbose,'on'), disp(['... loaded parameter file ''' basename '.xml''']); end
0140
0141
0142 DATA.events.time = [];
0143 DATA.events.description = {};
0144 eventFiles = dir([path separator basename '.*.evt']);
0145 if ~isempty(eventFiles),
0146 for i = 1:length(eventFiles),
0147 events = LoadEvents([path separator eventFiles(i).name]);
0148 if isempty(events.time), continue; end
0149 DATA.events.time = [DATA.events.time ; events.time];
0150 DATA.events.description = {DATA.events.description{:} events.description{:}}';
0151 if strcmp(verbose,'on'), disp(['... loaded event file ''' eventFiles(i).name '''']); end
0152 end
0153 [DATA.events.time,i] = sortrows(DATA.events.time);
0154 DATA.events.description = {DATA.events.description{i}}';
0155 else
0156 if strcmp(verbose,'on'), disp('... (no event file found)'); end
0157 end
0158
0159
0160 DATA.positions = [];
0161 if exist([path separator basename '.pos']),
0162 DATA.positions = LoadPositions([path separator basename '.pos'],DATA.rates.video);
0163 if strcmp(verbose,'on'), disp(['... loaded position file ''' basename '.pos''']); end
0164 elseif exist([path separator basename '.whl']),
0165 DATA.positions = LoadPositions([path separator basename '.whl'],DATA.rates.video);
0166 if strcmp(verbose,'on'), disp(['... loaded position file ''' basename '.whl''']); end
0167 elseif exist([path separator basename '.whl']),
0168 DATA.positions = LoadPositions([path separator basename '.mqa'],DATA.rates.video);
0169 if strcmp(verbose,'on'), disp(['... loaded position file ''' basename '.mqa''']); end
0170 else
0171 if strcmp(verbose,'on'), disp('... (no position file found)'); end
0172 end
0173
0174
0175 if strcmp(spikes,'on'),
0176 DATA.spikes = [];
0177 for i = 1:DATA.spikeGroups.nGroups,
0178 filename = [path separator basename '.' int2str(i) '.clu'];
0179 if exist(filename,'file'),
0180 try
0181 DATA.spikes = [DATA.spikes;LoadSpikeTimes(filename,DATA.rates.wideband)];
0182 if strcmp(verbose,'on'), disp(['... loaded spike files ''' basename '.' int2str(i) '.clu''']); end
0183 catch
0184 if strcmp(verbose,'on'), disp(['... (could not load spike files ''' basename '.' int2str(i) '.clu'')']); end
0185 end
0186 else
0187 filename = [path separator basename '.clu.' int2str(i)];
0188 if exist(filename,'file'),
0189 try
0190 DATA.spikes = [DATA.spikes;LoadSpikeTimes(filename,DATA.rates.wideband)];
0191 if strcmp(verbose,'on'), disp(['... loaded spike files ''' basename '.clu.' int2str(i) '''']); end
0192 catch
0193 if strcmp(verbose,'on'), disp(['... (could not load spike files ''' basename '.clu.' int2str(i) ''')']); end
0194 end
0195 end
0196 end
0197 end
0198 if isempty(DATA.spikes),
0199 if strcmp(verbose,'on'), disp('... (no spike files found)'); end
0200 end
0201 else
0202 if strcmp(verbose,'on'), disp('... (skipping spike files)'); end
0203 end
0204
0205
0206 DATA.session.basename = basename;
0207 DATA.session.path = path;
0208
0209 if strcmp(verbose,'on'), disp('Done'); end