Skip to content
Snippets Groups Projects

fix typos and add comments

Merged Lemmer, Jan requested to merge dev/descriptions into development
4 files
+ 57
49
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 34
29
@@ -4,18 +4,26 @@ function Publish(DataPaths,scriptPath, figure, options)
% DataPaths contains the path(s) to the research data, for multiple files
% use a cell array
% scriptPath contains the path to the script, this can be provided with
% the simple call of scriptPath = [mfilename('fullpath'),'.m'], note that
% the extension is mandatory
% the simple call of scriptPath = [mfilename('fullpath'),'.m']
%
% Options:
% Location sets the storage location. 'local' sets the storage location
% to the current folder (an export folder will be created), 'server' is a
% to the current folder (an export folder will be created), 'manual' opens
% a explorer window, where you can choose the folder. If you define a export
% path in the config file, this will used per default.
% remote path, that is defined in the config file.
% Two Methods are implemented 'individual' stores the data for
% each plot while 'centralized' uses a data folder and uses reference links
% to the original data (hdf5 only).
% ParentFolder is the folder Name where the exported data is stored if an
% 'ParentFolder' is the folder Name where the exported data is stored if an
% path is used, PlotId will use this path a storagePath
% 'ConfigFileName' is needed for handling multiple config files (see example)
% 'CSV' turns a summary table of all exports on or off
%
% DebugOptions:
% 'ShowMessage' and 'ForcePublish' are mainly for debugging.
% 'ShowMessage' will display Messages for every step of PlotID,
% 'ForcePublish' will publish even if one step was not successful (not recommended)
arguments
DataPaths {mustBeDataPath} % location of the data-file(s)
@@ -23,11 +31,11 @@ arguments
figure (1,:) {mustBeFigure} % Checks if figure is a figure object
options.Location {mustBeMember(options.Location ,{'local','server','manual','CI-Test'})} = 'local' % storage path
options.Method {mustBeMember(options.Method ,{'individual','centralized'})} = 'individual'
options.ParentFolder (1,:) {mustBeText} = 'export'
options.ParentFolder (1,:) {mustBeText} = 'PlotID_export' % name of the ParentFolder
options.ConfigFileName (1,:) {mustBeText} = 'config.json' %individual config names possible
options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true
options.CSV (1,1) {mustBeNumericOrLogical} = false
options.ShowMessages(1,1) {mustBeNumericOrLogical} = true
options.CSV (1,1) {mustBeNumericOrLogical} = true
options.ShowMessages(1,1) {mustBeNumericOrLogical} = false
options.ForcePublish (1,1) {mustBeNumericOrLogical} = false %publish anyway
end
@@ -38,7 +46,7 @@ if ~iscell(DataPaths)
DataPaths = {DataPaths}; %Cell array
end
% strings will cause problems, we therfore use chars
% strings will cause problems, therefore chars are used
for i=1:numel(DataPaths)
if isstring(DataPaths{i})
DataPaths{i} = char(DataPaths{i});
@@ -52,7 +60,7 @@ end
%catch multiple figures in fig
if numel(figure) > 1
figure = figure(1);
msg = ['Publish is designed for handeling one figure at once' newline,...
msg = ['Publish is designed for handling one figure at once' newline,...
'- publishes uses only the first figure.' newline , ...
'Consider an external for loop for multi figure export as provided in example.m'];
warning(msg);
@@ -68,7 +76,7 @@ end
ID = figure.Tag;
if isempty(ID)
% no ID found, User dialog for Folder name
% no ID found, user dialog for folder name
ID = inputdlg(['No ID defined- ' newline,...
'Please enter a folder name to continue:'],'Please enter a folder name');
ID = ID{1};
@@ -80,7 +88,7 @@ end
%% read config file
% there is only one config Object (handleClass)
configObj = PlotID.config(options.ConfigFileName);
% add user options
% read user options from config and set them for Publish
if isfield(configObj.configData, 'options')
fldnames = fieldnames(configObj.configData.options);
for ii=1:numel(fldnames)
@@ -89,10 +97,9 @@ if isfield(configObj.configData, 'options')
end
end
% Error and MSG handeling
% error and MSG handling object
dlgObj = PlotID.userDLG(ID,options);
%% storage location
switch options.Location
case 'local'
@@ -103,7 +110,7 @@ switch options.Location
scriptLocation = fileparts(scriptPath);
storPath = fullfile(scriptLocation,options.ParentFolder);
end
case 'exportPath' %legacy
case 'exportPath'
if isfolder(configObj.exportPath)
storPath = configObj.exportPath;
else
@@ -120,16 +127,16 @@ switch options.Location
storPath = configObj.configData.ServerPath;
case 'manual' %UI
storPath = uigetdir();
case 'CI-Test'
case 'CI-Test' %only for CI tests
storPath = fullfile(pwd,'CI_files',options.ParentFolder);
end
folderName = ['.',char(ID)]; %hidden folder
folderName = ['.',char(ID)]; % hidden folder
folderNameV = char(ID); %visible Folder
%% Create data directory
overwriteDir = false;
% if invisible Folder exists, delete it (publish was not succesfull before)
% if invisible Folder exists, delete it (publish was not successful before)
if isfolder(fullfile(storPath,folderName))
rmdir(fullfile(storPath,folderName),'s')
end
@@ -145,7 +152,7 @@ if isfolder(fullfile(storPath,folderNameV))
return; %terminate
end
end
% create folder
% create the folder
if ~mkdir(fullfile(storPath,folderName))
dlgObj.error('Directory could not be created - check remote path and permissions');
end
@@ -162,13 +169,13 @@ dlgObj.userMSG(msg);
if options.CopyUserFCN
fList = fList(~ismember(fList,scriptPath)); % rmv script from list
fList = fList(~contains(fList,'config.json')); % rmv config.json from list
fList = PlotID.removePltIdFiles(fList); % Do not copy files that are part of plot ID
fList = PlotID.removePltIdFiles(fList); % Do not copy files that are part of PlotID
if ~isempty(fList)
PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn');
end
end
%% Research data handeling
%% Research data handling
switch options.Method
case 'centralized'
DataFolderName = 'data';
@@ -229,7 +236,7 @@ exportPath = fullfile(storPath,folderName);
configObj.writeConfig(exportPath);
% add further Metadata
meta =struct();
meta = struct();
if ispc
meta.author = getenv('USERNAME');
end
@@ -259,12 +266,12 @@ catch
dlgObj.softError('Plot export was not successful');
end
%% final renaming and error/warning handeling
% if no error orcurred or if force publish is activated, rename the hidden
%% final renaming and error/warning handling
% if no error occurred or if force publish is activated, rename the hidden
% folder to a non hidden one, otherwise delete it.
if dlgObj.success || options.ForcePublish
oldPath = fullfile(storPath,folderName);
newPath = strrep(oldPath,'.',''); %remov dot
newPath = strrep(oldPath,'.',''); %remove dot
if overwriteDir
rmdir(newPath,'s');
dlgObj.userMSG(['old export ', folderNameV, ' deleted']);
@@ -272,8 +279,7 @@ if dlgObj.success || options.ForcePublish
status = movefile(oldPath,newPath); %rename directory
end
%% CSV EXport
% ToDo exclude in function
%% CSV export
if options.CSV
T = table();
T.research_Data = DataPaths'; T.PlotID(:) = {ID};
@@ -286,9 +292,8 @@ if options.CSV
end
if status
disp(['publishing of ', ID , ' to ', newPath, ' done']); %always displayed onsucess
else % publish was not sucessfull!
%replace with error from userDLG Class
disp(['publishing of ', ID , ' to ', newPath, ' done']); %always displayed on success
else % publish was not successful!
dlgObj.error(['publishing of ', ID , ' failed'])
end
Loading