6 WRITING PORTABLE PROGRAMS

 6.1 Meaning of Portability
 6.2 Why Portability Matters
 6.3 Achieving Portability

One of the key reasons for having a Starlink programming standard is to promote software portability. What is meant by this term, and why is it important?

6.1 Meaning of Portability

Other things being equal, it is clearly desirable for applications to be usable on different computers rather than be limited to just one type. Equally clearly, there may be a tradeoff between the extra trouble of ensuring that application code is highly machine-independent and the work of modifying or rewriting programs from time to time. The Starlink Application Programming Standard recognizes this tradeoff and allows the programmer to choose what degree of portability is appropriate, taking into account:

To put the recommendations of the Starlink Standard in context, consider four degrees of portability, called here Absolute Portability, Portable Fortran, Adaptable Fortran and Laissez-Faire.

ABSOLUTE PORTABILITY is where application source code compiles and runs on all types of computer without any alterations whatsoever. Once the programmer has completed work on an application, the code need never again be touched. To achieve this result, the programmer must be fully insulated from the facilities offered by the platform. Because the Fortran 77 standard does not include all those things which applications need to do, and in any case compilers vary in their compliance with and interpretation of the standard or have bugs, it is not possible to rely on pure standard Fortran. (Similar arguments apply to other languages.) The classic solution is to write applications in a private programming language, and to accommodate differences between computers, compilers and operating systems by providing different versions of the language interpreter software. This approach has the benefit that for any new platform, once a new version of the system software has been written, unlimited quantities of application code will run. However, having to use the systems’s own programming language provokes scepticism among users, introduces extra training needs, produces code which can only run within the system, and reduces the convenience and effectiveness of online source code debuggers. These drawbacks led Starlink to reject this approach.

PORTABLE FORTRAN, Starlink’s recommendation, is to write applications in an industry-standard language – Fortran 77 – with controlled use of certain platform-dependent features as sanctioned by Sections 2 and 4 of the present document. Significant departures from standard Fortran (for example the use of %VAL) should be present in only a small minority of modules, with most routines in de facto standard Fortran. These departures can, if and when necessary, easily be edited using simple preprocessors like forconv or even by hand. Furthermore, the programs can be understood and modified by non-specialists.

ADAPTABLE FORTRAN, also embraced by the Starlink Standard, differs from Portable Fortran in the degree to which departures from ANSI Fortran are tolerated. While gratuitous use of platform-specific features is frowned upon, it is accepted that some use of such features will be convenient and relatively harmless. Programs of this general level of portability are easy to write and to adapt manually for new platforms as required.

LAISSEZ-FAIRE programming is where programmers can use whatever the current machine’s Fortran compiler accepts – the objective is simply to have a program that works. If a new computer is introduced, authors can decide whether to adapt, rewrite or scrap their applications. This style of programming lies outside the Starlink Standard and is deprecated for anything more than a casual one-off.

The Absolute Portability and Portable Fortran categories presuppose substantial quantities of infrastructure software, libraries and utilities which leave the programmer free to concentrate on the application itself rather than worrying about user interfaces, error handling, input/output and so on. At the lowest levels within the infrastructure there is a small platform-specific kernel, which has to be rewritten for each new machine. The Adaptable Fortran and Laissez-Faire categories allow programmers to provide their own infrastructure if they wish.

Starlink’s recommendation is to base programs on the various standard tools and libraries, and to aim for the PORTABLE FORTRAN level in applications code.

6.2 Why Portability Matters

Despite the fact that for its first decade Starlink supported just one platform – VAX/VMS – the importance of avoiding platform-specific software has been stressed from the beginning. There are two main reasons for this. Firstly, there were and are collaborating astronomical institutions using non-Starlink types of computer – Data General, Fujitsu, Perkin-Elmer, CDC, Cray and various Unix platforms – and it is useful if they can run Starlink applications, and programs written by Starlink users. The second reason is to enable existing software to run on different sorts of Starlink equipment – currently Sun and DECstation as well as VAX/VMS. Quite apart from further Unix-based platforms, it is also possible that fast specialized processors will be added to the existing Starlink systems, and there is interest in using various types of Personal Computer. Attention to software portability – which means resisting the temptation to use Sun and DECstation features now just as much as avoiding VAX dependency in the past – means great benefits in the long term.

6.3 Achieving Portability

Programmers who have followed the recommendations given earlier in Section 2 are likely to encounter fewer difficulties in adapting their code to run on new and multiple platforms than programmers who have not. Of those recommendations, the key one is to work only with ANSI Standard Fortran 77 and only to use a VAX extension or an extension available on some other platform when it is essential, or safe, to do so. This advice should be borne in mind when reading the following notes, many of which refer to problems that afflict code where non-standard Fortran extensions have been used. The notes concentrate on the specific problem of adapting VAX/VMS applications to run on Unix platforms but also serve to illustrate more general portability issues.