Jason
2004-02-03 14:36:01 UTC
I just started on learning Fortran 90 and need your opinions on the
following code:
!!!!!!Start
module stuff
type t1
integer, dimension(:), allocatable::a
integer, dimension(:), allocatable::b
end type t1
type t2
type(t1), dimension(:), allocatable:: t1_a
integer, dimension(:), allocatable:: c
end type t2
end module stuff
program test
use stuff
implicit none
type(t2):: my_var
if(.not. allocated(my_var%t1_a)) allocate(my_var%t1_a(5))
if(.not. allocated(my_var%c)) allocate(my_var%c(5))
if(allocated(my_var%t1_a(1)%a)) then
write(*,*) "Size of my_var%t1_a(1)%a = ", size(my_var%t1_a(1)%a)
! deallocate(my_var%t1_a(1)%a)
end if
end program test
!!!!!!End
I tried my code on Visual Fortran 6.6, the f90 compiler that comes
with TrueUnix 64 and Irix 6.5. The code compiled and run on Visual
Fortran but not on TrueUnix 64 and Irix 6.5. On TrueUnix64 and Irisx
the compiler complain about array must have explict size, or use
pointers. But from I have read so far, my code has not violated any
Fortran standard.
As for VF6.6, even though I have not allocated any memory to
my_var%t1_a(1)%a, it's allocated with size of 0? If I try to
deallocate the memeory, there's an error. Why?
I can use pointers, but then I cannot use "intent(in)" declaration
with pointers. So I need your opinion on whether my code is standard
or not.
following code:
!!!!!!Start
module stuff
type t1
integer, dimension(:), allocatable::a
integer, dimension(:), allocatable::b
end type t1
type t2
type(t1), dimension(:), allocatable:: t1_a
integer, dimension(:), allocatable:: c
end type t2
end module stuff
program test
use stuff
implicit none
type(t2):: my_var
if(.not. allocated(my_var%t1_a)) allocate(my_var%t1_a(5))
if(.not. allocated(my_var%c)) allocate(my_var%c(5))
if(allocated(my_var%t1_a(1)%a)) then
write(*,*) "Size of my_var%t1_a(1)%a = ", size(my_var%t1_a(1)%a)
! deallocate(my_var%t1_a(1)%a)
end if
end program test
!!!!!!End
I tried my code on Visual Fortran 6.6, the f90 compiler that comes
with TrueUnix 64 and Irix 6.5. The code compiled and run on Visual
Fortran but not on TrueUnix 64 and Irix 6.5. On TrueUnix64 and Irisx
the compiler complain about array must have explict size, or use
pointers. But from I have read so far, my code has not violated any
Fortran standard.
As for VF6.6, even though I have not allocated any memory to
my_var%t1_a(1)%a, it's allocated with size of 0? If I try to
deallocate the memeory, there's an error. Why?
I can use pointers, but then I cannot use "intent(in)" declaration
with pointers. So I need your opinion on whether my code is standard
or not.