I am grateful to David Meidinger for providing the code.