author is ashamed of the quality. Drat. Closes PR ports/2027. Submitted by: Yukihiro Nakai <Nakai@Mlab.t.u-tokyo.ac.jp>