/* File: dunavantmodule.c
 * This file is auto-generated with f2py (version:2).
 * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,
 * written by Pearu Peterson <pearu@cens.ioc.ee>.
 * Generation date: Fri Feb  2 04:21:56 2018
 * Do not edit this file directly unless you know what you are doing!!!
 */

#ifdef __cplusplus
extern "C" {
#endif

/*********************** See f2py2e/cfuncs.py: includes ***********************/
#include <stdarg.h>
#include "Python.h"
#include "fortranobject.h"
/*need_includes0*/

/**************** See f2py2e/rules.py: mod_rules['modulebody'] ****************/
static PyObject *dunavant_error;
static PyObject *dunavant_module;

/*********************** See f2py2e/cfuncs.py: typedefs ***********************/
/*need_typedefs*/

/****************** See f2py2e/cfuncs.py: typedefs_generated ******************/
/*need_typedefs_generated*/

/********************** See f2py2e/cfuncs.py: cppmacros **********************/
#if defined(PREPEND_FORTRAN)
#if defined(NO_APPEND_FORTRAN)
#if defined(UPPERCASE_FORTRAN)
#define F_FUNC(f,F) _##F
#else
#define F_FUNC(f,F) _##f
#endif
#else
#if defined(UPPERCASE_FORTRAN)
#define F_FUNC(f,F) _##F##_
#else
#define F_FUNC(f,F) _##f##_
#endif
#endif
#else
#if defined(NO_APPEND_FORTRAN)
#if defined(UPPERCASE_FORTRAN)
#define F_FUNC(f,F) F
#else
#define F_FUNC(f,F) f
#endif
#else
#if defined(UPPERCASE_FORTRAN)
#define F_FUNC(f,F) F##_
#else
#define F_FUNC(f,F) f##_
#endif
#endif
#endif
#if defined(UNDERSCORE_G77)
#define F_FUNC_US(f,F) F_FUNC(f##_,F##_)
#else
#define F_FUNC_US(f,F) F_FUNC(f,F)
#endif

#ifdef DEBUGCFUNCS
#define CFUNCSMESS(mess) fprintf(stderr,"debug-capi:"mess);
#define CFUNCSMESSPY(mess,obj) CFUNCSMESS(mess) \
    PyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\
    fprintf(stderr,"\n");
#else
#define CFUNCSMESS(mess)
#define CFUNCSMESSPY(mess,obj)
#endif

#ifndef max
#define max(a,b) ((a > b) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) ((a < b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) ((a > b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a < b) ? (a) : (b))
#endif

#define rank(var) var ## _Rank
#define shape(var,dim) var ## _Dims[dim]
#define old_rank(var) (PyArray_NDIM((PyArrayObject *)(capi_ ## var ## _tmp)))
#define old_shape(var,dim) PyArray_DIM(((PyArrayObject *)(capi_ ## var ## _tmp)),dim)
#define fshape(var,dim) shape(var,rank(var)-dim-1)
#define len(var) shape(var,0)
#define flen(var) fshape(var,0)
#define old_size(var) PyArray_SIZE((PyArrayObject *)(capi_ ## var ## _tmp))
/* #define index(i) capi_i ## i */
#define slen(var) capi_ ## var ## _len
#define size(var, ...) f2py_size((PyArrayObject *)(capi_ ## var ## _tmp), ## __VA_ARGS__, -1)


/************************ See f2py2e/cfuncs.py: cfuncs ************************/
static int f2py_size(PyArrayObject* var, ...)
{
  npy_int sz = 0;
  npy_int dim;
  npy_int rank;
  va_list argp;
  va_start(argp, var);
  dim = va_arg(argp, npy_int);
  if (dim==-1)
    {
      sz = PyArray_SIZE(var);
    }
  else
    {
      rank = PyArray_NDIM(var);
      if (dim>=1 && dim<=rank)
        sz = PyArray_DIM(var, dim-1);
      else
        fprintf(stderr, "f2py_size: 2nd argument value=%d fails to satisfy 1<=value<=%d. Result will be 0.\n", dim, rank);
    }
  va_end(argp);
  return sz;
}

static int int_from_pyobj(int* v,PyObject *obj,const char *errmess) {
    PyObject* tmp = NULL;
    if (PyInt_Check(obj)) {
        *v = (int)PyInt_AS_LONG(obj);
        return 1;
    }
    tmp = PyNumber_Int(obj);
    if (tmp) {
        *v = PyInt_AS_LONG(tmp);
        Py_DECREF(tmp);
        return 1;
    }
    if (PyComplex_Check(obj))
        tmp = PyObject_GetAttrString(obj,"real");
    else if (PyString_Check(obj) || PyUnicode_Check(obj))
        /*pass*/;
    else if (PySequence_Check(obj))
        tmp = PySequence_GetItem(obj,0);
    if (tmp) {
        PyErr_Clear();
        if (int_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
        Py_DECREF(tmp);
    }
    {
        PyObject* err = PyErr_Occurred();
        if (err==NULL) err = dunavant_error;
        PyErr_SetString(err,errmess);
    }
    return 0;
}


/********************* See f2py2e/cfuncs.py: userincludes *********************/
/*need_userincludes*/

/********************* See f2py2e/capi_rules.py: usercode *********************/


/* See f2py2e/rules.py */
extern void F_FUNC_US(dunavant_order_num,DUNAVANT_ORDER_NUM)(int*,int*);
extern void F_FUNC_US(dunavant_rule,DUNAVANT_RULE)(int*,int*,double*,double*);
/*eof externroutines*/

/******************** See f2py2e/capi_rules.py: usercode1 ********************/


/******************* See f2py2e/cb_rules.py: buildcallback *******************/
/*need_callbacks*/

/*********************** See f2py2e/rules.py: buildapi ***********************/

/***************************** dunavant_order_num *****************************/
static char doc_f2py_rout_dunavant_dunavant_order_num[] = "\
order_num = dunavant_order_num(rule)\n\nWrapper for ``dunavant_order_num``.\
\n\nParameters\n----------\n"
"rule : input int\n"
"\nReturns\n-------\n"
"order_num : int";
/* extern void F_FUNC_US(dunavant_order_num,DUNAVANT_ORDER_NUM)(int*,int*); */
static PyObject *f2py_rout_dunavant_dunavant_order_num(const PyObject *capi_self,
                           PyObject *capi_args,
                           PyObject *capi_keywds,
                           void (*f2py_func)(int*,int*)) {
  PyObject * volatile capi_buildvalue = NULL;
  volatile int f2py_success = 1;
/*decl*/

  int rule = 0;
  PyObject *rule_capi = Py_None;
  int order_num = 0;
  static char *capi_kwlist[] = {"rule",NULL};

/*routdebugenter*/
#ifdef F2PY_REPORT_ATEXIT
f2py_start_clock();
#endif
  if (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\
    "O:dunavant.dunavant_order_num",\
    capi_kwlist,&rule_capi))
    return NULL;
/*frompyobj*/
  /* Processing variable rule */
    f2py_success = int_from_pyobj(&rule,rule_capi,"dunavant.dunavant_order_num() 1st argument (rule) can't be converted to int");
  if (f2py_success) {
  /* Processing variable order_num */
/*end of frompyobj*/
#ifdef F2PY_REPORT_ATEXIT
f2py_start_call_clock();
#endif
/*callfortranroutine*/
        (*f2py_func)(&rule,&order_num);
if (PyErr_Occurred())
  f2py_success = 0;
#ifdef F2PY_REPORT_ATEXIT
f2py_stop_call_clock();
#endif
/*end of callfortranroutine*/
    if (f2py_success) {
/*pyobjfrom*/
/*end of pyobjfrom*/
    CFUNCSMESS("Building return value.\n");
    capi_buildvalue = Py_BuildValue("i",order_num);
/*closepyobjfrom*/
/*end of closepyobjfrom*/
    } /*if (f2py_success) after callfortranroutine*/
/*cleanupfrompyobj*/
  /* End of cleaning variable order_num */
  } /*if (f2py_success) of rule*/
  /* End of cleaning variable rule */
/*end of cleanupfrompyobj*/
  if (capi_buildvalue == NULL) {
/*routdebugfailure*/
  } else {
/*routdebugleave*/
  }
  CFUNCSMESS("Freeing memory.\n");
/*freemem*/
#ifdef F2PY_REPORT_ATEXIT
f2py_stop_clock();
#endif
  return capi_buildvalue;
}
/************************* end of dunavant_order_num *************************/

/******************************* dunavant_rule *******************************/
static char doc_f2py_rout_dunavant_dunavant_rule[] = "\
xy,w = dunavant_rule(rule,order_num)\n\nWrapper for ``dunavant_rule``.\
\n\nParameters\n----------\n"
"rule : input int\n"
"order_num : input int\n"
"\nReturns\n-------\n"
"xy : rank-2 array('d') with bounds (2,order_num)\n"
"w : rank-1 array('d') with bounds (order_num)";
/* extern void F_FUNC_US(dunavant_rule,DUNAVANT_RULE)(int*,int*,double*,double*); */
static PyObject *f2py_rout_dunavant_dunavant_rule(const PyObject *capi_self,
                           PyObject *capi_args,
                           PyObject *capi_keywds,
                           void (*f2py_func)(int*,int*,double*,double*)) {
  PyObject * volatile capi_buildvalue = NULL;
  volatile int f2py_success = 1;
/*decl*/

  int rule = 0;
  PyObject *rule_capi = Py_None;
  int order_num = 0;
  PyObject *order_num_capi = Py_None;
  double *xy = NULL;
  npy_intp xy_Dims[2] = {-1, -1};
  const int xy_Rank = 2;
  PyArrayObject *capi_xy_tmp = NULL;
  int capi_xy_intent = 0;
  double *w = NULL;
  npy_intp w_Dims[1] = {-1};
  const int w_Rank = 1;
  PyArrayObject *capi_w_tmp = NULL;
  int capi_w_intent = 0;
  static char *capi_kwlist[] = {"rule","order_num",NULL};

/*routdebugenter*/
#ifdef F2PY_REPORT_ATEXIT
f2py_start_clock();
#endif
  if (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\
    "OO:dunavant.dunavant_rule",\
    capi_kwlist,&rule_capi,&order_num_capi))
    return NULL;
/*frompyobj*/
  /* Processing variable rule */
    f2py_success = int_from_pyobj(&rule,rule_capi,"dunavant.dunavant_rule() 1st argument (rule) can't be converted to int");
  if (f2py_success) {
  /* Processing variable order_num */
    f2py_success = int_from_pyobj(&order_num,order_num_capi,"dunavant.dunavant_rule() 2nd argument (order_num) can't be converted to int");
  if (f2py_success) {
  /* Processing variable xy */
  xy_Dims[0]=2,xy_Dims[1]=order_num;
  capi_xy_intent |= F2PY_INTENT_OUT|F2PY_INTENT_HIDE;
  capi_xy_tmp = array_from_pyobj(NPY_DOUBLE,xy_Dims,xy_Rank,capi_xy_intent,Py_None);
  if (capi_xy_tmp == NULL) {
    if (!PyErr_Occurred())
      PyErr_SetString(dunavant_error,"failed in converting hidden `xy' of dunavant.dunavant_rule to C/Fortran array" );
  } else {
    xy = (double *)(PyArray_DATA(capi_xy_tmp));

  /* Processing variable w */
  w_Dims[0]=order_num;
  capi_w_intent |= F2PY_INTENT_OUT|F2PY_INTENT_HIDE;
  capi_w_tmp = array_from_pyobj(NPY_DOUBLE,w_Dims,w_Rank,capi_w_intent,Py_None);
  if (capi_w_tmp == NULL) {
    if (!PyErr_Occurred())
      PyErr_SetString(dunavant_error,"failed in converting hidden `w' of dunavant.dunavant_rule to C/Fortran array" );
  } else {
    w = (double *)(PyArray_DATA(capi_w_tmp));

/*end of frompyobj*/
#ifdef F2PY_REPORT_ATEXIT
f2py_start_call_clock();
#endif
/*callfortranroutine*/
        (*f2py_func)(&rule,&order_num,xy,w);
if (PyErr_Occurred())
  f2py_success = 0;
#ifdef F2PY_REPORT_ATEXIT
f2py_stop_call_clock();
#endif
/*end of callfortranroutine*/
    if (f2py_success) {
/*pyobjfrom*/
/*end of pyobjfrom*/
    CFUNCSMESS("Building return value.\n");
    capi_buildvalue = Py_BuildValue("NN",capi_xy_tmp,capi_w_tmp);
/*closepyobjfrom*/
/*end of closepyobjfrom*/
    } /*if (f2py_success) after callfortranroutine*/
/*cleanupfrompyobj*/
  }  /*if (capi_w_tmp == NULL) ... else of w*/
  /* End of cleaning variable w */
  }  /*if (capi_xy_tmp == NULL) ... else of xy*/
  /* End of cleaning variable xy */
  } /*if (f2py_success) of order_num*/
  /* End of cleaning variable order_num */
  } /*if (f2py_success) of rule*/
  /* End of cleaning variable rule */
/*end of cleanupfrompyobj*/
  if (capi_buildvalue == NULL) {
/*routdebugfailure*/
  } else {
/*routdebugleave*/
  }
  CFUNCSMESS("Freeing memory.\n");
/*freemem*/
#ifdef F2PY_REPORT_ATEXIT
f2py_stop_clock();
#endif
  return capi_buildvalue;
}
/**************************** end of dunavant_rule ****************************/
/*eof body*/

/******************* See f2py2e/f90mod_rules.py: buildhooks *******************/
/*need_f90modhooks*/

/************** See f2py2e/rules.py: module_rules['modulebody'] **************/

/******************* See f2py2e/common_rules.py: buildhooks *******************/

/*need_commonhooks*/

/**************************** See f2py2e/rules.py ****************************/

static FortranDataDef f2py_routine_defs[] = {
  {"dunavant_order_num",-1,{{-1}},0,(char *)F_FUNC_US(dunavant_order_num,DUNAVANT_ORDER_NUM),(f2py_init_func)f2py_rout_dunavant_dunavant_order_num,doc_f2py_rout_dunavant_dunavant_order_num},
  {"dunavant_rule",-1,{{-1}},0,(char *)F_FUNC_US(dunavant_rule,DUNAVANT_RULE),(f2py_init_func)f2py_rout_dunavant_dunavant_rule,doc_f2py_rout_dunavant_dunavant_rule},

/*eof routine_defs*/
  {NULL}
};

static PyMethodDef f2py_module_methods[] = {

  {NULL,NULL}
};

#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef moduledef = {
  PyModuleDef_HEAD_INIT,
  "dunavant",
  NULL,
  -1,
  f2py_module_methods,
  NULL,
  NULL,
  NULL,
  NULL
};
#endif

#if PY_VERSION_HEX >= 0x03000000
#define RETVAL m
PyMODINIT_FUNC PyInit_dunavant(void) {
#else
#define RETVAL
PyMODINIT_FUNC initdunavant(void) {
#endif
  int i;
  PyObject *m,*d, *s;
#if PY_VERSION_HEX >= 0x03000000
  m = dunavant_module = PyModule_Create(&moduledef);
#else
  m = dunavant_module = Py_InitModule("dunavant", f2py_module_methods);
#endif
  Py_TYPE(&PyFortran_Type) = &PyType_Type;
  import_array();
  if (PyErr_Occurred())
    {PyErr_SetString(PyExc_ImportError, "can't initialize module dunavant (failed to import numpy)"); return RETVAL;}
  d = PyModule_GetDict(m);
  s = PyString_FromString("$Revision: $");
  PyDict_SetItemString(d, "__version__", s);
#if PY_VERSION_HEX >= 0x03000000
  s = PyUnicode_FromString(
#else
  s = PyString_FromString(
#endif
    "This module 'dunavant' is auto-generated with f2py (version:2).\nFunctions:\n"
"  order_num = dunavant_order_num(rule)\n"
"  xy,w = dunavant_rule(rule,order_num)\n"
".");
  PyDict_SetItemString(d, "__doc__", s);
  dunavant_error = PyErr_NewException ("dunavant.error", NULL, NULL);
  Py_DECREF(s);
  for(i=0;f2py_routine_defs[i].name!=NULL;i++)
    PyDict_SetItemString(d, f2py_routine_defs[i].name,PyFortranObject_NewAsAttr(&f2py_routine_defs[i]));


/*eof initf2pywraphooks*/
/*eof initf90modhooks*/

/*eof initcommonhooks*/


#ifdef F2PY_REPORT_ATEXIT
  if (! PyErr_Occurred())
    on_exit(f2py_report_on_exit,(void*)"dunavant");
#endif

  return RETVAL;
}
#ifdef __cplusplus
}
#endif
