This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/18022] New: problem with structure and calling a function


there are a bug when you mix structure and function. Only the first part of the
structure seems to act correctly. The best thing is to try this sample:

The tab and the pts must be equal in their components and it's not the case.

I saw another things I don't like (even if I think that the norm required
nothing), it's the initial value of a tab: the majorities of the value are 0 but
sometimes it's random, I'll prefer to have all the value random (you have no
choice to initialize all you're variable) or (better I think) to have all the
value equal at 0.

Thanks,

 
Nicolas

program test_bug

  implicit none

  character(len=20), dimension(4,2) :: tab_c
  real,dimension(4,2) :: tab
  integer :: i,j
  
  type :: point
     real :: x,y
  end type point
  type(point), dimension(4) :: pts
  
  tab_c(:,1)(:) = (/'1','2','3','4'/)
  tab_c(:,2)(:) = (/'2','3','4','5'/)

  print*, tab_c

  do i=1,2
     tab(:,i) = char2real_1d(tab_c(:,i))
  end do

  pts%x =  char2real_1d(tab_c(:,1))
  pts%y =  char2real_1d(tab_c(:,2))

  print*, "pts ",pts
  print*, "tab ", tab

contains
  function char2real_1d (tab_c,error) result (tab_r)
    character(len=*), dimension(:), intent(in) :: tab_c
    real, intent(in), optional :: error 

    real, dimension(size(tab_c)) :: tab_r

    integer :: i
    real:: err

    if (.not. (present(error))) then
       err = 9999.99
    else
       err = error
    end if
    do i=1,size(tab_c)       
       if (verify(trim(tab_c(i)),"0123456789-+.Ee " ) == 0) then
          read (unit=tab_c(i),fmt=*) tab_r(i)
       else
          tab_r (i) = err
       end if
    end do
  end function char2real_1d

end program test_bug

-- 
           Summary: problem with structure and calling a function
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gruel at astro dot ufl dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18022


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]