Fortran95实验指导 实验八 子程序

合集下载

FORTRAN95程序的设计实验

FORTRAN95程序的设计实验

FORTRAN95程序设计实验班级:核工11:薛院院学号:2110302026实验一一.实验容一个边长为8.5m的边形草地。

计算八边形草地的面积并输出。

二.问题分析(流程图)三.程序!核工程11!薛院院!2013.03.11!计算8边形的面积PROGRAM COLUMATEREAL(4) A !定义边长REAL(8) B,PINTEGER(1) NUMBER !定义边数REAL(8) AREAL !定义面积PRINT*,'请输入多边形的边数' READ*,NUMBERPRINT*,'请输入多边形的边长' READ*,AB=A/2/sin(3.14/NUMBER)P=A/2+BAREAL=SQRT(P*(P-A)*(P-B)**2) PRINT*,'该多边形的面积为:',AREAL END!输入边数 8 ;输入边长8.5!输出结果:43.8四.实验结果实验二一.实验容计算还清贷款的月算二.问题分析三.程序!核工程11!薛院院!2013.03.11!计算还清贷款的月数!PROGRAM CALUCATEREAL P,D,R,MINTEGER M1PRINT*,'请分别输入贷款月利息贷款数以及每月尝还数' READ*,P,D,RA=LOG10(1.0)PRINT*,AM=(LOG10(P)-LOG10(P-D*R))/LOG10(1+R)M1=INT(M+0.5)PRINT*,M1END四.实验结果实验三一.实验容用case结构和seclect语句实现税值计算二.问题分析(流程图)三.程序!核工11!薛院院!2110302026!计算应该缴纳的税program calucate_moneyinteger incomereal::income_ratereal::rate_1=0.03,rate_2=0.05,rate_3=0.07,rate_4=0.10,rate_5=0.14,rate_6=0.20print*,'请输入收入(以万为单位):' read*,incomeselect case(income)case(0:1000)income_rate=income*rate_1print*,'缴纳的税为: ',income_rate case(1001:2000)income_rate=income*rate_2print*,'缴纳的税为: ',income_rate case( 2001:5000)income_rate=income*rate_3print*,'缴纳的税为: ',income_rate case( 5001:10000)income_rate=income*rate_4print*,'缴纳的税为: ',income_rate case( 10001:50000)income_rate=income*rate_5print*,'缴纳的税为: ',income_rate case defaultincome_rate=income*rate_6print*,'缴纳的税为: ',income_rate end selectend四.实验结果实验四一.实验容计算1−12+13-14……+(−1)n+11n,其中n满足1+22+32……..+n2>a二.问题分析(流程图)三.程序!班级:核工11!:薛院院!日期:4.8!计算级数之和program mainreal::sum=1,term,sign=1,s=0 integer::a,i,n=0print*,'请输入一个较大的数(如10000)' read*,ado while(s<=a)n=n+1s=s+n**2enddodo i=1,nsign=-1*signterm=sign/isum=sum-termenddoprint*,sumend四.实验结果实验五一.实验容计算学生的平均成绩,每门课的平均成绩,三门课的平均成绩以及统计高于每门课的成绩和三门平均成绩的学生人数和占总人数的比例二.问题分析(流程图)三.程序!班级:核工程11!:薛院院!学号:2110302026!统计人数及比例program mainparameter(max=5)character*5::number(max)integer,dimension(3)::english,math,physicsreal::averages(max),english_ave,math_ave,physics_ave,average real::sum1=0,sum2=0,sum3=0integer(1)::n,n1=0,n2=0,n3=0,nn=0real::p1,p2,p3,ppprint*,'请输入学生人数'read*,nprint*,'请输入',n,'名学生的学号、英语、数学、物理成绩'print*,'数据之间用空格间隔。

第1章 Fortran95概述

第1章 Fortran95概述


四、Fortran95编译环境与上机步骤
明德笃志、博学创新
学再学习的能力、学愿学习的习惯
三、Fortran语言特点、程序设计引例(看书)
【例1-1】输入三个数据,计算它们的算数平均值 和几何平均值。
分析:假设用a,b,c分别表示三个数,在数学 上,要计算这三个数的算数平均值和几何平均值, 采用以下公式:
明德笃志、博学创新
学再学习的能力、学愿学习的习惯
一、程序设计、程序设计语言
【例1-1】输入三个数据,计算它们的算数平均值 和几何平均值。
分析:假设用a,b,c分别表示三个数,在数学 上,要计算这三个数的算数平均值和几何平均值, 采用以下公式:
算术平均值 = a + b + c 3
几何平均值 = 3 a × b × c
算法设计是程序设计的主要步骤。算法是指为 解决给定问题而需要计算机去一步一步执行的有穷 操作过程的描述。
一个算法必须具有以下特征: (1)有穷性 (2)确定性 (3)可执行性 (4)数据输入 (5)数据输出
明德笃志、博学创新
学再学习的能力、学愿学习的习惯
一、程序设计、程序设计语言
从根本上讲,程序就是用计算机语言描述的算
力和对基础知识的良好掌握。
明德笃志、博学创新
学再学习的能力、学愿学习的习惯
一、程序设计、程序设计语言
程序的处理对象是数据,每个数据都有一定的 特性和关联,因此为了更好的处理和操作,要研究 数据,对数据进行有规律的组织和构造。在算法设 计中,数据的组织和构造都有其基本方式和规律, 这种组织和构造方式称为数据结构。
明德笃志、博学创新
学再学习的能力、学愿学习的习惯
一、程序设计、程序设计语言

《FORTRAN95程序设计》学习笔记

《FORTRAN95程序设计》学习笔记

《FORTRAN 95程序设计》学习笔记66RPG gg★目录★《FORTRAN 95程序设计》学习笔记 (1)基础知识(基础、字符串、FORMAT、隐式、TYPE) (1)流程与控制(if、select、do) (4)数组(声明、隐式循环、整体操作、可变数组) (5)函数与子程序(子程序、函数、全局变量) (7)MODULE与面向对象(重载操作符、虚函数) (9)文件相关(OPEN、WRITE、READ) (10)指针(指向变量、数组、函数) (12)Visual Fortran 编译器(DLL,VB调用) (13)数值算法与IMSL(数值算法插件) (15)常用库函数(数学、数组、零碎、子程序) (16)基础知识(基础、字符串、FORMAT、隐式、TYPE)★【小玩意】二进制观察器:装在M.. Visual Studio\DF98\bin,有一个Bitviewer,可以观察变量储存方式★【语法】续行:行结尾或行开头使用 & 符号;注释:使用 ! 符号★【语法】数学表达式:+ ;- ;* ;/ ;( ;) ;**乘幂★【语法】程序结束:STOP (Ruby的exit)★【语法】输出:write(*,*),完整写法:write(unit=*,fmt=*)⏹建议:少用print,尽量用write★【语法】声明⏹整型:integer(kind=4) a ;其中kind是使用的bytes数,4 or 2◆其他写法:integer*4 a; integer(4) a⏹浮点:real(kind=4) a ;有效数位6位(12345678存为1.234567E7),如果是kind8则为15位有效数字◆此外:1E10:单精10^10,1D10:双精10^10⏹复数:complex :: a=(2,3)◆实部:real(a) ;虚部:imag(a)⏹布尔型:Logical,.true. 和 .false.★【语法与函数】字符串:character(20) string⏹注意理解,fortran的弱智字符串就是一个长度不能变的一维的东西,极其猥琐,和Java、Ruby不能相提并论的⏹string(13:13) = “a”:对第13个字节的读、存⏹string(2:3) = “go”⏹string(6) = “我的妈呀”:从第6个位置开始设置为“我的妈呀”⏹ a = string_a // string_b:用“//”连接两个字符串⏹【常用函数】char(num),ichar(char):ASCII码的转换相关功能⏹【常用函数】len(string),len_trim(string):长度,去掉尾部空格后的长度⏹【常用函数】index(string,key):找key在string首出现的位置⏹【常用函数】trim(string):返回去掉尾部空格的字符串(用途不大)⏹【函数】repeat(char,int):返回一个重复int次的char串⏹character(len=20) string 普通声明;character(len=*) string 接收的时候可自动长度★【规范格式】FORMAT格式化⏹ e.g.◆write (*,100) A◆100 format(I4) ←这里是100号标识调用的格式⏹参数控制符(前面加数字为重复次数,如4I6或<a>I6。

FORTRAN95程序设计实验

FORTRAN95程序设计实验

FORTRAN95程序设计实验FORTRAN95的基本语法包括变量定义、注释、循环和条件判断等。

在FORTRAN95中,变量可以通过关键字"INTEGER"、"REAL"和"CHARACTER"等进行定义。

例如,以下语句定义了一个整型变量A和一个浮点型变量B:INTEGER::AREAL::B注释可以通过用一个感叹号(!)开头进行标识。

例如:!这是一个注释循环可以使用关键字"DO"和"ENDDO"来实现。

例如,以下代码展示了一个简单的循环,计算了1到10的和:INTEGER::I,SUMSUM=0DOI=1,10SUM=SUM+IENDDO条件判断可以使用关键字"IF"、"THEN"、"ELSE"和"ENDIF"来实现。

例如,以下代码展示了一个简单的条件判断,判断一个数是否为正数:INTEGER::NUMREAD(*,*)NUMIF(NUM>0)THENPRINT*,"该数为正数"ELSEPRINT*,"该数为非正数"ENDIF在FORTRAN95中,还有其他的语法和特点,如数组、函数、子程序等。

下面的实例将展示如何使用FORTRAN95编写一个计算圆面积和周长的程序。

PROGRAM CircleREAL :: PI, R, Area, CircumferencePRINT*,"请输入半径:"READ(*,*)RArea = PI * R**2Circumference = 2 * PI * RPRINT *, "圆的面积为:", AreaPRINT *, "圆的周长为:", CircumferenceEND PROGRAM Circle以上程序首先定义了一个实数变量PI、半径R、面积Area和周长Circumference。

fortran95课程设计

fortran95课程设计

fortran95课程设计一、课程目标知识目标:1. 理解Fortran 95编程语言的基本概念和语法结构;2. 掌握Fortran 95的数据类型、变量声明和运算符使用;3. 学会使用控制结构(如循环、条件语句)进行程序设计;4. 了解数组、函数和子程序在Fortran 95中的应用。

技能目标:1. 能够编写简单的Fortran 95程序,实现基本的输入输出功能;2. 能够运用控制结构进行逻辑判断和循环操作;3. 能够使用数组进行批量数据处理;4. 能够编写简单的函数和子程序,实现代码的模块化。

情感态度价值观目标:1. 培养学生对编程的兴趣,激发自主学习编程的热情;2. 培养学生严谨、细致的编程习惯,注重代码的可读性和效率;3. 培养团队合作精神,学会在编程过程中与他人交流、协作;4. 提高学生的逻辑思维能力,培养解决实际问题的能力。

课程性质:本课程为计算机编程入门课程,以Fortran 95编程语言为载体,培养学生编程技能和逻辑思维能力。

学生特点:学生处于初中或高中阶段,具备一定的数学基础,对编程感兴趣,但可能缺乏实际编程经验。

教学要求:教师应注重理论与实践相结合,以实例为主线,引导学生掌握编程技能,培养编程兴趣。

同时,关注学生的个体差异,提供针对性的指导和支持。

通过本课程的学习,使学生能够达到上述课程目标,为后续编程学习打下坚实基础。

二、教学内容1. Fortran 95基础语法- 程序结构- 数据类型与变量声明- 运算符与表达式- 基本输入输出操作2. 控制结构- 选择结构(IF语句)- 循环结构(DO循环、WHILE循环)3. 数组与函数- 数组的基本操作与应用- 内置函数与自定义函数- 子程序与模块化编程4. 实践项目与案例分析- 简单的计算器程序- 温度转换程序- 数组排序程序- 函数与子程序的应用实例5. 编程规范与调试技巧- 编码规范与命名规则- 调试方法与技巧- 性能优化建议教学内容安排与进度:第一周:Fortran 95基础语法及程序结构第二周:数据类型与变量声明、运算符与表达式第三周:基本输入输出操作、选择结构(IF语句)第四周:循环结构(DO循环、WHILE循环)第五周:数组的基本操作与应用第六周:内置函数与自定义函数、子程序与模块化编程第七周:实践项目与案例分析(计算器程序、温度转换程序等)第八周:编程规范与调试技巧、性能优化本教学内容根据课程目标制定,涵盖了Fortran 95编程语言的核心知识点,通过理论与实践相结合的方式,使学生能够逐步掌握编程技能,培养解决实际问题的能力。

软件技术基础教学大纲(Fortran95)

软件技术基础教学大纲(Fortran95)

“计算机软件技术基础’’课程教学大纲(非电类各专业)课内学时:64(讲课40,课内上机实习24)课外上机实习: 40学分:3.5一、课程的性质,目的和任务本课程是为理工科(非电类)非计算机专业学生开设的一门必修的计算机基础课,其内容涉及程序设计语言(FORTRAN 95语言)、数据结构、实用软件开发方法。

本课程的教学目的主要是培养学生利用计算机处理问题的思维方式,使学生具有应用FORTRAN 95语言设计简单程序的能力,并初步掌握对不同类型的问题求解选择适当的数据结构和算法,为学生今后结合本专业知识、使用软件开发环境和工具解决实际问题、学习后续相关课程打下必要的基础。

二、教学基本要求1、掌握FORTRAN程序的基本组成要素,包括程序结构、数据类型、程序控制结构、过程和文件等基本概念。

2、理解结构化程序设计的基本思想,掌握“自顶向下,逐步求精”的程序设计技术,可以利用三种基本控制结构解决一些简单的问题。

3、熟练使用FORTRAN语言实现常用算法,初步掌握简单绘图程序设计方法。

4、熟悉程序设计中常用的数据结构及算法,初步掌握对不同类型的问题求解选择适当的数据结构。

5、了解软件开发方法的基本知识。

三、先修课程计算机基础导论四、教学内容及要求1.FORTRAN语言基础(2学时)主要内容:●程序设计概述●FORTRAN 95程序的基本结构、标准输入/输出●FORTRAN 95的基本数据类型,以及常量、变量、数组和字符串●FORTRAN 95的运算符和表达式基本要求:熟悉FORTRAN程序结构、程序书写格式,掌握基本数据类型的常量表示和变量的说明、表达式的构造与求值、常用内部函数的使用。

2.程序控制结构(4学时)主要内容:●算法及其特征●顺序结构语句:赋值、输入和输出语句●选择结构语句:if结构语句和select结构语句●循环结构语句:do和do While结构语句● exit、 cycle和goto语句基本要求:从结构化软件设计方法的观点,理解三种基本的控制结构,并能在简单程序的设计中熟练地运用它们。

Fortran95

Fortran95

Annex A(informative)Glossary of technical termsThe following is a list of the principal technical terms used in the standard and their definitions.A reference in parentheses immediately after a term is to the section where the term is defined or explained.The wording of a definition here is not necessarily the same as in the standard.action statement(2.1):A single statement specifying or controlling a computational action(R216). actual argument(12.4.1):An expression,a variable,a procedure,or an alternate return specifier that is specified in a procedure reference.allocatable variable(5.1.2.2):A variable having the ALLOCATABLE attribute.It may be referenced or defined only when it has space allocated.If it is an array,it has a shape only when it has space allocated.It may be a named variable or a structure component.argument(12):An actual argument or a dummy argument.argument association(16.7.1.1):The relationship between an actual argument and a dummy argument during the execution of a procedure reference.array(2.4.5):A set of scalar data,all of the same type and type parameters,whose individual elements are arranged in a rectangular pattern.It may be a named array,an array section,a structure component,a function value,or an expression.Its rank is at least one.Note that in F ORTRAN77,arrays were always named and never constants.array element(2.4.5,6.2.2):One of the scalar data that make up an array that is either named or is a structure component.array pointer(5.1.2.5.3):A pointer to an array.array section(2.4.5,6.2.2.3):A subobject that is an array and is not a structure component.array-valued:Having the property of being an array.assignment statement(7.5.1.1):A statement of the form"variable=expression".associate name(8.1.4.1):The name by which a selector of a SELECT TYPE or ASSOCIATE construct is known within the construct.association(16.7):Name association,pointer association,storage association,or inheritance association.assumed-shape array(5.1.2.5.2):A nonpointer dummy array that takes its shape from the associated actual argument.assumed-size array(5.1.2.5.4):A dummy array whose size is assumed from the associated actual argument.Its last upper bound is specified by an asterisk.attribute(5):A property of a data object that may be specified in a type declaration statement (R501).automatic data object(5.1):A data object that is a local entity of a subprogram,that is not a dummy argument,and that has a character length or array bound that is specified by an expression that is not an initialization expression.base type(4.5.3):An extensible type that is not an extension of another type.A type that is declared with the EXTENSIBLE attribute.belong(8.1.5.4.3,8.1.5.4.4):If an EXIT or a CYCLE statement contains a construct name,the statement belongs to the DO construct using that name.Otherwise,it belongs to the innermost DO construct in which it appears.binding label(12.5.2.7,15.2.7.1):A value of type default character that uniquely identifies how a variable,common block,subroutine,or function is known to a companion processor.block(8.1):A sequence of executable constructs embedded in another executable construct, bounded by statements that are particular to the construct,and treated as an integral unit.block data program unit(11.4):A program unit that provides initial values for data objects in named common blocks.bounds(5.1.2.5.1):For a named array,the limits within which the values of the subscripts of its array elements shall lie.character(3.1):A letter,digit,or other symbol.class(5.1.1.8):A class named N is the set of types extended from the type named N. characteristics(12.2):(1)Of a procedure,its classification as a function or subroutine,whether it is pure,whether it is elemental,whether it has the BIND attribute,the value of its bindinglabel,the characteristics of its dummy arguments,and the characteristics of its functionresult if it is a function.(2)Of a dummy argument,whether it is a data object,is a procedure,is a procedurepointer,is an asterisk(alternate return indicator),or has the OPTIONAL attribute.(3)Of a dummy data object,its type,type parameters,shape,the exact dependence of anarray bound or type parameter on other entities,intent,whether it is optional,whetherit is a pointer or a target,whether it is allocatable,whether it has the VALUE,ASYNCHRONOUS,or VOLATILE attributes,whether it is polymorphic,and whetherthe shape,size,or a type parameter is assumed.(4)Of a dummy procedure or procedure pointer,whether the interface is explicit,thecharacteristics of the procedure if the interface is explicit,and whether it is optional.(5)Of a function result,its type,type parameters,which type parameters are deferred,whether it is polymorphic,whether it is a pointer or allocatable,whether it is aprocedure pointer,rank if it is a pointer or allocatable,shape if it is not a pointer orallocatable,the exact dependence of an array bound or type parameter on otherentities,and whether the character length is assumed.character length parameter(2.4.1.1):The type parameter that specifies the number of characters for an entity of type character.character string(4.4.4):A sequence of characters numbered from left to right1,2,3,...character storage unit(16.7.3.1):The unit of storage for holding a scalar that is not a pointer and is of type default character and character length one.collating sequence(4.4.4.1):An ordering of all the different characters of a particular kind type parameter.common block(5.5.2):A block of physical storage that may be accessed by any of the scoping units in a program.companion processor(2.5.10):A mechanism by which global data and procedures may be referenced or defined.It may be a mechanism that references and defines such entities by means other than Fortran.The procedures can be described by a C function prototype.component(4.5):A constituent of a derived type.component order(4.5.4):The ordering of the components of a derived type that is used for intrinsic formatted input/output and for structure constructors.conformable(2.4.5):Two arrays are said to be conformable if they have the same shape.A scalar is conformable with any array.conformance(1.5):A program conforms to the standard if it uses only those forms and relationships described therein and if the program has an interpretation according to the standard.A program unit conforms to the standard if it can be included in a program in a manner that allows the program to be standard conforming.A processor conforms to the standard if it executes standard-conforming programs in a manner that fulfills the interpretations prescribed in the standard and contains the capability of detection and reporting as listed in1.5.connected(9.4.3):(1)For an external unit,the property of referring to an external file.(2)For an external file,the property of having an external unit that refers to it.constant(2.4.3.1.2):A data object whose value shall not change during execution of a program.It may be a named constant or a literal constant.construct(7.5.3,7.5.4,8.1):A sequence of statements starting with an ASSOCIATE,DO,FORALL, IF,SELECT CASE,SELECT TYPE,or WHERE statement and ending with the corresponding terminal statement.construct entit y(16):An entity defined by a lexical token whose scope is a construct.control mask(7.5.3):In a WHERE statement or construct,an array of type logical whose value determines which elements of an array,in a where-assignment-stmt,will be defined.data:Plural of datum.data entity(2.4.3):A data object,the result of the evaluation of an expression,or the result of the execution of a function reference(called the function result).A data entity has a data type(either intrinsic or derived)and has,or may have,a data value(the exception is an undefined variable). Every data entity has a rank and is thus either a scalar or an array.data object(2.4.3.1):A data entity that is a constant,a variable,or a subobject of a constant.data type(2.4.1):A named category of data that is characterized by a set of values,together with a way to denote these values and a collection of operations that interpret and manipulate the values.For an intrinsic type,the set of data values depends on the values of the type parameters.datum:A single quantity that may have any of the set of values specified for its data type.decimal symbol(9.8.1.6,10.5,10.7.8):The character that separates the whole and fractional parts in the decimal representation of a real number in a file.By default the decimal symbol is a decimal point(also known as a period).The current decimal symbol is determined by the current decimal edit mode.declared type(5.1.1.8,7.1.4):The data type that a data entity is declared to have.May differ from the data type during execution(the dynamic type)for polymorphic data entities.default initialization(4.5):If initialization is specified in a type definition,an object of the type will be automatically initialized.Nonpointer components may be initialized with values by default;pointer components may be initially disassociated by default.Default initialization is not provided for objects of intrinsic type.default-initialized(4.5.1.2):A subcomponent is said to be default-initialized if it will be initialized by default initialization.deferred binding(4.5.1.5):A type-bound procedure binding that specifies the NULL()intrinsic.A deferred binding shall not be invoked.deferred type parameter(4.3):A nonkind type parameter whose value is not specified in the declaration of an object,but instead is specified when the object is allocated or pointer-assigned. definable(2.5.4):A variable is definable if its value may be changed by the appearance of its designator on the left of an assignment statement.An allocatable variable that has not been allocated is an example of a data object that is not definable.An example of a subobject that is not definable is C(I)when C is an array that is a constant and I is an integer variable.defined(2.5.4):For a data object,the property of having or being given a valid value.defined assignment statement(7.5.1.3,12.3.2.1.2):An assignment statement that is not an intrinsic assignment statement and is defined by a subroutine and a generic interface that specifies ASSIGNMENT(=).defined operation(7.1.3,12.3.2.1.1):An operation that is not an intrinsic operation and is defined by a function that is associated with a generic identifier.deleted feature(1.7):A feature in a previous Fortran standard that is considered to have been redundant and largely unused.See section B.1for a list of features which that in a previous Fortran standard,but are not in this standard.A feature designated as an obsolescent feature in the standard may become a deleted feature in the next revision.derived type(2.4.1.2,4.5):A type whose data have components,each of which is either of intrinsic type or of another derived type.designator:See object designator.disassociated(2.4.6):A pointer is disassociated following execution of a DEALLOCATE or NULLIFY statement,or following pointer association with a disassociated pointer.dummy argument(12.5.2.1,12.5.2.2,12.5.2.4,12.5.4):An entity whose name appears in the parenthesized list following the procedure name in a FUNCTION statement,a SUBROUTINE statement,an ENTRY statement,or a statement function statement.dummy array:A dummy argument that is an array.dummy pointer:A dummy argument that is a pointer.dummy procedure(12.1.2.3):A dummy argument that is specified or referenced as a procedure. dynamic type(5.1.1.8,7.1.4):The type of a data entity during execution of a program.The dynamic type of a data entity that is not polymorphic is the same as its declared type.effective item(9.5.2):A scalar object resulting from expanding an input/output list according to the rules in9.5.2.elemental(2.4.5,7.5.1.3,12.7):An adjective applied to an operation,procedure,or assignment statement that is applied independently to elements of an array or corresponding elements of a set of conformable arrays and scalars.entity:The term used for any of the following:a program unit,procedure,abstract interface, operator,generic interface,common block,external unit,statement function,type,data entity, statement label,construct,type alias,or namelist group.executable construct(2.1):An action statement(R216)or an ASSOCIATE,CASE,DO,FORALL,IF, SELECT TYPE,or WHERE construct.executable statement(2.3.1):An instruction to perform or control one or more computational actions.explicit initialization(5.1):Explicit initialization may be specified for objects of intrinsic or derived type in type declaration statements or DATA statements.An object of a derived type that specifies default initialization may not appear in a DATA statement.explicit interface(12.3.1):For a procedure referenced in a scoping unit,the property of being an internal procedure,a module procedure,an intrinsic procedure,an external procedure that has an interface body,a recursive procedure reference in its own scoping unit,or a dummy procedure that has an interface body.explicit-shape array(5.1.2.5.1):A named array that is declared with explicit bounds.expression(2.4.3.2,7.1):A sequence of operands,operators,and parentheses(R722).It may be a variable,a constant,a function reference,or may represent a computation.extended type(4.5.3):An extensible type that is an extension of another type.A type that is declared with the EXTENDS attribute.extensible type(4.5.3):A type from which new types may be derived using the EXTENDS attribute.A type that is declared with either the EXTENSIBLE attribute or the EXTENDS attribute.extension type(4.5.3):A base type is an extension type of itself only.An extended type is an extension type of itself and of all types for which its parent type is an extension.extent(2.4.5):The size of one dimension of an array.external file(9.2):A sequence of records that exists in a medium external to the program.external linkage:The characteristic describing that a C entity is global to the program;defined in clause6.2.2of the C standard.external procedure(2.2.3.1):A procedure that is defined by an external subprogram or by a means other than Fortran.external subprogram(2.2):A subprogram that is not in a main program,module,or another subprogram.Note that a module is not called a subprogram.Note that in F ORTRAN77,a block data program unit is called a subprogram.external unit(9.4):A mechanism that is used to refer to an external file.It is identified by a nonnegative integer.file(9):An internal file or an external file.file storage unit(9.2.4):The unit of storage for an unformatted or stream file.final subroutine(4.5.1.9):A subroutines that is called automatically by the processor during finalization.finalizable(4.5.1.9):A type that has final subroutines,or that has a finalizable component.An object of finalizable type.finalization(4.5.10):The process of calling user-defined final subroutines immediately before destroying an object.function(2.2.3):A procedure that is invoked in an expression and computes a value which is then used in evaluating the expression.function result(12.5.2.1):The data object that returns the value of a function.function subprogram(12.5.2.1):A sequence of statements beginning with a FUNCTION statement that is not in an interface block and ending with the corresponding END statement.generic identifier(12.3.2.1):A lexical token that appears in an INTERFACE statement and is associated with all the procedures in the interface block.generic interface(4.5.1.5,12.3.2.1):An interface specified by a generic procedure binding or a generic interface block.generic interface block(12.3.2.1):An interface block with a generic specification.global entity(16.1.1):An entity identified by a lexical token whose scope is a program.It may be a program unit,a common block,or an external procedure.host(2.2):Host scoping unit.host association(16.7.1.3):The process by which a contained scoping unit accesses entities of its host.host scoping unit(2.2):A scoping unit that immediately surrounds another scoping unit.implicit interface(12.3.1):A procedure referenced in a scoping unit other than its own is said to have an implicit interface if the procedure is an external procedure that does not have an interface body,a dummy procedure that does not have an interface body,or a statement function.inherit(4.5.3):To acquire from a ponents or procedure bindings of an extended type that are automatically acquired from its parent type without explicit declaration in the extended type are said to be inherited.inheritance association(4.5.3.1,16.7.4):The relationship between the inherited components and the parent component in an extended type.inquiry function(13.1):A function that is either intrinsic or is defined in an intrinsic module and whose result depends on properties of the principal argument other than the value of the argument.intent(5.1.2.7):An attribute of a dummy argument data object that indicates whether it is used to transfer data into the procedure,out of the procedure,or both.instance of a subprogram(12.5.2.3):The copy of a subprogram that is created when a procedure defined by the subprogram is invoked.interface block(12.3.2.1):A sequence of statements from an INTERFACE statement to the corresponding END INTERFACE statement.interface body(12.3.2.1):A sequence of statements in an interface block from a FUNCTION or SUBROUTINE statement to the corresponding END statement.interface of a procedure(12.3):See procedure interface.internal file(9.3):A character variable that is used to transfer and convert data from internal storage to internal storage.internal procedure(2.2.3.3):A procedure that is defined by an internal subprogram.internal subprogram(2.2):A subprogram in a main program or another subprogram.intrinsic(2.5.7):An adjective that may be applied to data types,operators,assignment statements, procedures,and modules.Intrinsic data types,operators,and assignment statements are defined in this standard and may be used in any scoping unit without further definition or specification. Intrinsic procedures are defined in this standard or provided by a processor,and may be used in a scoping unit without further definition or specification.Intrinsic modules are defined in this standard or provided by a processor,and may be accessed by use association;procedures and types defined in an intrinsic module are not themselves intrinsic.Intrinsic procedures and modules that are not defined in this standard are called nonstandard intrinsic procedures and modules.invoke(2.2.3):(1)To call a subroutine by a CALL statement or by a defined assignment statement.(2)To call a function by a reference to it by name or operator during the evaluation of anexpression.keyword(2.5.2):A word that is part of the syntax of a statement or a name that is used to identify an item in a list.kind type parameter(2.4.1.1,4.4.1,4.4.2,4.4.3,4.4.4,4.4.5):A parameter whose values label the available kinds of an intrinsic type.label:See statement label.length of a character string(4.4.4):The number of characters in the character string.lexical token(3.2):A sequence of one or more characters with a specified interpretation.line(3.3):A sequence of0to132characters,which may contain Fortran statements,a comment,or an INCLUDE line.linked(12.5.3):When a C function with external linkage has the same binding label as a Fortran procedure,they are said to be linked.It is also possible for two Fortran entities to be linked.literal constant(2.4.3.1.2,4.4):A constant without a name.Note that in F ORTRAN77,this was called simply a constant.local entity(16.1.2):An entity identified by a lexical token whose scope is a scoping unit.local variable(2.4.3.1.1):A variable local to a particular scoping unit;not imported through use or host association,not a dummy argument,and not a variable in common.main program(11.1):A program unit that is not a module,external subprogram,or block data program unit.many-one array section(6.2.2.3.2):An array section with a vector subscript having two or more elements with the same value.module(2.2.4,11.3):A program unit that contains or accesses definitions to be accessed by other program units.module procedure(2.2.3.2):A procedure that is defined by a module subprogram.module subprogram(2.2):A subprogram that is in a module but is not an internal subprogram.name(3.2.1):A lexical token consisting of a letter followed by up to30alphanumeric characters (letters,digits,and underscores).Note that in F ORTRAN77,this was called a symbolic name. name association(16.7.1):Argument association,use association,or host association.named:Having a name.That is,in a phrase such as‘‘named variable,’’the word‘‘named’’signifies that the variable name is not qualified by a subscript list,substring specification,and so on.For example,if X is an array variable,the reference‘‘X’’is a named variable while the reference‘‘X(1)’’is an object designator.named constant(2.4.3.1.2):A constant that has a name.Note that in F ORTRAN77,this was called a symbolic constant.NaN(14.6):A Not-a-Number value of IEEE arithmetic.It represents an undefined value or a value created by an invalid operation.nonexecutable statement(2.3.1):A statement used to configure the program environment in which computational actions take place.numeric storage unit(16.7.3.1):The unit of storage for holding a scalar that is not a pointer and is of type default real,default integer,or default logical.numeric type(4.4):Integer,real or complex type.object(2.4.3.1):Data object.object designator(2.5.1):A name,followed by zero or more of the following:component selectors, array section selectors,array element selectors,and substring selectors.obsolescent feature(1.7):A feature that is considered to have been redundant but that is still in frequent use.operand(2.5.8):An expression that precedes or succeeds an operator.operation(7.1.2):A computation involving one or two operands.operator(2.5.8):A lexical token that specifies an operation.override(4.5.1, 4.5.3):When explicit initialization or default initialization overrides default initialization,it is as if only the overriding initialization were specified.If a procedure is bound to an extensible type,it overrides the one that would have been inherited from the parent type.parent type(4.5.3):The extensible type from which an extended type is derived.parent component(4.5.3.1):The component of an entity of extended type that corresponds to its inherited portion.passed-object dummy argument(4.5.1):The dummy argument of a type-bound procedure or procedure pointer component that becomes associated with the object through which the procedure was invoked.pointer(2.4.6):An entity that has the POINTER attribute.pointer assignment(7.5.2):The pointer association of a pointer with a target by the execution of a pointer assignment statement or the execution of an assignment statement for a data object of derived type having the pointer as a subobject.pointer assignment statement(7.5.2):A statement of the form"pointer-object=>target".pointer associated(6.3,7.5.2):The relationship between a pointer and a target following a pointer assignment or a valid execution of an ALLOCATE statement.pointer association(16.7.2):The process by which a pointer becomes pointer associated with a target.polymorphic(5.1.1.8):Able to be of differing types during program execution.An object declared with the CLASS keyword is polymorphic.preconnected(9.4.4):A property describing a unit that is connected to an external file at the beginning of execution of a program.Such a unit may be specified in input/output statements without an OPEN statement being executed for that unit.present(12.4.1.6):A dummy argument is present in an instance of a subprogram if it is associated with an actual argument and the actual argument is a dummy argument that is present in the invoking subprogram or is not a dummy argument of the invoking subprogram.procedure(2.2.3,12.1):A computation that may be invoked during program execution.It may be a function or a subroutine.It may be an intrinsic procedure,an external procedure,a module procedure,an internal procedure,a dummy procedure,or a statement function.A subprogram may define more than one procedure if it contains ENTRY statements.procedure interface(12.3):The characteristics of a procedure,the name of the procedure,the name of each dummy argument,and the generic identifiers(if any)by which it may be referenced. processor(1.2):The combination of a computing system and the mechanism by which programs are transformed for use on that computing system.processor dependent(1.5):The designation given to a facility that is not completely specified by this standard.Such a facility shall be provided by a processor,with methods or semantics determined by the processor.program(2.2.1):A set of program units that includes exactly one main program.program unit(2.2):The fundamental component of a program.A sequence of statements, comments,and INCLUDE lines.It may be a main program,a module,an external subprogram,or a block data program unit.prototype:The C analog of a function interface body;defined in6.7.5.3of the C standard.pure procedure(12.6):A procedure that is a pure intrinsic procedure(13.1,13.7),is defined by a pure subprogram,or is a statement function that references only pure functions.rank(2.4.4,2.4.5):The number of dimensions of an array.Zero for a scalar.record(9.1):A sequence of values or characters that is treated as a whole within a file. reference(2.5.5):The appearance of an object designator in a context requiring the value at that point during execution,the appearance of a procedure name,its operator symbol,or a defined assignment statement in a context requiring execution of the procedure at that point,or the appearance of a module name in a USE statement.Neither the act of defining a variable nor the appearance of the name of a procedure as an actual argument is regarded as a reference.result variable(2.2.3,12.5.2.1):The variable that returns the value of a function.rounding mode(14.3):The method used in IEEE arithmetic to choose the result of a floating-point operation that cannot be represented exactly.There are four modes;nearest,towards zero,up (towards∞),and down(towards-∞).scalar(2.4.4):(1)A single datum that is not an array.(2)Not having the property of being an array.scope(16):That part of a program within which a lexical token has a single interpretation.It may be a program,a scoping unit,a construct,a single statement,or a part of a statement.scoping unit(2.2):One of the following:(1)A program unit or subprogram,excluding any scoping units in it,(2)A derived type definition,or(3)An interface body,excluding any scoping units in it.section subscript(6.2.2):A subscript,vector subscript,or subscript triplet in an array section selector.selector:A syntactic mechanism for designating(1)Part of a data object.It may designate a substring,an array element,an array section,or a structure component.(2)The set of values for which a CASE block is executed.shape(2.4.5):For an array,the rank and extents.The shape may be represented by the rank-one array whose elements are the extents in each dimension.size(2.4.5):For an array,the total number of elements.specification expression(7.1.6):An expression with limitations that make it suitable for use in specifications such as nonkind type parameters or array bounds.specification function(7.1.6):A nonintrinsic function that may be used in a specification expression.。

fortran95的使用方法8

fortran95的使用方法8

第17章数据文件的编辑对于真实世界的任何数据,我们总是要赋予一定的表示形式,以适应人的阅读理解习惯,也就是对于任何数据文件的都存在一个约定的格式,因此当我们使用计算机来输出数据文件时,当然希望直接输出的就是我们所习惯阅读的带有相应格式的数据文件;同样,在我们向计算机输入数据文件时,也希望仍然按照我们习惯的格式约定直接输入到计算机,因此FORTRAN必须提供能够描述数据文件格式的适当的词汇与语句,从而方便人机对话。

实际上只要不是特别小的FORTRAN程序,无论是为了便于程序作者,还是便于其他用户的使用,都必须包含大量的数据输入输出的格式编辑方面的内容,因此掌握好语言的输入输出编辑功能,是编写一个好的FORTRAN程序的非常重要的方面。

对输入输出进行格式控制的基本任务,就是要在数据的机器内部表示与数据的格式化纪录或文件当中的表示之间,进行适当的转化。

当然从编程语言的角度来看,我们并不需要直接地参与这种具体的转化过程,因为数据的机器内部表示是非常依赖于具体的系统的,作为一种通用编程语言,FORTRAN并不需要具有描述具体系统的能力,FORTRAN所需要做的,只需要能够提供描述格式本身的语言就行了,系统如何根据这种描述而进行数据转换,则不需要程序编写者关心。

FORTRAN 95对于格式的描述主要就是依靠格式说明符来完成的,此外还可以运用名称列表集合名称来说明名称列表格式。

下面我们分别予以详细讨论。

17.1 显式格式说明显式的格式说明可以使用如下两种方式:●运用FORMAT语句;●运用字符表达式。

下面分节讨论这两种显式格式说明方式。

17.1.1 FORMAT语句FORMAT语句的一般语法形式(R1001)为:FORMAT format-specification其中格式说明(format-specification)的一般语法形式(R1002)为:( [ format-item-list ] )其中的格式项列表(format-item-list)在17.2节专门加以讨论。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验八 函数与子例行程序子程序是FORTRAN95提供的重要功能之一,FORTRAN95允许用户自己定义子程序,允许用户通过子程序设计和编写程序。

在设计和编写一个复杂的程序时,通常需要使用科学的程序设计方法,如:结构化程序设计方法、模块化程序设计方法、面向对象程序设计方法等,子程序功能完全支持结构化和模块化程序设计方法,结构化和模块化程序设计方法可通过子程序得到应用。

使用子程序可提高程序的可读性、可理解性、可维护性和可修改性,是编写高质量、高水平、高效率程序的有效手段。

子程序分内部子程序和外部子程序。

内部子程序是包含在程序单元CONTAINS 结构中的子程序,只有定义它们的程序单元才能调用执行它们。

内部子程序包括函数子程序和子例行程序两类,通常将函数子程序简称为函数,子例行程序简称为子程序。

本次实验是学习和掌握子程序的一次系统实验活动。

通过本次实验,能够熟练使用语句函数、内部子程序、外部子程序设计和编写程序,求解比较复杂的实际问题。

一、实验目的1.了解函数的有关基本概念,如:函数名称、函数自变量、函数调用、函数表达式等。

2.掌握语句函数定义、调用、参数的基本内容和使用规则。

3.掌握使用语句函数设计和编写程序的方法。

4. 了解内部子程序的有关基本概念,如:定义、调用、形式参数、实在参数、参数传递关系等。

5. 掌握内部子程序定义、调用、形式参数、实在参数、参数传递的基本内容和使用规则。

6. 掌握结构化程序设计方法。

7. 掌握使用内部子程序设计和编写程序的方法。

8. 了解递归概念,掌握递归问题的求解方法。

9. 掌握递归子程序定义、调用、参数传递关系的基本内容和使用规则。

10. 了解外部子程序概念,掌握并行、协调、合作编写大型复杂程序的方法。

11. 掌握外部子程序定义、调用、参数传递关系的基本内容和使用规则。

12. 掌握使用递归和外部子程序设计和编写程序的方法二、实验内容11、问题描述在解决某工程计算问题时,遇到下列函数:2()12y x x x =++2()f x =()p x =()q x =计算x=0.1,0.2,0.3时,上述函数的值,并输出。

使用语句函数编写程序实现之。

2、算法设计该问题求解算法比较简单,可使用顺序结构或循环结构实现。

根据分析,设计循环结构算法如下:算法:1)定义语句函数y(x),f(x),p(x),q(x)2)x=0.1;3)如果x>0.3,则转(7)执行;4)计算各函数值并输出;5)x=x+1;6)转(3)执行;7)结束3、程序编写设计和编写程序如下(不完整,请在下划线空白处填充正确内容):!班级:???!姓名:???!日期:???!语句函数应用PROGRAM MAINy(x)=1+2*x+x**2f(x)= __________________p(x)=__________________q(x)= __________________DO x=0.1,0.3,0.1yx=y(x)fx=f(x)px=____qx=q(x)PRINT*,'x=',xPRINT*,'y(x)=',yxPRINT*, _______________,'p(x)=',pxPRINT*, 'q(x)=',qx_________END4、实验要求●分析问题,理解算法,编写程序,将程序填写正确完整。

●函数计算必须使用语句函数实现。

●在D盘上创建新工作区:shiyan08和新项目:xm81。

●在项目xm81内创建源程序文件:xm81.f90,同时在文件中编辑输入程序。

●在项目xm81内编译、构建、运行、调试程序。

●将输出结果以注释形式编辑输入到源程序文件xm81.f90末尾。

●使用FORALL语句改写程序,实现程序的并行处理,提高程序运行和处理速度。

5、实验步骤●分析问题,理解算法,编写程序。

●启动软件开发环境Microsoft Developer Studio 。

●在D 盘上创建新工作区:shiyan08。

●在工作区shiyan08内创建新项目:xm81。

●在项目xm81内创建源程序文件xm81.f90,编辑输入源程序文本。

●编译、构建、运行、调试程序,得到输出结果。

●输出结果以注释形式编辑输入到源程序文件末尾。

● 在工作区shiyan08内创建新项目:xm811,在新项目内创建源程序文件xm811.f90,在文件中编辑输入已改写程序。

编译、构建、运行、调试程序,获得输出结果。

使用FORALL 语句改写程序如下:PROGRAM MAINy(x)=1+2*x+x**2f(x)= __________________p(x)=__________________q(x)= __________________REAL,DIMENSION(____)::yx,fx,px,qxFORALL(____)yx(i)=y(0.1*i)fx(i)=f(0.1*i)__________qx(i)=q(0.1*i)____________________DO I=1,3PRINT*,'x=',0.1*IPRINT*,'y(x)=',yx(I)PRINT*, _______________,'p(x)=',px(I)PRINT*, 'q(x)=',qx(I)ENDDOEND三、实验内容21、问题描述已知二项式公式如下:011222()......n n n n r n r r n n n n n n n x y C x C x y C x y C x y C y ---+=++++++其中:r n C 为二项式系数,通过下面公式计算:! (0,1,2,...,)()!!r n n C r n n r r ==- 计算5()x y +的二项展开式系数,并输出。

通过内部函数子程序计算阶乘和二项式系数,编写程序实现之。

2、算法设计分析问题,进行任务分解,得到求解问题的分层结构图,如图8-1所示。

根据任务分解图,自行设计和编写主程序来求解总问题,分别设计和编写子程序来求解子问题。

根据子问题的具体内容,设计和编写子程序为函数。

图8-1 任务分解及分层结构图3、程序编写设计和编写程序如下(不完整,请在下划线空白处填充正确内容):!班级:???!姓名:???!日期:???!计算n阶所有二项式系数PROGRAM MAININTEGER n,r,pPRINT'(A\)','请输入二项式阶数n:'READ*,nPRINT'(I2,A\)',n,'二项式系数有:'DO r=0,np=_________PRINT '(I4,2X\)',pENDDOPRINT*CONTAINS!计算阶乘函数FUNCTION fact(n)INTEGER fact,nfact=1DO i=1,nfact=_________ENDDO_________!计算任意一个二项式系数函数_________cnr(n,r)INTEGER cnr,n,rcnr=fact(n)/( _________)END FUNCTIONEND4、实验要求●分析问题,分解任务,设计算法,理解程序,将程序填写完整。

●阶乘和二项式系数计算要求使用内部函数子程序实现。

●输入输出数据采用有格式输入输出,使输入输出数据规范、醒目、简洁。

●在工作区:shiyan08内创建新项目:xm82。

●在项目xm82内创建源程序文件:xm82.f90,同时在文件中编辑输入程序。

●在项目xm82内编译、构建、运行、调试程序。

●将输出结果以注释形式编辑输入到源程序文件xm82.f90末尾。

●使用递归子程序改写阶乘计算程序。

5、实验步骤●分析问题,设计算法,编写程序。

●启动软件开发环境Microsoft Developer Studio。

●在工作区shiyan08内创建新项目:xm82。

●在项目xm82内创建源程序文件xm82.f90,编辑输入源程序文本。

●编译、构建、运行、调试程序,得到输出结果。

●输出结果以注释形式编辑输入到源程序文件末尾。

●在工作区shiyan08内创建新项目:xm821,在新项目内创建源程序文件xm821.f90,在文件中输入已改写程序。

编译、构建、运行、调试程序,获得输出结果。

四、实验内容31、问题描述已知两个正整数数列A和B,每个数列数据个数不定(最多50个)。

从A数列中删除B数列中出现的数,输出删除前后数列数据。

通过内部子例行程序完成删除操作。

编写程序实现之。

2、算法设计分析问题,进行任务分解,得到求解问题的分层结构图,如图8-2所示。

根据图8-2,设计和编写主程序求解总问题,设计和编写子例行程序求解子问题。

图8-2 任务分解及分层结构图根据分析,设计求解总问题算法如下:(1)输入A数列和B数列数据(数据个数不定,最多50个)。

(2)输出删除前的A数列和B数列数据。

(3)从A数列中删除B数列中出现的数据。

(4)输出删除后A数列数据。

(5)结束。

根据分析,设计求解子问题算法,绘制流程图如图8-3所示。

n、m分别表示A、B数列数据个数。

因为数据均为正整数,规定-1为删除标志,要删除的数据ai赋值为-1即可。

图8-3 流程图3、程序编写使用内部子例行程序设计和编写程序如下(含有若干错误,请查找并改正错误):!班级:???!姓名:???!日期:???!从A数列中删除B数列中出现的数据PROGRAM mainPARAMETER(max=50)INTEGER A(n),B(max),n,mPRINT '(A\)','请输入A数列数据个数n:'READ*,nPRINT '(A,I2,A)','请输入A数列',n,'个数据:'READ*,A(i),i=1,nPRINT '(A\)','请输入B数列数据个数m:'READ*,mPRINT '(A,I2,A)','请输入B数列',m,'个数据:',(B(i),i=1,m)PRINT*,'删除前A数列数据:'PRINT '(1X,<n>(I3,2X))',(A(i),i=1,n)PRINT*,'删除前B数列数据:'PRINT '(1X,<m>(I3,2X))',(B(i),i=1,m)CALL del(A,B)PRINT*,'删除后A 数列数据:'DOIF(A(i)/=-1) PRINT '(I3,2x\)',A(i)END DOPRINT*CONTAINS!数列内容删除SUBROUTINE del(A,B,n,m)INTEGER A(n),B(m),n,m,i,jDO i=1,nDO j=1,mIF(A(i)>B(j)) A(i)=-1END IFEND DOEND FUNCTIONEND4、实验要求●分析问题,分解任务,理解算法和程序,查找并改正程序错误,得到正确程序。

相关文档
最新文档