Abstract
LSODAR is a Fortran subroutine for integration of ordinary differential equations that has been actively maintained for over twenty years and gives high-quality results for a variety of problems. This paper demonstrates how such a "dusty deck" can be adapted to interface cleanly to a modern high-level language like Tcl, be made safe to use in the presence of threads and recursion, and take advantage of the symbolic computation capabilities available to Tcl. The result is an ODE solver for Tcl that is production-ready, at the expenditure of considerably less effort than it would take to develop comparable capabilities targeted specifically at Tcl. It presents a few tricks that should be handy in connecting other legacy Fortran applications to Tcl.
1. Introduction
Fortran has for decades been the first choice of language for scientific programming. Because of this, a great many Fortran codes are available for solving numeric problems, such as statistical analysis, root finding, and the integration of differential equations. Many of the best are available free of charge, having been developed by US Government researchers at taxpayer expense. These "treasures of the national labs" deserve to be more widely known outside the Fortran community, but the tremendous difference in style between Fortran and more modern languages inhibits their broader acceptance. This paper describes how one such code, LSODAR (Livermore Solver for Ordinary Differential equations with Automatic method selection and Root-finding) (4) was adapted to use in Tcl. Among the issues that have to be addressed for this code are adapting the long parameter lists of the Fortran calls to something more Tcl-friendly, managing dynamically allocated memory, dealing with Fortran callbacks (callbacks to EXTERNAL functions) at the Tcl level, and dealing with issues like recursion and multithreading. The combination is arguably greater than the sum of the parts, because Tcl's ability to perform symbolic calculations can be exploited in the combined code. The combined Fortran-Tcl system has the ability to use Tcl's symbolic capabilities to perform symbolic differentiation to exploit backward-differencing formulas.