Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

pointer problems in fortran

Boris_K_1
Beginner
626 Views

Hi

Im having serious issues with creating the propper data type for my new project, and can't seem to find a way around it. Im trying to create an object (a fortran type) which contains pointers to other objects of the same type, so I can create a web of objects which can be connected in which ever way I feel like it. I can solve it but the name of the variables then become very long. So I am hoping that someone out there can help me find a smoother solution. Let me give an example:
 

type data

integer :: localdata

type(data),dimension(:),pointer :: connections

end type data

 


This will not work because 'connections' are now a pointer to an array instead of an array of pointers. So far so good - to get around this it is of course possible to create an intermediate step:

 

 

 

type intermediate

type(data),pointer :: inter

end type intermediate

 


and then make 'connections' an array of type 'intermediate', but the problem then is that when trying to get hold og the localdata from one of the connections it will look like

 

 

 

 

data(i)%intermediate(j)%inter%localdata

 


quite the handful. One way to resolve this would be to create a pointer to 'localdata' and so skip the intermediate step, ie

 

 

 

 

type connection

integer,pointer :: localdata

end type connection

 


and then use the connection type, but I have quite a bit of localdata, not just one integer, so reforming connections (in case I want to change some of them) becomes quite a bit of work, since I need many pointers for each connection. Any way to resolve this thing so that getting to localdata will not be so cumbersome.

 

 

 

 

I hope that someone has a good idea that will solve this problem

 

 

BG

0 Kudos
3 Replies
mecej4
Honored Contributor III
626 Views

If the length of component object names is the main thing that you are concerned about, systematic use of the ASSOCIATE...END ASSOCIATE construct will alleviate the problem.

Another point that I wish to bring to your attention is that in Fortran POINTER is an attribute, not an intrinsic type, Of course, as you well know, things are different in C.

0 Kudos
Boris_K_1
Beginner
626 Views

Yes you're right, pointer is an attribute. I frased it for clarity. I'm aware that ASSOCIATE can solve the name length, but I just find that solution a bit clumsy, not very "elegant". I hope you understand what I mean. 

0 Kudos
jimdempseyatthecove
Honored Contributor III
626 Views

You could make the connections an array of C_PTR's of the LOC's, then use C_F_POINTER to cast it back to the type when needed.

Jim Dempsey

0 Kudos
Reply