Skip to content
Snippets Groups Projects
Commit 78e2b5cc authored by Lemmer, Jan's avatar Lemmer, Jan
Browse files

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
parent b68ff67d
Branches
Tags
2 merge requests!62Introduce changes for V1.0 RC 1,!59Improve centralized function by warnings and moving code to FCN
Pipeline #654693 passed
......@@ -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
......
......@@ -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');
......
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
# 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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment