fortran 所固有数据类型及运算符

Intrinsic Data Type
integer,real complex,logical,character这些都是fortran所内建(built-in)的数据类型

Integer Type
如: 23 0 1341324 42_short 42_long,其中 "short", "long" 指示着(designate)该整数的 参数类型( kind parameter)

Real Type
实数常量有两种形式(positional form、exponential form)。假设double和quad为代表着real kind的整型常量。下面一行则为positional form的实型常量。
13.5 0.1234 123.78909 00.30_double 3.0 0.1234789_quad
指数形式的实数由positional的实数、字母e 、有符号整数及可选的下划线(underscore)和类型参数(kind parameter)组成。字母e读作10的几次方(times 10 to the power)
例如 23.4e5 represents 23.4 times 10 to the power 5
    1.0e9_double 表示10亿,参数类型为double
    1.0e-3表示 1/1000    

Complex Type
复数由两部分组成:real part 和 imaginary part。在fortran中,复数的形式是这样的
(1.0, -1.0)  (-1.0, 3.1e-27) (3.14_double, -7.0_double)

Operators
+-*/ 加减乘除,还有一个求幂运算符(**)
<(小于less than) <=(小于等于less than or equal to) ==(等于equal to)
/= (非等于 not equal to) >= (大于或等于greater than or equal to) >(大于 greater than)

Logical Type
逻辑类型的常量为 .true. .false.,可能也会跟着一个下划线和类型参数
逻辑运算符有 .not. .and. .or. .eqv. .neqv.
请注意 .false. .eqv. .false. 的结果为真

Character Type
倘若在字符串中出现引号,就以两个引号来表示,两引号中无其他任何字符。如果字符串常量的类型没有指定,则在该字符串之前有一个表示类型的常量。例子如下
iso_10646_"Don't tread on me."
"He said, ""Don't tread on me."""
只有一个运算符产生的结果是字符串:concatenation,即 //
“wenbo" // "yiyun" 的结果是“wenboyiyun"

Parameters/Named Constants
一个参数是一个具名常量。每个参数必须在 type statement 中进行声明。
type statement 出现在 program statement 与 程序的可执行部分之间。
每个参数声明由以下组成:一个指示类型的关键字,后跟一个逗号,再后跟一个关键字 parameter,再后跟两个冒号(two colons),在双冒号的右边则是赋值语句
参数的值在声明时就被指定,而且在程序和执行过程中不可以被改变。具名常量(named constants)也由此而来。

program parameter_example
   integer, parameter :: &
      number_of_states = 50, &
      number_of_senators_per_state = 2, &
      number_of_senators = &
      number_of_states * number_of_senators_per_state
   print *, &
      "There are", number_of_states, &
      "states in the United States of America."
   print *, &
      "From this, we can calculate that there are"
   print *, number_of_senators, &
      "senators in the United States senate."
end program parameter_example


ampersand(&)表示延续到下一行。
使用parameters(named constants)的好处:不经意间更改具名常量时,计算机会提供诊断信息;具名常量而非直接值,增加程序代码的可读性,增加程序的可改性;编译器知道具名常量的值,所以其可以被用来指示数组长度或实型变量的kind
注意: Number_of_States 和 number_of_states 是同一个变量。

Kind Parameters
每一个固有的数据类型都有一个参数,被称做种类参数。  A kind parameter is intended to designate a machine representation for a particular
data type。Note that the value of the kind parameter is not usually the number of decimal digits of precision or range; on many systems, it is the number of bytes used to represent the value.
种类参数是整数,其值依赖于处理器
固有函数selected_int_kind和selected_real_kind就是用来选取合适的种类参数的。
1.0_short + 3.0_long 的值是 4.0_long


你可能感兴趣的:(fortran)