1 Reply Latest reply on Jul 18, 2013 1:11 AM by User12616316-Oracle

    Unformatted read/write of character arrays


      Dear all,


      please consider the following demo program to test formatted and unformatted read/write of character arrays


      >> cat charset.F90


      program chartest
        implicit none

        character(len=1), dimension(5) :: c1,c2

        c1(1) = 's'
        c1(2) = 'u'
        c1(3) = 'n'
        c1(4) = 'n'
        c1(5) = 'y'

        call write_char(c1)
        call read_char(c2)

        print *, c2


          subroutine write_char(c)
            character, dimension(:), intent(in) :: c

      #ifdef USE_FORMATTED
            write(unit=99,fmt='(A)') c
            write(unit=99) c
          end subroutine write_char

          subroutine read_char(c)
            character, dimension(:), intent(out) :: c

      #ifdef USE_FORMATTED
            read(unit=99,fmt='(A)') c
            read(unit=99) c
          end subroutine read_char

      end program chartest


      1) If this code is compiled for formatted read/write

      sunf90 -DUSE_FORMATTED chartest.F90

      then the compilation process terminates successfully and the resulting binary program works correctly.


      2) Trying to compile this code for unformatted read/write

      sunf90 chartest.F90

      leads to the following internal error

      INTERNAL COMPILER ERROR near line 27 in chartest.F90 (phase ConcretizeProcs):
          Assertion failed: array_type && array_type->num_elements(0)->is_computable()
          [internal line 1229 /net/feeler/export/home2/spica_intel-Linux/111116/lang/f90/fe/srcme/compiler/phases/concretize/concretize_utl.cpp]

      Line 27 is

      write(unit=99) c

      in subroutine write_char. Interestingly enough, this code compiles well with other compilers such as gcc, g95, ifort, openf90 which makes me believe that the code complies with standard fortran.


      Any help will be greatly appreciated.