Data Types In Fortran

Data
Data are constants provided to a program for use in computation or processing or execution.
Type
Means the information determines the way in which it is represented and the operations which may be performed on it.
Declaration of Fortran variables
As we know computers have no mind. It is also called servant, means what we tell to do, it does in very short period with no mistake. If it shows error that means something you have done wrong. Declaration of Fortran variables, means how the Fortran compiler will understand that something has been written, is variable or not.
In Fortran language there are six data types which are:
1) Integer Data type
An integer data type represent whole numbers and is always an exact representation of an integer value. It may assume a positive, negative, or zero value. It may assume only an integral value.
Integer variable
Rule
A Fortran integer variable name is any combination of one to six letters: I, J, K, L, M, or N. The name must not contain any character other than letters or digits. Means the first letter must start with one of these six letters.
Example:
MIN5
INTGR
The range of numbers covered by the integer type depends upon the system being used. For IBM PCs and 32 bit work stations the range is+-2147483647. One bit is used for sign and 31 bit for magnitude.
Declaration of integer variables
We have seen above about the integer variables. Now we will see how the computer understand, weather the given data is integer variable or not. It is only possible when a well defined data will be given to the computer memory i.e. to the compiler. By the following declaration integer variables are used in Fortran 77 programming language:
Declaration of integer variable is:
INTEGER list.
Where list is name of variables that has been specified as INTEGER type. This means now the computer will understand the above data as integer variable.
Example:
INTEGER KARA, MASS, IOTA
(no comma allowed after INTEGER but each variables should be separated by a comma).
2) Real Data type
Numbers, which may have fractional parts, stored using a floating-point representation with limited precision.
Real variable
Rule
A Fortran variable name is any combination of one to six letters or digits. The first character in the name must be one of the following letters, A, B, C, D, E, F, G, H, O, P, Q, R, S, T, U, V, W, X, Y, Z. The name must not contain any character other than letters or digits.
Example:
ALPHA
BITA
THETA
Declaration of real variable
REAL list
Where list is the name of variables that has been specified as REAL type.
Example:
REAL INTRS, MASS, DIST
(no comma is allowed after real but name of variables must be separated by comma)
3) Double precision Data type
Similar to real but with greater precision or both constants and variables having precision twice that of the normal real data types.
Double Precision constants
These are real constants and are coded in the exponential form with a letter E.
Example:
13.34567E+07.The maximum magnitude of a double precision constant varies from computer to computer.
Double Precision variables
A string of up to six letters or digits with first character a letter and declared as DOUBLE PRECISION. These are real variables which occupy double the memory than the single precision variables. A real number with mantissa length double that of a real constant. It occupy double the memory than the single precision variables.
Declaration of double precision variables
General form of declaration of double precision variables are:
DOUBLE PRECISION list
Here DOUBLE PRECISION are keywords and list shows variable names and variable names should be separated by comma.
Example:
DOUBLE PRECISION A, B, J
Here A, B and J are declared as double precision mode. (no comma allowed after DOUBLE PRECISIONbut each variables should be separated by a comma).
4) Complex Data type
Complex quantity consists of a real and imaginary part: a + ib; here a and b both are real. If a and b are real constants, then a + ib will be a complex constant. If a and b are real variables, then a + ib will be a complex variable. Complex numbers: stored as an ordered pair of real numbers.
(The first four types integer, real, double precision and complex all are related to numerical information and thus known as arithmetic data types).
Complex
a string of up to six letters or digits with first character a letter and declared as COMPLEX.
Declaration of Complex variables
General form of declaration of complex variables are:
COMPLEX list
Here COMPLEX is the keywords and list is the variable names which should be separated by a comma.
Example:
COMPLEX P, C1, C2
Here P, C1, C2 are complex variable names.
5) Logical Data type
If the result comes in yes or no or you can say if tells about decision then result can be categorized under Logical data type.
i.e. One which is either true or false.
Logical constants
These can only have one of two values:
.TRUE.
.FALSE.
Note: The dots enclosing the letters are required.
Declaration of logical variables
LOGICAL list
where LOGICAL is a keyword and list is names of variables.
Example:
LOGICAL P, PP, PPP
Here P, PP, PPP has been declared as logical and their values may be true or false.
6) Character Data type
This type of data are also of non-numeric in which string of characters of fixed length.
Character variables: Character variables are those which have character values.
Declaration of character variables
The general form of character variables declaration is:
CHARACTER [*1],v1[*11],v2[*12],…………
where *1, *11, *12,…….. are unsigned integer constants, variables or expression Here 11, 12 are length specifiers and indicate the length of the character variables. When the length specifier 1 is used and no other specifier is indicated, this means that all variables v1, v2, v3 ……. are of length 1 characters.