Scientific Computing

Set and use alias within Bash script

Bash scripts by default ignore aliases, unless the command

shopt -s expand_aliases

has been used before the aliased command. This is typically a good thing, as if one has set in ~/.bash_aliases something like

alias mv="mv -v"

any script using mv could produce extremely lengthy and verbose output when installing a program for example.

However, sometimes a user has multiple versions of a program installed in directories in $PATH and for whatever reason cannot use update-alternatives to make the desired one the default. Use update-alternatives instead whenever possible as this method described here is not as robust. Because we are not sourceing the Bash script, the alias scope is only within the Bash script itself. That is, once the script is done, the alias disappears.

If a script needs CMake 3.x and update-alternatives is not available, do within the Bash script:

shopt -s expand_aliases
alias cmake=/usr/bin/cmake3

Again, we stress this is not general or robust, so only do this as a last resort. sudo is not required for update-alternatives. Put the softlinks under $HOME/.local/bin and put that on your $PATH as a much better choice.

pytest AttributeError get_marker

Pytest 4.1 removed a deprecated API, resulting in errors like:

AttributeError: ‘Function’ object has no attribute ‘get_marker’

The fix requires update of affiliated pytest-* packages to at least:

  • pytest-cov 2.6.1
  • pytest-remotedata 0.3.1

At this time, conda doesn’t handle this automatically, so if you are a conda user:

conda install pytest-cov pytest-remotedata

Similarly for other affected packages–look at the last few lines of the error to get a hint as to what package is affected.

RFSpace SDR-IQ with SpectraVue 3 on Linux

RFSpace SpectraVue is a nice SDR GUI that work both online (with a radio) and offline (from a saved file). SpectraVue is a Windows program that also works on Linux via WINE. For USB based SDRs, since WINE doesn’t currently have USB support, we use the Linux program siqs-ftdi to connects to the SDR-IQ over USB, and provide the packets on a local network socket. For Debian and Ubuntu, siqs-ftdi is provided with the CuteSDR program, another useful SDR interface.

It is necessary to use siqs-ftdi on the Linux Terminal to make the USB → network connection, since WINE currently does not support USB in general. This method has worked for several years across various versions of WINE, SpectraVue and Linux.

SpectraVue on Linux is run via WINE. Configure WINE with MFC42 and VCRun2010:

winetricks mfc42 vcrun2010

Download RFSpace SpectraVue and run:

wine SpectraVueSetup*.exe

Add to ~/.bash_aliases

alias SpectraVue='wine $HOME/.wine/drive_c/SpectraVue/SpectraVue.exe'

For USB-connected RFSpace SDR-IQ, use siqs-ftdi to make the USB connection.

For Ubuntu, siqs-ftdi is available in the cutesdr package for Ubuntu:

apt install cutesdr

If siqs_ftdi is not included with your CuteSDR Ubuntu package, it’s possible to manually extract siqs-ftdi from the cutesdr*.deb for your platform using dpkg-deb:

mkdir cutesdr

dpkg-deb --raw-extract cutesdr*.deb cutesdr

cp cutesdr/usr/bin/siqs_ftdi ~/.local/bin

Ensure ~/.local/bin is on PATH by adding to ~/.profile:

export PATH=$PATH:$HOME/.local/bin

Install FTDI driver:

apt install libftdi1-2

To use SpectraVue with SDR-IQ:

  1. Be sure siqs-ftdi is running and SDR-IQ is plugged into the PC via USB.
  2. In SpectraVue, click InputDevice → SDR-IQ (or your radio model).
  3. Click SDR-IQ Setup → Interface Selection → Network
  4. click SDR-IQ Setup → Network SDR-IQ Setup → IP Address 127.0.0.1
  5. click Find and select your SDR-IQ

For a network (Ethernet) connected SDR, enter the IP address of the SDR. This does NOT work for USB-connected SDR such as SDR-IQ.

  1. In SpectraVue, click InputDevice and select your radio model.
  2. click SDR-IQ Setup → Network SDR-IQ Setup → IP Address (enter IP address of your SDR)
  3. click Find and select your SDR

To run SpectraVue simply start it up, perhaps by:

wine $HOME/.wine/drive_c/SpectraVue/SpectraVue.exe

USB SDR and SpectraVue on Linux is one of the best ways to use the RFSpace SDR-IQ or other USB-connected SDR on Linux.

Open a Terminal and type

siqs-ftdi

Open a second Terminal window and type:

SpectraVue

Errors like:

err:module:import_dll Library mfc100.dll (which is needed by L"C:\SpectraVue\IOModule.dll") not found
err:module:import_dll Library IOModule.dll (which is needed by L"C:\SpectraVue\SpectraVue.exe") not found
err:module:import_dll Library mfc100.dll (which is needed by L"C:\SpectraVue\SpectraVue.exe") not found

are fixed by

winetricks vcrun2010

The error

err:module:import_dll Library MFC42.DLL (which is needed by L"c:\\SpectraVue\\SDR14X.dll") not found

is fixed by

winetricks mfc42

Alternative: CuteSDR with RFSpace SDR-IQ on Linux

declutter htop disable thread display

htop is great for viewing processes on Unix-like systems. It has the unfortunate behavior of overwriting changes to a manually written ~/.htoprc. It seems the best way to disable threads is to remember the following:

  • capital H: toggle user thread display
  • capital K: toggle kernel thread display

This helps declutter the process tracking display.

Broken SSH scrolling

There can exist incompatible terminal types between the local and remote computers on an SSH connection. The issue arises when trying to scroll in a text editor on the remote computer such as nano, emacs or vim among others. The text display would become all scrambled.

On the local SSH client PC, make the entries to the problem remote connection(s) as follows in the ~/.ssh/config file on your local PC.

Host myhost
    RequestTTY yes
    RemoteCommand export TERM=linux && bash
RequestTTY yes
opens a pseudo-terminal on the remote server, like the ssh -t option. If you have trouble, try RequestTTY force
RemoteCommand
this should normally have a && bash at the end of the command, assuming you want an interactive SSH session. Otherwise the remote server runs the command and immediately disconnects.

CMake hex2dec and dec2hex

CMake hexidecimal to decimal conversion uses the convention that 0x prefix on a number implies it’s a hexadecimal number.

Suppose CMake scripts “hex2dec.cmake”:

math(EXPR decval "0x${hexval}" OUTPUT_FORMAT DECIMAL)

message(STATUS "Hex: ${hexval} => decimal: ${decval}")

running

cmake -Dhexval=14 -P hex2dec.cmake

yields:

– Hex: 14 => decimal: 20

Count lines of project code with CLOC

CLOC is a single-file Perl program that counts lines of code very quickly in large projects. If even more speed is needed, CLOC can run with parallel processes. Recent versions of CLOC are 10-100x faster than old versions. The Linux distro might have an old / slow CLOC version. It can be worth downloading the current version of CLOC if you use it a lot.

CLOC works on any operating system since it’s just Perl script.

For Linux / macOS: download latest cloc-*.pl to ~/.local/bin. Be sure $HOME/.local/bin is on your PATH by adding to ~/.profile:

export PATH=$HOME/.local/bin:$PATH

For convenience, make a softlink for cloc:

ln -s ~/.local/bin/cloc-*.pl ~/.local/bin/cloc

Make sure it’s executable:

chmod +x ~/.local/bin/cloc

For Windows download latest cloc-*.exe to c:\cloc\ and add c:\cloc to the user PATH.


To make CLOC run N times faster, you need the Perl Parallel::ForkManager library, which on Linux is installed by:

apt install libparallel-forkmanager-perl

then use like:

cloc --processes=4 .

For the GEMINI projects, we get a result like:

cloc --exclude-dir=vendor,archive,objects,subprojects  .
--exclude-dir
comma-separated list of directory names to exclude
     175 text files.
     168 unique files.
      22 files ignored.
github.com/AlDanial/cloc v 1.80  T=0.38 s (411.2 files/s, 69628.8 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Fortran 90                      35           3355           2809           9008
MATLAB                          71           1258           1202           4560
TeX                              1            266             76           1140
CMake                           20            315            119            857
Markdown                         3            175              0            366
make                             2             78             17            169
Bourne Shell                    13            113             97            160
INI                              6              1              0            126
Python                           4             65             15            122
NAnt script                      1             18              0             62
YAML                             1              7              9             19
-------------------------------------------------------------------------------
SUM:                           157           5651           4344          16589
-------------------------------------------------------------------------------

For debugging or finding what specific files are contributing to the total, use option:

cloc --categorized=cloc.log

Disable text wrapping in nano

Word wrapping in nano text editor can make scripts and files fail to run/parse properly. A simple edit can goof up a config or script by adding unwanted newlines. These settings are in general good for nano on any operating system.

Disable text wrap in nano by adding to ~/.nanorc

set nowrap

A suggested ~/.nanorc contains the following for good defaults including Python coding:

set constantshow
set tabsize 4
set nowrap
set tabstospaces
  • constantshow: show line and column of cursor position (on old nano version as in Red Hat 7, this option may not be recognized)
  • tabsize 4, tabstospaces: make tabs into 4 spaces
  • nowrap: disable long-line text wrapping

Nano syntax highlighting is enabled with include statements in ~/.nanorc.

WINE serial port links

WINE creates serial port softlinks( automatically.

Serial port mapping is managed via

WINEPREFIX=~/.wine wine regedit

Be sure to include the WINEPREFIX (default is ~/.wine)

Which WINE serial port to use: find the WINE serial port corresponding to the Linux serial port device name by watch log output from:

dmesg -w

when plugging in the serial ↔ USB adapter.

Using WINEPREFIX, start the WINE registry editor:

WINEPREFIX=~/.wine wine regedit

Configure the port–if the device is seen at /dev/ttyUSB0, and you want it to appear to WINE on COM1, edit HKEY_LOCAL_MACHINE\Software\Wine\Ports to have a new string entry named COM1 with value /dev/ttyUSB0.

Verify this setting (but do not edit) by:

ls ~/.wine/dosdevices

where again ~/.wine is the location of your WINEPREFIX.