Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable passing to c (type, dimension)

Status
Not open for further replies.

sanyibacsi

Programmer
Mar 10, 2009
3
AU
Hello There,

Well, I hope to get some help from here since the actual problem is happening on the C side... but it is quite Fortan related.

I call a C function from a Fortran somehow like:
Code:
type fe_node_property
    real, allocatable, dimension(:,:)    :: xf
    integer, allocatable, dimension(:,:) :: prop
    integer, allocatable, dimension(:)   :: mat
end type fe_node_property
type(fe_node_property) :: fe_node
integer :: size1, size2

! size1 == size of xf and mat, xf first dimension is 3
! size2 = second dimension of prop, first dimension is 3

call cppfunc(size1, size2, fe_node)

The C code looks more or less like:
Code:
extern "C" {
    void cppfunc_(int *pSize1, int *pSize2, char *pNode)
}

void cppfunc(int *pSize1, int *pSize2, char *pNode) {
    for (int i = 0; i < *pSize1; i++) {
        printf("%d float1, 2, 3: %f, %f, %f\n", i, (float)*(pNodes + (i * 3), (float)*(pNodes + (i * 3) + 1), (float)*(pNodes + (i * 3) + 2));
    }
}

I try to print the values arriving from Fortran. I think that the problem with the code above is that it just converts one character to float so I tried to convert four consecutive characters making up a number but did not succeed. It is not even clear to me what would be the order of the incoming variables since those dimension allocations are not quite conventional I guess.

Would somebody be able to help me explaining what structure of data should I expect and how to convert that from the type as those are?

Thank you very much,
Sandor
 
I tracked quite a bit what is going on and found out that all is fine if the arrays have a static length. However, as soon as those become allocatable, the values just go strange like if a wrong memory area is passed (using ifort 9.1).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top