Code Example Demonstrates Using a BLOCK DATA SubprogramLast reviewed: July 19, 1995Article ID: Q51496 |
The information in this article applies to:
SUMMARYA BLOCK DATA subprogram must appear at the beginning of the main program file, prior to the PROGRAM statement, or at the end of the file, after the END statement that closes the main program.
MORE INFORMATIONThe restrictions that apply to the placement of the BLOCK DATA statement in a source file are documented on page 123 of the Microsoft FORTRAN "Reference" manual for versions 5.0 and 5.1. The following code example demonstrates using the BLOCK DATA subprogram to initialize variables grouped in a named COMMON block.
Sample CodeC Compile options needed: None C ******** BLOCK DATA statement at beginning of file ***
BLOCK DATA MYBLOCK
INTEGER*2 INT1
REAL*4 REAL1
CHARACTER*2 CHAR1
LOGICAL LOG1
COMMON /TEST/ INT1, REAL1, CHAR1, LOG1
DATA INT1, REAL1, CHAR1, LOG1 /1, 4.0, 'ZZ', .TRUE./
END
C ******** Beginning of main program *******************
PROGRAM BLOCK
INTEGER*2 INT1
REAL*4 REAL1
CHARACTER*2 CHAR1
LOGICAL LOG1
COMMON /TEST/ INT1, REAL1, CHAR1, LOG1
WRITE (*,100) INT1, REAL1, CHAR1, LOG1
100 FORMAT (1X, I1, 3X, F3.1, 3X, A2, 3X, L1)
ENDProgram BLOCK produces the following output:
1 4.0 ZZ TThe code example above would also produce the same results if the BLOCK DATA subprogram was placed after the END statement that terminates the main program.
|
Additional reference words: kbinf 4.00 4.01 4.10 5.00 5.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |