Документ взят из кэша поисковой машины. Адрес оригинального документа : http://crydee.sai.msu.ru/f90/c2.html
Дата изменения: Sat Feb 17 17:40:06 1996
Дата индексирования: Mon Oct 1 19:41:02 2012
Кодировка:

Поисковые слова: п п п п п п п п п п п п п п п п п п п
Specifications

2. Specifications

My favorite statement in Fortran 90 is IMPLICIT NONE, which means that the implicit declaration is no longer used. This statement has been available in some implementations of Fortran 77. The use of that statement means that the probability of errors because of wrongly spelt variable names is drastically reduced. The first difference regarding specification of variables is that these can now be put together in one statement for each variable. Using Fortran 77 you can declare, for example, as follows
     REAL A, B, C
     PARAMETER (A = 3.141592654)
     DIMENSION B(3)
     DATA B /1.0, 2.0, 3.0 /
     DIMENSION C(100)
     DATA C /100*0.0/
that is one variable can occur in several lines. Using Fortran 90 you can instead write
     REAL, PARAMETER        :: A = 3.141592654
     REAL, DIMENSION(1:3)   :: B = (/1.0, 2.0, 3.0 /)
     REAL, DIMENSION(1:100) :: C = (/ ( 0.0, I = 1, 100 ) /)
The difference is not so large here but it's much larger in more complicated examples with many variables, especially since in Fortran 90 you have access to more properties. In the last example an extra parenthesis ( ) is required. I am grateful to Kristof Richmond for pointing that out to me.

The last example can also be generalized to assign different values to different parts of the vector.

 REAL, DIMENSION(5) :: D = (/ (4.0, I = 1, 3) , (17.0, I = 4, 5) /)
Since there are variables of different types there is an intrinsic function that shows the exact subtype of the variable used. This function is called KIND(x). This function can also be used for particular types of subtypes or kinds:
    KIND (0)                   integer
    KIND (0.0)                 floating point number
    KIND (.FALSE.)             logical variable
    KIND ("A")                 string of characters
There is an intrinsic function SELECTED_REAL_KIND, which returns the kind of the type REAL that has a representation with (at least) the precision and the exponential range requested. For example, the function SELECTED_REAL_KIND (8,70) is that kind of REAL that has at least 8 decimal digits accuracy and permits an exponent between 10**-70 and 10**70. The corresponding function for integers is called SELECTED_INT_KIND and of course has only one argument. With the choice SELECTED_INT_KIND (5) all integers between (but not including the limits) -100 000 and +100 000 are permitted. The kind of a type can be given a name.
     INTEGER,  PARAMETER    :: K5 = SELECTED_INT_KIND(5)
This kind of integers can be used in constants according to the following line
     -12345_K5
     +1_K5
     2_K5 
which is a rather unnatural specification, after the value we have to give an underscore _ followed by the name of the kind.

Use of variables of the new integer type can be declared in a nicer way

     INTEGER (KIND=K5)      :: IVAR
The corresponding is true for floating-point variables, if we first introduce a high-precision kind LONG with
 INTEGER, PARAMETER     :: LONG = SELECTED_REAL_KIND(15,99)
then we get the floating-point kind with at least 15 decimal digits accuracy and with an exponent range from 10**-99 to 10**+99. The corresponding constants are obtained as
     2.6_LONG
     12.34567890123456E30_LONG
and variables are declared with
     REAL (KIND=LONG)       :: LASSE
The old type conversions INT, REAL and CMPLX have been extended with the functions
     INT(X, KIND = K5)
which converts a floating-point number X to an integer of the kind K5, if Z is a complex number with
     REAL(Z, KIND(Z))
you get it converted to a floating-point number of the real type and of the same kind of Z (that is of course the real part of Z).

Double precision is not included in the new Fortran 90 in any other way than in the "old" Fortran 77, but it is assumed that the compiler supports the double or quadruple precision that may be available in the hardware. You can then define a suitable kind of the REAL, named DP or QP. You can of course use the old concept of DOUBLE PRECISION.

The reason for this rather cumbersome way is that it is not desirable to have too many compulsory precisions (for example single, double, quadruple, perhaps for both the cases REAL and COMPLEX) and also that the old concept DOUBLE PRECISION did not give a specified machine accuracy. Now you can relatively easily specify both which precision and which range of exponent you wish to use. Additional information about the kind is given in Appendix 6, where the different data types and their normal kinds on both DEC and SUN and also on the IBM PC is given in the NAG system for Fortran 90 and in the Cray system for Fortran 90.

Exercises

(2.1) What does the specification LOGIC ALL mean?
Solution.

(2.2) Specify a constant K with the value 0.75.
Solution.

(2.3) Specify an integer matrix PELLE with 3 rows and 4 columns.
Solution.

(2.4) Specify a floating-point number which corresponds to the double precision on an IBM and a single precision on Cray.
Solution.

(2.5) Specify some variables of the type above.
Solution.

(2.6) Specify some constants of the type above.
Solution.

(2.7) Is the following specification correct?

     REAL DIMENSION(1:3,2:3) :: AA
Solution.

(2.8) Is the following specification correct?

     REAL REAL
Solution.

(2.9) Is the following specification correct?

     COMMON :: A
Solution.


Last modified: 3 July 1995
boein@nsc.liu.se