diff --git a/+PlotID/@dataPath/dataPath.m b/+PlotID/@dataPath/dataPath.m index 67c3edea02d5b76fa8cc16b24dec9514fca2a6a4..bc4f395b77d5145f54785c98105d3fe51ac86ec5 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 45e8a31544fda24a9aa9836ea1e8e91628dd0b36..ddb90177022ed2dd22a82fb9fe4064e2c086c254 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 0000000000000000000000000000000000000000..f5c92e7bfd7bfde657135d7a133146cd1cfa8cb8 --- /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 b7deebb941ec6383b64992a0d01183de7a0aed5c..4dab2251b56ff03ea7d2b0badf06fa7cace0993c 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 33209f2d2a3864d40672f763136ac23666e84eda..921917e2ed0cafbb636fd940eccefda3da506b2f 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