- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page