Code Example Demonstrates Using a BLOCK DATA Subprogram

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 query words: kbinf 4.00 nofps 4.01 4.10 5.00 5.10

Keywords :
Version : :4.0,4.01,4.1,5.0,5.1
Platform :
Issue type :


Last Reviewed: November 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.