1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#!/bin/bash
# Returns the MATLAB version under the form x.y (not Rnnnn)
# Takes as argument the path to the MATLAB installation
#
# Alternatively, if the first argument is “--hex”, returns the MATLAB version
# as a pseudo-hexadecimal constant (0xMMmm) where MM is the major revision
# number (in decimal) and mm is the minor revision number (in decimal).
# E.g. version 9.14 is returned as 0x0914
# Copyright © 2009-2025 Dynare Team
#
# This file is part of Dynare.
#
# Dynare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Dynare is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Dynare. If not, see <https://www.gnu.org/licenses/>.
if [[ ($# == 0) || ($# == 1 && $1 == --hex) ]]; then
echo "Usage: $0 [--hex] /path/to/matlab" 2>&1
exit 1
fi
if [[ $1 == --hex ]]; then
hex=true
MATLAB=$2
else
hex=false
MATLAB=$1
fi
if [[ -f ${MATLAB}/VersionInfo.xml ]]; then
# The VersionInfo.xml file is present on all versions since R2017a, on all platforms.
# Extract the version number as x.y, since it is our preferred form, and is
# more robust to future versions.
MATLAB_VERSION=$(sed -En '/<version>/s/.*>([0-9]+\.[0-9]+).*/\1/p' "${MATLAB}/VersionInfo.xml")
elif [[ -f ${MATLAB}/bin/util/mex/version.txt ]]; then
# The bin/util/mex/version.txt file is present on Windows and macOS, at least
# since R2009b. It contains the release number (Rnnnnx).
MATLAB_VERSION=$(< "${MATLAB}/bin/util/mex/version.txt")
elif [[ -f ${MATLAB}/bin/mex || -f ${MATLAB}/bin/mexsh ]]; then
# Works on Linux and macOS until R2018a included. Returns the release number (Rnnnnx).
# Older MATLABs have the version in bin/mex, more recent in bin/mexsh
MATLAB_VERSION=$(sed -En "/^.*full_ver=/s/^.*full_ver='(R[^']+)'.*/\1/p" "${MATLAB}"/bin/mex*)
else
echo "Can’t determine the MATLAB version" 2>&1
exit 1
fi
# If needed, convert a release number (Rnnnnx) into a version number (x.y)
case ${MATLAB_VERSION} in
*2025[bB])
MATLAB_VERSION="25.2"
;;
*2025[aA])
MATLAB_VERSION="25.1"
;;
*2024[bB])
MATLAB_VERSION="24.2"
;;
*2024[aA])
MATLAB_VERSION="24.1"
;;
*2023[bB])
MATLAB_VERSION="23.2"
;;
*2023[aA])
MATLAB_VERSION="9.14"
;;
*2022[bB])
MATLAB_VERSION="9.13"
;;
*2022[aA])
MATLAB_VERSION="9.12"
;;
*2021[bB])
MATLAB_VERSION="9.11"
;;
*2021[aA])
MATLAB_VERSION="9.10"
;;
*2020[bB])
MATLAB_VERSION="9.9"
;;
*2020[aA])
MATLAB_VERSION="9.8"
;;
*2019[bB])
MATLAB_VERSION="9.7"
;;
*2019[aA])
MATLAB_VERSION="9.6"
;;
*2018[bB])
MATLAB_VERSION="9.5"
;;
*2018[aA])
MATLAB_VERSION="9.4"
;;
*2017[bB])
MATLAB_VERSION="9.3"
;;
*2017[aA])
MATLAB_VERSION="9.2"
;;
*2016[bB])
MATLAB_VERSION="9.1"
;;
*2016[aA])
MATLAB_VERSION="9.0"
;;
*2015[bB])
MATLAB_VERSION="8.6"
;;
*2015[aA])
MATLAB_VERSION="8.5"
;;
*2014[bB])
MATLAB_VERSION="8.4"
;;
*2014[aA])
MATLAB_VERSION="8.3"
;;
*2013[bB])
MATLAB_VERSION="8.2"
;;
*2013[aA])
MATLAB_VERSION="8.1"
;;
*2012[bB])
MATLAB_VERSION="8.0"
;;
*2012[aA])
MATLAB_VERSION="7.14"
;;
*2011[bB])
MATLAB_VERSION="7.13"
;;
*2011[aA])
MATLAB_VERSION="7.12"
;;
*2010[bB])
MATLAB_VERSION="7.11"
;;
*2010[aA])
MATLAB_VERSION="7.10"
;;
*2009[bB])
MATLAB_VERSION="7.9"
;;
*2009[aA])
MATLAB_VERSION="7.8"
;;
*2008[bB])
MATLAB_VERSION="7.7"
;;
*2008[aA])
MATLAB_VERSION="7.6"
;;
*2007[bB])
MATLAB_VERSION="7.5"
;;
*2007[aA])
MATLAB_VERSION="7.4"
;;
*2006[bB])
MATLAB_VERSION="7.3"
;;
*2006[aA])
MATLAB_VERSION="7.2"
;;
*14[sS][pP]3)
MATLAB_VERSION="7.1"
;;
*14[sS][pP]2)
MATLAB_VERSION="7.0.4"
;;
*14[sS][pP]1)
MATLAB_VERSION="7.0.1"
;;
[rR]14)
MATLAB_VERSION="7.0.0"
;;
esac
# Check that we have an x.y version number
if ! grep -qE '^[0-9.]+$' <<< "${MATLAB_VERSION}"; then
echo "Unknown MATLAB version: ${MATLAB_VERSION}" 2>&1
exit 1
fi
if [[ $hex == true ]]; then
echo -n "0x"
sed -e 's/\([0-9]*\)\.\([0-9]*\).*/Z\1ZZ\2Z/' \
-e 's/Z\([0-9]\)Z/Z0\1Z/g' \
-e 's/[^0-9]//g' <<< "${MATLAB_VERSION}"
else
echo "${MATLAB_VERSION}"
fi
|