Copyright (c) 1994 J. Adams, W. Brainerd, J. Martin, and B. Smith. All rights reserved. This file may not be copied without permission of the authors.
The CASE construct may be used to select for execution at most one of the blocks in the construct. Selection is based on a scalar value of type integer, character, or logical. A CASE construct may be named. It permits the following control flow:
! Character example ! Integer example
SELECT CASE (STYLE) RANGES: &
CASE DEFAULT SELECT CASE (ITEM)
CALL SOLID (X1,Y1,X2,Y2) CASE (1:7, 52:81) RANGES
CASE ("DOTS") BIN1 = BIN1 + 1.0
CALL DOTS (X1,Y1,X2,Y2) CASE (8:32, 51, 82) RANGES
CASE ("DASHES") BIN2 = BIN2 + 1.0
CALL DASHES (X1,Y1,X2,Y2) CASE (33:50, 83: ) RANGES
END SELECT BIN3 = BIN3 + 1.0
CASE DEFAULT RANGES
! Logical Example WRITE (*, "(`BAD ITEM')")
LIMIT: SELECT CASE (X > X_MAX) END SELECT RANGES
CASE (.TRUE.)
Y = X * 0.9
CASE (.FALSE.)
Y = 1.0 / X
END SELECT LIMIT
Tip: For program clarity, use an IF-THEN-ELSE construct rather than a logical CASE construct.
Expressions: Initialization
IF Construct and Statement
ISO 1539 : 1991, Fortran Standard, 8.1.3
Fortran 90 Handbook, 8.4
Programmer's Guide to Fortran 90, 2.4
A CASE construct is:
[ case-construct-name : ] SELECT CASE ( case-expression )
[ CASE ( case-value-range-list ) [ case-construct-name ]
block ]...
[ CASE DEFAULT [ case-construct-name ]
block ]
END SELECT [ case-construct-name ]
A case-value-range is one of:
case-value [ : case-value ]
case-value :
: case-value