- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am interested createan array of TYPE
But I don't understand how to.
Here a small example - not ok because I don't understand exactly
Suggestions ? (Thanks)
MODULE mod_TypeAllocate
IMPLICIT NONE
TYPE :: STRUCT
CHARACTER(LEN=2) :: CC
INTEGER, DIMENSION(2) :: II
REAL , DIMENSION(2) :: RR
END TYPE STRUCT
TYPE INFO
CHARACTER (LEN=12) :: NAME
TYPE(STRUCT) :: VAL
END TYPE INFO
CONTAINS
FUNCTION GETINFO(nv)
IMPLICIT NONE
INTEGER :: nv
TYPE(INFO), DIMENSION(:), POINTER :: GETINFO ! ??? allocatble, pointer ...
INTEGER :: istat
ALLOCATE(GETINFO(nv),STAT=istat)
GETINFO(1)%NAME = 'FIRST'
GETINFO(1)%VAL%CC = 'CC'
GETINFO(1)%VAL%II = 5
GETINFO(1)%VAL%RR = 99.99
END FUNCTION GETINFO
END MODULE mod_TypeAllocate
PROGRAM PRGTEST
USE mod_TypeAllocate
IMPLICIT NONE
TYPE(INFO), DIMENSION(:,:), POINTER :: VALS ! ??? allocatble, pointer ...
VALS = GETINFO(3)
END PROGRAM PRGTEST
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[fortran] TYPE(INFO), DIMENSION(:), POINTER :: VALS ! ??? allocatble, pointer ... ALLOCATE(VALS(3)) VALS = GETINFO(3) [/fortran]In your version, you tried to assign a value to a dangling pointer variable (no allocation yet) and declared VALS to be a two dimensional variable to which you tried to assign a one-dimensional array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes
But if I don't know exactly what is GETINFO. (IF module is a compiled module, binary only - no code)
If the code allocate, by example:
ALLOCATE(GETINFO(2*nv),STAT=istat)
I would function GETINFO allocate space and return values without program PRGTEST allocate variable VALS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My program PRGTEST just specify shape ( a one dimensionarray, (:),of type INFO )for variable VALS and function GETINFO allocate an array of size nv of type INFO.
Perhaps an INTERFACE statement is required (?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In PROGRAM you declare VALS as a 2D array of INFO objects.
In PROGRAM you use "VALS = GETINFO(3)" which states take the contents of the 1D array of INFO objects (as pointed to by the return from GETINFO) and copy it into the array VALSdescribed by the descriptor for VALS. VALS has a different shape as well as it is not allocated.
PROGRAM should declare VALS as a 1D pointer then use the pointer assignment "VALS => GETINFO(3)" to an unallocated VALS. You will not have a memory leak using this technique.
Did you want an array of pointers to 1D arrays of INFO objects?
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If that is true, then your first efforts should be devoted to finding from the author of GETINFO what the function type and calling conventions are. Once that information is set you can go about writing suitable interfaces and calls.
Failing that, you will have to investigate all possible interfaces to GETINFO, write test programs and check the results. This is time consuming; some alternatives may slip through the cracks, and the task may require facilities not available to you. That is why this should be a last resort, and it may very well turn out that it is going to be better to discard the only-binary-code routine of uncertain pedigree and rewrite your own version with the desired functionality.
Any help that you can get here is going to suffer from the handicap that the problem is ill-defined and, therefore, there are a number of tentative solutions that may be tried but with no guarantee of success.

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