0001 function Publish(DataPaths, ID, figures, options)
0002
0003
0004
0005
0006
0007
0008
0009
0010 arguments
0011 DataPaths
0012 ID (1,:) {mustBeNonzeroLengthText}
0013 figures (1,:) {mustBeFigure}
0014 options.Location {mustBeMember(options.Location ,['local','server','CI-Test'])} = 'local'
0015 options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual'
0016 options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true
0017 end
0018
0019 switch options.Location
0020 case 'local'
0021 storPath = fullfile(pwd,'export');
0022 case 'server'
0023 storPath = '\\FST-220\Jans-50GB-SMB\Lemmer';
0024 case 'CI-Test'
0025 storPath = fullfile(pwd,'CI_files','export');
0026 end
0027 folderName = char(ID);
0028
0029
0030 addpath(storPath);
0031 if mkdir(fullfile(storPath,folderName))
0032 else
0033 error('Directory could not be created - check remote path and permissions');
0034 end
0035
0036 disp('Publishing started');
0037
0038
0039 createFileCopy({[DataPaths.script,'.m']},folderName,storPath,ID, 'script');
0040
0041 if options.CopyUserFCN
0042 [fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script);
0043
0044 fList = fList(~ismember(fList,[DataPaths.script,'.m']));
0045 fList = removePltIdFiles(fList);
0046 if ~isempty(fList)
0047 createFileCopy(fList,folderName,storPath,ID,'userFcn');
0048 end
0049 end
0050
0051
0052 switch options.Method
0053 case 'centraliced'
0054
0055 if ~isfolder(fullfile(storPath,'data'))
0056 mkdir(fullfile(storPath,'data'));
0057 end
0058
0059 fList = dir(fullfile(storPath,'data', '**\*.*'));
0060 fList = fList(~[fList.isdir]);
0061 fList = struct2table(fList);
0062
0063
0064
0065 for i=1:numel(DataPaths.rdata)
0066
0067 [status, idx] = fileCompare(DataPaths.rdata{i},fList);
0068 if status
0069 sourcePath = fList.name{idx};
0070 createLinkedHDF5(sourcePath,storPath,ID);
0071 else
0072 createFileCopy(DataPaths.rdata,'data',storPath,ID,'dataCentral');
0073 end
0074 end
0075 case 'individual'
0076
0077 createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
0078 end
0079
0080
0081 for i=1:numel(figures)
0082 fig = figures(i);
0083 PlotName = [ID,'_plot',num2str(i)];
0084 RemotePath = fullfile(storPath ,folderName, PlotName);
0085
0086 savefig(fig,RemotePath);
0087 exportgraphics(fig,[RemotePath,'.png'],'Resolution',300);
0088 disp([num2str(i),' of ',num2str(numel(figures)),' figures exported']);
0089 end
0090
0091
0092
0093
0094 disp(['publishing of ', ID , ' done']);
0095
0096 end
0097
0098 function [] = createFileCopy(filePaths,folderName,storPath,ID,type)
0099
0100
0101 disp(['start to copy ', type]);
0102
0103
0104 for i = 1:numel(filePaths)
0105 FileNameAndLocation = filePaths{i};
0106 [~,name,ext] = fileparts(filePaths{i});
0107
0108 switch type
0109 case 'data'
0110 sufix = '_data';
0111 newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]);
0112 case 'dataCentral'
0113
0114 newfile = sprintf([name,ext]);
0115 case 'script'
0116 sufix = '_script';
0117 newfile = sprintf([ID, sufix ,ext]);
0118 case 'userFcn'
0119
0120 newfile = sprintf([name,ext]);
0121 otherwise
0122 error([type,' is not a valid type for createFileCopy'])
0123 end
0124
0125
0126 RemotePath = fullfile(storPath,folderName, newfile);
0127 copyfile(FileNameAndLocation,RemotePath);
0128 end
0129 disp([type, ' sucessfully published']);
0130
0131
0132
0133 end
0134
0135 function tf = mustBeFigure(h)
0136
0137 tf = strcmp(get(h, 'type'), 'figure') & isa(h, 'matlab.ui.Figure');
0138 end