Given the following:
char filename[num1][num2];
What is the Fortran binding for this?
This:
character(len=num2, kind=c_char), dimension(num1) :: filename
gives the error:
Component 'filename' of BIND(C) type at (1) must have length one
Given the following:
char filename[num1][num2];
What is the Fortran binding for this?
This:
character(len=num2, kind=c_char), dimension(num1) :: filename
gives the error:
Component 'filename' of BIND(C) type at (1) must have length one
Hi, I guess that is a two dimensional array? If yes, then
character(:), allocatable :: filename(:, :)
! I don't know what are you going to do with the array
! but Fortran is column major so we might save it as
! (num2, num1) instead of (num1, num2).
allocate (character(len=50, kind=c_char) : filename(num2, num1))
where len
represents the length of each array element.
If you want it to be the same as thing as the C variable
character(len=1, kind=c_char), dimension(num2,num1), bind(C, name='filename') :: filename
if you just want it to be interoperable with C, just leave of the bind(C...)
part
Excellent. Thanks @everythingfunctional.
Yes, indeed, I do need it to be interoperable with C.