matRad function to get the current matRad version (and git information when used from within a repository call [versionString,matRadVer] = matRad_version() input output versionString: Readable string build from version information matRadVer: struct with version information References - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright 2020 the matRad development team. This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [versionString,matRadVer] = matRad_version() 0002 % matRad function to get the current matRad version 0003 % (and git information when used from within a repository 0004 % 0005 % call 0006 % [versionString,matRadVer] = matRad_version() 0007 % 0008 % input 0009 % 0010 % output 0011 % versionString: Readable string build from version information 0012 % matRadVer: struct with version information 0013 % 0014 % References 0015 % - 0016 % 0017 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0018 % 0019 % Copyright 2020 the matRad development team. 0020 % 0021 % This file is part of the matRad project. It is subject to the license 0022 % terms in the LICENSE file found in the top-level directory of this 0023 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 0024 % of the matRad project, including this file, may be copied, modified, 0025 % propagated, or distributed except according to the terms contained in the 0026 % LICENSE file. 0027 % 0028 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 %Hardcoded version name / numbers 0031 matRadVer.name = 'Blaise'; 0032 matRadVer.major = 2; 0033 matRadVer.minor = 10; 0034 matRadVer.patch = 0; 0035 0036 tagged = false; 0037 0038 %Retreive branch / commit information from current git repo if applicable 0039 try 0040 %read HEAD file to point to current ref / commit 0041 repoGitDir = [fileparts(mfilename('fullpath')) filesep '.git']; 0042 headText = fileread([repoGitDir filesep 'HEAD']); 0043 0044 %Test if detached head (HEAD contains 40 hex SHA1 commit ID) 0045 i = regexp(headText,'[a-f0-9]{40}', 'once'); 0046 if ~isempty(i) 0047 matRadVer.branch = 'DETACHED'; 0048 matRadVer.commitID = headText(1:40); 0049 else %HEAD contains reference to branch 0050 headParse = textscan(headText,'%s'); 0051 refHead = headParse{1}{2}; 0052 refParse = strsplit(refHead,'/'); 0053 matRadVer.branch = refParse{end}; 0054 0055 %Read ID from ref path 0056 refID = fileread([repoGitDir filesep strjoin(refParse,filesep)]); 0057 matRadVer.commitID = refID(1:40); 0058 0059 %Check if we are on a tagged commit (i.e., release) 0060 %{ 0061 tagRefs = dir([repoGitDir filesep 'refs' filesep 'tags']); 0062 for t = 1:numel(tagRefs) 0063 if ~any(strcmp(tagRefs(t).name, {'.', '..'})) 0064 tagId = fileread([repoGitDir filesep 'refs' filesep 'tags' filesep tagRefs(t).name]); 0065 if strcmp(tagId(1:40),matRadVer.commitID) 0066 tagged=true; 0067 break; 0068 end 0069 end 0070 end 0071 %} 0072 0073 end 0074 0075 catch 0076 %Git repo information could not be read, set to empty 0077 matRadVer.branch = []; 0078 matRadVer.commitID = []; 0079 end 0080 0081 %Create a readable string 0082 %Git path first 0083 gitString = ''; 0084 if ~isempty(matRadVer.branch) && ~isempty(matRadVer.commitID) && ~tagged 0085 gitString = sprintf(' (%s-%s)',matRadVer.branch,matRadVer.commitID(1:8)); 0086 end 0087 0088 %Full string 0089 versionString = sprintf('v%d.%d.%d "%s"%s',matRadVer.major,matRadVer.minor,matRadVer.patch,matRadVer.name,gitString); 0090 0091 %This checks if no explicit assigment is done in which case the version is printed. 0092 if nargout == 0 0093 disp(['You are running matRad ' versionString]); 0094 end 0095 0096 end