LF Fortran 95 Language Reference - 健保藥局

1y ago
8 Views
1 Downloads
4.75 MB
341 Pages
Last View : 18d ago
Last Download : 3m ago
Upload by : Lilly Andre
Transcription

LF Fortran 95 Language Reference Revision G.02

Copyright Copyright 1994-2004 by Lahey Computer Systems, Inc. All rights reserved worldwide. This manual is protected by federal copyright law. No part of this manual may be copied or distributed, transmitted, transcribed, stored in a retrieval system, or translated into any human or computer language, in any form or by any means, electronic, mechanical, magnetic, manual, or otherwise, or disclosed to third parties. Trademarks Names of Lahey products are trademarks of Lahey Computer Systems, Inc. Other brand and product names are trademarks or registered trademarks of their respective holders. Disclaimer Lahey Computer Systems, Inc. and Fujitsu, Ltd. reserve the right to revise their software and publications with no obligation to notify any person or any organization of such revision. In no event shall Lahey Computer Systems, Inc. or Fujitsu, Ltd. be liable for any loss of profit or any other commercial damage, including but not limited to special, consequential, or other damages. Lahey Computer Systems, Inc. 865 Tahoe Boulevard P.O. Box 6091 Incline Village, NV 89450-6091 (775) 831-2500 Fax: (775) 831-8123 http://www.lahey.com Technical Support support2@lahey.com (all versions)

Table of Contents Introduction.vii Manual Organization .vii Notational Conventions .viii Elements of Fortran.1 Character Set. 1 Names . 1 Statement Labels. 2 Source Form . 2 Data. 4 Expressions . 19 Input/Output. 22 Input/Output Editing. 25 Statements. 33 Executable Constructs . 42 Procedures . 43 Program Units. 55 Scope . 58 Alphabetical Reference .61 ABS Function . 61 ACHAR Function . 62 ACOS Function . 62 ADJUSTL Function. 63 ADJUSTR Function . 63 AIMAG Function . 64 AINT Function . 64 ALL Function . 65 ALLOCATABLE Statement . 66 ALLOCATE Statement . 67 ALLOCATED Function . 69 ANINT Function. 69 ANY Function . 70 Arithmetic IF Statement (obsolescent) . 71 ASIN Function. 72 Assigned GOTO Statement (obsolescent) . 73 ASSIGN Statement (obsolescent) . 73 Assignment Statement . 74 ASSOCIATED Function . 77 ATAN Function . 78 ATAN2 Function .79 BACKSPACE Statement .80 BIT SIZE Function.81 BLOCK DATA Statement .81 BTEST Function .82 CALL Statement .83 CARG Function .86 CASE Construct .88 CEILING Function.90 CHAR Function .91 CHARACTER Statement.91 CLOSE Statement .94 CMPLX Function.95 COMMON Statement .96 COMPLEX Statement.98 Computed GOTO Statement (obsolescent).100 CONJG Function.101 CONTAINS Statement.102 CONTINUE Statement .103 COS Function.103 COSH Function .104 COUNT Function.104 CPU TIME Subroutine.105 CSHIFT Function.106 CYCLE Statement.107 DATA Statement.108 DATE AND TIME Subroutine .110 DBLE Function .111 DEALLOCATE Statement .112 DIGITS Function .113 DIM Function.113 DIMENSION Statement .114 DLL EXPORT Statement .115 DLL IMPORT Statement.116 DO Construct .116 DOT PRODUCT Function.119 DOUBLE PRECISION Statement.120 DPROD Function .122 DVCHK Subroutine (Windows Only) .122 ELEMENTAL Procedure.123 LF Fortran 95 Language Reference iii

Contents END Statement. 125 ENDFILE Statement . 126 ENTRY Statement. 127 EOSHIFT Function . 129 EPSILON Function . 130 EQUIVALENCE Statement. 131 ERROR Subroutine . 132 EXIT Statement . 133 EXIT Subroutine . 133 EXP Function . 134 EXPONENT Function. 134 EXTERNAL Statement . 135 FLOOR Function. 136 FLUSH Subroutine. 137 FORALL Construct . 137 FORALL Statement . 138 FORMAT Statement . 139 FRACTION Function. 146 FUNCTION Statement. 146 GETCL Subroutine. 149 GETENV Subroutine . 149 GO TO Statement. 150 HUGE Function. 150 IACHAR Function . 151 IAND Function. 152 IBCLR Function . 152 IBITS Function. 153 IBSET Function. 154 ICHAR Function . 155 IEOR Function . 155 IF Construct . 156 IF Statement . 157 IMPLICIT Statement. 158 INCLUDE Line . 160 INDEX Function . 161 INQUIRE Statement. 162 INT Function . 166 INTEGER Statement. 167 INTENT Statement. 168 INTERFACE Block . 169 INTRINSIC Statement . 175 INVALOP Subroutine (Windows only). 176 IOR Function . 176 IOSTAT MSG Subroutine. 177 iv LF Fortran 95 Language Reference ISHFT Function .178 ISHFTC Function.179 KIND Function .179 LBOUND Function.180 LEN Function.181 LEN TRIM Function.182 LGE Function.182 LGT Function.183 LLE Function .184 LLT Function .185 LOG Function .186 LOG10 Function .187 LOGICAL Function.187 LOGICAL Statement .188 MATMUL Function.190 MAX Function .191 MAXEXPONENT Function.192 MAXLOC Function .192 MAXVAL Function.193 MERGE Function .194 MIN Function.195 MINEXPONENT Function .196 MINLOC Function.197 MINVAL Function .198 ML EXTERNAL Statement .199 MOD Function .199 MODULE Statement .200 MODULE PROCEDURE Statement.201 MODULO Function.202 MVBITS Subroutine.202 NAMELIST Statement .203 NDPERR Function (Windows Only).204 NDPEXC Subroutine (Windows Only) .205 NEAREST Function .206 NINT Function.206 NOT Function .207 NULL Function.208 NULLIFY Statement .208 OPEN Statement .209 OPTIONAL Statement.212 OVEFL Subroutine (Windows Only) .213 PACK Function.213 PARAMETER Statement .214 PAUSE Statement (obsolescent).215

Contents Pointer Assignment Statement. 215 POINTER Function . 216 POINTER Statement . 217 PRECFILL Subroutine . 218 PRECISION Function . 218 PRESENT Function. 219 PRINT Statement. 220 PRIVATE Statement . 221 PRODUCT Function . 222 PROGRAM Statement . 223 PUBLIC Statement . 224 PURE Procedure. 225 RADIX Function . 226 RANDOM NUMBER Subroutine. 227 RANDOM SEED Subroutine . 227 RANGE Function . 228 READ Statement . 229 REAL Function. 231 REAL Statement. 232 REPEAT Function . 234 RESHAPE Function . 234 RETURN Statement . 235 REWIND Statement . 236 RRSPACING Function. 237 SAVE Statement. 237 SCALE Function . 238 SCAN Function . 239 SELECTED INT KIND Function . 240 SELECTED REAL KIND Function. 241 SEQUENCE Statement . 242 SET EXPONENT Function. 242 SHAPE Function . 243 SIGN Function. 244 SIN Function. 244 SINH Function. 245 SIZE Function. 245 SPACING Function . 246 SPREAD Function. 247 SQRT Function. 248 Statement Function . 248 STOP Statement . 249 SUBROUTINE Statement . 250 SUM Function . 251 SYSTEM Function (Linux only) . 252 SYSTEM Subroutine .252 SYSTEM CLOCK Subroutine.253 TAN Function .253 TANH Function .254 TARGET Statement .255 TINY Function .255 TRANSFER Function .256 TRANSPOSE Function.257 TRIM Function.257 Type Declaration Statement.258 TYPE Statement.258 UBOUND Function .260 UNDFL Subroutine (Windows Only) .261 UNPACK Function .262 USE Statement .263 VAL Function .264 VALUE Statement .265 VERIFY Function .266 VOLATILE Statement .267 WHERE Construct .268 WHERE Statement.270 WRITE Statement .271 Fortran 77 Compatibility .275 Different Interpretation Under Fortran 95.275 Different Interpretation Under Fortran 90.275 Obsolescent Features.276 New in Fortran 95.277 Intrinsic Procedures .283 Porting Extensions .305 Glossary .309 ASCII Character Set.319 LF Fortran 95 Language Reference v

Contents vi LF Fortran 95 Language Reference

1 Introduction Lahey/Fujitsu Fortran 95 (LF95) is a complete implementation of the Fortran 95 standard. Numerous popular extensions are supported. This manual is intended as a reference to the Fortran 95 language for programmers with experience in Fortran. For information on creating programs using the LF95 Language System, see the Lahey/Fujitsu Fortran 95 User’s Guide. Manual Organization The manual is organized in eight parts: Chapter 1, Elements of Fortran, takes an elemental, building-block approach, starting from Fortran’s smallest elements, its character set, and proceeding through source form, data, expressions, input/output, statements, executable constructs, and procedures, and ending with program units. Chapter 2, Alphabetical Reference, gives detailed syntax and constraints for Fortran statements, constructs, and intrinsic procedures. Appendix A, Fortran 77 Compatibility, discusses issues of concern to programmers who are compiling their Fortran 77 code with LF95. Appendix B, New in Fortran 95, lists Fortran 95 features that were not part of standard Fortran 77. Appendix C, Intrinsic Procedures, is a table containing brief descriptions and specific names of procedures included with LF95. Appendix D, Porting Extensions, lists the various non-standard features provided to facilitate porting from other systems. Appendix E, Glossary, defines various technical terms used in this manual. Appendix F, ASCII Chart, details the 128 characters of the ASCII set. LF Fortran 95 Language Reference vii

Introduction Notational Conventions The following conventions are used throughout the manual: blue text indicates an extension to the Fortran 95 standard. code is indicated by courier font. In syntax descriptions, [brackets] enclose optional items. An ellipsis, “.”, following an item indicates that more items of the same form may appear. Italics indicate text to be replaced by you. Non-italic letters in syntax descriptions are to be entered exactly as they appear. viii LF Fortran 95 Language Reference

1 Elements of Fortran Character Set The Fortran character set consists of letters: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z digits: 0 1 2 3 4 5 6 7 8 9 special characters: blank - * / ( ) , . ' : ! " % & ; ? and the underscore character ‘ ’. Special characters are used as operators, as separators or delimiters, or for grouping. ‘?’ and ‘ ’ have no special meaning. Lower case letters are equivalent to corresponding upper-case letters except in CHARACTER literals. The underscore character can be used as a non-leading significant character in a name. Names Names are used in Fortran to refer to various entities such as variables and program units. A name starts with a letter or a ‘ ’ and consists entirely of letters, digits, underscores, and the ‘ ’ character. A standard conforming name must be 31 characters or less in length, but LF95 accepts names of up to 240 characters in length. LF Fortran 95 Language Reference 1

Chapter 1 Elements of Fortran Examples of legal Fortran names are: aAaAa rose apples and oranges ROSE r2d2 Rose The three representations for the names on the line immediately above are equivalent. The following names are illegal: start with underscore 2start with a digit name ooo& oooooooo& oooooooo& oooooooo& &ooooooooo long illegal @ character Statement Labels Fortran statements can have labels consisting of one to five digits, at least one of which is non-zero. Leading zeros are not significant in distinguishing statement labels. The following labels are valid: 123 5000 10000 1 0001 The last two labels are equivalent. The same statement label must not be given to more than one statement in a scoping unit. Source Form Fortran offers two source forms: fixed and free. Fixed Source Form Fixed source form is the traditional Fortran source form and is based on the columns of a punched card. There are restrictions on where statements and labels can appear on a line. Except in CHARACTER literals, blanks are ignored. 2 LF Fortran 95 Language Reference

Free Source Form Except within a comment: Columns 1 through 5 are reserved for statement labels. Labels can contain blanks. Column 6 is used only to indicate a continuation line. If column 6 contains a blank or zero, column 7 begins a new statement. If column 6 contains any other character, columns 7 through 72 are a continuation of the previous non-comment line. There can be up to 19 continuation lines. Continuation lines must not be labeled. Columns 7 through 72 are used for Fortran statements. Columns after 72 are ignored. Fixed source form comments are formed by beginning a line with a ‘C’ or a ‘*’ in column 1. Additionally, trailing comments can be formed by placing a ‘!’ in any column except column 6. A ‘!’ in a CHARACTER literal does not indicate a trailing comment. Comment lines must not be continued, but a continuation line can contain a trailing comment. An END statement must not be continued. The ‘;’ character can be used to separate statements on a line. If it appears in a CHARACTER literal or in a comment, the ‘;’ character is not interpreted as a statement separator. Free Source Form In free source form, there are no restrictions on where a statement can appear on a line. A line can be up to 132 characters long. Blanks are used to separate names, constants, or labels from adjacent names, constants, or labels. Blanks are also used to separate Fortran keywords, with the following exceptions, for which the blank separator is optional: BLOCK DATA DOUBLE PRECISION ELSE IF END BLOCK DATA END DO END FILE END FUNCTION END IF END INTERFACE END MODULE END PROGRAM END SELECT END SUBROUTINE END TYPE END WHERE GO TO IN OUT SELECT CASE LF Fortran 95 Language Reference 3

Chapter 1 Elements of Fortran The ‘!’ character begins a comment except when it appears in a CHARACTER literal. The comment extends to the end of the line. The ‘;’ character can be used to separate statements on a line. If it appears in a CHARACTER literal or in a comment, the ‘;’ character is not interpreted as a statement separator. The ‘&’ character as the last non-comment, non-blank character on a line indicates the line is to be continued on the next non-comment line. If a name, constant, keyword, or label is split across the end of a line, the first non-blank character on the next non-comment line must be the ‘&’ character followed by successive characters of the name, constant, keyword, or label. If a CHARACTER literal is to be continued, the ‘&’ character ending the line cannot be followed by a trailing comment. A free source form statement can have up to 39 continuation lines. Comment lines cannot be continued, but a continuation line can contain a trailing comment. A line cannot contain only an ‘&’ character or contain an ‘&’ character as the only character before a comment. Data Fortran offers the programmer a variety of ways to store and refer to data. You can refer to data literally, as in the real numbers 4.73 and 6.23E5, the integers -3000 and 65536, or the CHARACTER literal "Continue (y/n)?". Or, you can store and reference variable data, using names such as x or y, DISTANCE FROM ORIGIN or USER NAME. Constants such as pi or the speed of light can be given names and constant values. You can store data in a fixedsize area in memory, or allocate memory as the program needs it. Finally, Fortran offers various means of creating, storing, and referring to structured data, through use of arrays, pointers, and derived types. Intrinsic Data Types The five intrinsic data types are INTEGER, REAL, COMPLEX, LOGICAL, and CHARACTER. The DOUBLE PRECISION data type available in Fortran 77 is still supported, but is considered a subset, or kind, of the REAL data type. Kind In Fortran, an intrinsic data type has one or more kinds. In LF95 for the CHARACTER, INTEGER, REAL, and LOGICAL data types, the kind type parameter (a number used to refer to a kind) corresponds to the number of bytes used to represent each respective kind. For the COMPLEX data type, the kind type parameter is the number of bytes used to represent the real or the imaginary part. Two intrinsic inquiry functions, SELECTED INT KIND 4 LF Fortran 95 Language Reference

Kind and SELECTED REAL KIND, are provided. Each returns a kind type parameter based on the required range and precision of a data object in a way that is portable to other Fortran 90 or 95 systems. The kinds available in LF95 are summarized in the following table: Table 1: Intrinsic Data Types Type Kind Type Parameter Notes INTEGER 1 Range: -128 to 127 INTEGER 2 Range: -32,768 to 32,767 INTEGER 4* Range: -2,147,483,648 to 2,147,483,647 INTEGER 8 Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 REAL 4* Range: 1.18 * 10-38 to 3.40 * 1038 Precision: 6-7 decimal digits REAL 8 Range: 2.23 * 10-308 to 1.79 * 10308 Precision: 15-16 decimal digits REAL 16 Range: 10-4931 to 104932 Precision: approximately 33 decimal digits COMPLEX 4* Range: 1.18 * 10-38 to 3.40 * 1038 Precision: 7-8 decimal digits COMPLEX 8 Range: 2.23 * 10-308 to 1.79 * 10308 Precision: 15-16 decimal digits COMPLEX 16 Range: 10-4931 to 104932 Precision: approximately 33 decimal digits LOGICAL 1 Values: .TRUE. and .FALSE. LOGICAL 4* Values: .TRUE. and .FALSE. CHARACTER 1* ASCII character set * default kinds LF Fortran 95 Language Reference 5

Chapter 1 Elements of Fortran Length The number of characters in a CHARACTER data object is indicated by its length type parameter. For example, the CHARACTER literal “Half Marathon” has a length of thirteen. Literal Data A literal datum, also known as a literal, literal constant, or immediate constant, is specified as follows for each of the Fortran data types. The syntax of a literal constant determines its intrinsic type. INTEGER literals An INTEGER literal consists of one or more digits preceded by an optional sign ( or -) and followed by an optional underscore and kind type parameter. If the optional underscore and kind type parameter are not present, the INTEGER literal is of default kind. Examples of valid INTEGER literals are 34 -256 345 4 78 mykind 34 and -256 are of type default INTEGER. 345 4 is an INTEGER of kind 4 (default INTEGER in LF95). In the last example, mykind must have been previously declared as a scalar INTEGER named constant with the value of an INTEGER kind type parameter (1, 2, or 4 in LF95). A binary, octal, or hexadecimal constant can appear in a DATA statement. Such constants are formed by enclosing a series of binary, octal, or hexadecimal digits in apostrophes or quotation marks, and preceding the opening apostrophe or quotation mark with a B, O, or Z for binary, octal, and hexadecimal representations, respectively. Two valid examples are B'10101' Z"1AC3" REAL literals A REAL literal consists of one or more digits containing a decimal point (the decimal point can appear before, within, or after the digits), optionally preceded by a sign ( or -), and optionally followed by an exponent letter and exponent, optionally followed by an underscore and kind type parameter. If an exponent letter is present the decimal point is optional. The exponent letter is E for single precision, D for double precision, or Q for quad precision. If the optional underscore and kind type parameter are not present, the REAL literal is of default kind. Examples of valid REAL literals are -3.45 .0001 34.E-4 1.4 8 The first three examples are of type default REAL. The last example is a REAL of kind 8. 6 LF Fortran 95 Language Reference

Literal Data COMPLEX literals A COMPLEX literal is formed by enclosing in parentheses a comma-separated pair of REAL or INTEGER literals. The first of the REAL or INTEGER literals represents the real part of the complex number; the second represents the imaginary part. The kind type parameter of a COMPLEX constant is 16 if either the real or the imaginary part or both are quadruple precision REAL, 8 if either the real or the imaginary part or both are double-precision REAL, otherwise the kind type parameter is 4 (default COMPLEX). Examples of valid COMPLEX literals are (3.4,-5.45) (-1,-3) (3.4,-5) (-3.d13,6. 8) The first three examples are of default kind, where four bytes are used to represent each part, real or imaginary, of the complex number. The fourth example uses eight bytes for each part. LOGICAL literals A LOGICAL literal is either .TRUE. or .FALSE., optionally followed by an underscore and a kind type parameter. If the optional underscore and kind type parameter are not present, the LOGICAL literal is of default kind. Examples of valid LOGICAL literals are: .false. .true. .true. mykind In the last example, mykind must have been previously declared as a scalar INTEGER named constant with the value of a LOGICAL kind type parameter (1 or 4 in LF95). The first two examples are of type default LOGICAL. CHARACTER literals A CHARACTER literal consists of a string of characters enclosed in matching apostrophes or quotation marks, optionally preceded by a kind type parameter and an underscore. If a quotation mark is needed within a CHARACTER string enclosed in quotation marks, double the quotation mark inside the string. The doubled quotation mark is then counted as a single quotation mark. Similarly, if an apostrophe is needed within a CHARACTER string enclosed in apostrophes, double the apostrophe inside the string. The double apostrophe is then counted as a single apostrophe. Examples of valid CHARACTER literals are "Hello world" 'don''t give up the ship!' ASCII 'foobeedoodah' "" '' ASCII must have been previously declared as a scalar INTEGER named constant with the value 1 to indicate the kind. The last two examples, which have no intervening characters between the quotes or apostrophes, are zero-length CHARACTER literals. LF Fortran 95 Language Reference 7

Chapter 1 Elements of Fortran Named Data A named data object, such as a variable, named constant, or function result, is given the properties of an intrinsic or user-defined data type, either implicitly (based on the first letter of the name) or through a type declaration statement. Additional information about a named d

Lahey/Fujitsu Fortran 95 (LF95) is a complete implementation of the Fortran 95 standard. Numerous popular extensions are supported. This manual is intended as a reference to the Fortran 95 language for programmers with expe-rience in Fortran. For information on creating programs using the LF95 Language System,

Related Documents:

Course focus on Fortran 90 (called Fortran for simplicity) Changes in later versions (mostly) not important for us ‣ Fortran 95: Minor revision of Fortran 90 ‣ Fortran 2003: Major additions to Fortran 95 ‣ Fortran 2008: Minor revision of Fortran 2003 gfortran compiler: ‣ Fortran 95: Completely supported

Fortran Evolution Fortran stands for FORmula TRANslation. The first compiler appeared in 1957 and the first official standard in 1972 which was given the name of Fortran 66'. This was updated in 1980 to Fortran 77, updated in 1991 to Fortran 90, updated in 1997 to Fortran 95, and further updated in 2004 to Fortran 2003. At each update some

INTRODUCTION TO ABSOFT FORTRAN Absoft Fortran is a complete implementation of the FORTRAN programming languages: FORTRAN 77, Fortran 90, and Fortran 95. It also completely implements ISO Technical Reports TR15580 and TR15581. The microprocessor-based computers of today are vastly more powerful and sophisticated than their predecessors.

Fortran is short for FORmula TRANslation and this guide is based on Fortran 90, which is a version agreed in 1990. Fortran 95, a later standard, was a minor revision of Fortran 90. The latest standard, Fortran 2003, is now supported by some compilers as well. Fortran was developed for general scientific computing and is a very

Lahey/Fujitsu Fortran 95 (LF95) is a complete implementation of the Fortran 95 standard. Numerous popular extensions are supported. This manual is intended as a reference to the Fortran 95 language for programmers with expe-rience in Fortran. For information on creating programs using the LF95 Language System,

Build with the Composer Edition (Continued) Boost Fortran Application Performance INTEL FORTRAN COMPILER on Linux* using Intel Fortran Compiler (Higher is Better) Deliver superior Fortran application performance. Get extensive support for the latest Fortran standards (including full Fortran

modern programming language. Fortran 95 is a small extension of Fortran 90. These latest versions of Fortran has many of the features we expect from a mod-ern programming languages. Now we have the Fortran 2003 which incorporates

astrology, the explanation was: “ that is the study of occult influence of stars, planets etc. on human affairs”. There was no significant difference in responses between the two conditions (INRA, 1993). However, in most European languages the suffix „ology‟, „ologie‟, „ologia‟ connotes an academic field of study. This may be enough to encourage respondents to think that .