-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanInfo.m
48 lines (40 loc) · 1.64 KB
/
scanInfo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% Function to ID scan information from host directory
function [imageList, mNum, scanDate, fileType] = scanInfo(dirName, allScanDirs)
% Check inputs
if ~(ischar(dirName) && (exist(dirName,'dir') == 7))
error('scanInfo:InvalidDirectory',['Invalid scan directory: ' dirName ' does not exist']);
end
if (exist('allScanDirs','var') && ~iscell(allScanDirs))
error('scanInfo:InvalidInput','Please enter a cell of characters for "allScanDirs"');
end
filt = 'rec0';
% Mouse ID
mNum = dirName;
% Update user
if exist('allScanDirs','var')
thisScanInd = find(strcmp(dirName,allScanDirs));
disp(['Analyzing scan # ' num2str(thisScanInd) ' of ' num2str(numel(allScanDirs))]);
else
disp(['Loading ' num2str(mNum)]);
end
% Scan Date
scanDate = readLogFile(getLogFile(dirName),'StudyDateandTime','Scanduration');
% File List
allFileStruct = dir(fullfile(dirName));
allFiles = cell(numel(allFileStruct),1);
for i = 1:numel(allFileStruct); allFiles{i} = allFileStruct(i).name; end
fileList = allFiles(contains(allFiles,filt));
% Check some files found
if isempty(fileList)
error('scanInfo:NoFilesFound',['No files matching filter "' filt '" in ' dirName]);
end
% Get File Type
fileTypeAll = cell(size(fileList)); for j = 1:numel(fileList); fileTypeAll{j} = fileList{j}(end-3:end); end
fileTypeAll_mat = cell2mat(fileTypeAll);
fileType = mode(fileTypeAll_mat);
if max(~strcmp(fileType,fileTypeAll))
warning('scanInfo:MultipleFileTypes',['Warning: Multiple imaging types located for "' mNum '" Will use files with extension: ' fileType]);
end
% Take only image files
imageList = fileList(contains(fileList,fileType));
end