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

-standard-semantics option supresses I/O for logical variables

John4
Valued Contributor I
866 Views

Hi,

When I compile and run the code below, with the -standard-semantics option, logical values are not written to the output file, and therefore the subsequent reads from the file fail. Without that option, I/O operations work just fine.

I'm not sure whether it has to do with the nested derived types. Is that the intended behavior? ---i.e., is it what the F2003 standard requires?

[fortran]module mod1

    implicit none
    private
    save

    type, public :: tm
        logical :: file = .FALSE.
    end type

    type, public :: tt
        integer :: seconds = -1
    end type

    type, public :: tf
        character(260) :: dir = ''
        integer :: sz = -1
        type(tt):: freq
        logical :: inv  = .FALSE.
        type :: other
    end type

    type, public :: test
        character(63) :: name = ''
        type(tf) :: file
    end type

    public readTest, writeTest

contains
    subroutine writeTest(this, file)
        type(test), allocatable, intent(IN) :: this(:)
        character(*), intent(IN) :: file
        integer :: i, ios, TMP_UNIT, nTest

    continue
        open (NEWUNIT = TMP_UNIT, FILE = file, STATUS = 'UNKNOWN', &
              ACCESS = 'SEQUENTIAL', DELIM = 'APOSTROPHE', ACTION = 'WRITE', &
              POSITION = 'REWIND', IOSTAT = ios, RECL = 512)
            if (ios /= 0) stop 'Error opening file'
            if (ALLOCATED(this)) then
                nTest = SIZE(this)
            else
                nTest = 0
            endif

            write (TMP_UNIT, *, IOSTAT = ios) nTest
            do i = 1, nTest
                write (TMP_UNIT, *, IOSTAT = ios) this(i)%name
                write (TMP_UNIT, *, IOSTAT = ios) this(i)%file 
            enddo 
            endfile (TMP_UNIT)
        close (TMP_UNIT)
    end subroutine

    logical function readTest(this, file) result(status)
        type(test), allocatable, intent(OUT) :: this(:)
        character(*), intent(IN) :: file
        integer :: i, ios, TMP_UNIT, nTest
        logical :: fileExists

    continue
        status = .FALSE.

        inquire (FILE = file, EXIST = fileExists)
        if (.NOT.  fileExists) then
            call writeTest(this, file)
            status = .TRUE.; return
        endif

        open (NEWUNIT = TMP_UNIT, FILE = file, STATUS = 'OLD', ACTION = 'READ', &
              POSITION = 'REWIND', IOSTAT = ios, RECL = 512)
            if (ios /= 0) stop 'Error opening file'
            read (TMP_UNIT, *, IOSTAT = ios) nTest
            if (nTest > 0) allocate (this(nTest))
            do i = 1, nTest
                read (TMP_UNIT, *, IOSTAT = ios) this(i)%name
                if (ios /= 0) stop 'Error loading file'
                read (TMP_UNIT, *, IOSTAT = ios) this(i)%file
                if (ios /= 0) stop 'Error loading file'
            enddo 
        close (TMP_UNIT)

        status = .TRUE.
    end function
end module mod1

program prog1
    use mod1
    implicit none

    type(test), allocatable :: t(:)
    logical :: retlog

continue
    allocate (t(5))
    call writeTest(t, 'garrick.dat')
    retlog = readTest(t, 'garrick.dat')
    print *, retlog
end program prog1[/fortran]

0 Kudos
1 Solution
Steven_L_Intel1
Employee
866 Views
The fix for this will be in Update 6.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
866 Views
Interesting. I'll take a look at this.
0 Kudos
Steven_L_Intel1
Employee
866 Views
The culprit is /assume:noold_ldout_format. For some reason it screws up LOGICAL components in nested types - works when you have the component directly in the output list. Issue ID is DPD200167936.
0 Kudos
Steven_L_Intel1
Employee
866 Views
This has been fixed in our sources, but I don't yet know when the fix will appear in the product.
0 Kudos
Steven_L_Intel1
Employee
867 Views
The fix for this will be in Update 6.
0 Kudos
Reply