fortran语言内部函数
fortran ln函数

fortran ln函数一、引言Fortran是一种高级编程语言,它最初是为科学和工程计算而设计的。
Fortran有很多内置的数学函数,其中包括ln函数。
在本文中,我们将介绍Fortran中的ln函数以及如何使用它。
二、什么是ln函数ln函数是自然对数函数,它是以e为底数的对数函数。
ln(x)表示e的多少次方等于x,其中e是一个常数(约等于2.71828),x是一个正实数。
三、Fortran中的ln函数在Fortran中,可以使用log()或log10()来计算对数。
log()计算以e 为底数的对数,而log10()计算以10为底数的对数。
因此,在Fortran中,可以使用以下代码来计算ln(x):result = log(x)四、示例代码下面是一个简单的示例程序,演示如何在Fortran中使用ln函数:program ln_exampleimplicit nonereal :: x, resultwrite(*,*) 'Enter a positive number: 'read(*,*) xresult = log(x)write(*,*) 'The natural logarithm of ', x, ' is ', resultend program ln_example五、解释在这个程序中,我们首先声明了两个变量:x和result。
x用于存储用户输入的值,result用于存储计算结果。
接下来,我们要求用户输入一个正实数,并将其存储在变量x中。
然后,我们使用log()函数计算ln(x),并将结果存储在变量result中。
最后,我们将结果输出到屏幕上。
六、结论在本文中,我们介绍了Fortran中的ln函数以及如何使用它。
ln函数是自然对数函数,它是以e为底数的对数函数。
在Fortran中,可以使用log()或log10()来计算对数。
通过一个简单的示例程序,我们演示了如何在Fortran中使用ln函数。
fortran语言中minval函数

fortran语言中minval函数Fortran语言是一种古老而强大的编程语言。
它是1954年由IBM公司开发的,目的是为了科学和工程计算。
Fortran语言在过去几十年里一直被广泛使用,并且在许多领域中仍然是一种主流语言,特别是在高性能计算领域和科学计算中。
在Fortran语言中,minval函数是一个非常有用的函数。
它用于确定给定数组中的最小值。
minval函数可以在任何类型的数组上使用,包括整数、实数和复数。
函数的原型如下:```minval(array [, dim] [, mask])```其中,array是一个要查找最小值的数组;dim是一个可选参数,用于指定查找的维度;mask也是一个可选参数,用于指定一个逻辑数组来选择要考虑的元素。
minval函数的工作原理非常简单。
它首先确定要查找的维度,如果未指定dim参数,则从整个数组中查找最小值。
然后,它遍历该维度上的所有元素,并返回数组中的最小值。
如果给定了mask参数,则minval函数只考虑被mask中对应为true的元素。
让我们来看几个使用minval函数的示例。
首先,让我们考虑一个简单的示例,其中我们有一个包含5个元素的整数数组:```integer :: arr(5) = [4, 2, 6, 1, 3]```我们可以使用minval函数来查找最小值,并将其存储在另一个整数变量中,如下所示:```integer :: min_valmin_val = minval(arr)```这将使min_val等于数组中的最小值1。
接下来,让我们考虑一个稍微复杂一些的示例,其中我们有一个包含多个维度的实数数组:```real :: arr(2, 3) = [[1.5, 2.8, 3.2], [0.3, 1.9, 2.1]] ```如果我们没有指定dim参数,那么minval函数将在整个数组中查找最小值。
因此,下面的代码将返回数组中的最小值0.3:```real :: min_valmin_val = minval(arr)```如果我们指定dim参数,那么minval函数将在指定的维度上执行查找。
fortran余数函数

fortran余数函数Fortran是一种编程语言,用于科学计算和数值分析。
它是一种古老而强大的语言,最早于1957年发布。
尽管它已经存在了很长一段时间,但它仍然被广泛使用,特别是在科学和工程领域。
Fortran有许多内置函数,其中一个就是计算余数的函数。
余数函数可以计算两个数相除后的余数。
Fortran中的余数函数称为MOD函数,它可以用来计算整数和实数的余数。
MOD函数有两个参数,一个是除数,另一个是被除数。
当两个参数都是整数时,MOD函数返回一个整数余数。
例如,如果我们要计算13除以5的余数,可以使用以下Fortran代码:```fortranprogram mod_exampleimplicit noneinteger :: dividend, divisor, remainderdividend = 13divisor = 5remainder = MOD(dividend, divisor)write(*,*) "余数为:", remainderend program mod_example```上述代码将输出"余数为: 3",因为13除以5得到的余数是3。
这个例子中,dividend被赋值为13,divisor被赋值为5,而remainder 则是MOD函数的结果。
除了整数之外,MOD函数还可以用于计算实数的余数。
当被除数和除数都是实数时,MOD函数将返回一个实数余数。
例如,如果我们要计算5.7除以2.1的余数,可以使用以下Fortran代码:```fortranprogram mod_exampleimplicit nonereal :: dividend, divisor, remainderdividend = 5.7divisor = 2.1remainder = MOD(dividend, divisor)write(*,*) "余数为:", remainderend program mod_example```上述代码将输出"余数为: 1.5",因为5.7除以2.1得到的余数是1.5。
Fortran常用函数

1、RANDOM_NUMBERSyntax ['sintæks] n. 语法CALL RANDOM_NUMBER (harvest结果)Intrinsic Subroutine(固有子程序):Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution.返回大于或等于0且小于1,服从均匀分布的随机数2、RNNOA/ DRNNOA (Single/Double precision)Generate pseudorandom numbers from a standard normal distribution using an acceptance/rejection method.产生服从标准正态分布的随机数Usage(用法)CALL RNNOA (NR, R)Arguments(参数)NR— Number of random numbers to generate. (Input) 要产生随机数的个数R— Vector of length NR containing the random standard normal deviates. (Output)输出长度为NR,随机正态分布的向量Comments(注解)The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator.程序RNSET可以用来初始化随机数发生器的种子ExampleIn this example, RNNOA is used to generate five pseudorandom deviates from a standard normal distribution.INTEGER ISEED, NOUT, NRREAL R(5)EXTERNAL RNNOA, RNSET, UMACHCCALL UMACH (2, NOUT)NR = 5ISEED = 123457CALL RNSET (ISEED)CALL RNNOA (NR, R)WRITE (NOUT,99999) R99999 FORMAT (' Standard normal random deviates: ', 5F8.4)ENDOutputStandard normal random deviates: 2.0516 1.0833 0.0826 1.2777 -1.22603、RESHAPEIntrinsic Function(内部函数)Constructs an array of a specified shape from the elements of another array. 构造规定形式的数组Syntax(语法)result = RESHAPE (source, shape [ , pad][ , order])source(Input) Any type. Array whose elements will be taken in standard Fortran array order (see Remarks), and then placed into a new array.shape(Input) Integer. One-dimensional array that describes the shape of the output array created from elements of source. 描述输出数组的大小的一维数组,The elements of shape are the sizes of the dimensions of the reshaped array in order. If pad is omitted 省略, the total size specified by shape must be less than or equal to source.pad 可选参数(Optional; input) Same type as source. Must be an array. If there are not enough elements in source to fill the result array, elements of pad are added in standardFortran array order. If necessary, extra copies of pad are used to fill the array.order 可选参数(Optional; input) Integer. One-dimensional array. Must be the same length as shape.Permutes the order of dimensions in the result array. The value of order must be a permutation of (1, 2,...n) where n is the size of shape.Return Value(返回值)The result is an array the same data type and kind as source and a shape as defined in shape.ExamplesINTEGER AR1( 2, 5)REAL F(5,3,8)REAL C(8,3,5)AR1 = RESHAPE((/1,2,3,4,5,6/),(/2,5/),(/0,0/),(/2,1/))! returns 1 2 3 4 5! 6 0 0 0 0!! Change Fortran array order to C array orderC = RESHAPE(F, (/8,3,5/), ORDER = (/3, 2, 1/))END4、SUMIntrinsic Function(内部函数)Sums elements of an array or the elements along an optional dimension. The elements summed can be selected by an optional mask.将数组中的元素求和Syntax(语法)result = SUM (array [ , dim] [ , mask])array(Input) Integer, real, or complex. Array whose elements are to be summed.dim 可选参数(Optional; input) Integer. Dimension along which elements are summed.1 ≤dim≤n, where n is the number of dimensions in array.mask 可选参数(Optional; input) Logical. Must be same shape as array. If mask is specified, only elements in array that correspond to .TRUE. elements in mask are summed.Return Value(返回值)Same type and kind as array and equal to the sum of all elements in array or the sum of elements along dimension dim. If mask is specified, only elements that correspondto .TRUE. elements in mask are summed. Returns a scalar if dim is omitted or array is one-dimensional. Otherwise, returns an array one dimension smaller than array.ExamplesINTEGER array (2, 3), i, j(3)array = RESHAPE((/1, 2, 3, 4, 5, 6/), (/2, 3/))! array is 1 3 5! 2 4 6i = SUM((/ 1, 2, 3 /)) ! returns 6j = SUM(array, DIM = 1) ! returns [3 7 11]WRITE(*,*) i, jEND5、SEEDRun-Time Subroutine Changes the starting point of the pseudorandom number generator. 改变随机数发生器的起始点ModuleUSE MSFLIBSyntax(语法)CALL SEED (iseed)iseed(Input) INTEGER(4). Starting point for RANDOM.Remarks(注解)SEED uses iseed to establish the starting point of the pseudorandom number generator.A given seed always produces the same sequence of values from RANDOM.If SEED is not called before the first call to RANDOM, RANDOM always begins with a seed value of one. If a program must have a different pseudorandom sequence each time it runs, pass the constant RND$TIMESEED (defined in MSFLIB.F90) to the SEED routine before the first call to RANDOM.ExampleUSE MSFLIBREAL randCALL SEED(7531)CALL RANDOM(rand)6、RANDOMPurposeRun-Time Subroutine Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution. 返回大于或等于0且小于1,服从均匀分布的随机数ModuleUSE MSFLIBSyntaxCALL RANDOM (ranval)ranval(Output) REAL(4). Pseudorandom number, 0 ≤ranval< 1, from the uniformdistribution.RemarksA given seed always produces the same sequence of values from RANDOM.If SEED is not called before the first call to RANDOM, RANDOM begins with a seed value of one. If a program must have a different pseudorandom sequence each time it runs, pass the constant RND$TIMESEED (defined in MSFLIB.F90) to SEED before the first call to RANDOM.All the random procedures (RANDOM, RAN, and RANDOM_NUMBER, and the PortLib functions DRAND, DRANDM, RAND, IRANDM, RAND, and RANDOM) use the same algorithms and thus return the same answers. They are all compatible and can be used interchangeably. (The algorithm used is a “Prime Modulus M Multiplicative Linear Congruential Generator,” a modified version of t he random number generator by Park and Miller in “Random Number Generators: Good Ones Are Hard to Find,” CACM, October 1988, Vol. 31, No. 10.)CompatibilityCONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIBExampleUSE MSFLIBREAL(4) ranCALL SEED(1995)CALL RANDOM(ran)7、FFT2BCompute the inverse Fourier transform of a complex periodic two-dimensional array.计算二维复数数组的逆傅里叶变换Usage(用法)CALL FFT2B (NRCOEF, NCCOEF, COEF, LDCOEF, A, LDA)Arguments(参数)NRCOEF— The number of rows of COEF. (Input) 数组COEF的行数NCCOEF— The number of columns of COEF. (Input) 数组COEF的列数COEF—NRCOEF by NCCOEF complex array containing the Fourier coefficients to be transformed. (Input) NRCOEF行NCCOEF列数组LDCOEF— Leading dimension of COEF exactly as specified in the dimension statement of the calling program. (Input)A—NRCOEF by NCCOEF complex array containing the Inverse Fourier coefficients of COEF. (Output) NRCOEF行NCCOEF列复数数组,包含数组COEF的逆傅里叶系数LDA— Leading dimension of A exactly as specified in the dimension statement of the calling program. (Input)Comments(注解)1.Automatic workspace usage isFFT2B4 * (NRCOEF + NCCOEF) + 32 + 2 *MAX(NRCOEF, NCCOEF) units, orDFFT2B8 * (NRCOEF + NCCOEF ) + 64 + 4 *MAX(NRCOEF, NCCOEF) units.Workspace may be explicitly provided, if desired, by use of F2T2B/DF2T2B. The reference isCALL F2T2B (NRCOEF, NCCOEF, A, LDA, COEF, LDCOEF,WFF1, WFF2, CWK, CPY)The additional arguments are as follows:WFF1— Real array of length 4 *NRCOEF + 15 initialized by FFTCI. The initialization depends on NRCOEF. (Input)WFF2— Real array of length 4 *NCCOEF + 15 initialized by FFTCI. The initialization depends on NCCOEF. (Input)CWK— Complex array of length 1. (Workspace)CPY— Real array of length 2 *MAX(NRCOEF, NCCOEF). (Workspace)2.The routine FFT2B is most efficient when NRCOEF and NCCOEF are the product of small primes.3.The arrays COEF and A may be the same.4.If FFT2D/FFT2B is used repeatedly, with the same values for NRCOEF and NCCOEF, then use FFTCI to fill WFF1(N = NRCOEF) and WFF2(N = NCCOEF). Follow this with repeated calls to F2T2D/F2T2B. This is more efficient than repeated calls toFFT2D/FFT2B.AlgorithmThe routine FFT2B computes the inverse discrete complex Fourier transform of a complex two-dimensional array of size (NRCOEF = N) ⨯ (NCCOEF = M). The method used is a variant of the Cooley-Tukey algorithm , which is most efficient when N and M are both products of small prime factors. If N and M satisfy this condition, then the computational effort is proportional to N M log N M. This considerable savings has historically led people to refer to this algorithm as the "fast Fourier transform" or FFT.Specifically, given an N⨯M array c = COEF, FFT2B returns in aFurthermore, a vector of Euclidean norm S is mapped into a vector of normFinally, note that an unnormalized inverse is implemented in FFT2D. The routine FFT2B is based on the complex FFT in FFTPACK. The package FFTPACK was developed by Paul Swarztrauber at the National Center for Atmospheric Research.ExampleIn this example, we first compute the Fourier transform of the 5 ⨯ 4 arrayfor 1 ≤n≤ 5 and 1 ≤m≤ 4 using the IMSL routine FFT2D. The resultis then inverted by a call to FFT2B. Note that the result is an array a satisfying a = (5)(4)x = 20x. In general, FFT2B is an unnormalized inverse with expansion factor N M.INTEGER LDA, LDCOEF, M, N, NCA, NRACOMPLEX CMPLX, X(5,4), A(5,4), COEF(5,4)CHARACTER TITLE1*26, TITLE2*26, TITLE3*26INTRINSIC CMPLXEXTERNAL FFT2B, FFT2D, WRCRNCTITLE1 = 'The input matrix is below 'TITLE2 = 'After FFT2D 'TITLE3 = 'After FFT2B 'NRA = 5NCA = 4LDA = 5LDCOEF = 5C Fill X with initial dataDO 20 N=1, NRADO 10 M=1, NCAX(N,M) = CMPLX(FLOAT(N+5*M-5),0.0)10 CONTINUE20 CONTINUECCALL WRCRN (TITLE1, NRA, NCA, X, LDA, 0)CCALL FFT2D (NRA, NCA, X, LDA, COEF, LDCOEF)CCALL WRCRN (TITLE2, NRA, NCA, COEF, LDCOEF, 0)CCALL FFT2B (NRA, NCA, COEF, LDCOEF, A, LDA)CCALL WRCRN (TITLE3, NRA, NCA, A, LDA, 0)CENDOutputThe input matrix is below1 2 3 41 ( 1.00, 0.00) ( 6.00, 0.00) ( 11.00, 0.00) ( 16.00, 0.00)2 ( 2.00, 0.00) ( 7.00, 0.00) ( 12.00, 0.00) ( 17.00, 0.00)3 ( 3.00, 0.00) ( 8.00, 0.00) ( 13.00, 0.00) ( 18.00, 0.00)4 ( 4.00, 0.00) ( 9.00, 0.00) ( 14.00, 0.00) ( 19.00, 0.00)5 ( 5.00, 0.00) ( 10.00, 0.00) ( 15.00, 0.00) ( 20.00, 0.00) After FFT2D1 2 3 41 ( 210.0, 0.0) ( -50.0, 50.0) ( -50.0, 0.0) ( -50.0, -50.0)2 ( -10.0, 13.8) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0)3 ( -10.0, 3.2) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0)4 ( -10.0, -3.2) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0)5 ( -10.0, -13.8) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0) After FFT2B1 2 3 41 ( 20.0, 0.0) ( 120.0, 0.0) ( 220.0, 0.0) ( 320.0, 0.0)2 ( 40.0, 0.0) ( 140.0, 0.0) ( 240.0, 0.0) ( 340.0, 0.0)3 ( 60.0, 0.0) ( 160.0, 0.0) ( 260.0, 0.0) ( 360.0, 0.0)4 ( 80.0, 0.0) ( 180.0, 0.0) ( 280.0, 0.0) ( 380.0, 0.0)5 ( 100.0, 0.0) ( 200.0, 0.0) ( 300.0, 0.0) ( 400.0, 0.0)8、TIMEFPurposePortLib Function Returns the number of seconds since the first time it is called, or zero.ModuleUSE PORTLIBSyntaxresult=TIMEF ( )Return ValueREAL(8). Number of seconds that have elapsed since the first time TIMEF( ) was called. The first time called, TIMEF returns 0.0D0.CompatibilityCONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIBExampleUSE PORTLIBINTEGER i, jREAL(8) elapsed_timeelapsed_time = TIMEF() DO i = 1, 100000j = j + 1END DOelapsed_time = TIMEF() PRINT *, elapsed_time END。
fortran find函数

fortran find函数Fortran是一种广泛用于科学计算和数值分析的编程语言,其内置了许多用于处理数组和矩阵操作的函数。
其中一个非常有用的函数就是find函数。
本文将详细介绍Fortran中的find函数以及其用法和特点。
在Fortran中,find函数用于在一个数组中搜索指定值或条件,并返回满足条件的元素的索引。
它可以帮助我们快速找到数组中满足我们需求的数据,从而进行进一步的处理和分析。
find函数的基本语法如下:```index = find(array, value [, dim])```其中,array是待搜索的数组,value是要搜索的值,dim是可选参数,用于指定在哪个维度上进行搜索。
如果不指定dim,则默认在整个数组上进行搜索。
find函数的返回值是一个整数,表示满足条件的元素在数组中的索引。
如果没有找到满足条件的元素,则返回0。
下面通过一个简单的例子来演示find函数的用法。
假设我们有一个包含10个元素的数组arr,我们想找到数组中值为5的元素的索引。
可以使用如下代码实现:```program find_exampleimplicit noneinteger, parameter :: n = 10integer :: arr(n) = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]integer :: indexindex = find(arr, 5)if (index == 0) thenprint *, "未找到满足条件的元素"elseprint *, "满足条件的元素在数组中的索引为:", indexend ifend program find_example```运行上述代码,输出结果为:```满足条件的元素在数组中的索引为: 5```可以看到,find函数成功找到了数组中值为5的元素,并返回了其在数组中的索引。
fortran 叉乘 内置函数

在计算机编程领域中,Fortran是一种非常古老的编程语言,它在科学计算和工程领域中仍然被广泛使用。
在Fortran中,叉乘(cross product)是一种非常重要的数学运算,它常常用于向量计算和几何学中。
叉乘是指两个向量的一种二元运算,其结果是另一个向量。
在Fortran 中,叉乘通常通过内置函数来实现,这使得程序员能够更加方便地进行向量运算。
叉乘的内置函数通常会接受两个输入向量,并返回它们的叉乘结果。
这个结果向量的方向由右手定则确定,其长度等于输入向量的模长乘积与它们之间的夹角的正弦值。
这样的内置函数可以极大地简化向量计算的复杂度,使得程序员可以更加专注于解决实际问题。
在实际应用中,叉乘的内置函数可以用于处理三维空间中的向量运算。
在计算机图形学中,我们经常需要计算物体的旋转和投影,这些都需要对向量进行叉乘运算。
内置函数能够帮助程序员更高效地实现这些复杂的计算。
叉乘的内置函数还可以用于解决物理学和工程学中的问题。
在计算电磁场中的力和磁感应强度时,就需要用到叉乘运算。
而内置函数的存在,则可以使得这些应用变得更加简单和可靠。
在总的来看,Fortran中的叉乘内置函数是一种非常有价值的工具,它可以帮助程序员更加方便和高效地进行向量运算。
无论是在科学计算领域,还是在工程和物理学中,这样的内置函数都具有非常重要的意义。
个人观点和理解:通过使用Fortran中的叉乘内置函数,程序员可以更加方便地进行向量运算,从而解决各种实际问题。
这种便利性不仅提高了编程的效率,也使得科学计算和工程领域的应用变得更加可靠和稳健。
我认为这样的内置函数在Fortran中具有非常重要的地位。
Fortran中叉乘内置函数的实际应用非常广泛,在计算机图形学、物理学和工程学等领域都有着重要的作用。
它的存在使得程序员能够更加专注于问题的实质,而不必花费过多的精力在实现向量运算上。
我对这种内置函数持非常肯定的态度,并希望它能够在更多的领域得到应用。
fortran函数

fortran函数Fortran是一种编程语言,它提供了许多内置的函数,可以帮助程序员更轻松地完成任务。
这些函数通常称为Fortran函数。
Fortran函数是一组预定义的操作,可以接受零个或多个参数,并返回一个值。
这些函数可以在程序中使用,以执行各种任务,例如数学计算、字符串处理、输入/输出操作等。
Fortran函数的语法与其他编程语言中的函数非常相似。
通常,它们由函数名、参数列表和返回值组成。
例如,下面是一个计算正弦值的Fortran函数:```REAL FUNCTION SIN(X)REAL XSIN = SIN(X)END```这个函数被命名为SIN,它接受一个实数作为参数,并返回它的正弦值。
函数的返回值使用等号分配。
在Fortran中,函数的参数可以是任何数据类型,包括整数、实数、字符串、逻辑值等。
Fortran函数还可以具有可选的参数,这些参数在调用函数时可以省略。
要使用Fortran函数,您需要在程序中调用它们。
通常,这涉及到指定函数名和参数列表,并将返回值存储在变量中。
例如,下面是一个调用上面定义的SIN 函数的示例:```REAL X, YX = 3.14159Y = SIN(X)```在这个例子中,我们首先定义了一个实数变量X,并将其设置为3.14159。
然后,我们调用SIN函数,并将X作为参数传递给它。
该函数计算X的正弦值,并将其存储在变量Y中。
总的来说,Fortran函数是一种非常有用的工具,可以帮助程序员轻松完成各种任务。
无论您是正在编写数学计算、数据处理还是其他类型的程序,Fortran函数都可以帮助您更轻松地完成工作。
Fortran常用函数

1、RANDOM_NUMBERSyntax ['sintæks] n. 语法CALL RANDOM_NUMBER (harvest结果)Intrinsic Subroutine(固有子程序):Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution.返回大于或等于0且小于1,服从均匀分布的随机数2、RNNOA/ DRNNOA (Single/Double precision)Generate pseudorandom numbers from a standard normal distribution using an acceptance/rejection method.产生服从标准正态分布的随机数Usage(用法)CALL RNNOA (NR, R)Arguments(参数)NR— Number of random numbers to generate. (Input) 要产生随机数的个数R— Vector of length NR containing the random standard normal deviates. (Output)输出长度为NR,随机正态分布的向量Comments(注解)The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator.程序RNSET可以用来初始化随机数发生器的种子ExampleIn this example, RNNOA is used to generate five pseudorandom deviates from a standard normal distribution.INTEGER ISEED, NOUT, NRREAL R(5)EXTERNAL RNNOA, RNSET, UMACHCCALL UMACH (2, NOUT)NR = 5ISEED = 123457CALL RNSET (ISEED)CALL RNNOA (NR, R)WRITE (NOUT,99999) R99999 FORMAT (' Standard normal random deviates: ', 5F8.4)ENDOutputStandard normal random deviates: 2.0516 1.0833 0.0826 1.2777 -1.22603、RESHAPEIntrinsic Function(内部函数)Constructs an array of a specified shape from the elements of another array. 构造规定形式的数组Syntax(语法)result = RESHAPE (source, shape [ , pad][ , order])source(Input) Any type. Array whose elements will be taken in standard Fortran array order (see Remarks), and then placed into a new array.shape(Input) Integer. One-dimensional array that describes the shape of the output array created from elements of source. 描述输出数组的大小的一维数组,The elements of shape are the sizes of the dimensions of the reshaped array in order. If pad is omitted 省略, the total size specified by shape must be less than or equal to source.pad 可选参数(Optional; input) Same type as source. Must be an array. If there are not enough elements in source to fill the result array, elements of pad are added in standardFortran array order. If necessary, extra copies of pad are used to fill the array.order 可选参数(Optional; input) Integer. One-dimensional array. Must be the same length as shape.Permutes the order of dimensions in the result array. The value of order must be a permutation of (1, 2,...n) where n is the size of shape.Return Value(返回值)The result is an array the same data type and kind as source and a shape as defined in shape.ExamplesINTEGER AR1( 2, 5)REAL F(5,3,8)REAL C(8,3,5)AR1 = RESHAPE((/1,2,3,4,5,6/),(/2,5/),(/0,0/),(/2,1/))! returns 1 2 3 4 5! 6 0 0 0 0!! Change Fortran array order to C array orderC = RESHAPE(F, (/8,3,5/), ORDER = (/3, 2, 1/))END4、SUMIntrinsic Function(内部函数)Sums elements of an array or the elements along an optional dimension. The elements summed can be selected by an optional mask.将数组中的元素求和Syntax(语法)result = SUM (array [ , dim] [ , mask])array(Input) Integer, real, or complex. Array whose elements are to be summed.dim 可选参数(Optional; input) Integer. Dimension along which elements are summed.1 ≤dim≤n, where n is the number of dimensions in array.mask 可选参数(Optional; input) Logical. Must be same shape as array. If mask is specified, only elements in array that correspond to .TRUE. elements in mask are summed.Return Value(返回值)Same type and kind as array and equal to the sum of all elements in array or the sum of elements along dimension dim. If mask is specified, only elements that correspondto .TRUE. elements in mask are summed. Returns a scalar if dim is omitted or array is one-dimensional. Otherwise, returns an array one dimension smaller than array.ExamplesINTEGER array (2, 3), i, j(3)array = RESHAPE((/1, 2, 3, 4, 5, 6/), (/2, 3/))! array is 1 3 5! 2 4 6i = SUM((/ 1, 2, 3 /)) ! returns 6j = SUM(array, DIM = 1) ! returns [3 7 11]WRITE(*,*) i, jEND5、SEEDRun-Time Subroutine Changes the starting point of the pseudorandom number generator. 改变随机数发生器的起始点ModuleUSE MSFLIBSyntax(语法)CALL SEED (iseed)iseed(Input) INTEGER(4). Starting point for RANDOM.Remarks(注解)SEED uses iseed to establish the starting point of the pseudorandom number generator.A given seed always produces the same sequence of values from RANDOM.If SEED is not called before the first call to RANDOM, RANDOM always begins with a seed value of one. If a program must have a different pseudorandom sequence each time it runs, pass the constant RND$TIMESEED (defined in MSFLIB.F90) to the SEED routine before the first call to RANDOM.ExampleUSE MSFLIBREAL randCALL SEED(7531)CALL RANDOM(rand)6、RANDOMPurposeRun-Time Subroutine Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution. 返回大于或等于0且小于1,服从均匀分布的随机数ModuleUSE MSFLIBSyntaxCALL RANDOM (ranval)ranval(Output) REAL(4). Pseudorandom number, 0 ≤ranval< 1, from the uniformdistribution.RemarksA given seed always produces the same sequence of values from RANDOM.If SEED is not called before the first call to RANDOM, RANDOM begins with a seed value of one. If a program must have a different pseudorandom sequence each time it runs, pass the constant RND$TIMESEED (defined in MSFLIB.F90) to SEED before the first call to RANDOM.All the random procedures (RANDOM, RAN, and RANDOM_NUMBER, and the PortLib functions DRAND, DRANDM, RAND, IRANDM, RAND, and RANDOM) use the same algorithms and thus return the same answers. They are all compatible and can be used interchangeably. (The algorithm used is a “Prime Modulus M Multiplicative Linear Congruential Generator,” a modified version of t he random number generator by Park and Miller in “Random Number Generators: Good Ones Are Hard to Find,” CACM, October 1988, Vol. 31, No. 10.)CompatibilityCONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIBExampleUSE MSFLIBREAL(4) ranCALL SEED(1995)CALL RANDOM(ran)7、FFT2BCompute the inverse Fourier transform of a complex periodic two-dimensional array.计算二维复数数组的逆傅里叶变换Usage(用法)CALL FFT2B (NRCOEF, NCCOEF, COEF, LDCOEF, A, LDA)Arguments(参数)NRCOEF— The number of rows of COEF. (Input) 数组COEF的行数NCCOEF— The number of columns of COEF. (Input) 数组COEF的列数COEF—NRCOEF by NCCOEF complex array containing the Fourier coefficients to be transformed. (Input) NRCOEF行NCCOEF列数组LDCOEF— Leading dimension of COEF exactly as specified in the dimension statement of the calling program. (Input)A—NRCOEF by NCCOEF complex array containing the Inverse Fourier coefficients of COEF. (Output) NRCOEF行NCCOEF列复数数组,包含数组COEF的逆傅里叶系数LDA— Leading dimension of A exactly as specified in the dimension statement of the calling program. (Input)Comments(注解)1.Automatic workspace usage isFFT2B4 * (NRCOEF + NCCOEF) + 32 + 2 *MAX(NRCOEF, NCCOEF) units, orDFFT2B8 * (NRCOEF + NCCOEF ) + 64 + 4 *MAX(NRCOEF, NCCOEF) units.Workspace may be explicitly provided, if desired, by use of F2T2B/DF2T2B. The reference isCALL F2T2B (NRCOEF, NCCOEF, A, LDA, COEF, LDCOEF,WFF1, WFF2, CWK, CPY)The additional arguments are as follows:WFF1— Real array of length 4 *NRCOEF + 15 initialized by FFTCI. The initialization depends on NRCOEF. (Input)WFF2— Real array of length 4 *NCCOEF + 15 initialized by FFTCI. The initialization depends on NCCOEF. (Input)CWK— Complex array of length 1. (Workspace)CPY— Real array of length 2 *MAX(NRCOEF, NCCOEF). (Workspace)2.The routine FFT2B is most efficient when NRCOEF and NCCOEF are the product of small primes.3.The arrays COEF and A may be the same.4.If FFT2D/FFT2B is used repeatedly, with the same values for NRCOEF and NCCOEF, then use FFTCI to fill WFF1(N = NRCOEF) and WFF2(N = NCCOEF). Follow this with repeated calls to F2T2D/F2T2B. This is more efficient than repeated calls toFFT2D/FFT2B.AlgorithmThe routine FFT2B computes the inverse discrete complex Fourier transform of a complex two-dimensional array of size (NRCOEF = N) ⨯ (NCCOEF = M). The method used is a variant of the Cooley-Tukey algorithm , which is most efficient when N and M are both products of small prime factors. If N and M satisfy this condition, then the computational effort is proportional to N M log N M. This considerable savings has historically led people to refer to this algorithm as the "fast Fourier transform" or FFT.Specifically, given an N⨯M array c = COEF, FFT2B returns in aFurthermore, a vector of Euclidean norm S is mapped into a vector of normFinally, note that an unnormalized inverse is implemented in FFT2D. The routine FFT2B is based on the complex FFT in FFTPACK. The package FFTPACK was developed by Paul Swarztrauber at the National Center for Atmospheric Research.ExampleIn this example, we first compute the Fourier transform of the 5 ⨯ 4 arrayfor 1 ≤n≤ 5 and 1 ≤m≤ 4 using the IMSL routine FFT2D. The resultis then inverted by a call to FFT2B. Note that the result is an array a satisfying a = (5)(4)x = 20x. In general, FFT2B is an unnormalized inverse with expansion factor N M.INTEGER LDA, LDCOEF, M, N, NCA, NRACOMPLEX CMPLX, X(5,4), A(5,4), COEF(5,4)CHARACTER TITLE1*26, TITLE2*26, TITLE3*26INTRINSIC CMPLXEXTERNAL FFT2B, FFT2D, WRCRNCTITLE1 = 'The input matrix is below 'TITLE2 = 'After FFT2D 'TITLE3 = 'After FFT2B 'NRA = 5NCA = 4LDA = 5LDCOEF = 5C Fill X with initial dataDO 20 N=1, NRADO 10 M=1, NCAX(N,M) = CMPLX(FLOAT(N+5*M-5),0.0)10 CONTINUE20 CONTINUECCALL WRCRN (TITLE1, NRA, NCA, X, LDA, 0)CCALL FFT2D (NRA, NCA, X, LDA, COEF, LDCOEF)CCALL WRCRN (TITLE2, NRA, NCA, COEF, LDCOEF, 0)CCALL FFT2B (NRA, NCA, COEF, LDCOEF, A, LDA)CCALL WRCRN (TITLE3, NRA, NCA, A, LDA, 0)CENDOutputThe input matrix is below1 2 3 41 ( 1.00, 0.00) ( 6.00, 0.00) ( 11.00, 0.00) ( 16.00, 0.00)2 ( 2.00, 0.00) ( 7.00, 0.00) ( 12.00, 0.00) ( 17.00, 0.00)3 ( 3.00, 0.00) ( 8.00, 0.00) ( 13.00, 0.00) ( 18.00, 0.00)4 ( 4.00, 0.00) ( 9.00, 0.00) ( 14.00, 0.00) ( 19.00, 0.00)5 ( 5.00, 0.00) ( 10.00, 0.00) ( 15.00, 0.00) ( 20.00, 0.00) After FFT2D1 2 3 41 ( 210.0, 0.0) ( -50.0, 50.0) ( -50.0, 0.0) ( -50.0, -50.0)2 ( -10.0, 13.8) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0)3 ( -10.0, 3.2) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0)4 ( -10.0, -3.2) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0)5 ( -10.0, -13.8) ( 0.0, 0.0) ( 0.0, 0.0) ( 0.0, 0.0) After FFT2B1 2 3 41 ( 20.0, 0.0) ( 120.0, 0.0) ( 220.0, 0.0) ( 320.0, 0.0)2 ( 40.0, 0.0) ( 140.0, 0.0) ( 240.0, 0.0) ( 340.0, 0.0)3 ( 60.0, 0.0) ( 160.0, 0.0) ( 260.0, 0.0) ( 360.0, 0.0)4 ( 80.0, 0.0) ( 180.0, 0.0) ( 280.0, 0.0) ( 380.0, 0.0)5 ( 100.0, 0.0) ( 200.0, 0.0) ( 300.0, 0.0) ( 400.0, 0.0)8、TIMEFPurposePortLib Function Returns the number of seconds since the first time it is called, or zero.ModuleUSE PORTLIBSyntaxresult=TIMEF ( )Return ValueREAL(8). Number of seconds that have elapsed since the first time TIMEF( ) was called. The first time called, TIMEF returns 0.0D0.CompatibilityCONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIBExampleUSE PORTLIBINTEGER i, jREAL(8) elapsed_timeelapsed_time = TIMEF() DO i = 1, 100000j = j + 1END DOelapsed_time = TIMEF() PRINT *, elapsed_time END。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
附录 FORTRAN 90标准函数符号约定:●I代表整型;R代表实型;C代表复型;CH代表字符型;S代表字符串;L代表逻辑型;A代表数组;P代表指针;T代表派生类型;AT为任意类型。
●s:P表示s类型为P类型(任意kind值)。
s:P(k)表示s类型为P类型(kind值=k)。
●[…]表示可选参数。
●*表示常用函数。
表1 数值和类型转换函数函数名说明ABS(x)*求x的绝对值∣x∣。
x:I、R,结果类型同x; x:C,结果:RAIMAG(x)求x的实部。
x:C,结果:RAINT(x[,kind])*对x取整,并转换为实数(kind)。
x:R, kind:I,结果:R(kind)AMAX0(x1,x2,x3,…)*求x1,x2,x3,…中最大值。
x I:I,结果:RAMIN0(x1,x2,x3,…)*求x1,x2,x3,…中最小值。
x I:I,结果:RANINT(x[,kind])*对x四舍五入取整,并转换为实数(kind)。
x:R, kind:I,结果:R(kind) CEILING(x)*求大于等于x的最小整数。
x:R,结果:ICMPLX(x[,y][,kind]))将参数转换为x、(x,0.0)或(x,y)。
x:I、R、C, y:I、R,kind:I,结果:C(kind) CONJG(x)求x的共轭复数。
x:C,结果:CDBLE(x)*将x转换为双精度实数。
x:I、R、C,结果:R(8)DCMPLX(x[,y])将参数转换为x、(x,0.0)或(x,y)。
x:I、R、C, y:I、R,结果:C(8)DFLOAT(x)将x转换为双精度实数。
x:I,结果:R(8)DIM(x,y)*求x-y和0中最大值,即MAX(x-y,0)。
x:I、R, y的类型同x,结果类型同x DPROD(x,y)求x和y的乘积,并转换为双精度实数。
x:R, y:R,结果:R(8)FLOAT(x)*将x转换为单精度实数。
x:I,结果:RFLOOR(x)*求小于等于x的最大整数。
x:R,结果:IIFIX(x)*将x转换为整数(取整)。
x:R,结果:IIMAG(x)同AIMAG(x)INT(x[,kind])*将x转换为整数(取整)。
x:I、R、C, kind:I,结果:I(kind)LOGICAL(x[,kind])*按kind值转换新逻辑值。
x:L,结果:L(kind)MAX(x1,x2,x3,…)*求x1,x2,x3,…中最大值。
x I为任意类型,结果类型同x IMAX1(x1,x2,x3,…)*求x1,x2,x3,…中最大值(取整)。
x I:R,结果:IMIN(x1,x2,x3,…)*求x1,x2,x3,…中最小值。
x I为任意类型,结果类型同x IMIN1(x1,x2,x3,…)*求x1,x2,x3…中最小值(取整)。
x I:R,结果:IMOD(x,y)*求x/y的余数,值为x-INT(x/y)*y。
x:I、R, y的类型同x,结果类型同x MODULO(x,y)求x/y余数,值为x-FLOOR(x/y)*y。
x:I、R, y的类型同x,结果类型同x NINT(x[,kind])*将x转换为整数(四舍五入)。
x:R, kind:I,结果:I(kind)REAL(x[,kind])*将x转换为实数。
x:I、R、C, kind:I,结果:R(kind)SIGN(x,y)*求x的绝对值乘以y的符号。
x:I、R, y的类型同x,结果类型同x SNGL(x)将双精度实数转换为单精度实数。
x:R(8),结果:RZEXT(x)用0向左侧扩展x。
x:I、L,结果:I表2 三角函数函数名说明ACOS(x)*求x的反余弦arccos(x)。
x:R,结果类型同x,结果值域:0~πACOSD(x)*求x的反余弦arccos(x)。
x:R,结果类型同x,结果值域:0~180°ASIN(x)*求x的反正弦arcsin(x)。
x:R,结果类型同x,结果为弧度,值域:0~πASIND(x)*求x的反正弦arcsin(x)。
x:R,结果类型同x,结果为度,值域:0~180°ATAN(x)*求x的反正切arctg(x)。
x:R,结果类型同x,结果为弧度,值域:-π/2~π/2 ATAND(x)*求x的反正切arctg(x)。
x:R,结果类型同x,结果为度,值域:-90~90°ATAN2(y,x)求x的反正切arctg(y/x)。
y:R,x和结果类型同x,结果值域:-π~πATAN2D(y,x)求x的反正切arctg(y/x)。
y:R,x和结果类型同x,结果值域:-180~180°COS(x)*求x的余弦cos(x)。
x:R、C,x取值弧度,结果类型同xCOSD(x)*求x的余弦cos(x)。
x:R,x取值度,结果类型同xCOSH(x)求x的双曲余弦ch(x)。
x:R,结果类型同xCOTAN(x)*求x的余切ctg(x)。
x:R,x取值度,结果类型同xSIN(x)*求x的正弦sin(x)。
x:R、C,x取值弧度,结果类型同xSIND(x)*求x的正弦sin(x)。
x:R,x取值度,结果类型同xSINH(x)求x的双曲正弦sh(x)。
x:R,结果类型同xTAN(x)*求x的正切tg(x)。
x:R,x取值弧度,结果类型同xTAND(x)*求x的正切tg(x)。
x:R,x取值度,结果类型同xTANH(x)求x的双曲正切th(x)。
x:R,结果类型同x注:三角函数名前有C、D的函数为复数、双精度型函数。
表3 指数、平方根和对数函数函数名说明ALOG(x)求x的自然对数ln(x)。
x:R(4),结果:R(4)ALOG10(x)求x以10为底一般对数log10(x)。
x:R(4),结果:R(4)EXP(x)*求指数,即e x。
x:R、C,结果类型同xLOG(x)*求自然对数,即e x。
x:R、C,结果类型同xLOG10(x)*求以10为底对数,即。
x:R,结果类型同xSQRT(x)*求x的平方根。
x:R、C,结果类型同x注:指数函数名、平方根函数名、对数函数名前有C、D的函数为复数、双精度型函数。
表4 参数查询函数函数名说明ALLOCATED(a)*判定动态数组a是否分配内存。
a:A,结果:L,分配:.TRUE.,未分配:.FALSE. ASSOCIATED(p[,t])*判定指针p是否指向目标t。
p:P,t:AT,结果:L,指向:.TRUE.,未指向:.FALSE. DIGITS(x)查询x的机内编码数值部分二进制位数(除符号位和指数位)。
x:I、R,结果:I EPSILON(x)*查询x类型可表示的最小正实数。
x:R,结果类型同x。
最小正实数:1.1920929E-07 HUGE(x)*查询x类型可表示的最大数。
x:I、R,结果类型同xILEN(x)查询x的反码值。
x:I,结果类型同xKIND(x)*查询x的kind参数值。
x:I、R、C、CH、L,结果:IMAXEXPONENT(x)*查询x的最大正指数值。
x:R,结果:I(4)MINEXPONENT(x)*查询x的最大负指数值。
x:R,结果:I(4)PRECISION(x)*查询x类型有效数字位数。
x:R、C,结果:I(4)PRESENT(x)查询可选形参x是否有对应实参。
x:AT,结果:L。
有:.TRUE.,没有:.FALSE. RADIX(x)查询x类型的基数。
x:I、R,结果:LRANGE(x)*查询x类型的指数范围。
x:I、R、C,结果:I(4)SIZEOF(x)*查询x的存储分配字节数。
x:AT,结果:I(4)TINY(x)*查询x的最小正值。
x:R,结果类型同x表5 实数检测和控制函数函数名说明EXPONENT(x)*求实数x机内编码表示的指数值。
x:R,结果:IFRACTION(x)*求实数x机内编码表示的小数值。
x:R,结果类型同xNEAREST(x,s)根据s的正负号求最接近x的值。
x:R,结果:R,且不为0RRSPACING(x)求x与系统最大数之间的差值。
x:R,结果类型同xSCALE(x,I)*求x乘以2i。
x:R,i:I,结果类型同xSET_EXPONENT(x,i)求由x的机内编码小数值与指数i组成的实数。
x:R,i:I,结果类型同x SPACING(x)*求x与x最近值的差值绝对值。
x:R,结果类型同x表6 字符处理函数函数名说明ACHAR(n)将ASCII码n转换为对应字符。
n:I,n值域:0~127,结果:CH(1)ADJUSTL(string)*将字符串string左对齐,即去掉左端空格。
string:CH(*),结果类型同string ADJUSTR(string)*将字符串string右对齐,即去掉右端空格。
string:CH(*),结果类型同string CHAR(n)*将ASCII码n转换为对应字符。
n:I,n值域:0~255,结果:CH(1)IACHAR(c)*将字符c转换为对应的ASCII码。
c:CH(1),结果:IICHAR(c)*将字符c转换为对应的ASCII码。
c:CH(1),结果:IINDEX(s,ss[,b])*求子串ss在串s中起始位置。
s:CH(*),ss:CH(*),b:L,结果:I。
b为真从右起LEN(s)*求字符串s的长度。
s:CH(*),结果:ILEN_TRIM(s)*求字符串s去掉尾部空格后的字符数。
s:CH(*),结果:ILGE(s1,s2)*按ASCII码值判定字符串s1大于等于字符串s2。
s1:CH(*),s1:CH(*),结果:L LGT(s1,s2)*按ASCII码值判定字符串s1大于字符串s2。
s1:CH(*),s1:CH(*),结果:LLLE(s1,s2)*按ASCII码值判定字符串s1小于等于字符串s2。
s1:CH(*),s1:CH(*),结果:L LLT(s1,s2)*按ASCII码值判定字符串s1小于字符串s2。
s1:CH(*),s1:CH(*),结果:LREPEAT(s,n)*求字符串s重复n次的新字符串。
s:CH(*),n:I,结果:CH(*)SCAN(s,st[,b])求串st中任一字符在串s中的位置。
s:CH(*),ss:CH(*),b:L,结果:ITRIM(s)*求字符串s去掉首尾部空格后的字符数。
s:CH(*),结果:CH(*)VERIFY(s,st[,b])求不在串st中字符在s中位置。
s:CH(*),ss:CH(*),b:L,结果:I。
b为真右起表7 二进制位操作函数函数名说明BIT_SIZE(n)*求n类型整数的最大二进制位数。
n:I,结果类型同nBTEST(n,p)判定整数n的二进制表示右起第p位是否为1。