From 2b8146f060cf3b6781a2e75039f592e6747adcd4 Mon Sep 17 00:00:00 2001 From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de> Date: Thu, 7 Oct 2021 09:40:04 +0200 Subject: [PATCH] add save Matlab Version to config file --- +PlotID/Publish.m | 40 ++++++++++++++++++++++++++++++++++------ example.m | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index f37952b..346dad0 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -29,6 +29,18 @@ if numel(figure) > 1 warning(msg); end +%read config file +try + txt = fileread('config.json'); + config = jsondecode(txt); + configError = false; +catch + msg = ['Error while reading the config file' newline,... + ' publishing on server not possible']; + warning(msg); + configError = true; +end + switch options.Location case 'local' if contains(options.ParentFolder, {'/','\'}) @@ -39,8 +51,6 @@ switch options.Location storPath = fullfile(scriptPath,options.ParentFolder); end case 'server' %from config File - txt = fileread('config.json'); - config = jsondecode(txt); storPath = config.ServerPath; case 'manual' %UI storPath = uigetdir(); @@ -60,13 +70,31 @@ end disp('Publishing started'); -%% Create a Copy of the script and User functions(optional) +%% Create a Copy of the script, config and user functions(optional) +% script PlotID.createFileCopy({[DataPaths.script,'.m']},folderName,storPath,ID, 'script'); -if options.CopyUserFCN - [fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script); - % plist contains the required MATLAB Toolboxes, maybe usefull in future +% config +[fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script); +if ~configError %config File must exist + % copy config file + configPath = PlotID.createFileCopy('config.json',folderName,... + storPath,ID, 'data'); + % add Metadata + config.MatlabVersion = version; + % TODO Add Toolboxes + %write config + fid = fopen(char(configPath),'w'); + txt = jsonencode(config,'PrettyPrint',true); + fprintf(fid,txt); + fclose(fid); +end + + +% user functions +if options.CopyUserFCN fList = fList(~ismember(fList,[DataPaths.script,'.m'])); % rmv script from list + fList = fList(~contains(fList,'config.json')); % rmv config.json from list fList = PlotID.removePltIdFiles(fList); % Do not copy files that are part of plot ID if ~isempty(fList) PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn'); diff --git a/example.m b/example.m index dfb5647..bda38be 100644 --- a/example.m +++ b/example.m @@ -52,6 +52,7 @@ h5write(fpath, "/y1", y1) 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 %% Plotting % This is still part of a normal script to produce plots. -- GitLab