BUF - A Fortran subset for the chemistry classroom - Journal of

Journal of Chemical Education .... subset of the the basic Fortran language presented as part of a brief introduction to computer programming. ... Com...
0 downloads 0 Views 1MB Size
Jon A. Kapecki Cornell University 1thoco, N e w York 14850 and William Switzer, Ill University of Illinois

BUF-A

Fortran Subset for the

Chemistry Classroom

Although the availability and importance of computers in all branches of chemistry has increased tremendously over the past few years, the incorporation of this modern technique for data analysis in course and laboratory work has been hampered by the generally heterogeneous backgrounds of most graduate and undergraduate chemistry classes. In many cases staff members have neither the time nor the interest to teach programming as part of a regular chemistry course, and although many excellent selfinstructional texts for beginning programmers are available, they are, in general, too long and detailed to serve as supplemental course reading. As a result when computers are used, students are usually supplied with a prepackaged program to process the data, perhaps a vague outline explaining how the program works, and instructions for its use. We have attempted to overcome this "black box" approach to data analysis by teaching a core subset of the basic Fortran language which we term "Basic Universal Fortran" (BUF). Usually given in the 1 A program to search for the possible origins of metastable peaks in mass spectra has been used with organic groups, and a bond distance program was written for s. crystallography class. A linear least squares program also serves as s, good example and can often be incorporated later into more complex programs.

form of an optional seminar or as part of the laboratory accompanying the lecture course, BUF can be easily covered in about 3 hr of informal lecture. The first 21/2 hr are devoted to the language rules with the remaining time used for designing and writing a simple program.' The actual writing of a working program has proved to be a very important part of the instruction as students have found t,hat this helps tie together the somewhat formal compiler rules. Students are encouraged to punch up and run the sample program, making their own modifications if they wish. No text is required for the lectures; instead students are supplied with a 16-page handout covering language rules, necessary "job control" cards, and preparation of Fortran cards. This BUF core guide has been used with both undergraduate and graduate students enrolled in courses in advanced physical chemistry, radiochemistry, and X-ray crystallography, and in a series of seminars for organic chemists. After completing this brief introduction to programming, the students have experienced little difficulty in applying BUF to the course material and writing more advanced programs to solve quantum mechanical problems, analyze nmr and microwave spectra, compute electron density contour maps (Fourier synthesis), or solve rate equations. Far more important, students

Volume

47, Number 2, February 1970

/

1 11

Content of the BUF Course

Compiler Languages and Compilers The Fortran Statement Card Variables and Constants-Naminz Conventions and Tvoes Operators and Assignment ~tatements no h q p . Uncondhonal GO TO Computed GO TO Arithmetic IF READ and WRITE Statements FORMAT Statements (F, E, I, and X fields,/and applicable carriage controls) Subroutines Job Control Cards Sample Pmgram

understand in a demonstrably practical manner how computers can be used to help solve chemical problems. The table outlines the material covered in the BUF core guide. The character of the Fortran taught has been termed "universal" as it is neutral enough to be used with large or small Fortran I1 or Fortran IV systems. The only exception to this involves the differences between the device-dependent and deviceindependent input/output statements in the two versions of Fortran. The built-in Fortran library functions are taught as operators (i.e, SQRT ( ) is the Fortran "operator" equivalent to the algebraic operator 4). As functions are not otherwise considered in BUF, we have found that the students accept them more naturally in this form. For variables, the default naming conventions are used exclusively. Dimensioned variables are introduced at the same time as simple variables as a means of classifying groups of similar data under a single name. The pitfalls associated with integer division and mixed mode arithmetic2 are noted. Mention is made of round-off errors for those groups doing matrix manipulations, but a discussion of this topic is not attempted. The logical I F statement is not taught even though it would often serve to simplify coding. Not only is the logical I F not available in Fortran I1 and on smaller computers using a basic subset Fortran IV, but this type of I F statement requires the introduction of the logical variables and operators which we feel to be an unnecessary addition to the core course. Nor is the A-format field discussed; labeling and the transfer of string data is accomplished with the H-field specification. Commands other than those listed in the table are not usually needed in student programs. Subroutines are not covered in any detail. Only the

112

/

Journal of Chemical Education

CALL statement is introduced so that students may use an instructor-supplied subroutine (such as HDIAG in quantum mechanical calculations) in their programming. We have found that the WATFOR compilera to be ideal for student programming. Although it produces somewhat inefficient code and cannot generate object modules, WATFrJK. compiles rapidly and has excellent diagnostics. At the University of Illinois installation, these diagnostics appear as English language messages rather than error codes and can usually be interpreted by the student without the need of instructor consultation. WATFOR also offers as a language extension "free input/output" (free I/O) in the form of READ and WRITE statements which do not require accompanying FORMAT designations. As it is FORMAT statements which usually are the cause of most of the difficulties encountered by the beginning programmer, free 1/0 might be used to replace the normal 1/0 taught in the BUF course with some loss in flexibility and considerable loss in generality. AlternativeIy, formatted 1/0 could be taught replacing the I, F, and E fields by the single Fortran IV G field specification. Throughout the lectures, it is stressed that BUF is a compatible subset of the full Fortran language, and students are encouraged to consult one of the many excellent Fortran textsqor further study. That the students generally enjoy this brief introduction to programming is evident from their many suggestions for further applications of computer techniques to course material. Acknowledgmenl

Dm. John Baldwin, Iain Paul, and Donald Secrest contributed many useful suggestions in the preparation of the course and the manuscript. Further development of the course was supported in part by NIH grant GM-42620 with the kind permission of Dr. Jerrold Meinwald. a Although the Fortran compilers associated with the IBM System/360 allow mixed mode computations, they are forbidden by many computers and by the ASA Standard. University of Waterloo (Canada) Fortran compiler for the IBM System/360 computer. * Far example: (a)BLATT, J. M., "Introduction to Fortran IV Programming: Using the WATFOR Compiler," Goodyear, D. D., "A Pacific Palisades, Calif., 1968; ( b ) MCCRACKEN, Guide to Fortran IV Programming," John Wiley & Sons, New York, 1965.