The Integer statement is used to declare the length and attributes of variables and functions of the type integer. This means that any variable declared with the integer statement has to have a whole number assigned to it. Integer variables will not support any number that contains decimal digits.
The first thing that you should realize about the INTEGER statement is that you must use this statement to declare any integer variables if you use the implicit none statement in your program. An illustration of this use can be seen below.
program test1 implicit none integer i,ldata,values(100)
If the IMPLICIT NONE statement is not used above, the compiler would automatically assume that any variable that began with an i, j, k, l, m or n would be an integer type.
Another important thing to remember about this statement is that it supports numerous attribute specifiers so that you can create integer variables for different uses inside of your program. For instance to create a parameter or a pointer array of type integer you would type lines of code similar to the following:
Integer, parameter :: nmax = 450 Integer, pointer,dimension(5,5) :: p1
Finally, a very powerful feature of the integer expression is that you have some control of the number of bytes that are used to represent an integer constant. This allows you to control the range of numbers that can be represented with an integer variable. To exercise this control, the use of the KIND specifier and the selected_int_kind function is required. Most machines will store integers using 32 bits of memory. This allows a programmer to represent numbers roughly as low as -2.1 billion all the way up to around 2.1 billion. If for sum reason you needed a larger range in numbers, like say up to one trillion, this can be accomplished in the following way.
integer, parameter :: int12 = selected_int_kind(12) integer(kind=int12) n,m,k
Take note that what gets stored in the variable int12 above is a integer value that corresponds to the bit configuration for the needed range. The bit configuration is then assigned to any variables that are declared in a integer statement that has kind=12 in it. However, for this particular example, be aware that not all computers support use of more than 32 bits to represent an integer. You should check the value of "int12" early in your program. A value of -1 indicates that the requested range of integer values is not available, and should result in an error message perhaps termination of the program.
Allocatable , Dimension, External, Intent, Intrinsic, Optional, Parameter, Pointer, Private, Public, Save, Target
For the use of selected_int_kind: lecture twenty one
examples of use: aorder.f and dual-errors.f
Written by Jason Wehr: email@example.com and Maintained by John Mahaffy : firstname.lastname@example.org