Port of generally useful routines from USGS PAGER application