Scientific Computing

Loading WSPR raw audio data

We encourage amateur radio operators and citizen scientists to save raw WSPR data in the form of two-minute long .wav files. Load each WAV file into Python like:

from scipy.io import wavfile

fn = '170620_1652.wav'  # naming convention is YYMMDD_HHMM.wav

fs, data = wavfile.read(fn)

This will result in fs=12000 Hz and data a 1440000 element 1-D vector of numpy.ndarray.

The WSPR baseband signals are user-selected in the 1400 .. 1600 Hz range. Other signals within the audio passband are useful as reference, for example JT65, FT4, and FT8 for additional paths to analyze.

Fix inability to type in Spyder IDE over VNC

With Ubuntu at the remote and local ends, if unable to type anything into the Spyder IDE when connecting remotely over VNC, try TurboVNC on the laptop. Download the latest TurboVNC .deb file and Install the .deb file

gdebi turbovnc*.deb

Now, the command vncviewer maps to the more advanced TurboVNC instead of TightVNC.


Before using TurboVNC, errors included

Qt: XKEYBOARD extension not present on the X server.

I tried putting in the remote system’s ~/.profile the line

export XKB_DEFAULT_RULES=base

based on Spyder Github Issue but with no luck.

Fortran sound playback - platform-independent

Some Fortran code used proprietary modules from Visual Fortran and the like for among other things, playing back sound from Fortran on Windows. I believe a more reliable and platform-independent way to playback sound from Fortran is to use an external application like ffplay, included with FFmpeg.

FFplay will play prerecorded audio files. Playback particular sounds based on filename.

This technique is not good for background music in a game, but is good for short sound effects to let you know your processing is done or for game sound effects in Fortran.

NOTE: use all lowercase filename, and don’t use spaces in names for best cross-platform compatibility and reliability.

Fortran program with sound example: use / as a file/directory separator on Fortran. // concatenates strings in Fortran.

program mysound

use iso_fortran_env, only : input_unit

implicit none

! configure ffplay -- could make if/else to allow other players
character(*), parameter :: playexe='ffplay'
character(*), parameter :: cmdopts='-autoexit -loglevel quiet -nodisp'

character(1000) :: fn, cmd

print *,'input sound filename to play'
read(input_unit,'(A)') fn  ! must be (A) and not *

cmd = playexe//' '//cmdopts//' '//trim(fn)
print *,trim(cmd) ! for debugging

! exitstat only works for wait=.true. by Fortran standard.
call execute_command_line(cmd, wait=.false.)

end program

More Fortran sound playback examples: robust Fortran sound playback example play_sound.f90 or implemented as a Fortran game with sound sound.f90.

Fortran terminal ISO standard

iso_fortran_env is respected by all common Fortran compilers, as implied by its name. iso_fortran_env is part of the Fortran 2003 specification and popular Fortran compilers added it a decade ago (Gfortran since at least GCC 4.3).

Why use iso_fortran_env terminal I/O: legacy programs written before Fortran 2003 often write to terminal with:

write(*,*) 'The value of X is ',x

or

write(6,*) 'The value of X is ',x

This is a problem when trying to debug with text output to terminal, especially where someone has used “6” for file I/O unit by mistake. Or, if trying to write to a file with an uninitialized unit number, stderr gets redirected to file fort.0.

Example

Print repeatedly to the same line, and combine prompt text on the same line with input.

iso_fortran_env terminal I/O: example prints to stdout, then stderr and finally asks for user input with a prompt on the same line.

program myterm
use iso_fortran_env
implicit none (type, external)
character(1000) :: usertxt  ! 1000 is an arbitrarily large number
integer :: ios

! could also just use print *,'printed to stdout'
write(output_unit,*) 'Printed to stdout'

write(error_unit,*) 'printed to stderr'

! prompt with caret on same line as input, here using a greater than sign >
write(output_unit,'(A)',advance='no') ' >'
flush(output_unit)

read(input_unit,"(A)", iostat=ios) usertxt
! trap Ctrl-D EOF on Unix-like systems to avoid crashing program
if (ios/=0) backspace(input_unit)  ! ctrl D gobble

write(output_unit,*) usertxt

end program

If stderr goes to file fort.0

If stderr from error_unit gets written to a file fort.0 instead of being printed to screen, this is an indication of open(u)ing a file without first setting a value for u, which might default to 0.

Unless needing to persist a file opening between calls of a function/subroutine, normally open a file with newunit.

program myfile
use iso_fortran_env
implicit none (type, external)

integer :: u, ios
character(1000) :: fn ! 1000 is an arbitrarily large number
character(1000) :: dat

print *, "please input file to open"

read(input_unit, '(a)', iostat=ios) fn
if(is_iostat_end(ios)) stop

! open file, using better to ask forgiveness than permission principle
! status='old' means generate error if file doesn't exist
open(newunit=u,file=fn, status='old',action='read',iostat=ios)
if (ios /= 0) then
    write(error_unit,*) 'could not open file ',trim(fn)
    error stop 'file IO error'
endif

read(u,'(A)') dat
print *,'first two lines of ',trim(fn),' are:'
print *,trim(dat)
read(u,'(A)') dat
print *,trim(dat)

close(u)  ! implicitly closed at end of program, but as good practice...
end program

Related:

Copying or moving WINE to a new PC

A new PC with different username cause two issues for WINE when copying old PC user files to a new PC. If the Linux username changed, you have to update the “exec” lines of the .desktop files that reside in ~/.local/share/applications/wine/Programs/ (or create softlinks). Sometimes the drive links in ~/.wine/dosdevices differ after copying. Update your shortcuts/softlinks as necessary.

Z38xx Jackson Labs GPS on Linux via WINE

To use Z38XX GPS logging program on Linux via WINE, first identify which serial port the GPS is on. Identify the WINE virtual serial port corresponding to the Linux serial port:

ls -l ~/.wine/dosdevices

if necessary change WINE serial port mapping. Start Z38XX.EXE and set Parameters → Serial Port to the port noted above. Set baud rate–Jackson Labs GPS typically use 115200 baud by default.

Ulrich and Ina Bangert sadly have both passed away, and the website is maintained by a friend. Regrettably, the source code for Z38XX is not known to be available, and so people have resorted to hex-editing the binary to adapt for new devices that would not otherwise work. We are thankful for Ulrich’s service to the GPS/TimeNut/Amateur Radio/Radio Science community, and hope that other authors will consider open-sourcing their code to help the community even more.

Z38XX 2013-04-23 is the last known version from Ulrich.

Fix Windows winload.efi expired error

A Windows PC that hasn’t been booted for months may get a black or blue error screen:

A component of your operating system has expired winload.efi

You will need to update to the latest version of Windows, after backing up your files. In BIOS/UEFI, set the date to about the time your PC last worked. If you’re not sure, set the date roughly 6-12 months into the past. Reboot and Windows should start, but will note an expired version of Windows. Windows will set the correct date automatically. Copy off all your data to an external drive. Don’t reboot! Do the “force upgrade” below.

If this fails, you can recover non-encrypted (non-Bitlocker) data by copying your data off to USB or network drive with an Ubuntu live USB stick or pull the hard drive and copy files.

Force upgrade with the Windows Update Assistant and run on that PC.

Python list of bytes to string

The bytes.join command converts list of bytes strings to a single ASCII string.

Example: in.dat is binary data with an ASCII header, so common to legacy code.

from pathlib import Path
infn = Path('in.dat')

with infn.open('rb') as f:
    line = f.readline().split()
    dat = line[-5:]
    header = line[:6]

    txt = bytes.join(b' ', header).decode('ascii')

with header=[b'this', b'is', b'a', b'yucky', b'ascii', b'header']