• Aucun résultat trouvé

DATA CLASSIFICATIONS

Dans le document VS FORTRAN (Page 60-64)

VARIABLES

CONSTANTS

All the data you usa in your program-whether it's data you've retrieved from an external device or data your program develops internally-must be constants, orbe contained in var; abIes or arrays. Data·in any of these classifications can b~ any of the data types previously described. Data classifications are discussed in the following sections.

A

variable is a named unit of data, occupying a storage area.

The value of a variable can change during program execution.

The name of a variable can determine its data type, as described in "Predetermined Data Type Definition," or you can define its data type explicitly, as described in "Explicit Data Type Definition."

The value contained in a variable is always the current value stored there. Before you've assigned a value to a variable, its contents are undefined. You can initialize values using the DATA statement; alternatively, your first executable statement referring to it--for example, a READ statement or an assignment statement-can assign a value to it.

Reference documentation for variables is given in the VS FORTRAN Application Programming: language Reference manual.

A

constant is a data item in a program that has a fixed, unvarying value. You can refer to a constant by its value, or you can name the constant and use the name in all program references.

The constants you can use are:

Arithmetic (integer, real, or complex)-use arithmetic constants for arithmetic operations, and to initialize

integer, real, or complex variables, and as arguments for subroutines, and so forth.

Logical-use logical constants in logical expressions, and to initialize logical variables, and as arguments for subroutines, and'so forth.

Character--use character constants in character and relational expressions, and to initialize character

variables, and as arguments for subroutines, and so forth.

Hollerith-use Hollerith constants to initialize data items in a FORMAT statement.

IBM EXTENSION

L

t

teral (old FORTRAN only)-si mi lar in usage to character constants.

Hexadecimal-use hexadecimal constants to initialize items.

' - - - END OF IBM EXTENSION _ _ _ _ _ _ _ _ _ --...1

Defining Constants

by Value

You can use constants in your program by simply specifying their values. Fo~ example:

CIRC =2*PI*RAD 42 Va FORTRAN Application Programming: Guide

0' l

(\"J

'~'

o

or

where the value 2 represents an integer constant of that value, and where the value 2.0 represents a real constant of that value.

You can specify all types of constants in this way:

Arithmetic constantS--integer, real, or complex.

• Integer Constant--written as an optional sign followed by a string of digits. For example:

-12345 12345

• Real Constant--can take three forms:

1. Basic Real Constani--written as an optional sign, followed by an integer part (made up of digits), followed by a decimal point, followed by a fraction part (made up of digits). Either the integer or fraction part can be omitted. For example:

+123.45

·0.12345

2. Integer Constant With Real Exeonent--written as an integer constant followed by a real exponent in the form of a letter, followed by a 1- or 2-digit

integer constant. Optionally, the exponent can be -signed. For example:

+12345E+2

-12300D-03

E exponent (which occupies four storage positions and has the value +1,234,500; the precision is

approximately 7.2 decimal digits) D exponent (which occupies eight storage positions and has the value -12.3; the precision is approximately 16.8 decimal digits) IBM EXTENSION

12345Q03 Q exponent (which occupies 16 storage positions and has the value +12,345,000; the precision

is approximately 35 decimal digits)

ENO OF IBM EXTENSION

3. Basic Real Constant With Real Exponent--written as a basic real constant followed by a real exponent;

the real exponent is written as one of the letters 0, E, or Q, followed by a 1- or 2-digit integer constant. Optionally, the exponent can be signed.

For example:

0.12345E+2

0.123450-03

E exponent (which occupies four storage positions and has the value +12.345; the precision is approximately 7.2 decimal digits) D exponent (which occupies eight storage positions and has the value

Coding Your Program--Advanced Programming 43

+0.00012345; the preC1Slon is approximately 16.8 decimal digits) IBM EXTENSION

-1234.5Q03 Q exponent (which occupies 16 storage positions and has the value -1,234,500; the precision is approximately 35 decimal digits)

END OF IBM EXTENSION

Co~plex Constant--written as a left parenthesis, followed by a pair of integer constants or real constants separated by a comma, followed by a right parenthesis.

The first integer or real constant represents the real part of the complex number; the second integer or real constant represents the imaginary part of the complex number. The real and imaginary parts need not be of the same size; the smaller part is made the same size as the larger part. For example:

(123.45,-123.45E2) (has the value +123.45, -12345i;

both the real and imaginary parts have a length of 4)

IBM EXTENSION

(123.45,-123.4502) (has the value +123.45, -12345i;

the real part has a length of 4, the imaginary part a length of 8) (The real part (a real constant) is converted to a real constant of length 8.)

(12345,-123.45Q2) (has the value +12345, -12345i;

the real part has a length of 4, the imaginary part a length of 16) (The real part (an integer constant) is converted to a real constant of length 16.)

END OF IBM EXTENSION

Note: In these examples, the character i has the value of the square root of -1.

Logical- Constant--written as .TRUE. or .FALSE. in expressions. (In input/output statements you can use T or F as abbreviations.>

IBM EXTENSION

(In the DATA initialization statement, you can also use T or F as abbrev lat ions. )

~--- END OF IBM EXTENSION - - - ' For a logical item named COMP, you can specify, for example:

LOGICAL COMP COMP=.FAlSE.

This sets the logical item COMP to the value "false."

44 VS FORTRAK Application Programming: Guide

0)

C

II !

10

10"'"

" ,

Character Constant-l""ri tten as an apostrophe, followed by a string of characters, followed by an apostrophe. The

character string can contain any characters in the computer's character set. For example:

'PARAMETER

= ,

'THE ANS~JER IS:'

"'TWAS BRILLIG AND THE SLITHY TOVES'

Note: If you want to include an apostrophe within the character constant, you code two adjacent apostrophes, as shown in the last example, which is displayed as:

'TWAS BRIllIG AND THE SlITHY TOVES

Hollerith Constant-valid only in a FORMAT statement. It is written as an integer constant followed by the letter H, followed by a string of characters. The character string can contain any characters in the computer's character set.

For example:

FORMATCI3,11H

=

THE NORM)

FORMATC2D8.6, 1SH ARE THE 2 ANSWERS) IBM EXTENSION

In old FORTRAN, the literal constant performs functions similar to the current FORTRAN character constant, and the current Hollerith constant. (Reference documentatiori is given in the IBM System/360 and System/370 FORTRAN IV language manual.)

Hexadecimal Constant--written as the character Z, followed by a hexadecimal number, made up of the digits 0 through 9 and the letters A through F. You write a hexadecimal

constant as 2 hexadecimal digits for each byte.

You can use hexadecimal constants only in a DATA statement to initialize data items of all types except character.

REAL *4 TEMP

DATA TEMP/ZCIC2C3C4/

END OF J:BM EXTENSION _ _ _ _ _ _ _ _ _ - J Reference documentation for program constants is given in the VS FORTRAN Application Programming: language Reference manual.

Coding Your Program--Advanced Programming 45

Dans le document VS FORTRAN (Page 60-64)