From 231c563c612b54c689ca33613465d3eed892a0c6 Mon Sep 17 00:00:00 2001
From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de>
Date: Tue, 3 Aug 2021 13:19:56 +0200
Subject: [PATCH] Fix Bug in Centralized Option, fix realtive Path Issues, fix
 indexing Issues by using tables

---
 .gitignore                  |   5 +++--
 copiedFile.h5               | Bin 896 -> 0 bytes
 example.m                   |  31 ++++++++++++++++---------------
 example_fcn.m               |   6 ++++++
 fcn_core/Publish.m          |  18 ++++++++++--------
 fcn_help/FileCompare.m      |  23 +++++++++++++++--------
 fcn_help/createLinkedHDF5.m |  10 +++++-----
 test_data.mat               | Bin 1531 -> 1526 bytes
 testdata_2.h5               | Bin 3064 -> 3064 bytes
 9 files changed, 55 insertions(+), 38 deletions(-)
 delete mode 100644 copiedFile.h5
 create mode 100644 example_fcn.m

diff --git a/.gitignore b/.gitignore
index 7604078..06d6bb3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,11 +26,12 @@ codegen/
 
 # Personal test files
 test*.m
-export/*
+test123_data.h5
 
-# files that are crfeated in example.m
+# files that are created in example.m
 testdata_2.h5
 test_data.mat
+export/*
 
 # Octave session info
 octave-workspace
diff --git a/copiedFile.h5 b/copiedFile.h5
deleted file mode 100644
index 137c2b657dc197e3e12acdc090e5ee5aea52f917..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 896
zcmeD5aB<`1lHy_j0S*oZ76t(j3y%LoK?5^H2+I8r;W02IKpBisx&unDV1h6h8CV!V
zauN_Og8<Zg1*my2{UJfFt{^2a^I<edY!r`%fQPGN04Nk9Km-E=0|%5o0ZnI6E;y}$
z*kHvV28Ec30hV%MDH29Q4CZ3sfZGWYVPnt$Q4EY64tzP8dD$WPt`#MzMR|!if(#5L
Usl_EJi6x2gMtT{h4Ei9200DkOhX4Qo

diff --git a/example.m b/example.m
index e803c2b..a489c7a 100644
--- a/example.m
+++ b/example.m
@@ -44,9 +44,9 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]);
 %% Tag the plot
 [figs, ID] = TagPlot(fig, ProjectID);
 
-%% call dummy function
-% a=1;
-% a = test_2(a);
+%% call a dummy function
+a=1;
+a = example_fcn(a);
 
 %% publishing
 
@@ -54,17 +54,18 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]);
 % figure
 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
 path.rdata =  {dataset1,dataset2} ; % don't forget the extension
 
-
-Publish(path, ID, figs, 'Location', 'local','Method','centraliced','CopyUserFCN',true)
-
-% Second Plot to test centralized method
-
-fig(2) =figure;
-plot(x,y,'-k');
-hold on
-plot(x1,y1,'-r');
-
-Publish(path, ID, figs, 'Location', 'local','Method','centraliced','CopyUserFCN',true)
\ No newline at end of file
+Publish(path, ID, figs, 'Location', 'local','Method','individual')
+
+%% Second Plot with identical data to test centralized method
+% 
+% fig2 =figure;
+% plot(x,y,'-k');
+% hold on
+% plot(x1,y1,'-r');
+% 
+% [fig2, ID] = TagPlot(fig2, ProjectID);
+% 
+% Publish(path, ID, fig2, 'Location', 'local','Method','centraliced')
\ No newline at end of file
diff --git a/example_fcn.m b/example_fcn.m
new file mode 100644
index 0000000..418f15c
--- /dev/null
+++ b/example_fcn.m
@@ -0,0 +1,6 @@
+function [outputArg1] = example_fcn(inputArg1)
+%TEST_2 just a dummy function
+outputArg1 = inputArg1;
+
+end
+
diff --git a/fcn_core/Publish.m b/fcn_core/Publish.m
index ebff3ca..9c2fc18 100644
--- a/fcn_core/Publish.m
+++ b/fcn_core/Publish.m
@@ -13,7 +13,7 @@ arguments
    figures (1,:) {mustBeFigure} % Checks if Figures are figures
    options.Location {mustBeMember(options.Location ,['local','server'])} = 'local' % storage path
    options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual'
-   options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = 'false' % should be true in realease !
+   options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true 
 end
 
 switch options.Location 
@@ -52,17 +52,19 @@ switch options.Method
         %check if data folder exists
         if ~isfolder(fullfile(storPath,'data'))
             mkdir(fullfile(storPath,'data'));
-        else %list all files
-            fList = dir(fullfile(storPath,'data', '**\*.*'));  %get list of files and folders in any subfolder
-            fList = fList(~[fList.isdir]);  %remove folders from list
         end
+        %list all files
+        fList = dir(fullfile(storPath,'data', '**\*.*'));  %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(DataPaths.rdata)            
             % check if identical file exists (status = 1)
-            [status, id] = fileCompare(DataPaths.rdata{i},fList);
+            [status, idx] = fileCompare(DataPaths.rdata{i},fList);
             if status
-               sourcePath = fullfile(fList(id).folder, fList(id).name);
+               sourcePath = fList.name{idx};
                createLinkedHDF5(sourcePath,storPath,ID);
             else % no identical file exists
                createFileCopy(DataPaths.rdata,'data',storPath,ID,'dataCentral');
@@ -87,14 +89,14 @@ end
     %warning('Plot export was not sucessful')
 %end
 
-disp(['Publishing of ', ID , ' done']);
+disp(['publishing of ', ID , ' done']);
 
 end %function
 
 function [] = createFileCopy(filePaths,folderName,storPath,ID,type)
 % Creates a copy of the files (can used for multiple paths in a cell array)
 % folderName is the name of the exporting folder
-    disp(['Start to copy ', type]);  
+    disp(['start to copy ', type]);  
             
 %     try        
         for i = 1:numel(filePaths)
diff --git a/fcn_help/FileCompare.m b/fcn_help/FileCompare.m
index 5a4039d..2921022 100644
--- a/fcn_help/FileCompare.m
+++ b/fcn_help/FileCompare.m
@@ -7,14 +7,15 @@ function [status, id] = fileCompare(filename,fileList)
 if isempty(fileList)
    % no comparison necessary
     status =false;
+    id = 0;
     return
 end
 
 [~,~,ext1] = fileparts(filename); 
-id = zeros(numel(fileList),1);
+id = zeros(height(fileList),1);
 
-for i=1:numel(fileList)
-    [~,~,ext2] = fileparts(fileList(i).name);
+for i=1:height(fileList)
+    [~,~,ext2] = fileparts(fileList.name(i));
 
     if ~isequal(ext1,ext2)
         %warning('File extension are not identical');
@@ -22,20 +23,26 @@ for i=1:numel(fileList)
         continue
     end
 
-    filepath = fullfile(fileList(i).folder,fileList(i).name);
+    filepath = fullfile(fileList.folder{i},fileList.name{i});
     if ispc
         [status,~] = system(['fc ' filename ' ' filepath]);
         % 0 -> identical, 1 -> not identical
          status = ~status; % false (not identical), true(identical)
-         id(i) = status;
-          
+                   
     elseif isunix %untested!
         [status,~] = system(['diff ' filename ' ' filepath]);
-        id(i) = ~status; % ???
     else
         warning('Platform not supported')
     end
-
+    
+    if status == 1        
+        id(i) = 1;
+    else 
+        % Status can also be any other number e.g. 2 
+        id(i) = 0;
+    end
+    
+    id =logical(id); %bugfix
 end
 
 end
diff --git a/fcn_help/createLinkedHDF5.m b/fcn_help/createLinkedHDF5.m
index 6564a7c..dd1e797 100644
--- a/fcn_help/createLinkedHDF5.m
+++ b/fcn_help/createLinkedHDF5.m
@@ -5,16 +5,16 @@ function [status] = createLinkedHDF5(SourceFile,TargetPath,ID)
 
 plist_id = 'H5P_DEFAULT';
 
-try
+% try
     fid = H5F.create(fullfile(TargetPath,ID,[ID,'_data.h5']));
     %create External Link to Sourcefile in the Group linkToExternal
     H5L.create_external(['..\data\',SourceFile],'/',fid, SourceFile ,plist_id,plist_id);
     H5F.close(fid);
     status = 1;
-catch
-    warning('No linked HDF file was created');
-    status = 0;
-end
+% catch
+%     warning('No linked HDF file was created');
+%     status = 0;
+% end
 
 end
 
diff --git a/test_data.mat b/test_data.mat
index 1d2004a11e0bf276402abe32cc62b6ed99f7e475..6f6642858ca39fe4ad4f41979dcdcca3b30b4877 100644
GIT binary patch
delta 882
zcmey({f&EqJ+Gm$m7$rHv4Mh-fsx_FK;?-EtQ$*And&{685k<&==N~?1gA5!{;&T3
z`+hf<2D7=LhUhA32~)KNi?Yiirn;|nbkOQQp=`i@Hh@KhYx7N)<s2y&8~g-#H~FmG
zl;SMz()RG8hSn}FW>cHCE+vkRj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