I am running version: ifort (IFORT) 12.1.5 20120612
My problem is basically that when characters are passed to a subroutine with len=*, the array constructor does not automatically take the maximum length as specified, but instead uses the length of the last argument to specify the type. This leads to truncated strings in some cases. If the lengths of a and b in the code snippet below are explicitly specified in the declaration, the constructor works correctly. If the constructor is explicitly typed, the constructor also works correctly.
Example Code:
module tst_char contains subroutine write_char(a, b) character(len=8), dimension(2) :: chars character(len=*), intent(in) :: a character(len=*), intent(in) :: b chars = (/ a , b /) write(*,*) 'array first element; auto constructor: ', chars chars = (/ character(len=20) :: a , b /) write(*,*) 'array first element; specified constructor: ', chars write(*,*) '-----' end subroutine write_char end module tst_char program run_char use tst_char call write_char('short', 'longer') call write_char('longer', 'short') call write_char('longer', 's') end program run_char
Output:
array first element; auto constructor: short longer
array first element; specified constructor: short longer
-----
array first element; auto constructor: longe short
array first element; specified constructor: longer short
-----
array first element; auto constructor: l s
array first element; specified constructor: longer s
-----
The snippet is also attached for convenience.
Patrick