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

Closes #12 and prepare User function export

parent 2e7318b7
No related branches found
No related tags found
3 merge requests!13PreRelease_V0.1,!12PreRelease_V0.1,!1Add Link-replacement feature
No preview for this file type
...@@ -41,19 +41,22 @@ hold on ...@@ -41,19 +41,22 @@ hold on
%fig(2) =figure; %fig(2) =figure;
plot(x1,y1,'-r'); plot(x1,y1,'-r');
set(gca, 'TickDir', 'out', 'YLim', [0,4]); set(gca, 'TickDir', 'out', 'YLim', [0,4]);
%% Tag the plot
% Tag the plot
[figs, ID] = TagPlot(fig, ProjectID); [figs, ID] = TagPlot(fig, ProjectID);
%% call dummy function
% a=1;
% a = test_2(a);
%% publishing %% publishing
% The functions needs the file location, the location of the data and the % The functions needs the file location, the location of the data and the
% figure % figure
path.script = mfilename('fullpath') % filename of the m.script path.script = mfilename('fullpath'); % filename of the m.script
% file name of the data (should be extended to handle arrays) % file name of the data (should be extended to handle arrays)
path.rdata = {dataset1,dataset2} ; % don't forget the extension path.rdata = {dataset1,dataset2} ; % don't forget the extension
Publish(path, ID, figs, 'Location', 'local','Method','individual') Publish(path, ID, figs, 'Location', 'local','Method','individual','CopyUserFCN',true)
...@@ -13,6 +13,7 @@ arguments ...@@ -13,6 +13,7 @@ arguments
figures (1,:) {mustBeFigure} % Checks if Figures are figures figures (1,:) {mustBeFigure} % Checks if Figures are figures
options.Location {mustBeMember(options.Location ,['local','server'])} = 'local' % storage path options.Location {mustBeMember(options.Location ,['local','server'])} = 'local' % storage path
options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual' options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual'
options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = 'false' % should be true in realease !
end end
switch options.Location switch options.Location
...@@ -32,20 +33,15 @@ end ...@@ -32,20 +33,15 @@ end
disp('Publishing started'); disp('Publishing started');
%% Create a Copy of the script %% Create a Copy of the script and User functions
createFileCopy({[DataPaths.script,'.m']},folderName,storPath,ID, 'script');
try if options.CopyUserFCN
%FileNameAndLocation=['C:\Users\Lemmer\Documents\GitLab\plot_identifier\MATLAB\test']; [fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script);
FileNameAndLocation= DataPaths.script; fList = fList(~ismember(fList,[DataPaths.script,'.m'])); % rmv script from list
newbackup=sprintf([ID,'_script.m']); fList = removePltIdFiles(fList); % Do not copy files that are part of plot ID
currentfile=strcat(FileNameAndLocation, '.m');
% Write a Copy of the Plotting Script
RemotePath = fullfile(storPath,folderName, newbackup);
copyfile(currentfile,RemotePath);
disp('Script sucessfully published');
catch
warning('Script export was not sucessful')
end end
%% Research data handeling %% Research data handeling
switch options.Method switch options.Method
case 'centraliced' % Work in progresss!!! case 'centraliced' % Work in progresss!!!
...@@ -55,14 +51,16 @@ switch options.Method ...@@ -55,14 +51,16 @@ switch options.Method
end end
% Check if the new plot is based on the original data-set % Check if the new plot is based on the original data-set
% copy the data(once) % copy the data(once)
createFileCopy(DataPaths.rdata,'data',storPath,ID); for i=1:numel(DataPaths.rdata)
% create a linked (soft) copy if fileCompare(filename1,filename2) % identical file exists
createLinkedHDF5(SourceFile,storPath,ID)
else % no identical file exists
createFileCopy(DataPaths.rdata{i},'data',storPath,ID,'data');
end
end
case 'individual' case 'individual'
% Create a copy of the research data % Create a copy of the research data
createFileCopy(DataPaths.rdata,folderName,storPath,ID); createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
end end
%% Export the Plots %% Export the Plots
%try %try
...@@ -83,23 +81,35 @@ disp(['Publishing of ', ID , ' done']); ...@@ -83,23 +81,35 @@ disp(['Publishing of ', ID , ' done']);
end %function end %function
function [] = createFileCopy(filePaths,folderName,storPath,ID) function [] = createFileCopy(filePaths,folderName,storPath,ID,type)
% Creates a copy of the files (can used for multiple paths in a cell array) % Creates a copy of the files (can used for multiple paths in a cell array)
% folderName is the name of the exporting folder % folderName is the name of the exporting folder
disp('Start to copy research data ...'); disp(['Start to copy ', type]);
switch type
case 'data'
sufix = '_data';
case 'script'
sufix = '_script';
case 'userFcn'
sufix = '';
otherwise
error([type,' is not a valid type for createFileCopy'])
end %switch
try try
for i = 1:numel(filePaths) for i = 1:numel(filePaths)
FileNameAndLocation = filePaths{i}; FileNameAndLocation = filePaths{i};
[~,~,ext] = fileparts(filePaths{i}); % get the extension [~,~,ext] = fileparts(filePaths{i}); % get the extension
newbackup = sprintf([ID,'_data',ext]); newbackup = sprintf([ID, sufix ,ext]);
% Write the copied file % Write the copied file
RemotePath = fullfile(storPath,folderName, newbackup); RemotePath = fullfile(storPath,folderName, newbackup);
copyfile(FileNameAndLocation,RemotePath); copyfile(FileNameAndLocation,RemotePath);
end end
disp('Research data sucessfully published'); disp([type, ' sucessfully published']);
catch catch
warning('Research data export was not sucessful') warning([type,' export was not sucessful'])
end %try end %try
end end
......
function [status] = fileCompare(filename1,filename2) function [status] = fileCompare(filename1,filename2)
%UNTITLED2 Summary of this function goes here %fileCompare checks if file1 is (binary) identical to file 2
% Detailed explanation goes here % the functions uses the windows system function fc or the unix function
% diff
[~,~,ext1] = fileparts(filename1); [~,~,ext1] = fileparts(filename1);
[~,~,ext2] = fileparts(filename2); [~,~,ext2] = fileparts(filename2);
if ~isequal(ext1,ext2) if ~isequal(ext1,ext2)
warning('File extension are not identical'); %warning('File extension are not identical');
status = false; status = false;
return return
end end
if ispc if ispc
filename2 = 'export\JL01-60DB3572\JL01-60DB3572_data.h5';
filename1 = 'export\JL01-60DB3576\JL01-60DB3576_data.h5';
[status,result] = system(['fc ' filename1 ' ' filename2]); [status,result] = system(['fc ' filename1 ' ' filename2]);
elseif isunix %untested! elseif isunix %untested!
filename2 = 'export/JL01-60DB3572/JL01-60DB3572_data.h5';
filename1 = 'export/JL01-60DB3576/JL01-60DB3576_data.h5';
[status,result] = system(['diff ' filename1 ' ' filename2]); [status,result] = system(['diff ' filename1 ' ' filename2]);
else else
warning('Platform not supported') warning('Platform not supported')
......
...@@ -6,15 +6,15 @@ plist_id = 'H5P_DEFAULT'; ...@@ -6,15 +6,15 @@ plist_id = 'H5P_DEFAULT';
% Work in Progress... Problem mit dem Pfad... % Work in Progress... Problem mit dem Pfad...
try %try
fid = H5F.create(fullfile(TargetPath,[ID,'_data.h5'])); fid = H5F.create(fullfile(TargetPath,[ID,'_data.h5']));
%create External Link to Sourcefile in the Group linkToExternal %create External Link to Sourcefile in the Group linkToExternal
H5L.create_external(SourceFile,'/',fid,'linkToExternal',plist_id,plist_id); H5L.create_external(SourceFile,'/',fid, SourceFile ,plist_id,plist_id);
H5F.close(fid); H5F.close(fid);
status = 1; status = 1;
catch % catch
warning('No linked HDF file was created'); % warning('No linked HDF file was created');
status = 0; % status = 0;
end % end
end end
function [fListClean] = removePltIdFiles(fList)
%removePltIdFiles removes functions that are part of PlotID out of flist
% Detailed explanation goes here
%addpath('..\fcn_core');
[~,names,ext] = fileparts(fList);
names = strcat(names, ext); % add ext for comparison
% Get a list of all .m files that are part of Plot id
PltID_flist = struct2table([dir('fcn_help'); dir('fcn_core')]); %get list of files
[~,~,PltID_flist.ext(:)] = fileparts(PltID_flist.name(:)); % add ext column
PltID_flist = PltID_flist(strcmp(PltID_flist.ext,'.m'),:);
% Comparison and filter
fListClean = fList(~ismember(names,PltID_flist.name));
end
File added
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment