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

    Unformatted read/write of character arrays

    be129a02-1429-47a5-b910-a32c16a7dda1

      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

        contains

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

      #ifdef USE_FORMATTED
            open(unit=99,file='char.dat',form='formatted')
            write(unit=99,fmt='(A)') c
      #else
            open(unit=99,file='char.dat',form='unformatted')
            write(unit=99) c
      #endif
            close(unit=99)
          end subroutine write_char

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

      #ifdef USE_FORMATTED
            open(unit=99,file='char.dat',form='formatted')
            read(unit=99,fmt='(A)') c
      #else
            open(unit=99,file='char.dat',form='unformatted')
            read(unit=99) c
      #endif
            close(unit=99)
          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.

       

      Matthias