Print

Print


FWIW, the Cray compiler does not complain about your example program:

> ftn test.f90
> srun -n1 ./a.out
Salary is    302.00 for 20.0 hours.
Salary is    302.00 for 20.0 hours.
> 


Cheers,
Bill

> On Jun 10, 2017, at 12:19 PM, Walt Brainerd <[log in to unmask]> wrote:
> 
> Consider the F08 standard, p. 218, 9.6.3, item (7) fourth bullet, just after NOTE 9.35:
> 
> If a list item of derived type in a formatted input/output statement is not processed by a defined in-
> put/output procedure, that list item is treated as if all of the components of the list item were specified
> in the list in component order;
> 
> This arises because of a disagreement between Intel and Gfortran.
> 
> The question is: what does "not processed by" mean?
> 
> Does it mean whether or not there is an appropriate interface for the dt accessible?
> Or must there be a DT edit descriptor that processes the io list item?
> 
> This is illustrated by the following program (sorry it is a bit long--of necessity, I think).
> 
> Intel 2017 accepts and runs it, while gfortran 7.0.1 gives a runtime error for the second
> WRITE statement.
> 
> module B_write_dt_mod
> 
>    implicit none
>    private
> 
>    type, public :: B_type
>       real :: amount
>    end type B_type
> 
>    interface write (formatted)
>       procedure :: Write_b_real
>    end interface
> 
>    public :: write (formatted)
> 
> contains
> 
> subroutine Write_b_real &
>    (amount, unit, b_edit_descriptor, v_list, iostat, iomsg)
> 
>    class (B_type), intent(in) :: amount
>    integer, intent(in) :: unit
>    character (len=*), intent(in) :: b_edit_descriptor
>    integer, dimension(:), intent(in) :: v_list
>    integer, intent(out) :: iostat
>    character (len=*), intent(inout) :: iomsg
>    write (unit=unit, fmt="("//b_edit_descriptor(3:)//")", iostat=iostat) amount%amount
> 
> end subroutine Write_b_real
> 
> end module B_write_dt_mod
> 
> program test_b_write_dt_mod
> 
>    use :: B_write_dt_mod
>    use, intrinsic :: iso_fortran_env, only: OUTPUT_UNIT
>    implicit none
>    real :: wage = 15.10
> 
>    write (unit=OUTPUT_UNIT, fmt="(a, DT'f9.2', a, f4.1, a)") &
>          "Salary is ", B_type(20.0 * wage), " for ", 20.0, " hours."
> 
> ! gfortran bombs on the following B_type(20.0); intel OK
>    write (unit=OUTPUT_UNIT, fmt="(a, DT'f9.2', a, f4.1, a)") &
>          "Salary is ", B_type(20.0 * wage), " for ", B_type(20.0), " hours."
> !  Note: B_type(20.0) corresponds to f4.1 format, not DT
> 
> end program test_b_write_dt_mod
> 
> 
> -- 
> Walt Brainerd

Bill Long                                                                       [log in to unmask]
Principal Engineer, Fortran Technical Support &   voice:  651-605-9024
Bioinformatics Software Development                      fax:  651-605-9143
Cray Inc./ 2131 Lindau Lane/  Suite 1000/  Bloomington, MN  55425