A variable is represented by a symbolic name which is associated with a particular place in the memory of your computer. The value of the variable is the value currently stored in that location and this value can be changed by assigning a new value to the variable.
Prior to using a particular variable, you have to specify its data type or, for those of you
who are more rigorous, declare the variable. It means that you assign a specific standard
type to this variable, which in turn tells your computer to allocate a sufficient amount of space
for storage of this data. This declaration of variables occurs after the statement
function (the last two subprograms will be explained later) and
typically has the following form:
integer number, val real resultIn this example,
realare data types and
resultare symbolic names of three variables. It should be clear that the first two variables are declared to contain integral numbers, whereas the last one will store a real number. You can always assign a data type to more than one variable in one line, provided that the variables are separated by commas.
Fortran provides several standard data types which are frequently used in F77 codes. A very short
compilation of the most useful ones is given below. You can see that each variable occupies a
different space in the memory of your computer. For the beginning you will often use two data types,
real, the former of which is commonly used for counting loops and the
latter contains the values used in your calculations.
||1 bit||stores either logical 0 (
||1 byte||integral numbers from -128 to 127|
||4 bytes||integral numbers from to|
||4 bytes||real numbers approx. between and|
||8 bytes||real numbers approx. between and|
||2 4 bytes||two
||2 8 bytes||two
||1 byte||one alphanumeric character|
A common task is to declare an array which can store a vector (1N, N1), matrix (MN) or a higher-dimensional array (MNP). This can be done for any numerical data type by simply declaring:
integer vect(5) real mat(4,10), tmat(2,5,9)The variable
vectis a vector of 5 components of type
matrepresents a matrix of
realnumbers with 4 rows and 10 columns and
tmatis a three-dimensional array in which each element is of type
real. The elements of the lastly-mentioned array can be accessed accordingly, e.g.