type/format mismatch despite implicit interface

Hello

I came across an error writing the result of an character-valued function to a character variable. The write command exits with a runtime error claiming a type/format mismatch, although the function is defined in the same module and its interface is (should be) therefore implicitly known to the write statement. The compiler points to another internal write statement within the character valued funcion, but this does not seem to be the problem because the latter works if its result is written to standard out (unit *).

I was able to reduce the problem to the following short test program (test.f90):

module isoprint

contains

  function isodate(values)
    implicit none

    character(len=20) :: isodate
    integer,intent(in) :: values(:)

    write(isodate,5000) values

5000 format (i4,2("-",i2.2),i3,2(":",i2.2,:))

  end function isodate

  subroutine print_iso_date()
    implicit none

    character(len=60) message

    print*,'Test program'
    print*,'this works: ', isodate( (/ 2010, 9, 1, 12, 15 /) )

    print*,'this does not: '
    write(message,'(a)')   isodate( (/ 2010, 9, 1, 12, 15 /) )
    print*, message

  end subroutine print_iso_date

end module isoprint

program test
  use isoprint

  implicit none

  call print_iso_date()

end program test

When I comile and run it with pgf90, I get the following output (here with PGI 9.0.4, I also tested PGI 10.9.0 with the same result):

.../scratch> pgf90 -V test.f90 ; a.out

pgf90 9.0-4 64-bit target on x86-64 Linux -tp k8-64e
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2009, STMicroelectronics, Inc.  All Rights Reserved.
PGF90/x86-64 Linux 9.0-4
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2009, STMicroelectronics, Inc.  All Rights Reserved.
PGF90/x86-64 Linux 9.0-4
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2009, STMicroelectronics, Inc.  All Rights Reserved.
 Test program
 this works: 2010-09-01 12:15
 this does not:
PGFIO-F-235/formatted write/internal file/edit descriptor does not match
item type.
 In source file test.f90, at line number 11

The reason for the runtime error seems to be the internal write statement in the print_iso_date() module procedure, not the one on line 11 pointed at by the runtime error message. It uses the format edit descriptor ‘(a)’, whereas the write statement seems to assume that the function isodate() is something other than character.

isodate() is a character function in the same module and hence its
interface is known to print_iso_date(), thus this looks like an incorrect treatement of the isodate() type in the internal write statement to me.

A hint that it might indeed be a compiler problem is that another compiler form a another vendor does not have this problem:

.../scratch> <another>f90 test.f90 ; a.out
 Test program
 this works: 2010-09-01 12:15
 this does not:
 2010-09-01 12:15

Any comments are welcome.

Regards
Pirmin

Hi Pirmin,

Recursive I/O is a feature in the Fortran 2003 standard. We are currently in the process of adding all Fortran 2003 features with recursive I/O expected some time later this year or early next.

Thanks,
Mat