Compact Fortran 95 Language Summary

zhaozj2021-02-16  101

Sender: Math (Fangq), Word Area: Mathtools Title: Compact Fortran 95 Language Summary [ZZ] Sending Station: Dharma Biggreen BBS (THU DEC 12 02:42:06 2002), station letters

Compact Fortran 95 Language Summary

This Summary WAS. It is not intended to be 100% Complete. Hopefully It Will Be Useful As a Memory Aid in Writing Fortran Program.

Contents Introduction to Fortran 95 Language Meta language used in this compact summary Structure of files that can be compiled Executable Statements and Constructs Declarations Key words (other than I / O) Key words related to I / O Operators Constants Input / Output Statements Formats Intrinsic Functions Other Links

Introduction to Fortran 95 Language ISO / IEC 1539: 1995

Brought to you by ANSI committee X3J3 and ISO-IEC / JTC1 / SC22 / WG5 (Fortran) This is neither complete nor precisely accurate, but hopefully, after a small investment of time it is easy to read and very useful.

This Is The Free Form Version of Fortran, No Statement Numbers, No C in Column 1, Start In Column 7 (Not Column 7), Typical INDENT 2, 3, OR 4 Spaces Per Each Structure. The Typical Extension IS .F90.

.................. ..

The rest of any line is a comment starting with an exclamation mark!

Put more Than One Statement Per line by Separating Statements with a semicolon; null statements are OK, So Lines can end with semicolons.

Separate Words with space or any form of "White Space" or puncture.

Meta Language Used in this Compact Summary

Means Fill in Something Appropriate for xxx and do not type the "<" ory ">".

... Ellipsis Means The Usual, Fill in Something, One or More Lines [stuff] Means Supply Nothing or at MOST One Copy ONE "stuff" [stuff1 [stuff2]] means if "stuff1" is incruded, Supply Nothing or at MOST One Copy of Stuff2.

"old" means it is in the language, Like Almost Every Feature Of Past Fortran Standards, But Should Not Be used to write new programs.

Structure of Files That Can Be Compiled

PROGRALLY FILE NAME IS .F90 Use Bring in Any Needed Modules Implicit None Good for Error Detection Order Is Important, No More Declarations End Program

Block Data Old Common, Dimension, Equivalence Now Obsolete End Block Data

Module BRING BAVE for ERROR Detection Can Have Private and public and interface end module

Subroutine Use: Call to Execute Implicit None Good for ERROR Detection End Subroutine

Subroutine (PAR1, PAR2, ...) USE: Call (arg1, arg2, ...) to Execute Implicit None Optional, Good for Error Detection Par1, Par2, ... Are Defined in Declarations and Can Be Specified in, Inout , Pointer, ETC. Return Optional, End Causes Automatic Return Entry (Par ...) OLD, OPTIONAL OTER ENTRIES End Subroutine

Function (PAR1, PAR2, ...) RESULT () USE: (Arg1, Arg2, ... argn) AS VARIABLE IMPLICIT NONE OPTIONAL, Good for Error Detection RSLT, PAR1, ... Are Defined in Declarations = Required Somewhere in execution [return] optional, end causes automatic return end functionold function (...) use: (arg1, arg2, ... argn) as variable = required somewhere in execution [return] optional, end causes automatic return end function

Executable Statements and Construction

Will Mean Exactly One Statement In this section

a Construct Is Multiple Lines

: Any Statement Can Have a label (a name)

= Assignment Statement

=> The pointer is now an alias for the variable => Pointer1 Now Points Same Place As Pointer2

Stop Can Be in Any Executable Statement Group, Stop Terminates Execution of The Program, Stop Can Have Optional OR String

Return EXIT from Subroutine Or Function

Do =, [,] optional:: do ...

EXIT / _OPTIONAL OR EXIT IF () EXIT / EXIT The loop cycle / _optional or cycle if () CYCLE / Continue with Next loop ity ity endo optional: end do

Do while () ... Optional EXIT AND CYCLE ALLOWED DO

DO ... EXIT Required to End The loop Optional Cycle Can Be Used End Doif () Execute The Statement If The Boolean Expression IS TRUE

IF () THEN ... EXECUTE IF Expression1 IS True else if () Then ... Execute if Expression2 is true else if () Then ... Execute if Expression3 is true ip ... EXECUTE IF ABOVE ELSE ... EXECUTE IF

Select case () optional: select case ... case () execute if expression == value case (:) execute if value1 <= expression <= value2 ... case default execute if no values ​​Above match End Select Optional End SELECT

Real, Dimension (10, 12) :: A, R A Sample Declaration for use with "where" ... where (a / = 0.0) Conditional Assignment, Only Assignment Allowed R = 1.0 / a elsewhere r = 1.0 Elements of r Set to 1.0 where a == 0.0 End Where Go To Old

Go to (), OLD

For I / O Statements, SEE: Section 10.0 Input / Output Statements

Many Old Forms of Statements Are Not Listed

Declarations

There Are Five (5) Basic Types: Integer, Real, Complex, Character and Logical. There May Be Any Number of User Deternal Types. A Modern (Not Old) Declaration Starts with a Type, Has Attributes, Then ::, Then Variable (s) Names

Integer I, Pivot, Query Oldinteger, Inout (inout) :: arg1

Integer (SELECTED_INT_KIND (5)) :: I1, I2

Integer, Parameter :: m = 7

Integer, Dimension (0: 4, -5: 5, 10: 100) :: A3D

Double Precision X Old

REAL (SELECTED_REAL_KIND (15, 300) :: X

Complex :: z

Logical, Parameter :: what_if = .true.

Character, Parameter :: me = "jon Squire"

Type A New User Type, Derived Type Declarations End Type

TYPE () :: stuff declaring stuff to be of deived type

REAL, DIMENSION (:, :), allocatable, Target :: A

REAL, DIMENSION (:, :), Pointer :: P

Attributes May Be:

allocatable no memory used here, allocate later dimension vector or multi dimensional array external will be defined outside this compilation intent argument may be in, inout or out intrinsic declaring function to be an intrinsic optional argument is optional parameter declaring a constant, can not be changed later pointer declaring a pointer private in a module, a private declaration public in a module, a public declaration save keep value from one call to the next, static target can be pointed to by a pointer Note: not all combinations of attributes are legal

Key Words (Other Than I / O)

Note: "Statement" Means Key Word That Starts A Statement, One Line Unless There I Continuation "&" "Construct" Means Multiple Lines, Usually Ending With "End ..." "Attribute" means it is buy in a statement to Further Define "Old" Means It Should Not Be Used in New Code

allocatable attribute, no space allocated here, later allocate allocate statement, allocate memory space now for variable assign statement, old, assigned go to assignment attribute, means subroutine is assignment (=

) Block data construct, old, compilation unit, replaced by module call statement, call a subroutine case statement, used in select case structure character statement, basic type, intrinsic data type common statement, old, allowed overlaying of storage complex statement, basic type , intrinsic data type contains statement, internal subroutines and functions follow continue statement, old, a place to put a statement number cycle statement, continue the next iteration of a do loop data statement, old, initialized variables and arrays deallocate statement, free up storage used by specified variable default statement, in a select case structure, all others do construct, start a do loop double precision statement, old, replaced by selected_real_kind (15,300) else construct, part of if else if else end if else if construct, part of if else if else end if elsewhere construct, part of where elsewhere end where end block data construct, old, ends block data end do construct, ends do end function construct, ends function end if construct, ends if end interface construct, ends interface end module construct, ends module end program construct, ends program end select construct, ends select case end subroutine construct, ends subroutine end type construct, ends type end where construct, ends where entry statement, Old,

another entry point in a procedure equivalence statement, old, overlaid storage exit statement, continue execution outside of a do loop external attribute, old statement, means defines else where function construct, starts the definition of a function go to statement, old, requires fixed form statement number if statement and construct, if (...) statement implicit statement, "none" is preferred to help find errors in a keyword for intent, the argument is read only inout a keyword for intent, the argument is read / write integer statement, basic type, intrinsic data type intent attribute, intent (in) or intent (out) or intent (inout) interface construct, begins an interface definition intrinsic statement, says that following names are intrinsic kind attribute, sets the kind of the FOLLOWING variables len attribute, sets the length of a character string logical statement, basic type, intrinsic data type module construct, beginning of a module definition namelist statement, defines a namelist of input / output nullify statement, nullify (some_pointer) now points nowhere only attribute , restrict what comes from a module operator attribute, indicates function is an operator, like optional attribute, a parameter or argument is optional out a keyword for intent, the argument will be written parameter attribute, old statement, makes variable real only pause old ,

replaced by stop pointer attribute, defined the variable as a pointer alias private statement and attribute, in a module, visible inside program construct, start of a main program public statement and attribute, in a module, visible outside real statement, basic type, intrinsic data type recursive attribute, allows functions and derived type recursion result attribute, allows naming of function result result (Y) return statement, returns from, exits, subroutine or function save attribute, old statement, keep value between calls select case construct, start of a case construct stop statement, terminate execution of the main procedure subroutine construct, start of a subroutine definition target attribute, allows a variable to take a pointer alias then part of if construct type construct, start of user defined type type () statement, declaration of a variable for a users type use statement, brings in a module where construct, conditional assignment while construct, a while form of a do loopKey words related to I / O

backspace statement, back up one record close statement, close a file endfile statement, mark the end of a file format statement, old, defines a format inquire statement, get the status of a unit open statement, open or create a file print statement, Performs Output to Screen Read Statement, Performs Input Rewind Statement, Move Read or Write Position To Beginning Write Statement, Performs Outputoperty

** Exponentiation * Multiplication / Division Addition - Subtraction // Concatenation == .EQ. Equality / = .ne. NOT Equal <.lt. LESS THAN> .GT. Greater Than <= .le. Less Than or Equal> = Greater Than or Equal .Not. Complement, Negation. Logical. Logical and. Logical EquiValence .neqv. Logical Not Equivalence, Exclusive OR

== Equality, Old .ne. Old .lt. Greater Than, Old .le. <= less Than or equal, old .ge.> = Greater Than Or Equal, Old

Other Punctuation:

/ ... / used in data, common, Namelist and Other Statements (/ ... /) Array Construction by Commas 6 * 1.0 in Some Contexts, 6 COPIES OF 1.0 (i: j: k) in Some Contexts, A List i, i K, i 2K, i 3K, ... i NK <= j (: j) j and all below (i :) i and all above (:) undefined or all in Range

Constants

Logical Constants:

True .false. false

Integer Constants:

0 1 -1 123456789Real Constants:

0.0 1.0 -1.0 123.456 7.1E 10 -52.715E-30

Complex constants:

(0.0, 0.0) (-123.456e 30, 987.654e-29)

Character Constants:

"ABC" "a" "123'abc $% # @!" "A quote" "" "ABC '' 'A' '123" ABC $% # @!' 'A apostrophe' ''

Derived Type Values:

Type name character (len = 30) :: Last Character (len = 30) :: First Character (len = 30) :: Middle End Type Name

Type address character (len = 40) :: street character (len = 40) :: more character (len = 20) :: city character (selected_int_kind (5)) :: zip_code integer SELECTED_INT_KIND (4)) :: Route_code End Type Address

TYPE PERSON TYPE (NAME) LFM TYPE (Address) SNAIL_MAIL End Type Person

Type (Person) :: A_Person = Person (Name ("Squire", "Jon", "S."), & address ("106 Regency Circle", "LINTHICUM", "MD", 21090, 1936) )

A_PERSON% SNAIL_MAIL% ROUTE_CODE == 1936

INPUT / OUTPUT STATEMENTS

Open () open (unit =, file =, iostat =) open (unit =, ... man more, see Below)

Close () close (unit =, iostat =, err =, status = "keep")

Read () read (Unit =, FMT =, iostat =, end =, err =) read (unit =, r =)

Write () Write (unit =, fmt =, iostat =, err =) Write (unit =, REC =)

Print *,

Rewind rebind (, Err =)

Backspace backspace (, iostat =)

Endfile endfile (, err =, iostat =) inquire (, exists =) Inquire (file = <"name">, opened =, access =) inquire (iolength =) x, y, a! gives "Recl" for "Open "

Namelist // defines a name list read (*, nml =) Reads Some / All Variables in Namelist Write (*, nml =) all variables in namelist & = ... / data for namelist read

Input / Output Specifiers

Access One of "Sequential" "Direct" "u" "w" "n" "" "" "" "" " "" None "end = Old ER = Old Err = OLD EXIST = file = <" File Name "> FMT = <"> or format formatted "undefined" "unform" "undefined" iolength = iostat = 0 == Good, negative == EOF, POSTIVE == Bad name = named = nml = nextrec = one greater Than Written Number = Opened = Pad One of "YES" "No" position one of "ASIS" "" REWIND "APPEND "REC = Recl = Size = Number of Characters Read Before Status One of" OLD "" New "" unknown "" SCRAT "" Keep "Unit =

Individual Questions Direct = "YES" "NO" "unknown" formatted = "yes" "no" "unknown" read = "yes" "no" "unknown" readwrite = "yes" "no" "unknown" sequential = "YES "" No "" unknown "unformatted =" yes "" no "" unknown "WRITE =" yes "" no "" unknown "Formats

Format an expected format can replace * in any I / o statement. include the format in apostrophens or quotes and keep the parenthesis.

Examples: Print "(3i5, / (2x, 3f7.2 /))", Write (6, '(a, e15.6e3 / a, g15.2)') a format include, the opening and closing parenthesis. A Format CONSISTS OF FORMAT ITEMS AND FORMAT Control Items Separated by Comma. A Format May Contain Grouping Parenthesis with an Optional Repeat Count.

Format Items, Data Edit Descriptors:

Key: w is the total width of the field (Filled with *** if overflow) m is the least number of digits in the Number of Decimal Digits in The Field E Is The Number of THE FIELD E Is The Number Of Decimal Digits in The Exponent Subfield C Is The Repeat Count For The Format Item N Is Number of Columns

CAW Data of Type Character (w Is Optional) CBW.M Data of Type Integer with Type Real - Same As E, OLD DOUBLE PRECISION CEW.D OR EW.de Data of Type Real Cenw.d OR Enw.de Data of Type Real - Exponent a Multiple of 3 CESW.D or Eswent Data of Type Real - First Digit Non Zero CFW.D Data of Type Real - No Exponent Printed CGW.D OR GW. Dee Data of Type REAL - Auto Format To F or E NH N Characters Follow The h integer with octal base cZw.m data of type integer with hexadecimal base "" literal characters to output, no list item '' literal characters to output, no list itemFormat Control Items, control edit descriptors:

BN ignore nonleading blanks in numeric fields BZ treat nonleading blanks in numeric fields as zeros nP apply scale factor to real format items old S printing of optional plus signs is processor dependent SP print optional plus signs SS do not print optional plus signs Tn tab to specified column TLn tab left n columns TRn tab right n columns nX tab right n columns / end of record (implied / at end of all format statements): stop format processing if no more list items can be: a variable an array name an implied do ((A (i, j), j = 1, n), i = 1, m) Parenthesis and commas as shown

NOTE: WHEN THEN ARE MORE ITEMS in The Repeat Rules for Formats Applies.

CAN be: a constant a variable an expected do ((A (i, j), j = 1, n), i = 1, m) Parenthesis and commas as shownnote: When there is more items in the Output List Than Format Items, The Repeat Rules for Formats Applies.

Repeat Rules for Formats:

Each format item is used with a list item They are used in order When there are more list items than format items, then the following rule applies:.. There is an implied end of record, /, at the closing parenthesis of the format, This is processed. scan The format backwards to the first left parenthesis. Use The Repeat Count, IF Any, In Front of this Parenthesis, Continue To Process Format Items and List items.

Note: An Infinite Loop Is Possible Print "(3i5 / (1x /))", i, J, K, L May Never STOP

Intrinsic functions

Intrinsic Functions are presented in alphabetical order and then grouped by topic. The function name appears first. The argument (s) and result give an indication of the type (s) of argument (s) and results. [, Dim =] indicates an Optional Argument "DIM". "Mask" Must Be Logical and Usually Conformable. "Character" and "string" are used interchangeably. A Brief Description or Additional Information May Appear.

Intrinsic functions (alphabetical):

abs (integer_real_complex) result (integer_real_complex) achar (integer) result (character) integer to character acos (real) result (real) arccosine | real | <= 1.0 0 <= result <= Pi adjustl (character) result (character) left adjust, blanks go to back adjustr (character) result (character) right adjust, blanks to front aimag (complex) result (real) imaginary part aint (real [, kind =]) result (real) truncate to integer toward zero all ( Mask [, DIM]) Result (Logical) True IF All Elements of Mask Are True Allocated (Array) Result (logical) True IF Array Is Allocated in Memory Anint (Real [, Kind =]) Result (Real) Round to nearest Integer ANY (Mask [, DIM =}) Result (Logical) True if any elements of mask area s (real) result (REAL) ArcSine | Real | <= 1.0 -pi / 2 <= result <= pi / 2 associated Pointer [, Target =]) Result (REAL) RESUE IF POINTINGTING ATAN (REAL) ARCTANGENT -PI / 2 <= Result <= Pi / 2 Atan2 (Y = Real, x = Real) Result (REAL) Arctangent -Pi <= result <= Pi Bit_SIZE (Integer) Result (I = Integer, POS = Integer) RESUE IF POS HAS A 1, POS = 0 .. CEiling (real) Result (Real) Truncate To Integer Toward Infinity Char (Integer [, Kind =]) Result (Character) Integer to Character [of Kind] CMPLX (x = real [, y = real] [Kind =]) Result (Complex) x xi conjg ) result (complex) reverse the sign of the imaginary part cos (real_complex) result (real_complex) cosine cosh (real) result (real) hyperbolic cosine count (mask [, dim =]) result (integer) count of true entries in mask Cshift (Array, Shift [, DIM =

]) Circular Shift Elements of Array, Is Right Date_and_time ([DATE =] [, Time =] [, ZONE =] [, VALUES =]) Y, M, D, UTC, H, M, S, Milli DBLE ( integer_real_complex) result (real_kind_double) convert to double digits (integer_real) result (integer) number of bits to represent model dim (x = integer_real, y = integer_real) result (integer_real) proper subtraction dot_product (vector_a, vector_b) result (integer_real_complex) inner product dprod (x = real, y = real) result (x_times_y_double) double precision product eoshift (array, shift [, boundary =] [, dim =]) end-off shift using boundary epsilon (real) result (real) smallest positive number added to 1.0 / = 1.0 exp (real_complex) result (real_complex) e raised to a power exponent (real) result (integer) the model exponent of the argument floor (real) result (real) truncate to integer towards negative infinity fraction ( REAL) RESULT (REAL) THE MODEL FRACTIONAL Part of the argument huge (Integer_real) Result (Integer_real) The Largest Model number iachar (character) result (integer) position of character in ASCII sequence iand (integer, integer) result (integer) bit by bit logical and ibclr (integer, pos) result (integer) argument with pos bit cleared to zero ibits (integer , pos, len) result (integer) extract len ​​bits starting at pos ibset (integer, pos) result (integer) argument with pos bit set to one ichar (character) result (integer) pos in collating sequence of character ieor (integer, Integer) Result (Integer) Bit by bit Logical Exclusive or index (String, Substring [, Back =

]) Result (integer) pos of substring int (integer_real_complex) result (integer) convert to integer ior (integer, integer) result (integer) bit by bit logical or ishft (integer, shift) result (integer) shift bits in argument by shift ishftc (integer, shift) result (integer) shift circular bits in argument kind (any_intrinsic_type) result (integer) value of the kind lbound (array, dim) result (integer) smallest subscript of dim in array len (character) result ( integer) number of characters that can be in argument len_trim (character) result (integer) length without trailing blanks lge (string_a, string_b) result (logical) string_a> = string_b lgt (string_a, string_b) result (logical) string_a> string_b lle (string_a, string_b) result (logical) string_a <= string_b llt (string_a, string_b) result (logical) string_a = string_b lgt (string_a, string_b) result (logical) string_a> string_b lle (string_a, string_b) result (logical) string_a <= string_b llt (string_a, string_b) Resu LT (LOGICAL) STRING_AOTHER LINKS

Go to TOP

Last Updated 9/21/98

- ☆ Source:. Green bbs.dartmouth.edu. [From: mars.bbs@bbs.dartmou]

转载请注明原文地址:https://www.9cbs.com/read-10978.html

New Post(0)