Fortran 90 笔记(一)

    xiaoxiao2021-03-25  88

    拖延症晚期(:з」∠),一边看官方文档一边做笔记

    官方文档ISO/IEC 1539 : 1991 (E):ftp://ftp.nag.co.uk/sc22wg5/N001-N1100/N692.pdf

    Section 1 : Overview

    stmt for statement attr for attribute decl for declaration spec for specifier def for definition int for integer desc for descriptor arg for argument op for operator

    这些是在文档中所用缩写

    is introduces a syntactic class definition or introduces a syntactic class alternative [ ] encloses an optional item [ ] … encloses an optionally repeated item which may occur zero or more times ■ continues a syntax rule

    文档所用语

    Section 2 : Fortran terms and concepts

    R201 executable-program is program-unit                [program-unit] … An executable-program must contain exactly one main-program program-unit.

    R202 program-unit is main-program          or external-subprogram          or module          or block-data

    R1101 main-program is [ program-stmt ]             [ specification-part ]             [ execution-part ]             [ internal-subprogram-part ]             end-program-stmt R203 external-subprogram is function-subprogram             or subroutine-subprogram R1215 function-subprogram is function-stmt                [ specification-part ]                [ execution-part ]                [ internal-subprogram-part ]                end-function-stmt R1219 subroutine-subprogram is subroutine-stmt                 [ specification-part ]                 [ execution-part ]                 [ internal-subprogram-part ]                 end-subroutine-stmt R1104 module is module-stmt          [ specification-part ]          [ module-subprogram-part ]          end-module-stmt R1110 block-data is block-data-stmt           [ specification-part ]           end-block-data-stmt R204 specification-part is [ use-stmt ] …              [ implicit-part ]              [ declaration-construct ] … R205 implicit-part is [ implicit-part-stmt ] …            implicit-stmt R206 implicit-part-stmt is implicit-stmt            or parameter-stmt            or format-stmt            or entry-stmt R207 declaration-construct is derived-type-def              or interface-block              or type-declaration-stmt              or specification-stmt              or parameter-stmt              or format-stmt              or entry-stmt              or stmt-function-stmt R208 execution-part is executable-construct             [ execution-part-construct ] … R209 execution-part-construct is executable-construct               or format-stmt               or data-stmt               or entry-stmt R210 internal-subprogram-part is contains-stmt                 internal-subprogram                 [ internal-subprogram ] … R211 internal-subprogram is function-subprogram             or subroutine-subprogram R212 module-subprogram-part is contains-stmt                  module-subprogram                  [ module-subprogram ] … R213 module-subprogram is function-subprogram             or subroutine-subprogram R214 specification-stmt is access-stmt            or allocatable-stmt            or common-stmt            or data-stmt            or dimension-stmt            or equivalence-stmt            or external-stmt            or intent-stmt            or intrinsic-stmt            or namelist-stmt            or optional-stmt            or pointer-stmt            or save-stmt            or target-stmt R215 executable-construct is action-stmt              or case-construct              or do-construct              or if-construct              or where-construct R216 action-stmt is allocate-stmt         or assignment-stmt         or backspace-stmt         or call-stmt         or close-stmt         or computed-goto-stmt         or continue-stmt         or cycle-stmt         or deallocate-stmt         or endfile-stmt         or end-function-stmt         or end-program-stmt         or end-subroutine-stmt         or exit-stmt         or goto-stmt         or if-stmt         or inquire-stmt         or nullify-stmt         or open-stmt         or pointer-assignment-stmt         or print-stmt         or read-stmt         or return-stmt         or rewind-stmt         or stop-stmt         or where-stmt         or write-stmt         or arithmetic-if-stmt         or assign-stmt         or assigned-goto-stmt         or pause-stmt Constraint: An execution-part must not contain an end-function-stmt, end-program-stmt, or end-subroutine-stmt.

    2.2 Program unit concepts (程序单元)

    Program units are the fundamental components of a Fortran program. A program unit may be a main program,an external subprogram, a module, or a block data program unit. A subprogram may be a function subprogram or a subroutine subprogram. A module contains definitions that are to be made accessible to other program units. A block data program unit is used to specify initial values for data objects in named common blocks. Each type of program unit is described in Section 11 or 12. An external subprogram is a subprogram that is not contained within a main program, a module, or another subprogram. An internal subprogram is a subprogram that is contained within a main program or another subprogram. A module subprogram is a subprogram that is contained in a module but is not an internal subprogram. A program unit consists of a set of nonoverlapping scoping units. A scoping unit is (1) A derived-type definition (4.4.1), (2) A procedure interface body, excluding any derived-type definitions and procedure interface bodies contained within it (12.3.2.1), or (3) A program unit or subprogram, excluding derived-type definitions, procedure interface bodies, and subprograms contained within it. A scoping unit that immediately surrounds another scoping unit is called the host scoping unit.

    2.2.1 Executable program (可执行程序)

    An executable program consists of exactly one main program unit and any number (including zero) of other kinds of program units. The set of program units may include any combination of the different kinds of program units in any order. The main program is described in 11.1.

    11.1 Main program

    A main program is a program unit that does not contain a SUBROUTINE, FUNCTION, MODULE, or BLOCK DATA statement as its first statement. R1101 main-program is [ program-stmt ]             [ specification-part ]             [ execution-part ]             [ internal-subprogram-part ]             end-program-stmt R1102 program-stmt is PROGRAM program-name R1103 end-program-stmt is END [ PROGRAM [ program-name ] ] Constraint: In a main-program, the execution-part must not contain a RETURN statement or an ENTRY statement. Constraint: The program-name may be included in the end-program-stmt only if the optional program-stmt is used and, if included, must be identical to the program-name specified in the program-stmt. Constraint: An automatic object must not appear in the specification-part (R204) of a main program. The program name is global to the executable program, and must not be the same as the name of any other program unit, external procedure, or common block in the executable program, nor the same as any local name in the main program. An example of a main program is: PROGRAM ANALYSE REAL A, B, C (10,10)       ! Specification part CALL FIND           ! Execution part CONTAINS SUBROUTINE FIND       ! Internal procedure … END SUBROUTINE FIND END PROGRAM ANALYSE 11.1.1 Main program specifications The specifications in the scoping unit of the main program must not include an OPTIONAL statement, an INTENT statement, a PUBLIC statement, a PRIVATE statement, or their equivalent attributes (5.1.2). A SAVE statement has no effect in a main program. 11.1.2 Main program executable part The sequence of execution-part statements specifies the actions of the main program during program execution. Execution of an executable program (R201) begins with the first executable construct of the main program. A main program must not be recursive; that is, a reference to it must not appear in any program unit in the executable program, including itself. Execution of an executable program ends with execution of the end-program-stmt of the main program or with execution of a STOP statement in any program unit of the executable program. 11.1.3 Main program internal procedures Any definitions of internal procedures in the main program must follow the CONTAINS statement. Internal procedures are described in 12.1.2.2. The main program is called the host of its internal procedures.

    一个可执行的程序必须包括一个主程序的程序单元,并可添加其他程序单元。一个程序单元可以是主程序(main-program),或外部子程序(external-subprogram),或模块(module),或是数据块子程序(block-data)。 而一个主程序包括 1.程序声明(program-stmt),由PROGRAM开头,可省略,省略时默认程序名为main。 2.规范部分(specification-part),可省略,包括    零个或多个USE语句(use-stmt,用于调用模块),    隐式部分(implicit-part,包括      implicit语句implicit-stmt——如果使用到了不经定义的变量fortran会根据implicit语句,按照变量的开始字母,自行给变量规定类型,!一般建议加上implicit none来关上implicit,规范代码。      零个或多个隐式声明部分implicit-part-stmt,包括implicit语句implicit-stmt、或parameter语句parameter-stmt——定义常量、或format语句format-stmt——格式化输入输出、或entry语句entry-stmt——在特定语句中提供给外部例程入口。),    零个或多个声明部分(declaration-construct,包括      定义派生类型derived-type-def,      或接口块interface-block——提供函数所使用形参类型说明,      或类型声明type-declaration-stmt——定义变量类型,      或规范声明specification-stmt,包括access语句access-stmt——文件访问、或allocatable语句allocatable-stmt——声明动态数组、或common语句common-stmt——开辟公用区、或data语句data-stmt——给变量或数组赋初值、或dimension语句dimension-stmt——声明数组、或equivalence语句equivalence-stmt——共用内存声明、或external语句external-stmt——声明之后的子程序为外部声明的、或intent语句intent-stmt——声明所传输的参数用途、或intrinsic语句intrinsic-stmt——声明内部函数、或namelist语句namelist-stmt——把一组相关变量封装在一起、或optional语句optional-stmt——允许过程被调用时省略所传输值、或pointer语句pointer-stmt——声明指针、或save语句save-stmt——保存过程执行后其中的变量值、或target语句target-stmt——声明变量为目标或者说是声明显式接口,      或parameter语句parameter-stmt——定义常量,      或format语句format-stmt——格式化输入输出,      或entry语句entry-stmt——在特定语句中提供给外部例程入口,      或函数声明stmt-function-stmt——声明函数。)。 3.执行部分(execution-part),可省略,包括    可执行构造(executable-construct,包括      执行声明action-stmt,包括allocate语句allocate-stmt——分配内存、或赋值语句assignment-stmt、或backspace语句backspace-stmt——使得连接到特殊单元的文件出现在当前记录前、或call语句call-stmt——调用子程序、或close语句close-stmt——关闭文件、或计算的goto语句computed-goto-stmt——以一变量的值为依据跳转到标签表中的某一标签所对应的语句、或continue语句continue-stmt——无意义、或cycle语句cycle-stmt——结束此次循环并开始下一次循环、或deallocate语句deallocate-stmt——释放内存、或endfile语句endfile-stmt——标记最后一个结束记录、或end函数语句end-function-stmt——结束函数、或end程序语句end-program-stmt——结束程序、或end过程语句end-subroutine-stmt——结束过程、或exit语句exit-stmt——跳出循环、或goto语句goto-stmt——跳转到程序的任意语句、或if语句if-stmt——选择结构、或inquire语句inquire-stmt——查询特定命名文件或连接的属性、或nullify语句nullify-stmt——解除指针当前的联合状态并使其指向不能使用的内存地址、或open语句open-stmt——打开文件、或指针赋值语句pointer-assignment-stmt、或print输出语句print-stmt、或read输入语句read-stmt、或返回语句return-stmt、或rewind语句rewind-stmt——将文件的位置指针退回到第一个记录、或stop语句stop-stmt——停止程序、或where语句where-stmt——用于设置数组、或write输出语句write-stmt、或算数if选择语句arithmetic-if-stmt——用于判断一表达式并根据其与零的比较来选择分支、或assign语句assign-stmt——用于在goto语句前赋值、或assign赋值goto语句assigned-goto-stmt——用assign赋值给一变量在根据该变量跳转到一语句、或pause语句pause-stmt——使程序停顿,      或select case选择结构case-construct,      或do循环结构do-construct,      或if选择结构if-construct,      或where选择结构where-construct,)    零个或多个执行部分结构(execution-part-construct ,包括      可执行构造executable-construct——上述,      或format语句format-stmt——格式化输入输出,      或data语句data-stmt——给变量或数组赋初值,      或entry语句entry-stmt——在特定语句中提供给外部例程入口, 4.内部子程序部分(internal-subprogram-part),可省略,包括     contains语句(contains-stmt,声明内部函数、子程序),     一个或多个子程序(internal-subprogram,包括       函数子程序function-subprogram,包括函数声明function-stmt、规范部分specification-part——上述可省略、执行部分execution-part——上述可省略、内部子程序部分internal-subprogram-part——可嵌套可省略、end函数语句end-function-stmt,       子例程subroutine-subprogram,包括例程声明subroutine-stmt、规范部分specification-part——上述可省略、执行部分execution-part——上述可省略、内部子程序部分internal-subprogram-part——可嵌套可省略、end例程语句end-subroutine-stmt, ) 5.end程序语句(end-program-stmt)。 !注意:执行部分(execution-part)不能包含end函数语句(end-function-stmt),end程序语句(end-program-stmt)或end例程语句(end-subroutinestmt)。 一个例子: PROGRAM ANALYSE REAL A, B, C (10,10)       ! Specification part规范部分 CALL FIND           ! Execution part执行部分 CONTAINS SUBROUTINE FIND       ! Internal procedure内部子程序 … END SUBROUTINE FIND END PROGRAM ANALYSE      一般性例子: 出处: http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html PROGRAM program-name IMPLICIT NONE [specification part] [execution part] [subprogram part] END PROGRAM program-name

    转载请注明原文地址: https://ju.6miu.com/read-36243.html

    最新回复(0)