Calling METIS_NodeND in Metis 5.0.2 from fortran95

I have been using METIS_NodeND from a FORTRAN program successfully for a number of years; the
main difficulty has been that it did not have a `graceful exit' for the cases where it failed.

I noticed that version 5.0.2 now supplies flags for errors & would like to upgrade to it.
However, I can't figure out how to:
1) set the options required
a) calling METIS_SetDefaultOptions sets all elements of the integer vector supplied to -1
b) options(METIS_OPTION_NUMBERING) = 1 gives me an error as the variable METIS_OPTION_NUMBERING
is not defined
2) retrieve the variables METIS_OK, METIS_ERROR, etc.

What am I missing? Is there a module somewhere which sets these quantities (including metis.h does not work)??

Has anybody got this to work and would be able to give an example?

thanks in advance for any help!

RE: These are defined in metis.h.

These are defined in metis.h.

RE: metis.h for fortran

thanks for your prompt reply.

how then do I make the contents of metis.h available to my fortran program -
I can't simply include it as you would in a c program (I tried, it fails
with 'not a valid fortran statement'). Is there a Fortran version of metis.h ?

RE: RE: calling METIS_NodeND from fortran95

you would need to have a .c file let's say "metis.c" which has nothing but the following line.

#include "metis.h"

and compile this file with your favorite c compiler. you have an object "metis.o".

You would also need to write a wrapper module in fortran 95. Let's say "metis_interface.f95"
Which includes all the relevant parameters, variables and interface for call to "METIS_NodeND" or any other such routines you need using
"ISO_C_BINDING" module that allows to call C routines from fortran.

E.g.,

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!file : metis_interface.f95
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module metis_interface
use,intrinsic::ISO_C_BINDING
integer::ia,ic
integer(C_INT)::metis_ne,metis_nn
integer(C_INT)::ncommon,objval
integer(C_INT)::nparts
integer(C_INT),allocatable,dimension(:)::eptr,eind,perm,iperm
integer(C_INT),allocatable,dimension(:)::epart,npart
type(C_PTR)::vwgt,vsize,twgts
integer(C_INT)::opts(0:40)
interface
integer(C_INT) function METIS_SetDefaultOptions(opts) bind(C,name="METIS_SetDefaultOptions")
use,intrinsic::ISO_C_BINDING
implicit none
integer(C_INT)::opts(0:40)
end function METIS_SetDefaultOptions
end interface
interface
integer(C_INT) function METIS_NodeND(nvtxs,xadj,adjncy,vwgt,opts,perm,iperm) bind(C,name="METIS_NodeND")
use,intrinsic::ISO_C_BINDING
implicit none
integer(C_INT)::nvtxs
integer(C_INT),dimension(*)::xadj,adjncy,perm,iperm
type(C_PTR),value::vwgt
integer(C_INT)::opts(0:40)
end function METIS_NodeND
end interface
end module metis_interface
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

use this module in your main program.

now, your calling sequence in fortran may look like following.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ndmetis_call_status=METIS_SetDefaultOptions(options)
options(17)=1 ! METIS_OPTION_NUMBERING = 17 needs to be set to make sure it uses fortran numbering
ndmetis_call_status=METIS_NodeND(nn,dcs,dc,vwgts,options,perm,iperm)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Finally, don't forget to link the main program and interface module with the compiled c object that includes "metis.h" and you may have to use -lmetis -lm to include relevant libraries.