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

Add comments, remove some commandline outputs

parent 1514c3e6
No related branches found
No related tags found
2 merge requests!13PreRelease_V0.1,!12PreRelease_V0.1
Pipeline #564170 canceled
...@@ -17,7 +17,7 @@ arguments ...@@ -17,7 +17,7 @@ arguments
options.Method {mustBeMember(options.Method ,{'individual','centralized'})} = 'individual' options.Method {mustBeMember(options.Method ,{'individual','centralized'})} = 'individual'
options.ParentFolder (1,:) {mustBeText} = 'export' options.ParentFolder (1,:) {mustBeText} = 'export'
options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true
options.CSV (1,1) {mustBeNumericOrLogical} = false options.CSV (1,1) {mustBeNumericOrLogical} = false
end end
%catch multiple figures in fig %catch multiple figures in fig
...@@ -29,7 +29,7 @@ if numel(figure) > 1 ...@@ -29,7 +29,7 @@ if numel(figure) > 1
warning(msg); warning(msg);
end end
%read config file %% read config file
try try
txt = fileread('config.json'); txt = fileread('config.json');
config = jsondecode(txt); config = jsondecode(txt);
...@@ -41,6 +41,7 @@ catch ...@@ -41,6 +41,7 @@ catch
configError = true; configError = true;
end end
%% storage location
switch options.Location switch options.Location
case 'local' case 'local'
if contains(options.ParentFolder, {'/','\'}) if contains(options.ParentFolder, {'/','\'})
...@@ -66,7 +67,7 @@ elseif mkdir(fullfile(storPath,folderName)) ...@@ -66,7 +67,7 @@ elseif mkdir(fullfile(storPath,folderName))
else else
error('Directory could not be created - check remote path and permissions'); error('Directory could not be created - check remote path and permissions');
end end
disp('Publishing started'); disp(['publishing of ', ID, ' started']);
%% Create a Copy of the script, config and user functions(optional) %% Create a Copy of the script, config and user functions(optional)
% script % script
......
...@@ -2,78 +2,78 @@ function [storagePaths] = createFileCopy(filePaths,folderName,storPath,ID,type) ...@@ -2,78 +2,78 @@ function [storagePaths] = createFileCopy(filePaths,folderName,storPath,ID,type)
% Creates a copy of the files (can be used for multiple paths in a cell array) % Creates a copy of the files (can be used for multiple paths in a cell array)
% folderName is the name of the exporting folder % folderName is the name of the exporting folder
% returns the storage paths were files were stored % returns the storage paths were files were stored
disp(['start to copy ', type]);
if ~iscell(filePaths) if ~iscell(filePaths)
%fixes Issue if Filepath is a char and not a cell array %fixes Issue if Filepath is a char and not a cell array
filePaths = {filePaths}; filePaths = {filePaths};
end end
try try
storagePaths = cell(numel(filePaths,1)); storagePaths = cell(numel(filePaths,1));
for i = 1:numel(filePaths) for i = 1:numel(filePaths)
FileNameAndLocation = filePaths{i}; FileNameAndLocation = filePaths{i};
[~,name,ext] = fileparts(filePaths{i}); % get the extension [~,name,ext] = fileparts(filePaths{i}); % get the extension
switch type switch type
case 'data' case 'data'
newfile = sprintf([name,ext]); %keep original name newfile = sprintf([name,ext]); %keep original name
%old behaviour %old behaviour
%sufix = '_data'; %sufix = '_data';
%newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]); %newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]);
case 'dataCentral' case 'dataCentral'
%keep original name %keep original name
newfile = sprintf([name,ext]); newfile = sprintf([name,ext]);
case 'script' case 'script'
sufix = '_script'; sufix = '_script';
newfile = sprintf([ID, sufix ,ext]); newfile = sprintf([ID, sufix ,ext]);
case 'userFcn' case 'userFcn'
%keep original name %keep original name
newfile = sprintf([name,ext]); newfile = sprintf([name,ext]);
otherwise otherwise
error([type,' is not a valid type for createFileCopy']) error([type,' is not a valid type for createFileCopy'])
end %switch end %switch
RemotePath = fullfile(storPath,folderName, newfile); RemotePath = fullfile(storPath,folderName, newfile);
% Check if remote file already exists % Check if remote file already exists
count = 0; count = 0;
while isfile(RemotePath) && ismember(type,{'data','dataCentral'}) while isfile(RemotePath) && ismember(type,{'data','dataCentral'})
% Add a Sufix number to new file name % Add a Sufix number to new file name
% TODO add more inteligent way then a simple sufix % TODO add more inteligent way then a simple sufix
count = count + 1; count = count + 1;
[~,name,ext] = fileparts(RemotePath); [~,name,ext] = fileparts(RemotePath);
if count < 2 if count < 2
RemotePath = fullfile(storPath,folderName,... RemotePath = fullfile(storPath,folderName,...
[name,'_',num2str(count),ext]); [name,'_',num2str(count),ext]);
else else
RemotePath = fullfile(storPath,folderName,... RemotePath = fullfile(storPath,folderName,...
[name(1:end-length(num2str(count))),num2str(count),ext]); [name(1:end-length(num2str(count))),num2str(count),ext]);
end end
[~, name, ~] = fileparts(RemotePath); [~, name, ~] = fileparts(RemotePath);
msg = ['Filename ',name,... msg = ['Filename ',name,...
' already exists in the data folder' newline,... ' already exists in the data folder' newline,...
' PlotID will add an suffix if you continue.' newline,... ' PlotID will add an suffix if you continue.' newline,...
' This can cause serious confusions.']; ' This can cause serious confusions.'];
warning(msg); warning(msg);
m = input('Do you want to continue, Y/N [Y]:','s'); m = input('Do you want to continue, Y/N [Y]:','s');
if ismember(m,{'N','n'}) if ismember(m,{'N','n'})
errorMSG = ['Filename already exists in data folder.' newline,... errorMSG = ['Filename already exists in data folder.' newline,...
' Rename the File and restart PlotID.']; ' Rename the File and restart PlotID.'];
error(); error();
end
end end
copyfile(FileNameAndLocation,RemotePath);
storagePaths{i} = RemotePath;
end end
disp([type, ' sucessfully published']); copyfile(FileNameAndLocation,RemotePath);
catch storagePaths{i} = RemotePath;
warning([type,' export was not sucessful']) end
disp([type, ' sucessfully published']);
catch
warning([type,' export was not sucessful'])
if exist('errorMSG') if exist('errorMSG')
error(errorMSG); error(errorMSG);
end %try end
end end %try
end %function
...@@ -3,40 +3,32 @@ ...@@ -3,40 +3,32 @@
%% Clear Environment %% Clear Environment
clear; clc; close all; clear; clc; close all;
addpath('CI_files'); % Test scripts
try try
delete testdata2.h5; delete testdata2.h5;
end end
%% Set ProjectID %% Set ProjectID
% ProjectID can also be set in the config file % ProjectID can also be set in the config file
% TODO: decide how projectID and optionally ORCID will be implemented
% ORCID placed on startup (alternative?) - projectID as persistent
% otherwise dialogue?
% Leave empty for using the ID from the config file % Leave empty for using the ID from the config file
ProjectID = 'FST03'; ProjectID = 'Example';
%% Data %% Data
% Creating Random Data to use as data-file % only necessary for this example
x = linspace(0,7); % Creating Random Data to use as data-file
y = rand(1,100)+2; x = linspace(0,7); y = rand(1,100)+2;
dataset1 = 'test_data.mat'; dataset1 = 'test_data.mat';
% Use absolute paths for good practise % Use absolute paths for good practise
dataset1 = fullfile(pwd,dataset1); dataset1 = fullfile(pwd,dataset1);
save(dataset1,'x','y'); save(dataset1,'x','y');
% some data for the .h5 file
x1 = linspace(0,2*pi); y1 = sin(x1)+2;
% some data as .h5 % define filepath & name
x1 = linspace(0,2*pi);
y1 = sin(x1)+2;
% define file path & name
dataset2 = 'testdata2.h5'; dataset2 = 'testdata2.h5';
dataset2 = fullfile(pwd,dataset2); dataset2 = fullfile(pwd,dataset2);
fpath = dataset2; fpath = dataset2;
...@@ -49,14 +41,14 @@ h5write(fpath, "/y1", y1) ...@@ -49,14 +41,14 @@ h5write(fpath, "/y1", y1)
%% function calls %% function calls
% Place for post-processing of the data, or additional related code. % Place for post-processing of the data, or additional related code.
a = 1;
% example_fcn is a dummy function to show the functionality % example_fcn is a dummy function to show the functionality
a = example_fcn(a); a = 1; a = example_fcn(a);
%p = betacdf(0.5,1,1); % to test Toolboxes %p = betacdf(0.5,1,1); % to test toolboxes
%% Plotting %% Plotting
% This is still part of a normal script to produce plots. % This is still part of a normal script to produce plots.
% Make sure to save each figure in a variable to pass to PlotID-functions. % Make sure to save each figure in a variable
% to pass it to PlotID-functions.
fig(1) = figure; fig(1) = figure;
plot(x,y,'-k'); plot(x,y,'-k');
box off; hold on; box off; hold on;
...@@ -73,17 +65,19 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]); ...@@ -73,17 +65,19 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]);
%% Publishing %% Publishing
% Second part of plotID % Second part of plotID
% The functions needs the file location, the location of the data and the % The functions needs the file location of the script, the location of the
% figure and can take several options. % data and the figure and can take several options (see readme).
% TODO add explanations for Options
path.script = mfilename('fullpath'); % filename of the m.script path.script = mfilename('fullpath'); % filename of the m.script
% file names of the datasets % file names of the datasets
%(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5'
path.rdata = {dataset1,dataset2} ; % don't forget the extension path.rdata = {dataset1,dataset2} ; % don't forget the extension
%call publishing
PlotID.Publish(path, ID, fig(1), 'Location', 'local' ,'Method','individual') PlotID.Publish(path, ID, fig(1), 'Location', 'local' ,'Method','individual')
%% Example 2: multiple plots plot, all based on data-set2 (hdf5) %% Example 2: multiple plots plot, all based on dataset2 (hdf5)
% for individual data-sets, use an appropriate array % for individual data-sets, use an appropriate array
fig(2) = figure; fig(2) = figure;
...@@ -100,13 +94,18 @@ path.script = mfilename('fullpath'); % filename of the m.script ...@@ -100,13 +94,18 @@ path.script = mfilename('fullpath'); % filename of the m.script
% file names of the datasets % file names of the datasets
path.rdata = {dataset2} ; % don't forget the extension path.rdata = {dataset2} ; % don't forget the extension
% publsihing via for-loop % publsihing via a for-loop
for i=1: numel(fig) for i=1: numel(fig)
PlotID.Publish(path, IDs{i}, fig(i), 'Location', 'server','Method','individual'); PlotID.Publish(path, IDs{i}, fig(i), 'Location', 'local',...
'Method','individual');
end end
%% Second Plot with identical data to test centralized method %% Second Plot with identical data to test centralized method
% ToDO Add better description % A central data folder is used for saving the research data files, the
% subfolders contain linked hdf5-files (if hdf5 is used). This is
% recommended, if many plots are made from the same data set. Attention,
% the linked HDF5 will not work when a subfolder was moved or the data
% folder was deleted
fig2 =figure; fig2 =figure;
plot(x,y,'-k'); plot(x,y,'-k');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment