A general rule for compiling and running old code in any language is to first try to get it working for known input / output via emulation or virtual machine.
Many old codes were made before linters and other correctness checks we’ve long taken for granted.
The codes may use non-standard tricks to boost efficiency that haven’t been significant for decades.
A modern Fortran compiler that can compile Fortran 66 standard code without modification is Intel oneAPI.
The
-f66
flag enables Fortran 66 compatibility.
A key behavior difference with Fortran 66 is that Do loops always run at least once.
This behavior is not available in Gfortran.
If one has the ability to use a virtual machine with unmaintained compilers like g77 and the -fonetrip flag, this behavior can be emulated.
However, this behavior was simply
not addressed
in the
Fortran 66 standard.
After correct operation is established, Fortran 66 code often needs adjustments to work with modern compilers.
The Fortran Wiki has an excellent article on
modernizing Fortran syntax.
Always make a copy of the file first.
Sometimes 10,000+ lines will match so it can be tedious to check.
Similar operations may be needed if a mix of tabs and spaces are used.
To move line numbers left, run this regex and replace with null (nothing):
^\s+(?=\d+\s)
To make code start in column 7, recall that fixed format (Fortran <= 77) code has line numbers in columns 1-5 of each line numbers
After the prior operation, push the actual code right of column 6 by replacing this regex with appropriate number of spaces:
(?<=^\d+\s+)
Other compatibility notes:
$ can be used like a semicolon in CDC Cyber Fortran
put procedures in separate files for duplicated line numbers.
Matlab documentation discloses in which Matlab release a function was introduced.
Sometimes the documentation omits to say when a feature / option was added to an existing function.
To avoid needless iterating and possible misapplications of a function in an older release, it’s useful to check the
previous Matlab release documentation.
After clicking on a specific release, one can search for functions within that release only.
Across operating systems, “hibernate” is a power-saving state that saves the current session to disk and powers down the computer, allowing for a quick resume later while not having the long-term battery drain of suspend mode that keeps the RAM powered.
Sometimes as part of diagnosing problems or ensuring that a remote computer stays powered on, hibernate might be disabled.
If restoring such a computer to personal use, or if experiencing issues where a laptop computer has a drained battery after a couple days of non-use, it may be useful to enable hibernate mode.
Check the current state of hibernate mode by running the following command in Windows Terminal:
powercfg /availablesleepstates
If hibernate is enabled, the output will include “Hibernate” in the list of available sleep states.
To enable hibernate mode:
powercfg /hibernate on
However, the option in Control Panel → Power Options → Change plan settings → Change advanced power settings → Sleep → “Hibernate after”
may not be available until making the following registry change:
Reopen The Control Panel → Power Options → Change plan settings → Change advanced power settings, and the “Hibernate after” option should now be available.
Alternatively, enable the hibernate timer setting from the Terminal, where the values are in minutes:
powercfg /setACvalueindex scheme_current SUB_SLEEP HIBERNATEIDLE 43200# 12 hours hibernate while plugged into AC power (or set to 0 for never)powercfg /setDCvalueindex scheme_current SUB_SLEEP HIBERNATEIDLE 10800# 3 hours hibernate while on battery (or set to 0 for never)powercfg /setactive SCHEME_CURRENT
# Set the current power scheme to apply changes
Matlab version upgrade and AddOns installer was significantly changed in Matlab R2025a.
Matlab release upgrades can be initiated from the “bell” icon or from the
Matlab Help menu.
Upgrading or Add-On install requires a graphical connection to the computer (Remote Desktop, VNC, or similar).
Offline installs
are considerably more complex and are not for the typical Matlab user.
The bell icon on the upper right corner of the Matlab Desktop typically shows when a Matlab update is available.
Matlab can force checking for update, even if the bell is not showing an update, with our script
MatlabReleaseUpgrade.m.
Matlab
Add-On Explorer
is launched from the Matlab Desktop and requires a graphical connection.
The
mpm CLI installer
can be used to install Matlab and Add-Ons from the command line.
On macOS, Matlab does not source any shell configuration files like ~/.zshrc or ~/.bashrc.
Any environment variables set in these files, such as those added by package managers like Homebrew, will not be available in the Matlab environment.
Instead, set desired environment variables in the Matlab startup.m script like:
Where “/opt/homebrew/bin” was obtained from the system command brew --prefix.
We recommend not running system() scripts in startup.m unless truly necessary to avoid delaying Matlab startup time or affecting startup stability.
Then programs installed by Homebrew like CMake, GCC, etc. will be on Path environment variable in Matlab.
Note that the Matlab commands below only affect commands withing that same command line:
Get MPI on Windows with C and Fortran by any one of:
MS-MPI,
Intel oneAPI
or Windows Subsystem for Linux libopenmpi-dev.
We often use MPI via
MSYS2
with GCC / Gfortran compilers on Windows.
Upon installing or updating Intel oneAPI compilers and libraries on Windows, you may experience CMake failing to find MPI for MinGW.
This happens because Intel compilers put Intel MPI on the system PATH.
Fix this by removing Intel MPI from the system PATH and use the Intel Compiler shell instead, which provides all the needed directories.
These techniques allow a Windows development machine to use Notepad++ more effectively.
Notepad++ is a free source code editor and Notepad.
It was first released in 2003 and is an
open source project.
winget install Notepad++.Notepad++
Notepad++ from command line:
add to user environment variable Path the binary path of Notepad++ – typically at %PROGRAMFILES%\Notepad++.
This allows using notepad++ from the Windows Terminal.
Notepad++ shortcut icon open a new window:
When using multiple virtual desktops, by default Notepad++ snaps to the other desktop when clicking the Notepad++ start menu icon.
Make the Notepad++ icon open a new Notepad++ window by editing the Notepad++ start menu shortcut, appending
-multiInst
to the right and outside of the quoted full Target path to notepad++.exe.
This allows opening multiple Notepad++ windows, each with its own set of tabs.
Notepad++ open directory as project:
To open a directory as a project, use the command line option -openFoldersAsWorkspace followed by the path to the directory.
We have found this is often a server-side configuration issue, particularly when it only occurs with a specific server.
The server may be using an older version of OpenSSH that still supports arcfour-hmac, or it may have been configured to allow this encryption type.
To check settings in the SSH client configuration file, look for lines that specify Ciphers or MACs.
If arcfour-hmac is listed, it should be removed.
The Matlab external language interface to Python in Matlab releases before R2022a has a bug with the JIT compilation via
Matlab execution engine
such that any mention of the py.* namespace will make a function unusable if Python is not
available.
Especially problematic is functions that can work without Python (say in an if-else or switch block) where the mere presence of a py.* call will cause the entire function to fail if Python is not available.
To workaround this issue in Matlab older than R2022a, use a private function to encapsulate the Python call.
This way, the main function will not be affected by the Python call.
functionresult =my_fun2(input)if has_python()
result = encaps_fun2(input);
else% fallback code when Python is not availableendend
Make a private function in file “private/encaps_fun2.m”:
functionresult =encaps_fun2(input)result = py.some_module.some_function(input);
end
Matlab external language
interfaces
includes .NET on Windows, Linux, and macOS.
This allows efficiently calling .NET assemblies and using .NET libraries directly from Matlab.
The Matlab function
dotnetenv
is used to set up and check the active .NET environment in Matlab.
Environment variable DOTNET_ROOT is vital for Matlab to detect the .NET installation, particularly on Linux and macOS.
If Matlab is having issues detecting the .NET installation NET.isNETSupported is false, determine the value for DOTNET_ROOT from system Terminal:
dotnet --info
If “dotnet” command is not found, install .NET SDK:
macOS: brew install dotnet
Windows: winget install Microsoft.DotNet.SDK.9 # whatever the desired version is
Matlab Online (Linux): if .NET isn’t detected, use .NET install script to install .NET SDK.
Find the “dotnet” executable and run dotnet --info to get the DOTNET_ROOT path.
If this path is not defined, look for the Base Path, and pick the directory that contains the “dotnet” executable.
Set the DOTNET_ROOT environment variable in Matlab by adding to Matlab startup.m so that future Matlab sessions have the correct DOTNET_ROOT set.
edit(fullfile(userpath,'startup.m'))
Then add the following line to startup.m:
setenv("DOTNET_ROOT", <DOTNET_ROOT path from dotnet --info>)
Restart Matlab.
Do the following one-time command to finish setting up .NET in Matlab:
dotnetenv("core", Version=8)
The Version number must match the major version of .NET in DOTNET_ROOT.
On future Matlab sessions, dotnetenv() will be empty until the first .NET command is run, for example
NET.isNETSupported
then (optionally) running dotnetenv() shows the current .NET environment.