Scientific Computing

Installing GNU Radio

GNU Radio is trivially easy to install on Ubuntu, which includes the UHD driver.

apt install gnuradio

DO NOT use GNU Radio from a virtual machine in general with an SDR, as typically many packets will be lost and the data will not be useful. The typical best choice is to use a GNU Radio live USB image. Frequent GNU Radio users often dual boot into Ubuntu for working with SDR.

Build GNU Radio from source

Optionally compile GNU radio yourself

HP Printer setup on Linux

The HP-Setup program sets up HP printers on Linux and is easy to install and use.

Install HP setup program:

apt install hplip

Get the IP address of your networked HP printer from its front panel or the network address e.g. myprinter.local The CLI method is very quick and reliable.

CLI

Add the HP printer to the PC by:

hp-setup -i PrinterAddress

where PrinterAddress is the IP address e.g. 10.0.0.64 or a network name like myprinter.local

HP setup will try to select a PPD file, usually it finds a good one. Perhaps name the printer by the room name or department – it’s arbitrary.

After setup, the printer will show in:

  • system “Printers” window
  • CUPS under https://localhost:631/printers/ → Manage Printers

GUI

As noted above, this method may not work until HP updates their program to use a current Qt version.

Start GUI by typing hp-setup then select

  1. Network
  2. Manual Discovery
  3. type in printer IP address

The Printer should be instantly discovered and you’re ready to print.

Update BIOS via FreeDOS on Linux PC

BIOS update via FreeDOS works across many PCs, including Dell and Gigabyte. The key is that the OEM provides BIOS as a DOS executable.

Setup DOS-bootable USB drive: download the DOS-flashable BIOS firmware from the OEM e.g. support.dell.com Determine USB drive device (e.g. /dev/mmcblk0) by issuing this command before and after USB drive insertion:

lsblk

Format (permanently erase) this USB drive with

umount /dev/mmcblk0

mkdosfs -F 32 /dev/mmcblk0

Download the FreeDOS “USB Full Image” and extract the FD*.img file. Write this image to the USB stick:

dd if=FD*.img of=/dev/mmcblk0 bs=4M

the image write will take a minute or two, depending on the write speed of the USB stick. To be sure it’s done, wait for this command to exit in a second Terminal window:

sync

Update BIOS: extract/copy ALL the BIOS self-extracted files to the root of the FreeDOS flash drive from Linux. Insert the USB flash drive into the PC to be flashed Upon powerup, choose to boot from the USB drive. This might require pressing F12 key. In the BIOS boot device menu, look under Legacy boot. If Legacy boot is not enabled, it may need to be enabled to see the FreeDOS USB drive. Do NOT install FreeDOS, just boot to DOS when prompted by FreeDOS. In FreeDOS prompt, type the name of the .exe or .bat file for the firmware update as per OEM instructions. The flashing process may take several minutes.

If the PC says

operating system not found

on this DOS USB drive, try it in another PC. If it still doesn’t work, try another model of USB flash drive. Some flash drives just are not amenable to being booted from.

If a new computer motherboard seems to be dead out of the box, be sure the power supply is working and connected correctly. It may have a CPU that’s too new for the motherboard BIOS.

Specific example: This happened for Gigabyte GA-Q87M-D2H with version F6 BIOS. Version F7 BIOS was necessary for Haswell Refresh CPUs. I had to put an “old” CPU in the motherboard to flash the motherboard BIOS!

What does Gfortran -std=legacy allow?

The Gfortran flag -std=legacy disables warning for very out of date non-standard Fortran syntax that should not be used anymore. However, where you are using a legacy package where the code isn’t being changed, using -std=legacy can be necessary, particularly for Gfortran ≥ 8.

Some of the syntax enabled by -std=legacy includes pre-Fortran 77 arbitrary length arrays, where A(1) was declared instead of A(*) in Fortran 77 or A(:) in modern Fortran.

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