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

Warning 7951 on open statement

van_der_merwe__ben
New Contributor I
2,411 Views

For the following code:

      INTEGER UNIT,RECL,IOSTAT,iu
      CHARACTER FILE*(*),STATUS*(*),ACCESS*(*),FORMAT*(*),CSTAT*20
...
         ELSEIF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY') THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT,
     +      BUFFERED='YES',BLOCKSIZE=8192,BUFFERCOUNT=500)

The compiler says:

warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
---------------------------------------------^
warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
---------------------------------------------^

So that makes me think I can fix this by simply removing the ", FILE=FILE" portion since it will be ignored, but then all sort of runtime errors ensue that do not happen otherwise?

So what is the proper way of fixing the code to not have this warning?

0 Kudos
22 Replies
van_der_merwe__ben
New Contributor I
2,065 Views

It looks like it doesnt like the CSTAT variable, so using the explicit string instead of variable seems to make it happy:

 

         IF ( CSTAT.EQ.'SCRATCH' ) THEN
            OPEN(UNIT=UNIT,STATUS='SCRATCH',ACCESS=ACCESS,FORM=FORMAT,
     +      IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS='NEW',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY') THEN
            OPEN(UNIT=UNIT,STATUS='UNKNOWN',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT,
     +      BUFFERED='YES',BLOCKSIZE=8192,BUFFERCOUNT=500)

 

0 Kudos
Steve_Lionel
Honored Contributor III
2,065 Views

It is much more useful if you can post a small but complete source that demonstrates the problem, rather than forcing people who want to help you to add missing pieces and hope they guessed right. It's often the case that posting only snippets omits crucial information. I'd also ask that you stop using fixed-form source if you are doing new development.

That all said, I can't reproduce this problem in the current compiler version. I have a faint recollection of something similar many years ago.Which compiler version are you using?

0 Kudos
van_der_merwe__ben
New Contributor I
2,065 Views

Lionel, you are correct, my apologies! For new development we do use F90. We are using:

Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.5.281 Build 20190815

I shall have a go at reproducing a small stand alone example, but it looks like explicitly using a string for STATUS rather than a variable avoids the warnings.

0 Kudos
Steve_Lionel
Honored Contributor III
2,061 Views

Here's the code I tested (I used free-form):

subroutine foo (FILE, STATUS, ACCESS, FORMAT, CSTAT)
INTEGER UNIT,RECL,IOSTAT,iu
CHARACTER FILE*(*),STATUS*(*),ACCESS*(*),FORMAT*(*),CSTAT*20

        IF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS, &
           FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ELSE IF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY') THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS, &
           FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT, &
           BUFFERED='YES',BLOCKSIZE=8192,BUFFERCOUNT=500)
           END IF

           END

 

0 Kudos
van_der_merwe__ben
New Contributor I
2,069 Views

Attached is a VS2019 solution which shows this in the output window:

1>Console1.f
1>F:\test2\Console1\Console1.f(12): warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]
1>F:\test2\Console1\Console1.f(15): warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]

And yes, for any new development we definitely use free form! This is old code where I have always been meaning to clean up that warning.

 

0 Kudos
van_der_merwe__ben
New Contributor I
2,069 Views

The warning seems to be falsely triggered, and can be avoided by using an explicit string for STATUS instead. BTW: I also had trouble making the warning appear in the standalone code, not sure exactly what triggers it.

0 Kudos
andrew_4619
Honored Contributor III
2,069 Views

In your example the CSTAT is a local variable that is not initialised  and the compiler can see that it is a null string. Your code has an error set cstat='scratch' .or some other valid value.

0 Kudos
van_der_merwe__ben
New Contributor I
2,069 Views

This little snippet should be above the first IF:

      IU = INDEX(STATUS,'_')
	IF(IU.GT.0) THEN
	   CSTAT = STATUS(:IU-1)
	ELSE
	   CSTAT = STATUS
	ENDIF

The warning appears regardless.

0 Kudos
van_der_merwe__ben
New Contributor I
2,061 Views

The full real function also has a number of other OPEN statements using STATUS where there is no warning.

0 Kudos
van_der_merwe__ben
New Contributor I
2,061 Views

Here is the project with the snippet added, the warnings are still there.

0 Kudos
andrew_4619
Honored Contributor III
2,061 Views

deleted

0 Kudos
andrew_4619
Honored Contributor III
2,063 Views

This gives the error for line 10 but if I comment out lines 7 & 8 the error goes away so I think maybe it is a parsing bug in the compiler or something like that. It may also relate to having a variable called status which is a Fortran keyword...

      SUBROUTINE MOPEN (UNIT,FILE,STATUS,ACCESS,FORMAT,RECL,IOSTAT)
      INTEGER UNIT,RECL,IOSTAT,iu
      CHARACTER FILE*(*),STATUS*(*),ACCESS*(*),FORMAT*(*),CSTAT*20
      CSTAT = STATUS
      
         IF ( CSTAT.EQ.'SCRATCH' ) THEN
            OPEN(UNIT=UNIT,STATUS='SCRATCH',ACCESS=ACCESS,FORM=FORMAT,
     +      IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ENDIF
      END

.

0 Kudos
van_der_merwe__ben
New Contributor I
2,063 Views

Andrew, I agree, I have often glanced at that code and warning and thinking "what? why?". I have logged this as a bug with intel,request number 04505944. I can avoid it by explicitly using a STATUS string, so this is minor.

0 Kudos
andrew_4619
Honored Contributor III
2,063 Views

warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]

Line 6 triggers the warning on line 8

      SUBROUTINE MOPEN ()
      CHARACTER FILE*20
      character CSTAT*20
      CSTAT = 'NEW'
      IF ( CSTAT.EQ.'SCRATCH' ) THEN
          OPEN(UNIT=22,STATUS='SCRATCH') 
      ELSEIF ( CSTAT.EQ.'NEW' ) THEN
          OPEN(UNIT=22,STATUS=CSTAT,FILE=FILE)
      ENDIF
      END

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,059 Views

I haven't experimented with the code, as for an observation, what happens when you use:

       ...,STATUS=TRIM(CSTAT),...

Jim Dempsey

0 Kudos
FortranFan
Honored Contributor III
2,061 Views

@van der merwe, ben:

Note the standard says

 9    12.5.6.18 STATUS= specifier in the OPEN statement
10 1 The scalar-default-char-expr shall evaluate to OLD, NEW, SCRATCH, REPLACE, or UNKNOWN.

So line 16 in your code can be non-conforming if CSTAT evaluates to 'MODIFY'.

You can suppress diagnostics if you so choose using /Qdiag-disable compiler option:

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-diag-qdiag

Or you can edit your code like so:

      SUBROUTINE MOPEN (UNIT,FILE,STATUS,ACCESS,FORMAT,RECL,IOSTAT)
      INTEGER UNIT,RECL,IOSTAT,iu
      CHARACTER FILE*(*),STATUS*(*),ACCESS*(*),FORMAT*(*),CSTAT*20
*
      CSTAT = STATUS
*
      IF ( RECL.GT.0 ) THEN
      ELSE
         IF ( CSTAT.EQ.'SCRATCH' ) THEN
            OPEN(UNIT=UNIT,STATUS='SCRATCH',ACCESS=ACCESS,FORM=FORMAT,
     +      IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS='NEW',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY' ) THEN
            OPEN(UNIT=UNIT,STATUS='UNKNOWN',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT,
     +      BUFFERED='YES',BLOCKSIZE=8192,BUFFERCOUNT=500)
         ELSEIF ( CSTAT.EQ.'OLD' ) THEN
            OPEN(UNIT=UNIT,STATUS='OLD',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',ACTION='READ',IOSTAT=IOSTAT) 
         ELSEIF ( CSTAT.EQ.'APPEND') THEN
            OPEN(UNIT=UNIT,STATUS='UNKNOWN',FILE=FILE,ACCESS='APPEND',
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)            
         ENDIF
      ENDIF
*
      RETURN
      END

 

0 Kudos
andrew_4619
Honored Contributor III
2,061 Views

@@FF This gives the warning there is no connection to the non-conformance in the OP code.

      SUBROUTINE MOPEN ()
      CHARACTER(20) :: myFILE = 'fred.txt'
      character(20) :: CSTAT  = 'NEW'
      !character(20), parameter :: CSTAT='NEW' ! this ILO the line above eliminated the warning
      OPEN(UNIT=22,STATUS='OLD') 
      OPEN(UNIT=23,STATUS=CSTAT,FILE=myFILE)
      END

 

0 Kudos
andrew_4619
Honored Contributor III
2,061 Views

And finally because I have lost interest now this is the minimal reproducer in free format

SUBROUTINE MOPEN2 () 
      character(20) :: CSTAT  = 'NEW'
      !character(20), parameter :: CSTAT='NEW' ! this line ILO the line above eliminates the warning
      OPEN( UNIT = 22, STATUS = 'OLD') ! if this line is commented out there is no warning for the next line
      OPEN( UNIT = 23, STATUS = CSTAT, FILE = 'fred.txt' )
      ! above line gives warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   ['fred.txt']
END

 

0 Kudos
FortranFan
Honored Contributor III
2,061 Views

andrew_4619 wrote:

@@FF This gives the warning there is no connection to the non-conformance in the OP code. ..

OP shared code which used literal constants such as 'SCRATCH' and 'OLD' with STATUS= specification on certain lines but the variable CSTAT on some other e.g.,

      CHARACTER .. CSTAT*20
*
      CSTAT = STATUS
*
      ..
         ELSEIF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY') THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,

So my suggestion is to either suppress the warning if it's bothersome to OP, or to modify the code line that has 'STATUS=CSTAT' with a literal constant like on other lines.  But then STATUS='MODIFY' won't be conforming per Fortran standard, so OP will have to decide whether to go with the literal 'UNKNOWN' in that case.

The code in Quote #17 doesn't generate the warning.

C:\Temp>type Console1.f
      SUBROUTINE MOPEN (UNIT,FILE,STATUS,ACCESS,FORMAT,RECL,IOSTAT)
      INTEGER UNIT,RECL,IOSTAT,iu
      CHARACTER FILE*(*),STATUS*(*),ACCESS*(*),FORMAT*(*),CSTAT*20
*
      CSTAT = STATUS
*
      IF ( RECL.GT.0 ) THEN
      ELSE
         IF ( CSTAT.EQ.'SCRATCH' ) THEN
            OPEN(UNIT=UNIT,STATUS='SCRATCH',ACCESS=ACCESS,FORM=FORMAT,
     +      IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY') THEN
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT,
     +      BUFFERED='YES',BLOCKSIZE=8192,BUFFERCOUNT=500)
         ELSEIF ( CSTAT.EQ.'OLD' ) THEN
            OPEN(UNIT=UNIT,STATUS='OLD',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',ACTION='READ',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'APPEND') THEN
            OPEN(UNIT=UNIT,STATUS='UNKNOWN',FILE=FILE,ACCESS='APPEND',
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ENDIF
      ENDIF
*
      RETURN
      END

C:\Temp>ifort /c Console1.f
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.0.166 Build 20191121
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

Console1.f(13): warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
---------------------------------------------^
Console1.f(16): warning #7951: The STATUS= specifier has the value SCRATCH, the FILE= specifier will be ignored in the OPEN statement.   [FILE]
            OPEN(UNIT=UNIT,STATUS=CSTAT,FILE=FILE,ACCESS=ACCESS,
---------------------------------------------^

C:\Temp>type modified-Console1.f
      SUBROUTINE MOPEN (UNIT,FILE,STATUS,ACCESS,FORMAT,RECL,IOSTAT)
      INTEGER UNIT,RECL,IOSTAT,iu
      CHARACTER FILE*(*),STATUS*(*),ACCESS*(*),FORMAT*(*),CSTAT*20
*
      CSTAT = STATUS
*
      IF ( RECL.GT.0 ) THEN
      ELSE
         IF ( CSTAT.EQ.'SCRATCH' ) THEN
            OPEN(UNIT=UNIT,STATUS='SCRATCH',ACCESS=ACCESS,FORM=FORMAT,
     +      IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'NEW' ) THEN
            OPEN(UNIT=UNIT,STATUS='NEW',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'UNKNOWN' .OR. CSTAT.EQ.'MODIFY' ) THEN
            OPEN(UNIT=UNIT,STATUS='UNKNOWN',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT,
     +      BUFFERED='YES',BLOCKSIZE=8192,BUFFERCOUNT=500)
         ELSEIF ( CSTAT.EQ.'OLD' ) THEN
            OPEN(UNIT=UNIT,STATUS='OLD',FILE=FILE,ACCESS=ACCESS,
     +      FORM=FORMAT,SHARE='DENYWR',ACTION='READ',IOSTAT=IOSTAT)
         ELSEIF ( CSTAT.EQ.'APPEND') THEN
            OPEN(UNIT=UNIT,STATUS='UNKNOWN',FILE=FILE,ACCESS='APPEND',
     +      FORM=FORMAT,SHARE='DENYWR',IOSTAT=IOSTAT)
         ENDIF
      ENDIF
*
      RETURN
      END

C:\Temp>ifort /c modified-Console1.f
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.0.166 Build 20191121
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.


C:\Temp>

 

0 Kudos
andrew_4619
Honored Contributor III
1,939 Views

Workarounds are easy, but not withstanding any issues with the OP's code (not least the considering that fixed format makes my eyes bleed) primary issue is a bug in the compiler. 

0 Kudos
Reply