## Specification StatementsFortran, as most other higher level programming languages, supports several different data types to make data manipulation easier. The most frequently used data types are integers and real single precision floating point numbers. Other data types are real double precision floating numbers, complex numbers, characters, character strings and logical data. In a Fortran statement, data can appear either as a literal (e.g., 4.55, 16, -5.4e-4) or as a variable name which identifies a location in memory to store the data. The variable name in Fortran must begin with a letter and the length of the name is 6 characters long. Capital letters are treated the same way as lower-case letters, i.e., AAA is the same variable as aaa. There are some compilers which allow longer variable names but most older compilers do not. Some compilers allow long variable names but recognize the first 6 characters only, so the two variable names, number14 and number15, point to the same memory location. Therefore, to be safe, use shorter variable names. The basic Fortran types of integer and real single precision numbers do not have to be specified and there is a default which all Fortran programmers should memorize. All variable names which begins which the letters A-H and O-Z represent, by default, Single Precision Real Numbers. All variable names which begins with I, J, K, L, M and N represent, by default, Integers (whole numbers). All other types of variables have to defined at the beginning of the program module (main program or subprograms) using specification statements. There is no particular order for these specification statements, but they must appear before ANY executable statements. ## INTEGERSInteger literals in Fortran are written as whole numbers. For example, 124 -448 0 32767 2147483647 -9874 In particular, the values, 32767 and 2147483647, are of interest because they are the largest value for a 2-byte integer and a 4-byte integer, respectively. To define an integer variable in a Fortran program unit, use the following statements: integer*2 short1,short2 integer*4 long1,long2 integer reg1,reg2 implicit integer q The "integer*2" statement specifies the variable names to be short 2-byte integers which has a range from -32768 to 32767. The "integer*4" statement specifies the variable names to be long 4-byte integers which covers the range from -2147483648 to 2147483647. The "integer" statement specifies the standard integer type for the machine in which the compiler operates. For SUN UNIX system, it is integer*4; for most of the older minicomputer, it is integer*2. The "implicit integer q" statement tells the compiler that all variable names which begin with a "q" is made an integer. It would override the standard defaults. As required for all Fortran statements, the leading word, "integer," must start on column 7 or later. ## SINGLE PRECISION REAL NUMBERSSingle Precision Real (floating point numbers) literals in Fortran are written in different variations as follows: 5.229 -4.78 0. 1.00 3.2767e+2 +3.141593 1.89e-14 -0.65e-2 The number of significant digits for Single Precision Literals is 7. Therefore, it is not necessary to write more than 7 digits of accuracy, the pre-processor of the compiler would round it off appropriately. The letter "e" embedded in some of the literals in the above examples represents the exponent of 10. For example, -0.65e-2 means -0.65 times the -2 power of 10; it is equivalent to 0.0065. To define a Single Precision Real variable in a Fortran program unit, use the following statements: real*4 a,b,c real g,h implicit real m The "real*4" statement specifies the variable names to be single precision 4-byte real numbers which has 7 digits of accuracy and a magnitude range of 10 from -38 to +38. The "real" statement is the same as "real*4" statement in nearly all 32-bit computers. The "implicit real m" statement tells the compiler that all variable names which begin with an "m" is made a Single Precision variable. It would override the standard defaults. As required for all Fortran statements, the leading word, "real," must start on column 7 or later. ## DOUBLE PRECISION REAL NUMBERSDouble Precision Real (floating point numbers) literals in Fortran are written in different variations as follows: 3.1415926535d+0 -4.78d+6 1.0d+0 The number of significant digits for Double Precision Literals is 15. The letter "d" must be embedded in the literal, otherwise, the compiler's pre-processor would round it off to be a Single Precision literal. For example, 3.1415926535 would be read as 3.141593 while 3.1415926535d+0 would be stored with all the digits intact. The letter "d" for double precision numbers has the same meaning as "e" for single precision numbers. To define a Double Precision Real variable in a Fortran program unit, use the following statements: real*8 aa,bb,cc double precision gg,hh implicit real*8 k implicit double precision j The "real*8" statement specifies the variable names to be double precision 8-byte real numbers which has 15 digits of accuracy and a magnitude range of 10 from -308 to +308. The "double precision" statement is the same as "real*8" statement in nearly all 32-bit computers. The "implicit real*8 k" statement tells the compiler that all variable names which begin with an "k" is made a Double Precision variable. It would override the standard defaults. "implicit double precision j" woud do the same as "implicit real*8 j" for 32-bit computers. ## LOGICAL LITERALS AND VARIABLESLogical literals can be written in only two ways, they are: .true. .false. As expected, there are only two states to the Logical literal. To define a Logical variable in a Fortran program unit, use the statement: logical s implicit logical i The "logical" statement specifies the variable names to be true/false or Boolean variables. The "implicit logical i" statement tells the compiler that all variable names which begin with an "i" is made a logical variable. It would override the standard defaults. ## SINGLE PRECISION COMPLEX NUMBERSSingle Precision Complex literals in Fortran are written in different variations as follows: (5.229,-4.78) (0.0,1.0) (3.2767e+2,-0.65e-2) Complex literals are composed of two Single Precision numbers, one for the real part and another for the imaginary part. SO all the rules for Single Precision literals would apply. To define a Single Precision Complex variable in a Fortran program unit, use the following statements: complex*8 ca,cb,cc complex cg,ch implicit complex r The "complex*8" statement specifies the variable names to contain two single precision 4-byte numbers which has 7 digits of accuracy and a magnitude range of 10 from -38 to +38. The "complex" statement is the same as "complex*8" statement in nearly all 32-bit computers. The "implicit complex r" statement tells the compiler that all variable names which begin with an "r" is made a Single Precision complex variable. It would override the standard defaults. As required for all Fortran statements, the leading word, "complex," must start on column 7 or later. |