- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
module typedat
implicit none
type :: dat
integer :: trow,tcol,tnum,nin,nout
type(dat),pointer,dimension(:)::next !Pointer to an array of things of type dat,so find a way to store prev or next into array
type(dat),pointer,dimension(:)::prev !Pointer to an array of things of type dat
end type
end module
program multipleio
use typedat
implicit none
integer,allocatable,dimension(:)::torder2,torder1,torder3,allt
type(dat),target,dimension(:),allocatable::totdat
type(dat),pointer::head,temp,temp1
type(dat),pointer::first(:),last(:),prevdup(:),nextdup(:),prev1dup(:),next1dup(:)
integer,dimension(:),allocatable :: a(:),b(:)
open(17,file='tuborder.txt')
do i=1,ttub
allocate(a(totdat(i)%nin),b(totdat(i)%nout))
read(17,*) a(1:totdat(i)%nin),b(1:totdat(i)%nout)
allocate(prevdup(totdat(i)%nin,nextdup(totdat(i)%nout))
if (totdat(i)%nin .gt. 0) then
do j=1,totdat(i)%nin
do k=1,ttub
if (a(j)==totdat(k)%tnum) then
temp=>totdat(k)
prevdup(j)=temp
end if
end do
end do
end if
totdat(i)%prev=>prevdup(1:totdat(i)%nin) !Linking the current tube as previous tube for next tube
if (totdat(i)%nout .gt. 0) then
do j=1,totdat(i)%nout
do k=1,ttub
if (b(j)==totdat(k)%tnum) then
temp=>totdat(k)
nextdup(j)=temp
end if
end do
end do
end if
totdat(i)%next=>nextdup(1:totdat(i)%nout)!Linking the next tube to current tube
deallocate(a,b)
end do
close(17)
I am trying to write a program to follow flow inside tubes. I planned to use linked list with pointer "next" in my data structure shall point to the next tube of the path.I am facing a problem to link the various tubes when i am having multiple inlets or outlets for a tube. I want my current tube to point to next tube via next pointer and similarly to its previous tubes via prev pointer. If multiple inlets and outlets are there i am reading them into an arrays a,b and using them. Derived structure of "type (dat)" above contains tube information. The underlined lines above are the major concern for me. When i am using => in those lines i am getting an error of this kind
Error 1 error #8524: The syntax of this data pointer assignment is incorrect: either 'bound spec' or 'bound remapping' is expected in this context
and when i am just using = as above my pointers links are not coming correctly. I am new to Fortran and got stuck, kindly help me with this.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The flaw in your design is that you intend nextdup and prevdup to be arrays of pointers as in C and other languages. This is not allowed in Fortran. You can, on the other hand, embed a pointer inside a new type, say dupptr_type, and declare an array of this type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if (totdat(i)%nin .gt. 0) then
do j=1,totdat(i)%nin
do k=1,ttub
if (a(j)==totdat(k)%tnum) then
pdup(j)%prevdup=>totdat(k) ! pdup is a type having pointer prevdup
end if
end do
end do
end if
totdat(i)%prev=>pdup(1:totdat(i)%nin)%prevdup !Linking the current tube as previous tube for next tube
if (totdat(i)%nout .gt. 0) then
do j=1,totdat(i)%nout
do k=1,ttub
if (b(j)==totdat(k)%tnum) then
ndup(j)%nextdup=>totdat(k) ! ndup is a type having pointer nextdup
end if
end do
end do
end if
totdat(i)%next=>ndup(1:totdat(i)%nout)%nextdup !Linking the next tube to current tube
deallocate(a,b,pdup,ndup)
end do
I did the changes, but how to append this to next and prev pointers of type dat. I know that the above highlighted way is not correct as again it will take that statement as array of pointers which is not possible in fortran. How do i change the above code so that i can point next to an array of next tubes and prev to an array of prev tubes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Reddy, Karunakar,
You may want to go through the thread link below in detail, in particular the technique recommended in Quote #13 - you may find it helpful.
https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/755612

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