<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
   Please find attached an example that uses the bind C and passes a PETSc object through.<br>
<br>
   Note that you cannot pass directly a Fortran derived type to C. <br>
<br>
    Barry<br>
</div>
</span></font></div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
<br>
> On Jun 7, 2018, at 12:37 PM, Anthony Ruth <Anthony.J.Ruth.12@nd.edu> wrote:<br>
> <br>
> Hello,<br>
> <br>
> I am trying to call a function in a C library from fortran. The fortran code should pass a Mat object to the C code. I defined the interface within the fortran code like this:
<br>
> <br>
> #include <petsc/finclude/petscmat.h><br>
> <br>
> interface<br>
>     subroutine MY_FUNC(A_Mat) bind ( C, name = "MY_FUNC" )<br>
>        use petscmat<br>
>       Mat, intent(in) :: A_Mat<br>
>     end subroutine MY_FUNC<br>
>   end interface<br>
> <br>
> When I try to compile the code it produces this error:<br>
> <br>
> Variable ‘a_mat’ at (1) is a dummy argument to the BIND(C) procedure ‘MY_FUNC’ but is not C interoperable because derived type ‘tmat’ is not C interoperable<br>
> <br>
> My interpretation of the error is that there is some mismatch between the Mat data type defined in fortran and the Mat data type defined in C, so that I cannot pass one to the other. Is this true? Is there a compatible way to pass the Mat? Are the C and fortran
 implementations actually properly aligned and interchangeable so that all that is needed is something to tell the compiler to try anyway? I tried changing the data type of A_Mat to Integer Pointer (void *), but ran into a syntax error when attempting that.
<br>
> <br>
> regards,<br>
> Anthony Ruth<br>
> NASA Space Technology Research Fellow<br>
> Condensed Matter Theory<br>
> University of Notre Dame<br>
<br>
</div>
</span></font></div>
</body>
</html>