FIX: HF0451.EXE - F6700: READ with END= and Character Formats

ID: Q75761

The information in this article applies to:

SYMPTOMS

Programs compiled with Microsoft FORTRAN versions 5.0 and 5.1 and run for a period of time can generate the error:

   run-time error F6700:
   -heap space exceeded

CAUSE

The three conditions that are necessary to cause this error are:

1. The program must contain a READ or WRITE statement that contains

   an END=, ERR=, or IOSTAT= specification.

2. The READ or WRITE statement that contains one of the above
   specifications must use a character string variable for a FORMAT
   specifier.

3. The program code must repeatedly execute the READ or WRITE statement in
   such a way as to force the use of one of the specifications; for
   example, repeatedly hitting the end of a file and causing the END=
   specification to go to the specified label.

Given the above conditions, the near heap will fill up with replicates of the character string FORMAT specifier until the F6700 error is generated. The larger the character string, the faster the near heap will be filled up. The F6700 error most commonly occurs on an OPEN statement. The OPEN statement allocates some memory in both the near and far heap and will fail with the F6700 error if sufficient near heap does not exist.

RESOLUTION

A patched version of a component (PUTERR.OBJ) of the run-time library has been made available as an application note. With the new replacement routines in the PUTERR.OBJ module, the accumulation of allocated memory on the near heap does not occur because the memory used is correctly deallocated following termination of the READ or WRITE statement.

The following file is available for download from the Microsoft Software Library:

 ~ HF0451.exe (size: 27151 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

STATUS

Microsoft has confirmed this to be a problem in FORTRAN versions 5.0 and 5.1. This problem was corrected in FORTRAN PowerStation.

MORE INFORMATION

The following code can be used to reproduce the problem:

Sample Code

      parameter(n=19000)
      integer*4 ai
      integer*1 arr1(n),arr2(n),arr3(n)
      character*256 str,formstr

      formstr = '(a)'
      str = 'this is junk'
      open(1,file='test.dat')

      write(1,formstr) str
      rewind(1)
      ai = 1
10 read(1,formstr,end=20) str
      goto 10

20 rewind(1)
      write(*,*)
      write(*,*) 'At end of file at iteration ',ai
      ai=ai+1
      goto 10
      end

Additional query words:
Keywords          : kbfile kbFortranPS kbLangFortran 
Issue type        : kbbug
Solution Type     : kbfix

Last Reviewed: December 12, 1998