Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

Run-Time Check Failure #2 - Stack around the variable '_RUNTIME$IDAY' was corrupted.

Wen_C_
Beginner
1,428 Views
I bought the intel fortran and visual studio 2013, I ran a simple example program which ran well in my old fortran compiler, but it did not run on this intel fortran.  I use debug mode and found the problem in one small subroutine:
    
      SUBROUTINE RUNTIME
      INTEGER*2 IYEAR,IMONTH,IDAY,IHOUR,IMIN,ISEC,I100TH
      CALL GETDAT(IYEAR,IMONTH,IDAY)
      CALL GETTIM(IHOUR,IMIN,ISEC,I100TH)
      IF ( IHOUR .LE. 12 ) THEN
           WRITE(*,9001) IHOUR,IMIN,ISEC,I100TH,IMONTH,IDAY,IYEAR
      ELSE
           IHOUR = IHOUR-12
           WRITE(*,9002) IHOUR,IMIN,ISEC,I100TH,IMONTH,IDAY,IYEAR
      ENDIF
 
9001 FORMAT(/3X,'Time: ',I2.2,':',I2.2,':',I2.2,'.',I2.2,' am',
     +        3X,'Date: ',I2.2,'-',I2.2,'-',I4.4)
9002 FORMAT(/3X,'Time: ',I2.2,':',I2.2,':',I2.2,'.',I2.2,' pm',
     +        3X,'Date: ',I2.2,'-',I2.2,'-',I4.4)
 
      RETURN
      END
 
The error message is:
Run-Time Check Failure #2 - Stack around the variable '_RUNTIME$IDAY' was corrupted.
 
Do you have any idea what was wrong with this subroutine ?
0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,428 Views

Reformatting the code for reeadibility

       SUBROUTINE RUNTIME
       INTEGER*2 IYEAR,IMONTH,IDAY,IHOUR,IMIN,ISEC,I100TH
       CALL GETDAT(IYEAR,IMONTH,IDAY)
       CALL GETTIM(IHOUR,IMIN,ISEC,I100TH)
       IF ( IHOUR .LE. 12 ) THEN
            WRITE(*,9001) IHOUR,IMIN,ISEC,I100TH,IMONTH,IDAY,IYEAR
       ELSE
            IHOUR = IHOUR-12
            WRITE(*,9002) IHOUR,IMIN,ISEC,I100TH,IMONTH,IDAY,IYEAR
       ENDIF
9001   FORMAT(/3X,'Time: ',I2.2,':',I2.2,':',I2.2,'.',I2.2,' am',
      +        3X,'Date: ',I2.2,'-',I2.2,'-',I4.4) 
9002   FORMAT(/3X,'Time: ',I2.2,':',I2.2,':',I2.2,'.',I2.2,' pm',
      +        3X,'Date: ',I2.2,'-',I2.2,'-',I4.4)
       RETURN 
       END 

Your original code was written for 16-bit systems where GETDAT and GETTIM return INTEGER*2 values. The default in Intel Fortran is that these return 32-bit values, so when you called GETDAT with 16-bit variables, storage was corrupted. The error message alerted you to this.

Our documentation for GETDAT says:

All arguments must be of the same integer kind, that is, all must be INTEGER(2) or all must be INTEGER(4).

If INTEGER(2) arguments are passed, you must specify USE IFPORT.

So the solution for you is to either change the INTEGER*2 to INTEGER*4, or add the line "USE IFPORT" immediately after the SUBROUTINE statement. This brings in a generic declaration for GETDAT (and GETTIM) which will select the proper routine to use.

0 Kudos
Wen_C_
Beginner
1,428 Views

Thank you very much.  I am an old Fortran guy, these are new to me.  Thanks again.  really appreciate.

0 Kudos
FortranFan
Honored Contributor III
1,428 Views

Wen C. wrote:

Thank you very much.  I am an old Fortran guy, these are new to me.  Thanks again.  really appreciate.

If you plan to do more with Fortran, please see Dr Fortran blog: https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world.  The books in this blog can quickly bring you up to speed!

0 Kudos
Reply