Code Example Demonstrates Using a BLOCK DATA Subprogram

Last reviewed: July 19, 1995
Article ID: Q51496
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1

SUMMARY

A 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 INFORMATION

The 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 Code

C 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)

      END

Program BLOCK produces the following output:

   1   4.0   ZZ   T

The 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
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 19, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.