[MOAB-dev] Question about iMesh and Fortran 90/2003
Chris Eldred
chris.eldred at gmail.com
Thu Nov 14 20:20:56 CST 2013
Hey Moab-Dev,
I am trying to write a Fortran code that uses iMesh to call MOAB, and
I keep running into errors. What I would like to be able to do it is
to convert an adjacency returned by iMesh_getEntAdj from type(c_ptr)
to integers. In MOAB using C++ this seems to be trivial (use id =
id_from_handle(HANDLE) . It would also be useful to have the dual of
this operator (handle = handle_from_id(ID) ). I can't seem to get it
to work in Fortran however. My code is:
subroutine get_adjacency(entity, entity_requested, adjacencyptr, adjacency_size)
implicit none
integer(kind=c_int) :: alloc, adjacency_size
integer(kind=c_int) :: entity_requested
integer(kind=c_int), pointer, dimension(:) :: adjacency
type(c_ptr) :: entity
type(c_ptr) :: adjacencyptr_C
type(c_ptr), pointer, dimension(:) :: adjacencyptr
alloc = 0
call iMesh_getEntAdj( mesh, entity, entity_requested, adjacencyptr_C,
alloc, adjacency_size, ierr)
CHECK("Couldn't get adjacencies")
call C_F_POINTER(adjacencyptr_C, adjacencyptr, [alloc])
adjacency = transfer(adjacencyptr,adjacency,adjacency_size)
end subroutine get_adjacency
I have tried using the transfer function, but that produces memory
(segmentation fault) errors. Everything before this line works fine. I
am using the Fortran 2003 modules (iMesh_iso.F03) from
https://redmine.scorec.rpi.edu/anonsvn/itaps/software/trunk/interfaces/iMesh/examples/FindAdjacency/.
I've also looked through the iBase and iMesh documentation, but there
is very little information there about using Fortran instead of C/C++.
I am not very familiar with mixed C/Fortran programming, so it is
entirely possible that I just don't understand what is going on.
Thanks,
Chris Eldred
--
Chris Eldred
DOE Computational Science Graduate Fellow
Graduate Student, Atmospheric Science, Colorado State University
B.S. Applied Computational Physics, Carnegie Mellon University, 2009
chris.eldred at gmail.com / celdred at atmos.colostate.edu
More information about the moab-dev
mailing list