- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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
Ссылка скопирована
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
[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.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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 (?)
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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.

- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати