/* File: fImageD11module.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>.
 * See http://cens.ioc.ee/projects/f2py2e/
 * Generation date: Fri Mar  6 13:44:22 2015
 * $Revision:$
 * $Date:$
 * Do not edit this file directly unless you know what you are doing!!!
 */
#ifdef __cplusplus
extern "C" {
#endif

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

/**************** See f2py2e/rules.py: mod_rules['modulebody'] ****************/
static PyObject *fImageD11_error;
static PyObject *fImageD11_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

#define rank(var) var ## _Rank
#define shape(var,dim) var ## _Dims[dim]
#define old_rank(var) (((PyArrayObject *)(capi_ ## var ## _tmp))->nd)
#define old_shape(var,dim) (((PyArrayObject *)(capi_ ## var ## _tmp))->dimensions[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)

#define CHECKSCALAR(check,tcheck,name,show,var)\
  if (!(check)) {\
    char errstring[256];\
    sprintf(errstring, "%s: "show, "("tcheck") failed for "name, var);\
    PyErr_SetString(fImageD11_error,errstring);\
    /*goto capi_fail;*/\
  } else 
#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


/************************ See f2py2e/cfuncs.py: cfuncs ************************/
static int double_from_pyobj(double* v,PyObject *obj,const char *errmess) {
  PyObject* tmp = NULL;
  if (PyFloat_Check(obj)) {
#ifdef __sgi
    *v = PyFloat_AsDouble(obj);
#else
    *v = PyFloat_AS_DOUBLE(obj);
#endif
    return 1;
  }
  tmp = PyNumber_Float(obj);
  if (tmp) {
#ifdef __sgi
    *v = PyFloat_AsDouble(tmp);
#else
    *v = PyFloat_AS_DOUBLE(tmp);
#endif
    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 (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
    Py_DECREF(tmp);
  }
  {
    PyObject* err = PyErr_Occurred();
    if (err==NULL) err = fImageD11_error;
    PyErr_SetString(err,errmess);
  }
  return 0;
}

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 float_from_pyobj(float* v,PyObject *obj,const char *errmess) {
  double d=0.0;
  if (double_from_pyobj(&d,obj,errmess)) {
    *v = (float)d;
    return 1;
  }
  return 0;
}

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 = fImageD11_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(compute_gv,COMPUTE_GV)(float*,float*,float*,float*,float*,float*,float*,int*);
/*eof externroutines*/

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


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

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

/********************************* compute_gv *********************************/
static char doc_f2py_rout_fImageD11_compute_gv[] = "\
Function signature:\n\
  gv = compute_gv(xlylzl,omega,wvln,wedge,chi,t,[n])\n\
Required arguments:\n"
"  xlylzl : input rank-2 array('f') with bounds (3,n)\n"
"  omega : input rank-1 array('f') with bounds (n)\n"
"  wvln : input float\n"
"  wedge : input float\n"
"  chi : input float\n"
"  t : input rank-1 array('f') with bounds (3)\n"
"Optional arguments:\n"
"  n := shape(xlylzl,1) input int\n"
"Return objects:\n"
"  gv : rank-2 array('f') with bounds (3,n)";
/* extern void F_FUNC_US(compute_gv,COMPUTE_GV)(float*,float*,float*,float*,float*,float*,float*,int*); */
static PyObject *f2py_rout_fImageD11_compute_gv(const PyObject *capi_self,
                           PyObject *capi_args,
                           PyObject *capi_keywds,
                           void (*f2py_func)(float*,float*,float*,float*,float*,float*,float*,int*)) {
  PyObject * volatile capi_buildvalue = NULL;
  volatile int f2py_success = 1;
/*decl*/

  float *xlylzl = NULL;
  npy_intp xlylzl_Dims[2] = {-1, -1};
  const int xlylzl_Rank = 2;
  PyArrayObject *capi_xlylzl_tmp = NULL;
  int capi_xlylzl_intent = 0;
  PyObject *xlylzl_capi = Py_None;
  float *omega = NULL;
  npy_intp omega_Dims[1] = {-1};
  const int omega_Rank = 1;
  PyArrayObject *capi_omega_tmp = NULL;
  int capi_omega_intent = 0;
  PyObject *omega_capi = Py_None;
  float wvln = 0;
  PyObject *wvln_capi = Py_None;
  float wedge = 0;
  PyObject *wedge_capi = Py_None;
  float chi = 0;
  PyObject *chi_capi = Py_None;
  float *t = NULL;
  npy_intp t_Dims[1] = {-1};
  const int t_Rank = 1;
  PyArrayObject *capi_t_tmp = NULL;
  int capi_t_intent = 0;
  PyObject *t_capi = Py_None;
  float *gv = NULL;
  npy_intp gv_Dims[2] = {-1, -1};
  const int gv_Rank = 2;
  PyArrayObject *capi_gv_tmp = NULL;
  int capi_gv_intent = 0;
  int n = 0;
  PyObject *n_capi = Py_None;
  static char *capi_kwlist[] = {"xlylzl","omega","wvln","wedge","chi","t","n",NULL};

/*routdebugenter*/
#ifdef F2PY_REPORT_ATEXIT
f2py_start_clock();
#endif
  if (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\
    "OOOOOO|O:fImageD11.compute_gv",\
    capi_kwlist,&xlylzl_capi,&omega_capi,&wvln_capi,&wedge_capi,&chi_capi,&t_capi,&n_capi))
    return NULL;
/*frompyobj*/
  /* Processing variable wedge */
    f2py_success = float_from_pyobj(&wedge,wedge_capi,"fImageD11.compute_gv() 4th argument (wedge) can't be converted to float");
  if (f2py_success) {
  /* Processing variable xlylzl */
  xlylzl_Dims[0]=3;
  capi_xlylzl_intent |= F2PY_INTENT_IN;
  capi_xlylzl_tmp = array_from_pyobj(PyArray_FLOAT,xlylzl_Dims,xlylzl_Rank,capi_xlylzl_intent,xlylzl_capi);
  if (capi_xlylzl_tmp == NULL) {
    if (!PyErr_Occurred())
      PyErr_SetString(fImageD11_error,"failed in converting 1st argument `xlylzl' of fImageD11.compute_gv to C/Fortran array" );
  } else {
    xlylzl = (float *)(capi_xlylzl_tmp->data);

  /* Processing variable wvln */
    f2py_success = float_from_pyobj(&wvln,wvln_capi,"fImageD11.compute_gv() 3rd argument (wvln) can't be converted to float");
  if (f2py_success) {
  /* Processing variable chi */
    f2py_success = float_from_pyobj(&chi,chi_capi,"fImageD11.compute_gv() 5th argument (chi) can't be converted to float");
  if (f2py_success) {
  /* Processing variable t */
  t_Dims[0]=3;
  capi_t_intent |= F2PY_INTENT_IN;
  capi_t_tmp = array_from_pyobj(PyArray_FLOAT,t_Dims,t_Rank,capi_t_intent,t_capi);
  if (capi_t_tmp == NULL) {
    if (!PyErr_Occurred())
      PyErr_SetString(fImageD11_error,"failed in converting 6th argument `t' of fImageD11.compute_gv to C/Fortran array" );
  } else {
    t = (float *)(capi_t_tmp->data);

  /* Processing variable n */
  if (n_capi == Py_None) n = shape(xlylzl,1); else
    f2py_success = int_from_pyobj(&n,n_capi,"fImageD11.compute_gv() 1st keyword (n) can't be converted to int");
  if (f2py_success) {
  CHECKSCALAR(shape(xlylzl,1)==n,"shape(xlylzl,1)==n","1st keyword n","compute_gv:n=%d",n) {
  /* Processing variable gv */
  gv_Dims[0]=3,gv_Dims[1]=n;
  capi_gv_intent |= F2PY_INTENT_OUT|F2PY_INTENT_HIDE;
  capi_gv_tmp = array_from_pyobj(PyArray_FLOAT,gv_Dims,gv_Rank,capi_gv_intent,Py_None);
  if (capi_gv_tmp == NULL) {
    if (!PyErr_Occurred())
      PyErr_SetString(fImageD11_error,"failed in converting hidden `gv' of fImageD11.compute_gv to C/Fortran array" );
  } else {
    gv = (float *)(capi_gv_tmp->data);

  /* Processing variable omega */
  omega_Dims[0]=n;
  capi_omega_intent |= F2PY_INTENT_IN;
  capi_omega_tmp = array_from_pyobj(PyArray_FLOAT,omega_Dims,omega_Rank,capi_omega_intent,omega_capi);
  if (capi_omega_tmp == NULL) {
    if (!PyErr_Occurred())
      PyErr_SetString(fImageD11_error,"failed in converting 2nd argument `omega' of fImageD11.compute_gv to C/Fortran array" );
  } else {
    omega = (float *)(capi_omega_tmp->data);

/*end of frompyobj*/
#ifdef F2PY_REPORT_ATEXIT
f2py_start_call_clock();
#endif
/*callfortranroutine*/
        (*f2py_func)(xlylzl,omega,&wvln,&wedge,&chi,t,gv,&n);
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("N",capi_gv_tmp);
/*closepyobjfrom*/
/*end of closepyobjfrom*/
    } /*if (f2py_success) after callfortranroutine*/
/*cleanupfrompyobj*/
  if((PyObject *)capi_omega_tmp!=omega_capi) {
    Py_XDECREF(capi_omega_tmp); }
  }  /*if (capi_omega_tmp == NULL) ... else of omega*/
  /* End of cleaning variable omega */
  }  /*if (capi_gv_tmp == NULL) ... else of gv*/
  /* End of cleaning variable gv */
  } /*CHECKSCALAR(shape(xlylzl,1)==n)*/
  } /*if (f2py_success) of n*/
  /* End of cleaning variable n */
  if((PyObject *)capi_t_tmp!=t_capi) {
    Py_XDECREF(capi_t_tmp); }
  }  /*if (capi_t_tmp == NULL) ... else of t*/
  /* End of cleaning variable t */
  } /*if (f2py_success) of chi*/
  /* End of cleaning variable chi */
  } /*if (f2py_success) of wvln*/
  /* End of cleaning variable wvln */
  if((PyObject *)capi_xlylzl_tmp!=xlylzl_capi) {
    Py_XDECREF(capi_xlylzl_tmp); }
  }  /*if (capi_xlylzl_tmp == NULL) ... else of xlylzl*/
  /* End of cleaning variable xlylzl */
  } /*if (f2py_success) of wedge*/
  /* End of cleaning variable wedge */
/*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 compute_gv *****************************/
/*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[] = {
  {"compute_gv",-1,{{-1}},0,(char *)F_FUNC_US(compute_gv,COMPUTE_GV),(f2py_init_func)f2py_rout_fImageD11_compute_gv,doc_f2py_rout_fImageD11_compute_gv},

/*eof routine_defs*/
  {NULL}
};

static PyMethodDef f2py_module_methods[] = {

  {NULL,NULL}
};

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

#if PY_VERSION_HEX >= 0x03000000
#define RETVAL m
PyObject *PyInit_fImageD11(void) {
#else
#define RETVAL
PyMODINIT_FUNC initfImageD11(void) {
#endif
  int i;
  PyObject *m,*d, *s;
#if PY_VERSION_HEX >= 0x03000000
  m = fImageD11_module = PyModule_Create(&moduledef);
#else
  m = fImageD11_module = Py_InitModule("fImageD11", f2py_module_methods);
#endif
  Py_TYPE(&PyFortran_Type) = &PyType_Type;
  import_array();
  if (PyErr_Occurred())
    {PyErr_SetString(PyExc_ImportError, "can't initialize module fImageD11 (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 'fImageD11' is auto-generated with f2py (version:2).\nFunctions:\n"
"  gv = compute_gv(xlylzl,omega,wvln,wedge,chi,t,n=shape(xlylzl,1))\n"
".");
  PyDict_SetItemString(d, "__doc__", s);
  fImageD11_error = PyErr_NewException ("fImageD11.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*)"fImageD11");
#endif

  return RETVAL;
}
#ifdef __cplusplus
}
#endif
