- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use CVF 6.6C.
I have a large DLL that contains some subroutines that share data at present using COMMON blocks containing fixed dimension arrays rather than using an unwieldy argument list, since there are a relatively large number of arrays. The contents of the arrays are defined in one routine and used in one of several other routines during one call to the DLL, that is, the data does not need to be saved between DLL calls. At present I size the arrays with dimensions large enough to easily cope with the size of the data I expect to generate, based on experience.
I now want the code to be safer and more flexible in that I want to vary the maximum dimensions of the arrays to match values that are computed during the same call to the DLL, so that there is no danger of the DLL crashing with an access violation while trying to use more memorybeyond whatthe fixed-dimension arrays allow.I therefore hope that I can switch tousing ALLOCATABLE arrays in a MODULE, allocate them and compute their contents in one routine and USE the MODULE in another routine thatneeds to usethe contents of the arrays and their dimensions. Is this allowed? If so, is it straightforward or are there pitfalls to beware? TIA.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's a while since I used CVF 6 but I think it should be OK
It is the sort of thing I have done a lot of in IVF :
module x
integer, parameter :: HERE = 5! some valid parameter
integer, allocatable :: ival(:)
! more arrays as required
contains
subroutine x_alloc_arrays(nsize, ierr)
integer :: nsize
integer :: ierr
if (nsize < HERE) then
! array will be too small do something
else
allocate(ival(nsize), stat=ier
ival = 0! Initialise the array
endif
end subroutine x_alloc_arrays
subroutine x_dealloc_arrays(ierr)
integer :: ierr
if (allocated(ival)) deallocate(ival, stat=ierr)
end subroutine x_dealloc_arrays
! Other routines to get from or put values to the array(s)
end module x
And so on, with appropriate error trapping of course.
Les

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