fortran标准库函数

合集下载

fortran基本函数

fortran基本函数

FORTRAN 90标准函数(一)(2012-07-03 17:14:57)转载▼分类:学习标签:fortran函数教育符号约定:●I代表整型;R代表实型;C代表复型;CH代表字符型;S代表字符串;L代表逻辑型;A代表数组;P代表指针;T代表派生类型;AT为任意类型。

●s:P表示s类型为P类型(任意kind值)。

s:P(k)表示s类型为P类型(kind值=k)。

●[…]表示可选参数。

●*表示常用函数。

注:三角函数名前有C、D的函数为复数、双精度型函数。

注:指数函数名、平方根函数名、对数函数名前有C、D的函数为复数、双精度型函数。

表4 参数查询函数atan2函数的值域是多少?我从网上找到一个fortran函数的日志,说此值域是-π~π,但正常反正切函数的值域应该是-π/2~π/2。

对atan2函数不够了解,所以不知道你的答案对不对,我个人认为不对。

我是用正常的反正切函数atan(v/u)来算的:FORTRAN:if (u>0..and.v>0.) dir=270-atan(v/u)*180/piif (u<0..and.v>0.) dir=90-atan(v/u)*180/piif (u<0..and.v<0.) dir=90-atan(v/u)*180/piif (u>0..and.v<0.) dir=270-atan(v/u)*180/piif (u==0..and.v>0.) dir=180if (u==0..and.v<0.) dir=0if (u>0..and.v==0.) dir=270if (u<0..and.v==0.) dir=90if (u==0..and.v==0.) dir=999其中uv等于零的五种情况要单独挑出来,不然程序会有瑕疵。

atan函数换成atand函数的话直接是度数,不用*180/pi我四个象限和轴都试了,应该没错。

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。

fortran里的gamma函数

fortran里的gamma函数
在Fortran中,gamma函数是阶乘函数的一般化,通常用于处理非整数值。Fortran标准库通常提供了gamma函数的实现,你可以使用内置的gamma函数来计算。
以下是一个使用Fortran中gamma函数的简单例子:
program
real(8)::result
!设置x的值
=5.0
!调用gamma函数计算gamma(x)
resulma('') = 'result
end program
在上述示例中,gamma函数接受一个实数作为参数,并返回对应的gamma函数值。请注意,gamma函数通常被设计为处理实数,因此参数可以是非整数。
在实际使用中,你可能需要根据你的编译器和Fortran版本查看相关文档,以确保gamma函数的可用性和正确用法。不同的Fortran编译器可能在实现上有一些差异。

fortran 三角函数

fortran 三角函数

fortran 三角函数Fortran是一门古老的编程语言,最初由IBM公司在20世纪50年代开发。

它的全称是Formula Translation,因为最初它是用来进行科学和工程计算,特别是数值计算的语言。

Fortran具有很强的数学运算能力,自然而然地也就包含了各种三角函数的计算。

在Fortran中,三角函数可以使用数学库函数来计算。

Fortran的数学库包含了许多用于科学计算的函数,包括三角函数,对数函数,指数函数等等。

下面是Fortran中常见的三角函数及其用法:1. sin函数Sin函数可用于计算给定角度的正弦值。

Fortran命令为sin(x),其中x是以弧度为单位的角度。

要计算30度的sin值,可以使用以下Fortran代码:program sin_exampleimplicit nonereal :: sin30sin30 = sin(30*3.14159/180)write(*,*) sin30end program sin_example在这个例子中,我们将30度的值转换为弧度,并将结果存储在sin30变量中。

我们输出sin30的值。

2. cos函数Cos函数可用于计算给定角度的余弦值。

Fortran命令为cos(x),其中x是以弧度为单位的角度。

要计算60度的cos值,可以使用以下Fortran代码:program cos_exampleimplicit nonereal :: cos60cos60 = cos(60*3.14159/180)write(*,*) cos60end program cos_example在这个例子中,我们将60度的值转换为弧度,并将结果存储在cos60变量中。

我们输出cos60的值。

3. tan函数Tan函数可用于计算给定角度的正切值。

Fortran命令为tan(x),其中x是以弧度为单位的角度。

要计算45度的tan值,可以使用以下Fortran代码:program tan_exampleimplicit nonereal :: tan45tan45 = tan(45*3.14159/180)write(*,*) tan45end program tan_example在这个例子中,我们将45度的值转换为弧度,并将结果存储在tan45变量中。

Fortran标准函数库

Fortran标准函数库

附录 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转换为单精度实数。

fortran find函数

fortran find函数

Fortran Find函数1. 简介Fortran是一种高性能科学计算语言,广泛用于数值计算和科学工程。

在Fortran 中,有许多内置函数可用于数组和字符串的操作。

其中一个常用的函数是Find函数,用于查找数组中的元素。

2. Find函数的语法和用法Find函数的语法如下:index = Find(array, value [, dim])其中,array是要搜索的数组,value是要查找的元素,dim是可选参数,指定在哪个维度上进行查找。

如果不指定dim,则默认在整个数组中查找。

Find函数返回一个整数值,表示查找到的元素在数组中的位置。

如果找不到该元素,则返回0。

下面是一个示例代码,演示了Find函数的用法:program find_exampleimplicit noneinteger :: array(5) =[1, 3, 5, 7, 9]integer :: indexindex = Find(array, 5)if (index == 0) thenprint *, "Element not found"elseprint *, "Element found at index", indexend ifend program find_example上述代码中,我们定义了一个包含5个元素的整数数组array,并使用Find函数查找值为5的元素。

如果找到了该元素,则输出其在数组中的位置;如果未找到,则输出提示信息。

3. Find函数的工作原理Find函数的工作原理是通过遍历数组中的元素,逐个与要查找的元素进行比较,直到找到匹配的元素或遍历完整个数组。

在Fortran中,数组的索引是从1开始的。

因此,在查找过程中,Find函数会从数组的第一个元素开始比较,直到找到匹配的元素或遍历到最后一个元素。

4. Find函数的应用场景Find函数在很多情况下都可以派上用场。

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。

常用C语言标准库函数

常用C语言标准库函数

常用C语言标准库函数C语言编译系统提供了众多的预定义库函数和宏。

用户在编写程序时,可以直接调用这些库函数和宏。

这里选择了初学者常用的一些库函数,简单介绍了各函数的用法和所在的头文件。

1.测试函数Isalnum原型:int isalnum(int c)功能:测试参数c是否为字母或数字:是则返回非零;否则返回零头文件:ctype.hIsapha原型:int isapha(int c)功能:测试参数c是否为字母:是则返回非零;否则返回零头文件:ctype.hIsascii原型:int isascii(int c)功能:测试参数c是否为ASCII码(0x00~0x7F):是则返回非零;否则返回零头文件:ctype.hIscntrl原型:int iscntrl(int c)功能:测试参数c是否为控制字符(0x00~0x1F、0x7F):是则返回非零;否则返回零头文件:ctype.hIsdigit原型:int isdigit(int c)功能:测试参数c是否为数字:是则返回非零;否则返回零。

头文件:ctype.hIsgraph原型:int isgraph(int c)功能:测试参数c是否为可打印字符(0x21~0x7E):是则返回非零;否则返回零头文件:ctype.hIslower原型:int islower(int c)功能:测试参数c是否为小写字母:是则返回非零;否则返回零头文件:ctype.hIsprint原型:int isprint(int c)功能:测试参数c是否为可打印字符(含空格符0x20~0x7E):是则返回非零;否则返回零头文件:ctype.hIspunct原型:int ispunct(int c)功能:测试参数c是否为标点符号:是则返回非零;否则返回零头文件:ctype.hIsupper原型:int isupper(inr c)功能:测试参数c是否为大写字母:是则返回非零;否则返回零Isxdigit原型:int isxdigit(int c)功能:测试参数c是否为十六进制数:是则返回非零;否则返回零2.数学函数abs原型:int abs(int i)功能:返回整数型参数i的绝对值头文件:stdlib.h,math.hacos原型:double acos(double x)功能:返回双精度参数x的反余弦三角函数值头文件:math.hasin原型:double asin(double x)功能:返回双精度参数x的反正弦三角函数值头文件:math.hatan原型:double atan(double x)功能:返回双精度参数的反正切三角函数值头文件:math.hatan2原型:double atan2(double y,double x)功能:返回双精度参数y和x由式y/x所计算的反正切三角函数值头文件:math.hcabs原型:double cabs(struct complex znum)功能:返回一个双精度数,为计算出复数znum的绝对值。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
ISHL(n,s)
对n向左(s为正)或向右(s为负)移动s位(逻辑移位)。n:I,s:I,结果类型同n
NOT(n)*
对n进行按位逻辑“非”运算。n:I,结果类型同n
表8数组运算、查询和处理函数
函数名
说明
ALL(m[,d])*
判定逻辑数组m各元素是否都为“真”。m;L-A,d:I,结果:L(缺省d)或L-A(d=维)
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取值弧度,结果类型同x
COSD(x)*
求x的余弦cos(x)。x:R,x取值度,结果类型同x
FLOOR(x)*
求小于等于x的最大整数。x:R,结果:I
IFIX(x)*
将x转换为整数(取整)。x:R,结果:I
IMAG(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,…中最大值。xI为任意类型,结果类型同xI
MAX1(x1,x2,x3,…)*
求x1,x2,x3,…中最大值(取整)。xI:R,结果:I
MIN(x1,x2,x3,…)*
求x1,x2,x3,…中最小值。xI为任意类型,结果类型同xI
MIN1(x1,x2,x3,…)*
SCAN(s,st[,b])
求串st中任一字符在串s中的位置。s:CH(*),ss:CH(*),b:L,结果:I
TRIM(s)*
求字符串s去掉首尾部空格后的字符数。s:CH(*),结果:CH(*)
VERIFY(s,st[,b])
求不在串st中字符在s中位置。s:CH(*),ss:CH(*),b:L,结果:I。b为真右起
将整数n二进制表示右起第p位置1。n:I,p:+I,p值域:0~64结果类型同n
IEOR(m,n)*
对m和n进行按位逻辑“异或”运算。m:I,n:I,结果类型同m
IOR(m,n)*
对m和n进行按位逻辑“或”运算。m:I,n:I,结果类型同m
ISHA(n,s)*
对n向左(s为正)或向右(s为负)移动s位(算术移位)。n:I,s:I,结果类型同n
ALLOCATED(a)*
判定动态数组a是否分配存储空间。a:A,结果:L。分配:.TRUE.,未分配.FALSE.
ANY(m[,d])*
判定逻辑数组m是否有一元素为“真”。m;L-A,d:I,结果:L(缺省d)或L-A(d=维)
SCALE(x,I)*
求x乘以2i。x:R,i:I,结果类型同x
SET_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)
注:指数函数名、平方根函数名、对数函数名前有C、D的函数为复数、双精度型函数。
表4参数查询函数
函数名
说明
ALLOCATED(a)*
判定动态数组a是否分配内存。a:A,结果:L,分配:.TRUE.,未分配:.FALSE.
ASSOCIATED(p[,t])*
判定指针p是否指向目标t。p:P,t:AT,结果:L,指向:.TRUE.,未指向:.FALSE.
LEN_TRIM(s)*
求字符串s去掉尾部空格后的字符数。s:CH(*),结果:I
LGE(s1,s2)*
按ASCII码值判定字符串s1大于等于字符串s2。s1:CH(*),s1:CH(*),结果:L
LGT(s1,s2)*
按ASCII码值判定字符串s1大于字符串s2。s1:CH(*),s1:CH(*),结果:L
IACHAR(c)*
将字符c转换为对应的ASCII码。c:CH(1),结果:I
ICHAR(c)*
将字符c转换为对应的ASCII码。c:CH(1),结果:I
INDEX(s,ss[,b])*
求子串ss在串s中起始位置。s:CH(*),ss:CH(*),b:L,结果:I。b为真从右起
LEN(s)*
求字符串s的长度。s:CH(*),结果:I
求x1,x2,x3…中最小值(取整)。xI:R,结果:I
MOD(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])*
ISHC(n,s)*
对n向左(s为正)或向右(s为负)移动s位(循环移位)。n:I,s:I,结果类型同n
ISHFT(n,s)*
对n向左(s为正)或向右(s为负)移动s位(逻辑移位)。n:I,s:I,结果类型同n
ISHFTC(n,s[,size])
对n最右边size位向左(s为正)或向右(s为负)移动s位(循环移位)
TAN(x)*
求x的正切tg(x)。x:R,x取值弧度,结果类型同x
TAND(x)*
求x的正切tg(x)。x:R,x取值度,结果类型同x
TANH(x)
求x的双曲正切th(x)。x:R,结果类型同x
注:三角函数名前有C、D的函数为复数、双精度型函数。
表3指数、平方根和对数函数
函数名
说明
ALOG(x)
求x的自然对数ln(x)。x:R(4),结果:R(4)
表1数值和类型转换函数
函数名
说明
ABS(x)*
求x的绝对值∣x∣。x:I、R,结果类型同x; x:C,结果:R
AIMAG(x)
求x的实部。x:C,结果:R
AINT(x[,kind])*
对x取整,并转换为实数(kind)。x:R, kind:I,结果:R(kind)
AMAX0(x1,x2,x3,…)*
求x1,x2,x3,…中最大值。xI:I,结果:R
AMIN0(x1,x2,x3,…)*
求x1,x2,x3,…中最小值。xI:I,结果:R
ANINT(x[,kind])*
对x四舍五入取整,并转换为实数(kind)。x:R, kind:I,结果:R(kind)
CEILING(x)*
求大于等于x的最小整数。x:R,结果:I
KIND(x)*
查询x的kind参数值。x:I、R、C、CH、L,结果:I
MAXEXPONENT(x)*
查询x的最大正指数值。x:R,结果:I(4)
MINEXPONENT(x)*
查询x的最大负指数值。x:R,结果:I(4)
PRECISION(x)*
查询x类型有效数字位数。x:R、C,结果:I(4)
(x)
将整数n二进制表示右起第p位值取反。n:I,p:+I,p值域:0~64结果类型同n
IBCLR(n,p)
将整数n二进制表示右起第p位置0。n:I,p:+I,p值域:0~64结果类型同n
IBITS(i,p,l)
从整数n二进制表示右起第p位开始取l位。n:I,p:+I,l:+I,结果类型同n
IBSET(n,p)
ADJUSTL(string)*
将字符串string左对齐,即去掉左端空格。string:CH(*),结果类型同string
ADJUSTR(string)*
将字符串string右对齐,即去掉右端空格。string:CH(*),结果类型同string
CHAR(n)*
将ASCII码n转换为对应字符。n:I,n值域:0~255,结果:CH(1)
DIGITS(x)
查询x的机内编码数值部分二进制位数(除符号位和指数位)。x:I、R,结果:I
EPSILON(x)*
查询x类型可表示的最小正实数。x:R,结果类型同x。最小正实数:1.1920929E-07
HUGE(x)*
查询x类型可表示的最大数。x:I、R,结果类型同x
ILEN(x)
查询x的反码值。x:I,结果类型同x
LLE(s1,s2)*
按ASCII码值判定字符串s1小于等于字符串s2。s1:CH(*),s1:CH(*),结果:L
LLT(s1,s2)*
按ASCII码值判定字符串s1小于字符串s2。s1:CH(*),s1:CH(*),结果:L
REPEAT(s,n)*
求字符串s重复n次的新字符串。s:CH(*),n:I,结果:CH(*)
表7二进制位操作函数
函数名
说明
BIT_SIZE(n)*
求n类型整数的最大二进制位数。n:I,结果类型同n
BTEST(n,p)
判定整数n的二进制表示右起第p位是否为1。n:I,p:+I,p值域:0~64结果:L
IAND(m,n)*
对m和n进行按位逻辑“与”运算。m:I,n:I,结果类型同m
相关文档
最新文档