added "subroutine" to some end statements in fortran (required for compiling with Intel Fortran)