- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've got two codes, which I want to combine. In one code I've got type:
TYPE, PUBLIC ::m_type INTEGER :: m, REAL ( KIND( 1.0D+0 ) ), ALLOCATABLE, DIMENSION(:) :: val END TYPE
and subroutine which uses this type as an input:
subroutine sub(m) type(m_type), intent(in) :: matrix .... end subroutine
In the second code, which calls the subroutine sub(), I have already allocated array, let say x(:), and I don't want to allocate once more memory for m%val, just for copying data, because size of x(:) is huge. Is there any way to assign m%val with values of x(:) without allocating additional memory? In C pointer will do the trick, but I don't know how I could use it here. I dont want to change subroutine sub(), because it will cause changes not only in my part of the code.
Any ideas?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See if MOVE_ALLOC can be made to do the work for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran has pointers
module m_mod TYPE, PUBLIC ::m_type INTEGER :: m, REAL ( KIND( 1.0D+0 ) ), ALLOCATABLE, POINTER, DIMENSION(:) :: val END TYPE end module m_mod ... real, kind(1.0D+0), allocatable, target :: x(:) ... Allocate(x(isHuge)) ... call sub(m) ... subroutine sub(m) use m_mod type(m_type) :: m ... m%val => x ! or x(from:to)
Your post was not clear as to if sub were initializing m%val or using. The above shows part of initializing.
*** Just as in C/C++, it is your responsibility to assure that the underlying x is not deallocated (or reallocated) during the lifetime of pointers pointing to (portions of) it.
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