Scientific Computing

Surprising modern Fortran behaviors

Here are a couple things that may trip up a classic or modern Fortran programmer.

Single line IF

The single line IF in both classic and modern Fortran only “captures” the first statement. If you use a semicolon, the code after the semicolon is always executed!

  • Correct:

    if (.true.) x = x+1
  • Incorrect: Here y always is y+1 !!

    if (.true.) x = x+1; y=y+1

MOD() vs. MODULO()

Fortran 77 had mod(), which could output negative numbers. This is often NOT the behavior you want, as other languages’ mod() functions only output positive numbers.

So typically, use Fortran modulo().

FFmpeg Live stream

YouTube Live streaming (optionally including other sites simultaneously) with screensharing is simple and stable with FFmpeg or OBS Studio.

Webcam:

ffmpeg \
-f alsa -ac 2 -i hw:1,0 \
-f v4l2 -r 10 -i /dev/video0 \
-c:v libx264 -pix_fmt yuv420p -preset ultrafast -g 20 -b:v 2500k \
-c:a aac -ar 44100 \
-threads 0 -bufsize 512k \
-f flv rtmp://a.rtmp.youtube.com/live2/YOURSTREAM &> stream.log

FFmpeg audio option -f alsa -ac 2 -i hw:1,0 uses -ac 2 for stereo to hardware address 1,0. For default audio device, use -f alsa -i pulse. Obtain hardware addresses via arecord -l. Note that monoaural -ac 1 doesn’t work on some hardware. -c:a aac -ar 44100 is AAC encode audio at 44.1 kHz sampling frequency (passing audio up to about 22 kHz, CD-quality).

FFmpeg video option -f v4l2 -r 10 -i /dev/video0 say to acquire video from webcam /dev/video0 at 10 fps, using the native resolution of the webcam. Force webcam resolution like -s 640x480. -c:v libx264 -pix_fmt yuv420p -preset ultrafast -g 20 -b:v 2500k encodes video using the H.264 video compression algorithm, prioritizing reduced CPU utilization, in blocks of 20 frames with a target bitrate of 2.5 Mbps.

FFmpeg config -threads 0 -bufsize 512k lets FFmpeg choose the number of CPU threads, with a 512kB buffer. Adjust buffer size as needed–tradeoff between latency and robustness. -f flv rtmp://a.rtmp.youtube.com/live2/YOURSTREAM &> stream.log uses the FLV container format, live stream to YouTube, with stream ID YOURSTREAM. Don’t let others know the Stream ID!.

Screenshare: use the same command as above, swapping -f v4l2 -r 10 -i /dev/video0 with

-f x11grab -r 10 -s 1024x720 -i :0.0+0,24

-f x11grab -r 10 -s 1024x720 -i :0.0+0,24 sets screengrab at 10 fps, starting in the upper left hand corner, send a 1024x720 pixel video. If your screen resolution is more than 1024x720, there would be unsent regions at the bottom and/or right side.

Audio-only:

ffmpeg -f alsa -ac 2 -i pulse -c:a aac -ar 8000 -f rtp rtp://localhost:1234

Connect from the local or remote PC to rtp:://serverip:1234.

Restream.io multisite livestreaming with FFmpeg

Restream.io has a free basic service that streams to over 30 sites, from a single incoming stream from FFmpeg. While FFmpeg can “tee” live-stream to multiple sites, this uses N times the data bandwidth for N sites, which doesn’t scale well. Restream.io takes one incoming stream and sends it to multiple sites, saving the streaming creator’s Internet data bandwidth. This is useful for slow Internet connections or where Internet connection cost is expensive per gigabyte.

The free service from restream.io works for YouTube Live among others.

  • restream.io can send stream notifications to the feed.
  • restream.io sends preview/link to stream
  • use Titles on restream.io to set stream titles all at once (before stream start)

Getting NEXRAD weather radar archive data

NOAA archives NEXRAD and TDWR radar data.

12000x5400 PNGs are available since 2010 (6000x2400 back to 1995). This Python program downloads composite reflectivity data rapidly using multiple download threads.

Interactive HTML5 National Reflectivity Mosaic

Unfortunately a colormap-data table or function isn’t readily available. Of course it’s inside the NEX2IMG program, but I would have to hack this a bit to extract the function. Another approach would be to use the HSV map to bin the PNG data.

Nexrad map

Notes

Python Launcher executable scripts Windows

Python programs can be launched by

python myprog.py

The Python Launcher, on Windows allows running by simply

myprog.py

based on the shebang

#!/usr/bin/env python

which works on Windows and Unix-like OS to search the user’s PATH for the desired Python executable.

Notes

Specific executables #!/usr/bin/python are only for specific situations like GNU Radio. Generally, please use #!/usr/bin/env python.

WROL 950 FM translator 100.3 FM

FM translator W262CV on 100.3 FM greatly expands the AM listening audience of WROL 950 Class D AM. WROL’s 5kW day signal from Rumney Marsh Reservation in Saugus is greatly attenuated to 90 watts at night to protect stations including:

  • WIBX Utica, NY
  • WKDN King of Prussia, PA
  • CKNB New Brunswick, Canada

This means WROL night coverage is weak in Boston and even core North Shore communities that are well within WROL day coverage.

FM translators for AM: AM Revitalization FM translators for AM stations attempt to provide the AM daytime coverage 24 hours a day via 250 watt or less transmissions in the FM broadcast band. Having an FM signal can be a boon for station advertising revenue–provided the FM coverage is not disrupted by unexpected factors such as illegal broadcasters. The Feb. 2017 R&O extended the 60 dBu (1 mV/m) FM translator contour to the greater of the AM 2 mV/m contour or 25 mile radius.

WROL W262CV 100.3 specifications

  • 45 watts
  • 42 21 46.35012 N 071 05 08.18621W (WGS84) Near the MIT Kendall MBTA stop, on the Marriott Hotel on Broadway (next to Microsoft NERD building).
  • height above ground: 90 meters

WROL FM translator interference: the 100.3 pirates changed frequency, but WROL 100.3 faces severe challenges from, and presents new challenges to other licensed stations. Listeners to these existing stations may object to the new WROL 100.3 translator.

Co-channel

50 kW WHEB is the primary limitation to coverage, particularly in the northeastern parts of Boston. However, one can merely switch to WROL 950 AM in northeast exurbs of Boston as per W262CV Exhibit 3 interference study.

Licensed co-channel interferers include:

  • WKIT Bangor, ME
  • WHEB Portsmouth, NH 50 kW station that interfered with Dorchester 100.3 pirate, sometimes overriding pirate down to at least Chinatown area.
  • W262CL Brattleboro, VT
  • WKKB Middletown, RI
  • WFFG Warrensburg, NY
  • W262AS Bridgehampton, NY

Adjacent channel

For most listeners, co-channel WHEB is more limiting than first adjacent WBRS.

  • WBRS 100.1 Brandeis Univ., Waltham (25 watts)

Add bookmark folder in Ubuntu Nautilus

Ubuntu Gnome 3-based desktop is even better than Unity. However, I was puzzled by the lack of a folder bookmark menu item in Nautilus, Ubuntu’s default “File Explorer”.

Fix: simply dragging and dropping a folder into the left sidebar adds a folder bookmark in Nautilus.

Improved Sondrestrom, Greenland internet speed

For many years, $45/GByte and 400 kbps with 200+ ms ping was the state of the art internet connection at Sondrestrom near Kangerlussuaq, Greenland. Recent Internet upgrades give nearly 1 Mbps upload and multiple Mbps download.

Speedtest results Greenland

Speedtest results for Greenland internet

Xauthority with VirtualBox on Wayland

Wayland desktop after install / upgrade a VirtualBox Extension Pack may get a “can’t find Xauthority”. The fix is to revert to X11 as recommended by Ubuntu.

Fix by logging out, and at the login screen select X11 login. Install the VirtualBox Expansion Pack Logout and switch back to the default login (with Wayland). VirtualBox will work in Wayland.

Recover macOS with no mouse, keyboard only

A recent macOS upgrade to High Sierra mysteriously broke the Apple mouse Bluetooth connection. Despite the computer showing the mouse as paired, no motion of the cursor or response to clicks. The keyboard alone can reconnect the mouse if no wired mouse was available.

The frequently used Apple key is equivalent to the key on a PC keyboard.

  1. open the Go To folder dialog with Cmd Shift g
  2. type /Applications
  3. highlight (select) System Preferences with the arrow keys
  4. Cmd o to open System Preferences
  5. Select Bluetooth. You may see your mouse already paired.
  6. Use Tab to select the “x” (it’s hard to see the highlight due to the flat color scheme.
  7. press Space to delete the mouse pairing
  8. Cmd n to setup new device. Flip mouse power switch off, then on again if it doesn’t show up.
  9. select the mouse and press Enter.