Fortran tutorial

Download Fortran tutorial

Post on 10-Oct-2015

75 views

Category:

Documents

2 download

Embed Size (px)

DESCRIPTION

Fortran tutorial

TRANSCRIPT

<ul><li><p>FORTRAN 77 4.0 Reference Manual</p><p>A Sun Microsystems, Inc. Business</p><p>Part No.: 802-2998-10Revision A, November 1995</p><p>2550 Garcia AvenueMountain View, CA 94043U.S.A.</p></li><li><p>PleaseRecycle</p><p> 1995 Sun Microsystems, Inc. 2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A.</p><p>All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distributionand decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization ofSun and its licensors, if any.</p><p>Portions of this product may be derived from the UNIX system and from the Berkeley 4.3 BSD system, licensed from the University ofCalifornia. Third-party software, including font technology in this product, is protected by copyright and licensed from Suns Suppliers.</p><p>RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government is subject to restrictions as set forth in subparagraph(c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR 52.227-19.</p><p>The product described in this manual may be protected by one or more U.S. patents, foreign patents, or pending applications.</p><p>TRADEMARKSSunSoft, A Sun Microsystems, Inc. Business, Sun, Sun Microsystems, the Sun logo, Sun Microsystems Computer Corporation, the SunMicrosystems Computer Corporation logo, the SunSoft logo, Solaris, SunOS, and OpenWindows are trademarks or registered trademarks ofSun Microsystems, Inc. in the U.S. and certain other countries. UNIX is a registered trademark in the United States and other countries,exclusively licensed through X/Open Company, Ltd. OPEN LOOK is a registered trademark of Novell, Inc. PostScript and Display PostScriptare trademarks of Adobe Systems, Inc. Intel is a registered trademark of Intel Corporation. Pentium is a trademark of Intel Corporation.Cray is a registered trademark of Cray Research, Inc. VAX and VMS are registered trademarks of Digital Equipment Corporation. CDCis a registered trademark of Control Data Corporation. UNIVAC is a registered trademark of UNISYS Corporation. All other product, service,or company names mentioned herein are claimed as trademarks and trade names by their respective companies.</p><p>All SPARC trademarks, including the SCD Compliant Logo, are trademarks or registered trademarks of SPARC International, Inc. in the UnitedStates and may be protected as trademarks in other countries. SPARCcenter, SPARCcluster, SPARCompiler, SPARCdesign, SPARC811,SPARCengine, SPARCprinter, SPARCserver, SPARCstation, SPARCstorage, SPARCworks, microSPARC, microSPARC-II, and UltraSPARC arelicensed exclusively to Sun Microsystems, Inc. Products bearing SPARC trademarks are based upon an architecture developed by SunMicrosystems, Inc.</p><p>The OPEN LOOK and Sun Graphical User Interfaces were developed by Sun Microsystems, Inc. for its users and licensees. Sunacknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computerindustry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Suns licensees whoimplement OPEN LOOK GUIs and otherwise comply with Suns written license agreements.</p><p>X Window System is a trademark of the X Consortium.</p><p>Some of the material in this manual is based on the Bell Laboratories document entitled A Portable Fortran 77 Compiler, by S. I. Feldmanand P. J. Weinberger, dated August 1, 1978. Material on the I/O Library is derived from the paper entitled Introduction to the f77 I/OLibrary, by David L. Wasley, University of California, Berkeley, California 94720. Further work was done at Sun Microsystems.</p><p>THIS PUBLICATION IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUTNOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.</p><p>THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES AREPERIODICALLY ADDED TO THE INFORMATION HEREIN, THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THEPUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THEPROGRAMS(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME.</p></li><li><p>iii FORTRAN 77 Reference Manual</p><p>Contents</p><p>Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii</p><p>1. Elements of FORTRAN 77 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1</p><p>1.1 Operating Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . 1</p><p>1.2 Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2</p><p>1.3 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2</p><p>1.4 Basic Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2</p><p>1.5 Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3</p><p>1.6 Symbolic Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5</p><p>1.7 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7</p><p>1.8 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7</p><p>Executable or Nonexecutable Statements . . . . . . . . . . . . . . . . 7</p><p>FORTRAN 77 Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8</p><p>1.9 Source Line Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8</p><p>Standard Fixed Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8</p><p>Tab-Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9</p></li><li><p>iv FORTRAN 77 Reference Manual</p><p>Mixing Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9</p><p>Continuation Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9</p><p>Extended Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9</p><p>Padding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10</p><p>Comments and Blank Lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . 10</p><p>Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11</p><p>2. Data Types and Data Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13</p><p>2.1 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13</p><p>Rules for Data Typing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14</p><p>Array Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14</p><p>Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14</p><p>Properties of Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16</p><p>2.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25</p><p>Character Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26</p><p>Complex Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28</p><p>COMPLEX*16 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29</p><p>COMPLEX*32 (Quad Complex) Constants . . . . . . . . . . . . . . . 29</p><p>Integer Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30</p><p>Logical Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31</p><p>Real Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32</p><p>REAL*8 (Double-Precision Real) Constants . . . . . . . . . . . . . . 33</p><p>REAL*16 (Quad Real) Constants . . . . . . . . . . . . . . . . . . . . . . . 34</p><p>Typeless Constants (Binary, Octal, Hexadecimal). . . . . . . . . . 35</p><p>2.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39</p></li><li><p>Contents v</p><p>2.4 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40</p><p>Array Declarators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40</p><p>Array Names with No Subscripts . . . . . . . . . . . . . . . . . . . . . . . 43</p><p>Array Subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44</p><p>Array Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45</p><p>2.5 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46</p><p>2.6 Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48</p><p>Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49</p><p>Field Declaration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49</p><p>Rules and Restrictions for Structures . . . . . . . . . . . . . . . . . . . . 50</p><p>Rules and Restrictions for Fields . . . . . . . . . . . . . . . . . . . . . . . 50</p><p>Record Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51</p><p>Record and Field Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52</p><p>Substructure Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54</p><p>Unions and Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56</p><p>2.7 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58</p><p>Syntax Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58</p><p>Usage of Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58</p><p>Address and Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59</p><p>Optimization and Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61</p><p>3. Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65</p><p>3.1 Expressions, Operators, and Operands . . . . . . . . . . . . . . . 65</p><p>3.2 Arithmetic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66</p><p>Basic Arithmetic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 67</p></li><li><p>vi FORTRAN 77 Reference Manual</p><p>Mixed Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70</p><p>Arithmetic Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72</p><p>3.3 Character Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74</p><p>Character String Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . 76</p><p>Rules of Assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78</p><p>3.4 Logical Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78</p><p>3.5 Relational Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80</p><p>3.6 Constant Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81</p><p>3.7 Record Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82</p><p>3.8 Evaluation of Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 83</p><p>4. Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85</p><p>4.1 ACCEPT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85</p><p>4.2 ASSIGN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86</p><p>4.3 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87</p><p>4.4 AUTOMATIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93</p><p>4.5 BACKSPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95</p><p>4.6 BLOCK DATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97</p><p>4.7 BYTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98</p><p>4.8 CALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99</p><p>4.9 CHARACTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102</p><p>4.10 CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105</p><p>4.11 COMMON. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108</p><p>4.12 COMPLEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110</p><p>4.13 CONTINUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113</p></li><li><p>Contents vii</p><p>4.14 DATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114</p><p>4.15 DECODE/ENCODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117</p><p>4.16 DIMENSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119</p><p>4.17 DO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122</p><p>4.18 DO WHILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127</p><p>4.19 DOUBLE COMPLEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130</p><p>4.20 DOUBLE PRECISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131</p><p>4.21 ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133</p><p>4.22 ELSE IF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134</p><p>4.23 ENCODE/DECODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136</p><p>4.24 END . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137</p><p>4.25 END DO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138</p><p>4.26 END FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139</p><p>4.27 END IF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141</p><p>4.28 END MAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142</p><p>4.29 END STRUCTURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142</p><p>4.30 END UNION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143</p><p>4.31 ENTRY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144</p><p>4.32 EQUIVALENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147</p><p>4.33 EXTERNAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149</p><p>4.34 FORMAT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151</p><p>4.35 FUNCTION (External) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155</p><p>4.36 GO TO (Assigned) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157</p><p>4.37 GO TO (Computed). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159</p></li><li><p>viii FORTRAN 77 Reference Manual</p><p>4.38 GO TO (Unconditional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161</p><p>4.39 IF (Arithmetic) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162</p><p>4.40 IF (Block). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163</p><p>4.41 IF (Logical)...</p></li></ul>

Recommended

View more >