Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

vallue not assigned to variable declared "character(len=:) :: textblock(:)"

I expect that whether textblock is declared len=: or len=80 that the following code would produce a successful assignment to textblock; but in one case textblock is unallocated on version 16.  Is this still an issue with V 17?

! place in file testit.F90; compile with ifort, then "ifort -DCOLON"
! ifort testit.F90 -o fixedlen;./fixedlen
! ifort -DCOLON testit.F90 -o colon;./colon
program testit
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifdef COLON
character(len=:),allocatable :: textblock(:)
character(len=*),parameter   :: string='LEN=:'
#else
character(len=80),allocatable :: textblock(:)
character(len=*),parameter   :: string='LEN=80'
#endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
integer                      :: i
   textblock=[ character(len=40) :: &
   '#########',&
   '#       #',&
   '#       ###################',&
   '#                         #',&
   '#             #############',&
   '#             #',&
   '###############']
   write(*,*)   'FOR ',string
   write(*,*)   'ALLOCATED ',allocated(textblock)
   write(*,*)   'SIZE      ',size(textblock)
   if(size(textblock).gt.0)then
      write(*,*)'LEN       ',len(textblock(1))
   endif
   write(*,'(a)')(trim(textblock(i)),i=1,size(textblock))
end program testit
 

0 Kudos
1 Reply
Highlighted

I tried your code with 17.0

I tried your code with 17.0 compiler and found both can work as expected:

$ ifort -fpp test.f90
$ ./a.out
 FOR LEN=80
 ALLOCATED  T
 SIZE                 7
 LEN                 80
#########
#       #
#       ###################
#                         #
#             #############
#             #
###############
$ ifort -fpp -DCOLON test.f90
$ ./a.out
 FOR LEN=:
 ALLOCATED  T
 SIZE                 7
 LEN                 40
#########
#       #
#       ###################
#                         #
#             #############
#             #
###############

 

Thanks,

Xiaoping Duan

Intel Customer Support

 

0 Kudos