diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index 678cc15269f0b2a3fc01088e3a6f651a112a4c54..4f82c2cd3ebec1b380f77836b4d232b91db7f9d9 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -17,7 +17,7 @@ arguments options.Method {mustBeMember(options.Method ,{'individual','centralized'})} = 'individual' options.ParentFolder (1,:) {mustBeText} = 'export' options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true - options.CSV (1,1) {mustBeNumericOrLogical} = false + options.CSV (1,1) {mustBeNumericOrLogical} = false end %catch multiple figures in fig @@ -29,7 +29,7 @@ if numel(figure) > 1 warning(msg); end -%read config file +%% read config file try txt = fileread('config.json'); config = jsondecode(txt); @@ -41,6 +41,7 @@ catch configError = true; end +%% storage location switch options.Location case 'local' if contains(options.ParentFolder, {'/','\'}) @@ -66,7 +67,7 @@ elseif mkdir(fullfile(storPath,folderName)) else error('Directory could not be created - check remote path and permissions'); end -disp('Publishing started'); +disp(['publishing of ', ID, ' started']); %% Create a Copy of the script, config and user functions(optional) % script diff --git a/+PlotID/createFileCopy.m b/+PlotID/createFileCopy.m index a6c89593ecae599d7fa4471aa1c806e899e16446..061f10903343ccde4ea33ea666f93b19f414cb79 100644 --- a/+PlotID/createFileCopy.m +++ b/+PlotID/createFileCopy.m @@ -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) % folderName is the name of the exporting folder % returns the storage paths were files were stored - disp(['start to copy ', type]); - if ~iscell(filePaths) - %fixes Issue if Filepath is a char and not a cell array - filePaths = {filePaths}; - end +if ~iscell(filePaths) + %fixes Issue if Filepath is a char and not a cell array + filePaths = {filePaths}; +end - try - storagePaths = cell(numel(filePaths,1)); - for i = 1:numel(filePaths) - FileNameAndLocation = filePaths{i}; - [~,name,ext] = fileparts(filePaths{i}); % get the extension - - switch type - case 'data' - newfile = sprintf([name,ext]); %keep original name - %old behaviour - %sufix = '_data'; - %newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]); - case 'dataCentral' - %keep original name - newfile = sprintf([name,ext]); - case 'script' - sufix = '_script'; - newfile = sprintf([ID, sufix ,ext]); - case 'userFcn' - %keep original name - newfile = sprintf([name,ext]); - otherwise - error([type,' is not a valid type for createFileCopy']) - end %switch - - RemotePath = fullfile(storPath,folderName, newfile); - +try + storagePaths = cell(numel(filePaths,1)); + for i = 1:numel(filePaths) + FileNameAndLocation = filePaths{i}; + [~,name,ext] = fileparts(filePaths{i}); % get the extension + + switch type + case 'data' + newfile = sprintf([name,ext]); %keep original name + %old behaviour + %sufix = '_data'; + %newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]); + case 'dataCentral' + %keep original name + newfile = sprintf([name,ext]); + case 'script' + sufix = '_script'; + newfile = sprintf([ID, sufix ,ext]); + case 'userFcn' + %keep original name + newfile = sprintf([name,ext]); + otherwise + error([type,' is not a valid type for createFileCopy']) + end %switch + + RemotePath = fullfile(storPath,folderName, newfile); + % Check if remote file already exists - count = 0; - while isfile(RemotePath) && ismember(type,{'data','dataCentral'}) - % Add a Sufix number to new file name - % TODO add more inteligent way then a simple sufix - count = count + 1; - [~,name,ext] = fileparts(RemotePath); - if count < 2 - RemotePath = fullfile(storPath,folderName,... - [name,'_',num2str(count),ext]); - else - RemotePath = fullfile(storPath,folderName,... - [name(1:end-length(num2str(count))),num2str(count),ext]); - end - [~, name, ~] = fileparts(RemotePath); - - - msg = ['Filename ',name,... - ' already exists in the data folder' newline,... - ' PlotID will add an suffix if you continue.' newline,... - ' This can cause serious confusions.']; - warning(msg); - m = input('Do you want to continue, Y/N [Y]:','s'); - - if ismember(m,{'N','n'}) - errorMSG = ['Filename already exists in data folder.' newline,... - ' Rename the File and restart PlotID.']; - error(); - end + count = 0; + while isfile(RemotePath) && ismember(type,{'data','dataCentral'}) + % Add a Sufix number to new file name + % TODO add more inteligent way then a simple sufix + count = count + 1; + [~,name,ext] = fileparts(RemotePath); + if count < 2 + RemotePath = fullfile(storPath,folderName,... + [name,'_',num2str(count),ext]); + else + RemotePath = fullfile(storPath,folderName,... + [name(1:end-length(num2str(count))),num2str(count),ext]); + end + [~, name, ~] = fileparts(RemotePath); + + + msg = ['Filename ',name,... + ' already exists in the data folder' newline,... + ' PlotID will add an suffix if you continue.' newline,... + ' This can cause serious confusions.']; + warning(msg); + m = input('Do you want to continue, Y/N [Y]:','s'); + + if ismember(m,{'N','n'}) + errorMSG = ['Filename already exists in data folder.' newline,... + ' Rename the File and restart PlotID.']; + error(); end - copyfile(FileNameAndLocation,RemotePath); - storagePaths{i} = RemotePath; end - disp([type, ' sucessfully published']); - catch - warning([type,' export was not sucessful']) + copyfile(FileNameAndLocation,RemotePath); + storagePaths{i} = RemotePath; + end + disp([type, ' sucessfully published']); +catch + warning([type,' export was not sucessful']) if exist('errorMSG') error(errorMSG); - end %try -end + end +end %try +end %function diff --git a/example.m b/example.m index 92e79d652ef49d346c18b1ac6e71ae143e77c813..492711c999d27bc475e8439b1fc2a284091f774c 100644 --- a/example.m +++ b/example.m @@ -3,40 +3,32 @@ %% Clear Environment clear; clc; close all; -addpath('CI_files'); % Test scripts try delete testdata2.h5; end - %% Set ProjectID % 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 -ProjectID = 'FST03'; - +ProjectID = 'Example'; %% Data -% Creating Random Data to use as data-file +% only necessary for this example -x = linspace(0,7); -y = rand(1,100)+2; +% Creating Random Data to use as data-file +x = linspace(0,7); y = rand(1,100)+2; dataset1 = 'test_data.mat'; + % Use absolute paths for good practise dataset1 = fullfile(pwd,dataset1); save(dataset1,'x','y'); +% some data for the .h5 file +x1 = linspace(0,2*pi); y1 = sin(x1)+2; -% some data as .h5 -x1 = linspace(0,2*pi); -y1 = sin(x1)+2; - -% define file path & name +% define filepath & name dataset2 = 'testdata2.h5'; dataset2 = fullfile(pwd,dataset2); fpath = dataset2; @@ -49,14 +41,14 @@ h5write(fpath, "/y1", y1) %% function calls % Place for post-processing of the data, or additional related code. -a = 1; % example_fcn is a dummy function to show the functionality -a = example_fcn(a); -%p = betacdf(0.5,1,1); % to test Toolboxes +a = 1; a = example_fcn(a); +%p = betacdf(0.5,1,1); % to test toolboxes %% Plotting % 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; plot(x,y,'-k'); box off; hold on; @@ -73,17 +65,19 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]); %% Publishing % Second part of plotID -% The functions needs the file location, the location of the data and the -% figure and can take several options. -% TODO add explanations for Options +% The functions needs the file location of the script, the location of the +% data and the figure and can take several options (see readme). path.script = mfilename('fullpath'); % filename of the m.script % file names of the datasets + +%(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5' path.rdata = {dataset1,dataset2} ; % don't forget the extension +%call publishing 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 fig(2) = figure; @@ -100,13 +94,18 @@ path.script = mfilename('fullpath'); % filename of the m.script % file names of the datasets path.rdata = {dataset2} ; % don't forget the extension -% publsihing via for-loop +% publsihing via a for-loop 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 %% 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; plot(x,y,'-k');