Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two pointers into one 1

Status
Not open for further replies.

albi73

Programmer
Sep 16, 2010
18
0
0
IT
Hi dear friens,
I have the following problem that i think might be a solution

suppose to heve the following code:
[code/]
real, dimension(1:3), target :: max
real, dimension(1:4), target :: min
real, dimension:)), pointer :: p1,p2

p1=>max
p2=>min
[/code]


so far it is all ok.
What i'd like do is the possibility to call all the targets (max and min) by using only one pointer. I'm not able to find a way to define a p3 (pointer) where p3(1),p3(2),p3(3),p3(4),p3(5),p3(6),p3(7) will point to max(1),max(2),max(3),min(1),min(2),min(3),min(4) .


Ciao, Albi


 

You cannot do that with a "real vector pointer" because the "vector" [max(1),max(2),max(3),min(1),min(2),min(3),min(4)] is not a FORTRAN vector : in a FORTRAN vector there is constant distance (constant stride) between two successive elements.

But you can proceed as follows :

Code:
program test

implicit none

type t
  real,pointer :: value
end type

real, dimension(1:3), target :: max
real, dimension(1:4), target :: min
type(t) :: p3(SIZE(max)+size(min))
integer :: i

do i=1,size(max)
  p3(i)%value => max(i)
enddo

do i=1,size(min)
  p3(i+size(max))%value => min(i)
enddo

p3(3)%value = 1
p3(4)%value=2

write(*,*) max(3),min(1)

end program

With the result :

Code:
  1.000000       2.000000

Unfortunately, you cannot use p3:))%value as a vector of real values because, again, the distance between two successive elements is not constant.





François Jacq
 
Thanks dear FJacq,
again your reply turn on the light of my brain (and it's not so easy, it is really a black box :) ).
This night going to home I was thinking this soluction, but I didn't understand the real motivation, which is that: poiter, like array, have to respect the costant stride. So I suppose pointers charge the targer address of an array -inheriting the size- only if they are sequential. The gap between max(3) and min(1) causes the problem. Again i can't define p3:))%value for the same motivation, but clearly it would like very practical.

The Question: If I want to nullify the pointers i suppose to be compelled to write somethin like:
Code:
do i=1,(size(max)+size(min))
  nullify(p3(i)%value)
enddo

 
Or :

Code:
do i=1,(size(max)+size(min))
  p3(i)%value => null()
enddo

But calling nullify is perfect too.

François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top