[ Pobierz całość w formacie PDF ]

adjustments made to maintain alignment.
You can initialize a field that is a variable, array, substring, substructure, or
union.
Statements 233
4
Examples
Example 1: A structure of five fields:
STRUCTURE /PRODUCT/
INTEGER*4 ID/ 99 /
CHARACTER*16 NAME
CHARACTER*8 MODEL/ 'Z' /
REAL*4 COST
REAL*4 PRICE
END STRUCTURE
RECORD /PRODUCT/ CURRENT, PRIOR, NEXT, LINE(10)
In the above example, a structure named PRODUCT is defined to consist of the
fields ID, NAME, MODEL, COST, and PRICE. Each of the three variables,
CURRENT,PRIOR, andNEXT, is a record which has thePRODUCT structure, and
LINE is an array of 10 such records. Every such record has itsID initially set to
99, and its MODEL initially set to Z.
Example 2: A structure of two fields:
STRUCTURE /VARLENSTR/
INTEGER*4 NBYTES
CHARACTER A*25
END STRUCTURE
RECORD /VARLENSTR/ VLS
VLS.NBYTES = 0
The above structure matches the one used by the pc Pascal compiler from
SunSoft for varying length strings. The 25 is arbitrary.
234 FORTRAN 77 Reference Manual
4
4.67 SUBROUTINE
The SUBROUTINE statement identifies a named program unit as a subroutine,
and specifies arguments for it.
Syntax
SUBROUTINE sub [ ( [ fd [, fd ] & ])]
sub Name of subroutine subprogram
d Variable name, array name, record name, or dummy procedure name, an
asterisk, or an ampersand
Description
A subroutine subprogram must have a SUBROUTINE statement as the first
statement. A subroutine can have any other statements, except aBLOCK DATA,
FUNCTION, PROGRAM, or another SUBROUTINE statement.
sub is the name of a subroutine and is a global name, and must not be the same
as any other global name such as a common block name or a function name.
Nor can it be the same as any local name in the same subroutine.
d is the dummy argument, and multiple dummy arguments are separated by
commas. d can be one of the following:
" Variable name
" Array name
" Dummy procedure name
" Record name
" Asterisk (*) or an ampersand (&)
The dummy arguments are local to the subroutine and must not appear in any
of the following statements, except as a common block name:
" EQUIVALENCE
" PARAMETER
" SAVE
" STATIC
" AUTOMATIC
" INTRINSIC
Statements 235
4
" DATA
" COMMON
The actual arguments in the CALL statement that references a subroutine must
agree with the corresponding formal arguments in theSUBROUTINE statement,
in order, number, and type. An asterisk (or an ampersand) in the formal
argument list denotes an alternate return label. A RETURN statement in this
procedure can specify the ordinal number of the alternate return to be taken.
Examples
Example 1: A variable and array as parameters:
SUBROUTINE SHR ( A, B )
CHARACTER A*8
REAL B(10,10)
&
RETURN
END
Example 2: Standard alternate returns:
In this example, theRETURN 1 PROGRAM TESTALT
statement refers to the first
CALL RANK ( N, *8, *9 )
alternate return label (first*).
WRITE (*,*) 'OK - Normal Return [n=0]'
TheRETURN 2 statement refers
STOP
to the second alternate return
8 WRITE (*,*) 'Minor - 1st alternate return [n=1]'
label (second *) specified in the
STOP
SUBROUTINE statement.
9 WRITE (*,*) 'Major - 2nd alternate return [n=2]'
END
SUBROUTINE RANK ( N, *, * )
IF ( N .EQ. 0 ) RETURN
IF ( N .EQ. 1 ) RETURN 1
RETURN 2
END
Example 3: Nonstandard alternate returns:
CALL SUB(& , &label, & )
236 FORTRAN 77 Reference Manual
4
is treated as:
CALL SUB(& , *label, & )
4.68 TYPE
The TYPE statement writes to stdout.
Syntax
TYPE f [, iolist ]
or:
TYPE grname
f Format identifier
iolist List of output variables
grname Name of the namelist group
Description
The TYPE statement is provided for compatibility with older versions of
FORTRAN 77, and is equivalent to the following:
" PRINT f [, iolist ]
" PRINT grname
" WRITE(*, f ) [ iolist ]
" WRITE(*,grname )
Examples
Example 1: Formatted output:
INTEGER V(5)
TYPE 1, V
1 FORMAT( 5 I3 )
Statements 237
4
Example 2: Namelist output:
CHARACTER S*16
INTEGER N
NAMELIST /G/ N, S
&
TYPE G
4.69 The Type Statement
The type statement specifies the data type of items in the list, optionally
specifies array dimensions, and initializes with values.
Syntax
type v [/ clist /] [,v [/ clist /]&
v Variable name, array name, array declarator, symbolic name of a constant,
statement function or function subprogram name
clist List of constants. There are more details about clist in the section on the
DATA statement.
type can be preceded by either AUTOMATIC or STATIC.
type can be one of the following type specifiers:
BYTE INTEGER
CHARACTER INTEGER*2
CHARACTER*n INTEGER*4
CHARACTER*(*) INTEGER*8
COMPLEX LOGICAL
COMPLEX*8 LOGICAL*1
COMPLEX*16 LOGICAL*2
COMPLEX*32 (SPARC only) LOGICAL*4
DOUBLE COMPLEX LOGICAL*8
DOUBLE PRECISION REAL
REAL*4
REAL*8
REAL*16 (SPARC only)
238 FORTRAN 77 Reference Manual
4
n, as in CHARACTER*n, must be greater than 0.
Description
A type statement can be used to:
" Confirm or to override the type established by default or by the IMPLICIT
statement
" Specify dimension information for an array, or confirm the type of an
intrinsic function
" Override the length by one of the acceptable lengths for that data type
A type statement can assign initial values to variables, arrays, or record fields
by specifying a list of constants (clist) as in a DATA statement.
The general form of a type statement is:
type VariableName / constant / &
or:
type ArrayName / constant, & /
or:
type ArrayName / r*constant /
where r is a repeat factor.
Example: Various type statements:
CHARACTER LABEL*12 / 'Standard' /
COMPLEX STRESSPT / ( 0.0, 1.0 ) /
INTEGER COUNT / 99 /, Z / 1 /
REAL PRICE / 0.0 /, COST / 0.0 /
REAL LIST(8) / 0.0, 6*1.0, 0.0 /
When you initialize a data type, remember the following restrictions:
" For a simple variable, there must be exactly one constant.
" If any element of an array is initialized, all must be initialized.
Statements 239
4
" You can use an integer as a repeat factor, followed by an asterisk (*), followed
by a constant. In the example above, six values of 1.0 are stored into array [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • elpos.htw.pl