From 78e2b5cc7793390fd9bbe06bc0f7cfed2919dd48 Mon Sep 17 00:00:00 2001 From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de> Date: Thu, 24 Feb 2022 10:00:56 +0100 Subject: [PATCH] Move code of the centralized method into an function Reasons: Clearness, eliminate unwanted dependencies, improve readability ID is also stored in dataObj so no need to pass it individually --- +PlotID/@dataPath/dataPath.m | 3 +- +PlotID/Publish.m | 52 +-------------------------- +PlotID/centralized.m | 68 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 5 ++- Examples/PlotID_centralized.m | 10 +++++- 5 files changed, 84 insertions(+), 54 deletions(-) create mode 100644 +PlotID/centralized.m diff --git a/+PlotID/@dataPath/dataPath.m b/+PlotID/@dataPath/dataPath.m index 67c3ede..bc4f395 100644 --- a/+PlotID/@dataPath/dataPath.m +++ b/+PlotID/@dataPath/dataPath.m @@ -6,7 +6,8 @@ classdef dataPath < handle properties (SetAccess = protected) DataPaths (1,:) cell % dataPaths tmpPath % path to TMP files - ID %ID + ID %PlotID + dataFolderName = 'data' %name for the data folder when using centralized end methods diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index 45e8a31..ddb9017 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -167,58 +167,8 @@ end %% Research data handling switch options.Method case 'centralized' - DataFolderName = 'data'; - warning(['Linked HDF5 can only be moved with their ',... - 'respective master files in the ', DataFolderName, ' folder.']); - % check if data folder exists - if ~isfolder(fullfile(storPath,DataFolderName)) - mkdir(fullfile(storPath,DataFolderName)); - end - % to get relative Paths - currentPath = fullfile(storPath); + [status, msg] = PlotID.centralized(storPath, dataObj, folderName); - %list all files - fList = dir(fullfile(storPath,DataFolderName, ['**',filesep,'*.*'])); - %get list of files and folders in any subfolder - fList = fList(~[fList.isdir]); %remove folders from list - fList = struct2table(fList); - - % Check if the new plot is based on the original data-set - % copy the data(once) - for i=1:numel(dataObj.DataPaths) - % check if identical file exists (status = 1) - [~, idx] = PlotID.fileCompare(dataObj.DataPaths{i},fList); - % create Linked HDF5 files for identical files - if any(idx) - fList.path = fullfile(fList.folder,fList.name); - sourcePath = fList{idx,'path'}; - if ~iscell(sourcePath) - sourcePath = {sourcePath}; - end - relativeSourcePath = strrep(sourcePath,currentPath,''); - - if contains(sourcePath,{'.h5','.hdf5'}) % Linking only for HDF5 - linkedHDFPath = fullfile(storPath,folderName); - PlotID.createLinkedHDF5(relativeSourcePath{1,1},linkedHDFPath); - end - else % no identical file exists - %Copy the file in data and create the links (if hdf5) - [dataPath, status, msg] = PlotID.createFileCopy(dataObj.DataPaths{i},'data',storPath,ID,'dataCentral'); - pathToData = strrep(dataPath,currentPath,''); - %WIP - if contains(dataObj.DataPaths{i},{'.h5','.hdf5'}) % Linking only for HDF5 - % and create also linked files in the plot folder - linkedHDFPath = fullfile(storPath,folderName); - [status] = PlotID.createLinkedHDF5(pathToData,linkedHDFPath); - end %if - end %if - % add do not move message - doNotMove = ['do not move this folder without the ',... - DataFolderName, ' folder']; - fid = fopen(fullfile(storPath,folderName,[doNotMove,'.txt']),'w'); - fprintf(fid,doNotMove); fclose(fid); - end %for - clear DataFolderName doNotmove case 'individual' % Create a copy of the research data [~, status, msg] = PlotID.createFileCopy(dataObj.DataPaths,folderName,storPath,ID, 'data'); diff --git a/+PlotID/centralized.m b/+PlotID/centralized.m new file mode 100644 index 0000000..f5c92e7 --- /dev/null +++ b/+PlotID/centralized.m @@ -0,0 +1,68 @@ +function [status, msg] = centralized(storPath, dataObj, folderName) +%centralized stores the research files in a centrelized folder. Linked +%files are created for subsequent folders (HDF5 only). +msg = ''; +warning(['Linked HDF5 can only be moved with their ',... + 'respective master files in the ', dataObj.dataFolderName, ' folder.']); + +% check if data folder exists +if ~isfolder(fullfile(storPath,dataObj.dataFolderName)) + mkdir(fullfile(storPath,dataObj.dataFolderName)); +end +% to get relative Paths +currentPath = fullfile(storPath); + +%list all files +fList = dir(fullfile(storPath,dataObj.dataFolderName, ['**',filesep,'*.*'])); +%get list of files and folders in any subfolder +fList = fList(~[fList.isdir]); %remove folders from list +fList = struct2table(fList); + +% Check if the new plot is based on the original data-set + % copy the data(once) +for i=1:numel(dataObj.DataPaths) + % check if identical file exists (status = 1) + [~, idx] = PlotID.fileCompare(dataObj.DataPaths{i},fList); + % create l inked HDF5 files for identical files + if any(idx) + fList.path = fullfile(fList.folder,fList.name); + sourcePath = fList{idx,'path'}; + if ~iscell(sourcePath) + sourcePath = {sourcePath}; + end + relativeSourcePath = strrep(sourcePath,currentPath,''); + + if contains(sourcePath,{'.h5','.hdf5'}) % Linking only for HDF5 + linkedHDFPath = fullfile(storPath,folderName); + [status] = PlotID.createLinkedHDF5(relativeSourcePath{1,1},linkedHDFPath); + end + else % no identical file exists + %Copy the file in data and create the links (if hdf5) + [dataPath, status, msg] = PlotID.createFileCopy(dataObj.DataPaths{i},... + 'data',storPath,dataObj.ID,'dataCentral'); + pathToData = strrep(dataPath,currentPath,''); + + if ~status + return; % an error orccured + end + + %WIP + if contains(dataObj.DataPaths{i},{'.h5','.hdf5'}) % Linking only for HDF5 + % and create also linked files in the plot folder + linkedHDFPath = fullfile(storPath,folderName); + [status] = PlotID.createLinkedHDF5(pathToData,linkedHDFPath); + else + warning(['You use the centralized method for non hdf files,',... + newline, 'Your research files are located in the ',... + DataFolederName , 'folder.']); + status = true; + end %if + end %if + % add do not move message + doNotMove = ['do not move this folder without the ',... + dataObj.dataFolderName, ' folder']; + fid = fopen(fullfile(storPath,folderName,[doNotMove,'.txt']),'w'); + fprintf(fid,doNotMove); fclose(fid); +end %for + +end \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b7deebb..4dab225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -# V0.3 +# V1.0 RC1 - Add changelog - Add support for file or function name as scriptPath - Add support for passing Variables in publish +- Move centralized method in fuction +- Improve usability +- Improve documentation diff --git a/Examples/PlotID_centralized.m b/Examples/PlotID_centralized.m index 33209f2..921917e 100644 --- a/Examples/PlotID_centralized.m +++ b/Examples/PlotID_centralized.m @@ -22,4 +22,12 @@ fig2 = figure; plot(x.^2,y,'-r'); [fig2, ID] = PlotID.TagPlot(fig2); -PlotID.Publish(datapath,scriptPath, fig2, 'Method','centralized') \ No newline at end of file +PlotID.Publish(datapath,scriptPath, fig2, 'Method','centralized') + +%% Note: +% If you rerun this script PlotId will tell you that a identical named (but +% not binary idetical) file exists in the data folder. This is intended, +% due protect the user from overwritting non (binary) identical files. The +% reason for this is that two hdf files with the same data are not idetical +% when recreated (see line 11). Usually you would use an existing file +% without changing it. \ No newline at end of file -- GitLab