- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
I want to call a subroutine in fortran from C++. but this subroutine has an array with variable length.
Here is a example:
SUBROUTINE foo(A)
INTEGER, DIMENSION(:), INTENT(IN) :: A
INTEGER :: len
...
len = size(A)
...
END SUBROUTINE foo
as we can see, the size of A can be obtained through size(). but this works only with array created in fortran. If such routine is called from C/C++, how could I pass the information of array size?
thanks a lot.
Here is a example:
SUBROUTINE foo(A)
INTEGER, DIMENSION(:), INTENT(IN) :: A
INTEGER :: len
...
len = size(A)
...
END SUBROUTINE foo
as we can see, the size of A can be obtained through size(). but this works only with array created in fortran. If such routine is called from C/C++, how could I pass the information of array size?
thanks a lot.
Ссылка скопирована
1 Ответить
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
If you use a deferred-shape array, with (:) bounds, you will need to have the C code pass a Fortran array descriptor. The details of this are in the mixed-language programming section of the User Manual (or Programmer's Guide for CVF.)
However, a much simpler approach is to write the Fortran routine as follows:
SUBROUTINE foo(A,N)
INTEGER, INTENT(IN) :: N
INTEGER, DIMENSION(N), INTENT(IN) :: A
INTEGER :: len
and pass the upper bound of the array from the C code as an ordinary integer variable (passed by reference here). Do keep in mind that C arrays start at index 0, while Fortran starts at 1, so you may need to make adjustments. Or you could declare the Fortran array (0:N).
However, a much simpler approach is to write the Fortran routine as follows:
SUBROUTINE foo(A,N)
INTEGER, INTENT(IN) :: N
INTEGER, DIMENSION(N), INTENT(IN) :: A
INTEGER :: len
and pass the upper bound of the array from the C code as an ordinary integer variable (passed by reference here). Do keep in mind that C arrays start at index 0, while Fortran starts at 1, so you may need to make adjustments. Or you could declare the Fortran array (0:N).
Ответить
Параметры темы
- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати