% FrontEnd utility to copy source result sheet into Exp_ folders of % StudiesQHTCP/StudyName/Exp1(2,3,4). This allow the automation of path % capture to the StudiesDataArchieve.txt study log. % Select, copy and Capture Study Exp_ details to study log %Exp meta data collection % Set path variables wCodeDir=pwd; Wstudy=fullfile('../', wCodeDir); studyDate=datetime('now'); %Load results file meta data into workspace try ExpLabel= strcat('Exp',wCodeDir(end)) questdlg('\fontsize{20} Select the !!Results File','File Selection','OK', struct('Default','OK','Interpreter','tex')); [resFile,resPath]= uigetfile('*.txt') copyfile((fullfile(resPath,resFile)),fullfile(wCodeDir)) resDate= char(regexp(resFile, '(\d\d\_\d\d\d\d)|( \d\d\_\d\d\d\d|\d\d\d\d\d\d)','match')) cd .. if ispc lastSep=max(strfind(Wstudy,'\')) studyName=Wstudy((lastSep+1):end) else lastSep=max(strfind(Wstudy,'/')) studyName=Wstudy((lastSep+1):end) end % Build the study info array S.sDate(1)= {studyDate}; S.sName(1)= {studyName} S.sPath(1)= {Wstudy} S.ELabel(1)= {ExpLabel} S.EresDate(1)= {resDate} S.EresFile(1)= {resFile} S.EresPath(1)= {resPath} cd .. fid = fopen('StudiesDataArchive.txt','a'); fprintf(fid,'StudyDate\tStudyName\tStudyPath\tExpNum\tExpDate\tExpPath\tResultFile\n'); fprintf(fid, '%s\t %s\t %s\t %s\t %s\t %s\t %s \n',S.sDate{1},S.sName{1},S.sPath{1},S.ELabel{1},S.EresDate{1},S.EresPath{1},S.EresFile{1}); fclose(fid); fclose('all'); catch cd(wCodeDir) disp('Error: Unable to Execute ExpFrontend.m') end cd(wCodeDir) %************************************************************************************* %************************************************************************************* %##################################################################################### %Improved storage ammenable for database use %FrontEnd utility to copy source result sheet into Exp_ folders of %StudiesQHTCP/StudyName/Exp1(2,3,4). This allow the automation of path %capture to the StudiesDataArchieve.txt study log. %Select, copy and Capture Study Exp_ details to study log studyDateNow= studyDate %preserve the 'Now' date nowNumFNm= strcat((int2str(now)),'.mat') % from previous section incase the /StudyName doesn't have a standard date %capture the /StudiesQHTCP directory for storing log data cd ../.. logPath= pwd %is /.../Exp_ cd(wCodeDir) %Try to load an existing data set from previous Frontend calls try %end ~ln121 load(fullfile(logPath,'.studyLog.mat')) %load(fullfile('../../','studyLog.mat')) catch %If no studyLog.mat found [Initial First Entry] ExpLabel= strcat('Exp',wCodeDir(end)) resDate= char(regexp(resFile, '(\d\d\_\d\d\d\d)|( \d\d\_\d\d\d\d|\d\d\d\d\d\d)','match')) cd .. %move up to current study folder from ../Exp_ folder; %Study meta data collection Wstudy= pwd %Capture the specific current Study directory try %try to extract study date from folder name studyDate= char(regexp(Wstudy, '(\d\d\_\d\d\d\d)|( \d\d\_\d\d\d\d|\d\d\d\d\d\d)| \d\d\d\d\d\d)','match')) S.sDate(1)= {studyDate}; catch %if unsuccessful, accept the current date and convert to a 6 char string studyDate= yyyymmdd(studyDateNow); studyDate= (int2str(studyDate)) studyDate= studyDate(3:8) end %Capture StudyName if ispc lastSep=max(strfind(Wstudy,'\')) studyName= Wstudy((lastSep+1):end) else lastSep=max(strfind(Wstudy,'/')) studyName= Wstudy((lastSep+1):end) end %Put current First data entry into Structure of Save to StudyLog.mat file S.sDate(1)= {studyDate}; S.sName(1)= {studyName} S.sPath(1)= {Wstudy} S.ELabel(1)= {ExpLabel} S.EresDate(1)= {resDate} S.EresFile(1)= {resFile} S.EresPath(1)= {resPath} cd(wCodeDir) logFiletxt= fullfile(logPath,'StudiesDataArchive4DB.txt') %relative .txt path %Initialize the StudiesDataArchive.txt file with the First row of meta data %Print to a .txt spreadsheet the first set of data in the logFiletxt file fid = fopen(logFiletxt,'w'); fprintf(fid,'StudyDate\tStudyName\tStudyPath\tExpNum\tExpDate\tExpPath\tResultFile\n'); fprintf(fid, '%s\t %s\t %s\t %s\t %s\t %s\t %s \n',studyDate,studyName,Wstudy,ExpLabel,resDate,resPath,resFile); fclose(fid); %Save the first entry meta data into a permanent .mat files for future recall save(fullfile(logPath,'studyLog4DB.mat'), 'S') save(fullfile(logPath,'.studyLog.mat'), 'S') save(fullfile(logPath,'.nowNumFNm.mat'), 'S') end %end for try for the First entry only %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %++++++++END of FIRST ENTRY startup section++++++++++++++++++++++++++++++++ %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %Begin routine for all Entries After the Initial data entry**************** ExpLabel= strcat('Exp',wCodeDir(end)) resDate= char(regexp(resFile, '(\d\d\_\d\d\d\d)|( \d\d\_\d\d\d\d|\d\d\d\d\d\d)','match')) %Capture date from !!Results file cd .. %Move to the current study folder %Capture study meta dat Wstudy= pwd % Capture the path to the current study %Attempt to extract study date from folder name and convert to a %searchable numeric date studyDate= char(regexp(Wstudy, '(\d\d\_\d\d\d\d)|( \d\d\_\d\d\d\d|\d\d\d\d\d\d)| \d\d\d\d\d\d)','match')) if ~isempty(studyDate) %If no date in folder name use current date and convert to 6char string S.sDate(1)= {studyDate}; if isequal((str2num(studyDate(3))),'_') %Remove '_' so that date is a number for easy DB search studyDate= strcat(studyDate(1:2),studyDate(4:6)) end else studyDate= yyyymmdd(studyDateNow); studyDate= (int2str(studyDate)) studyDate= studyDate(3:8) end if ispc lastSep=max(strfind(Wstudy,'\')) studyName= Wstudy((lastSep+1):end) else lastSep=max(strfind(Wstudy,'/')) studyName= Wstudy((lastSep+1):end) end %Put meta data into a structure for storage (studyLog.mat) and future %compare operations lastRow= length(S.sPath) %Compare these just obtained paths with those stored in the studyLog.mat %file and add a new row if the study or results sheet meta data is new or different cd .. %Move the the /QHTPCstudies folder logtxt= 'StudiesDataArchive4DB.txt' logFiletxt= fullfile(logPath,logtxt) % try matched=0; for n= 1:(lastRow) if strcmp(Wstudy,S.sPath(n)) && strcmp(resPath, S.EresPath(n)) && strcmp(ExpLabel, S.ELabel(n)) matched= 1; break end end %Update the StudiesDataArchive.txt file with a new row of meta data if matched== 0 %if no match for this entry then add a line to the text archive file fid = fopen(logFiletxt,'w'); S.sDate(lastRow+1)= {studyDate}; S.sName(lastRow+1)= {studyName}; S.sPath(lastRow+1)= {Wstudy}; S.ELabel(lastRow+1)= {ExpLabel}; S.EresDate(lastRow+1)= {resDate}; S.EresFile(lastRow+1)= {resFile}; S.EresPath(lastRow+1)= {resPath}; for n= 1:(lastRow +1) %Print to a .txt spreadsheet and Save update to .mat files if n==1 fprintf(fid,'StudyDate\tStudyName\tStudyPath\tExpNum\tExpDate\tExpPath\tResultFile\n'); end fprintf(fid, '%s\t %s\t %s\t %s\t %s\t %s\t %s \n',S.sDate{n},S.sName{n},S.sPath{n},S.ELabel{n},S.EresDate{n},S.EresPath{n},S.EresFile{n}); end fclose(fid); %close DBase amenable study log file after data update save((fullfile(logPath,'studyLog4DB.mat')), 'S') % path for studyLog.mat save((fullfile(logPath,'.studyLog.mat')), 'S') %path backup studyLogBU.mat save((fullfile(logPath,strcat('.',nowNumFNm))), 'S') end fclose('all'); catch cd(wCodeDir) %Return to the location of the frontend.m code (/studyName/Exp_) fclose('all'); clear S %clear data structure variable 'S.' end cd(wCodeDir) %Return to the location of the frontend.m code (/studyName/Exp_) clear all %clear workspace variables