Intel fortran-80 Type Statement, Input Statements, Value Assignment Statement, Output Statements

Models: fortran-80

1 130
Download 130 pages 742 b
Page 10
Image 10
1.1.2 Type Statement

Introduction To FORTRAN

FORTRAN-SO

1.1.2 Type Statement

Every variable used in a FORTRAN program has a type - integer, real, logical, character, or Hollerith. The CHARACTER type statement says that the variable PNAME represents character data and may have up to 12 characters.

No type statement is needed for the other variables listed (AB, HITS, AVO). The FORTRAN variable-naming convention tells us implicitly that these variables are to be used to name real data. This convention is described later in section 2.2.2.1.

1.1.3 Input Statements

Following the CHARACTER statement in the example are two input statements. The first tells the program to read input data; the second describes the format of the input data.

The number 10 in the READ statement tells the program that the input format is found in statement 10. The rest of the statement lists the variables whose values will be specified by the person at the console. By default,thein,pu(is reaclfrOl11tbecori-

soleierlllinaL

The FORMAT statement (labeled statement 10) tells the program what kind of data to expect. 'A' indicates the first field of data is a string of alphanumeric characters having the length of PNAME, the player's name. '2(2X, F3.0)' is equivalent to

2X, F3.0, 2X, F3.0

and refers to the AB and HIT fields. '2X' indicates two blanks will be entered followed by a 3-digit floating-point (F) number whose decimal portion contains '0' digits. Clearly, no batter comes to the plate 79.3 times or has 22.8 hits.

One might ask at this point why we didn't specify these fields to be 'integer' data; that is,

2(2X,13}

The reason is that FORTRAN truncates the remainder when one integer is divided by another. Since AB ~ HITS, all averages would be '0' except for the rare player batting 1.000.

1.1.4 Value Assignment Statement

The actual batting average calculation is done by the next statement:

AVG = HITS/AB

This is one form of assignment statement, in which the variable' AVO' is assign- ed the value of the expression 'HITS/ AB.'

1.1.5 Output Statements

Following the calculation are two output lines. The first tells the program to write output data; the next describes the format of the output.

In the PRINT statement, the number 20 indicates that the output format is found in ~t~teI11e~t?O:'.flN~¥.E'~nd'AV9' are the items whose values are to be printed. lly

Qefa;tllt~.theoutpqtis~xi~t~n. ~qtheconsoJe.

1-2

Page 10
Image 10
Intel fortran-80 manual Type Statement, Input Statements, Value Assignment Statement, Output Statements, soleierlllinaL