fortran programmers’ landaur/courses/handouts/fprog.pdf • fortran 77 examples appear in...

Download Fortran Programmers’ landaur/COURSES/Handouts/Fprog.pdf • Fortran 77 examples appear in tab format,

Post on 19-Apr-2020

0 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • 2550 Garcia Avenue Mountain View, CA 94043 USA 415 960-1300 fax 415 969-9131

    A Sun Microsystems, Inc. Business

    Fortran Programmer’s Guide

    Part No.: 802-5664-10 Revision A, December 1996

    SunSoft, Inc.

    Fortran 77 4.2 Fortran 90 1.2

  • Please Recycle

    Copyright 1996 Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A. All rights reserved.

    This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any.

    Portions of this product may be derived from the UNIX® system, licensed from Novell, Inc., and from the Berkeley 4.3 BSD system, licensed from the University of California. UNIX is a registered trademark in the United States and other countries and is exclusively licensed by X/Open Company Ltd. Third-party software, including font technology in this product, is protected by copyright and licensed from Sun’s suppliers.

    RESTRICTED RIGHTS: Use, duplication, or disclosure by the U.S. Government is subject to restrictions of FAR 52.227- 14(g)(2)(6/87) and FAR 52.227-19(6/87), or DFAR 252.227-7015(b)(6/95) and DFAR 227.7202-3(a).

    Sun, Sun Microsystems, the Sun logo, Solaris, SunSoft, Sun WorkShop, Sun Performance WorkShop and Sun Performance Library are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the United States and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc.

    The OPEN LOOK® and Sun™ Graphical User Interfaces were developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun’s written license agreements.

    f90 IS DERIVED FROM CRAY CF90™, A PRODUCT OF CRAY RESEARCH, INC.

    THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.

  • Contents iii

    Contents

    Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

    1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Standards Conformance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Features of the Fortran Compilers . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Related Sun Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2. Fortran Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Accessing Files From Fortran 77 Programs . . . . . . . . . . . . . . . . . . 5

    Accessing Named Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Opening Files Without a Name. . . . . . . . . . . . . . . . . . . . . . . . . 7

    Preconnected Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    Opening Files Without an OPEN Statement . . . . . . . . . . . . . . . 8

    Passing File Names to Programs. . . . . . . . . . . . . . . . . . . . . . . . 9

    VAX / VMS Logical File Names (f77 Only) . . . . . . . . . . . . . 12

    Direct I/O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    Internal Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

  • iv Fortran Programmer’s Guide

    Tape I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    Using TOPEN Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    Fortran Formatted I/O for Tape . . . . . . . . . . . . . . . . . . . . . . . . 17

    Fortran Unformatted I/O for Tape . . . . . . . . . . . . . . . . . . . . . . 17

    Tape File Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    End-of-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    Using Multifile Tapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    Fortran 90 I/O Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    3. Program Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    Facilitating Program Builds With the make Utility . . . . . . . . . . . . 21

    The makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    make Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    Overriding of Macro Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    Suffix Rules in make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    Version Tracking and Control With SCCS . . . . . . . . . . . . . . . . . . . 26

    Controlling Files With SCCS . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

    Checking Files Out and In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    4. Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    Understanding Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    Advantages of Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    Linker Debugging Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

  • Contents v

    Generating a Load Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    Listing Other Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    Consistent Compiling and Linking . . . . . . . . . . . . . . . . . . . . . 34

    Library Search Paths and Order . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    Search Order for Standard Library Paths. . . . . . . . . . . . . . . . . 35

    Library Search Path and Order — Static Linking . . . . . . . . . . 36

    Library Search Path and Order — Dynamic Linking . . . . . . . 37

    Creating Static Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    Tradeoffs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    Creation of a Simple Static Library . . . . . . . . . . . . . . . . . . . . . 40

    Creating Dynamic Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

    Tradeoffs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

    Position-Independent Code and –pic . . . . . . . . . . . . . . . . . . . 45

    Binding Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    A Simple Dynamic Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    Libraries Provided with Sun Fortran Compilers. . . . . . . . . . . . . . 48

    Shippable Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    5. Program Analysis and Debugging . . . . . . . . . . . . . . . . . . . . . . . 51

    Global Program Checking (f77 Only) . . . . . . . . . . . . . . . . . . . . . 51

    GPC Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

    How to Invoke Global Program Checking . . . . . . . . . . . . . . . 53

    Some Examples of -Xlist and Global Program Checking . 55

    Suboptions for Global Checking Across Routines . . . . . . . . . 59

  • vi Fortran Programmer’s Guide

    –Xlist Suboption Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 61

    Some Examples Using Suboptions . . . . . . . . . . . . . . . . . . . . . . 65

    Special Compiler Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    Subscript Bounds (–C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    Undeclared Variable Types (–u) . . . . . . . . . . . . . . . . . . . . . . . . 67

    Version Checking (–V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

    Interactive Debugging With dbx and The WorkShop . . . . . . . . . 68

    Debugging Optimized Programs . . . . . . . . . . . . . . . . . . . . . . . 69

    Viewing Compiler Listing Diagnostics. . . . . . . . . . . . . . . . . . . . . . 69

    6. Floating-Point Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Recommended

View more >