From a620cbf6f1149278dff986d451d171e28ad92af2 Mon Sep 17 00:00:00 2001
From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de>
Date: Thu, 23 Sep 2021 12:02:32 +0200
Subject: [PATCH] fixed some minor Issues

---
 +PlotID/Publish.m          | 20 +++++++++++++-------
 +PlotID/createFileCopy.m   |  8 +++++---
 +PlotID/createLinkedHDF5.m |  8 +++++++-
 +PlotID/fileCompare.m      | 10 ++++++++++
 4 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m
index 448fa51..1843f8d 100644
--- a/+PlotID/Publish.m
+++ b/+PlotID/Publish.m
@@ -92,14 +92,20 @@ switch options.Method
             [~, idx] = PlotID.fileCompare(DataPaths.rdata{i},fList);
             % create Linked HDF5 files for identical files
             if any(idx)
-            sourcePath = fList{idx,'name'}; % If there are multiple copies already, this only picks the last entry
-            if contains(sourcePath,{'.h5','.hdf5'}) % Linking only for HDF5
-                PlotID.createLinkedHDF5(sourcePath,storPath,ID);
-            end
+                sourcePath = fList{idx,'name'}; % If there are multiple copies already, this only picks the last entry
+                if contains(sourcePath,{'.h5','.hdf5'}) % Linking only for HDF5
+                    PlotID.createLinkedHDF5(sourcePath,storPath,ID);
+                end
             else % no identical file exists
-               PlotID.createFileCopy(DataPaths.rdata{i},'data',storPath,ID,'dataCentral');
-            end
-        end
+                %Copy the file in data 
+                PlotID.createFileCopy(DataPaths.rdata{i},'data',storPath,ID,'dataCentral');
+                %WIP
+%                 if contains(DataPaths.rdata{i},{'.h5','.hdf5'}) % Linking only for HDF5
+%                    % and create linked files in the plot folder 
+%                    PlotID.createLinkedHDF5(DataPaths.rdata{i},storPath,ID);
+%                 end  %if
+            end %if
+        end %for
     case 'individual'
         % Create a copy of the research data    
         PlotID.createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
diff --git a/+PlotID/createFileCopy.m b/+PlotID/createFileCopy.m
index e10a1d9..c77e355 100644
--- a/+PlotID/createFileCopy.m
+++ b/+PlotID/createFileCopy.m
@@ -14,9 +14,11 @@ function [] = createFileCopy(filePaths,folderName,storPath,ID,type)
             [~,name,ext] = fileparts(filePaths{i}); % get the extension
                           
             switch type
-                case 'data'
-                    sufix = '_data';
-                    newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]);
+                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]);
diff --git a/+PlotID/createLinkedHDF5.m b/+PlotID/createLinkedHDF5.m
index 17ad29d..5e6e71c 100644
--- a/+PlotID/createLinkedHDF5.m
+++ b/+PlotID/createLinkedHDF5.m
@@ -10,11 +10,17 @@ if iscell(SourceFile)
     SourceFile = SourceFile{1};
 end
 
+[~,filename,ext] = fileparts(SourceFile);
+
 % try
-    fid = H5F.create(fullfile(TargetPath,ID,[ID,'_data.h5']));
+    %old
+    %fid = H5F.create(fullfile(TargetPath,ID,[ID,'_data.h5']));
+    
+    fid = H5F.create(fullfile(TargetPath,ID,[filename,ext]));
     %create External Link to Sourcefile in the Group linkToExternal
     H5L.create_external(['..\data\',SourceFile],'/',fid, SourceFile ,plist_id,plist_id);
     H5F.close(fid);
+    disp([fullfile(TargetPath,ID,[filename,ext]),' created']);
     status = 1;
 % catch
 %     warning('No linked HDF file was created');
diff --git a/+PlotID/fileCompare.m b/+PlotID/fileCompare.m
index 9ccebdd..5e07704 100644
--- a/+PlotID/fileCompare.m
+++ b/+PlotID/fileCompare.m
@@ -24,7 +24,14 @@ for i=1:height(fileList)
     end
 
     filepath = fullfile(fileList{i,'folder'},fileList{i,'name'});
+    
+
+    %% old
+    %crucial performance due to matlab bug 
+    %(see
+    %https://de.mathworks.com/matlabcentral/answers/338553-performance-of-system-dos-function)
     if ispc
+        filename = ['"',filename,'"'];% Bugfix for spaces in path
         [status,~] = system(['fc ' filename ' ' char(filepath)]);
         % 0 -> identical, 1 -> not identical
          status = ~status; % false (not identical), true(identical)
@@ -34,9 +41,12 @@ for i=1:height(fileList)
     else
         warning('Platform not supported')
     end
+    %%
     
     if status == 1        
         id(i) = 1;
+        id =logical(id); %bugfix
+        return;
     else 
         % Status can also be any other number e.g. 2 
         id(i) = 0;
-- 
GitLab