please help me to understand this point before I will waste time.
I'd like to understand if it is possible to use allocatable into a "type structure". I tested this easy code:
program test_allocation
type elettrone
real,allocatable, dimension , :: vx
!real,pointer, dimension , :: vx
end type
type(elettrone) :: mpi
allocate(mpi%vx(1:2,1:3))
mpi%vx=reshape((/1,2,3,4,5,6/),(/2,3/))
print *,mpi%vx
!print *,mpi
read (*,*)
end program
It well works, but if i use the line "print *,mpi" (above commented), I obtain the following error message: .... a derived type ultimately contains an allocatable component cannot be specified in the i/o item.
My question is:
may I use allocatable array in to a "type structure"? Why above - in same cases - it seems to work but on books I read that it is not permitted and that one must use pointers? (again above using the pointer the result is the same)
Can I go ahead using the allocatable array as i did before thinking to use a more structurated programming?
I hope you'll halp me to figure out this point.
Thanks, Albi73
I'd like to understand if it is possible to use allocatable into a "type structure". I tested this easy code:
program test_allocation
type elettrone
real,allocatable, dimension , :: vx
!real,pointer, dimension , :: vx
end type
type(elettrone) :: mpi
allocate(mpi%vx(1:2,1:3))
mpi%vx=reshape((/1,2,3,4,5,6/),(/2,3/))
print *,mpi%vx
!print *,mpi
read (*,*)
end program
It well works, but if i use the line "print *,mpi" (above commented), I obtain the following error message: .... a derived type ultimately contains an allocatable component cannot be specified in the i/o item.
My question is:
may I use allocatable array in to a "type structure"? Why above - in same cases - it seems to work but on books I read that it is not permitted and that one must use pointers? (again above using the pointer the result is the same)
Can I go ahead using the allocatable array as i did before thinking to use a more structurated programming?
I hope you'll halp me to figure out this point.
Thanks, Albi73