Integrating Peter S's fortran fix of 22 Oct 2013. Fixed a few test failures.