diff --git a/SCaseDB/@SCaseDB/SCaseDB.m b/SCaseDB/@SCaseDB/SCaseDB.m deleted file mode 100644 index 662cdd7..0000000 --- a/SCaseDB/@SCaseDB/SCaseDB.m +++ /dev/null @@ -1,178 +0,0 @@ -classdef SCaseDB < handle - % SCaseDB object all the functions for SCase measurements and handling. - - % Author: Matthieu Boubat, EPFL-LBO - % Creation: 2020-01-13 - % - - properties - cases - end - - - - - - properties ( Hidden = true, Access = private ) - logFid - startTime - dataRoot - pool - end - - - - - - methods ( Hidden = true, Access = private ) - - function fid = startLog(obj) - % inputs: - % outputs: log file id (fid) - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% definitions - fid = []; - logDir = 'log'; - MAX_LOG_FILE = 5; - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - if isempty(dir(logDir)) - error(sprintf(['No "%s" directory here.\nCreate one or move to ',... - 'a directory containing one.'],logDir)); - end - - %%%%%%%%%%%%%% cleaning of 'log' directory if max log file number exceeded - logFileList = dir([logDir '\SCaseDB_*.log']); - if length(logFileList) > MAX_LOG_FILE - for i = 1:length(logFileList)-MAX_LOG_FILE+1 - delete(fullfile(logDir,logFileList(i).name)); - end - end - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% create log file - obj.startTime.Format = '_yyyy_MM_dd_HHmmss'; - fid = fopen(fullfile(logDir,['SCaseDB' char(obj.startTime) '.log']),'w'); - obj.logFid = fid; - - obj.logn('SCaseDB.log') - obj.startTime.Format = 'default'; - obj.logn('Date: %s',char(obj.startTime)) - obj.logn(''); - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - end - - - - function log(obj,str,varargin) - % to be used like sprintf(). - % write arguments in current log file. - if strfind(str,'\') - str = strrep([' [backslashes replaced by slashes]' str],'\','/'); - end - str = sprintf(str,varargin{:}); - fprintf(obj.logFid,str); - end - - - - function logn(obj,str,varargin) - % to be used like sprintf(). - % write arguments in current log file. - obj.log(str,varargin{:}); - fprintf(obj.logFid,'\n'); - end - - end - - - - - - methods - - function obj = SCaseDB(varargin) - % class constructor - % input: data root directory path (e.g: shoulder/data, Z:\\dataDev) - obj.startTime = datetime('now'); - obj.logFid = obj.startLog; - - if nargin - if exist(varargin{1},'dir') - obj.dataRoot = varargin{1}; - end - else - obj.dataRoot = '/shoulder/dataDev'; - end - - tic - if isempty(gcp('nocreate')) - localCluster = parallel.cluster.Local; - obj.pool = parpool(localCluster.NumWorkers); - else - obj.pool = gcp; - end - toc - - obj.cases = containers.Map; - obj.listSCase - end - - - - function listSCase(obj,varargin) - % fulfill 'cases' property - folderList = dir([obj.dataRoot '/*/*/*/*/CT-*']); - - for i = 1:length(folderList) - SCase = regexp(folderList(i).folder,'[NP]\d{1,3}','match','once'); - obj.cases(SCase) = []; - end - - for i = 1:length(folderList) - SCase = regexp(folderList(i).folder,'[NP]\d{1,3}','match','once'); - if ~isempty(obj.cases(SCase)) - continue - end - subList = dir(fullfile(folderList(i).folder,'CT-*')) ; - chosen = fullfile(subList(1).folder,subList(1).name); - for j = 1:length(subList) - if ~isempty(dir(fullfile(subList(j).folder,subList(j).name,'amira'))) - chosen = fullfile(subList(j).folder,subList(j).name); - break; - end - end - - if isempty(dir(fullfile(chosen,'matlab','SCase.mat'))) - obj.cases(SCase) = ShoulderCase(SCase); - else - obj.cases(SCase) = load(fullfile(chosen,'matlab','SCase.mat')); - obj.cases(SCase) = obj.cases(SCase).SCase; - end - end - end - - - - function comment(obj,str,varargin) - % to be used like sprintf(). - % write arguments in current log file. - obj.log('COMMENT'); - obj.logn([': ' str],varargin{:}); - end - - - - function delete(obj) - % class destructor - fclose(obj.logFid); - clear obj - end - - end - - - - - -end