/* Generated by Cython 0.24 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [], 
        "extra_compile_args": [
            "-std=gnu99"
        ], 
        "libraries": [
            "madx", 
            "stdc++", 
            "c"
        ]
    }
}
END: Cython Metadata */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_24"
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
  #define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
typedef struct {
    unaryfunc am_await;
    unaryfunc am_aiter;
    unaryfunc am_anext;
} __Pyx_PyAsyncMethodsStruct;
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
#else
#define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)

#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif


#define __PYX_ERR(f_index, lineno, Ln_error) \
{ \
  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
}

#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__cpymad__libmadx
#define __PYX_HAVE_API__cpymad__libmadx
#include "pyport.h"
#include "madX/mad_def.h"
#include "madX/mad_gcst.h"
#include "madX/mad_array.h"
#include "madX/mad_name.h"
#include "madX/mad_table.h"
#include "madX/mad_expr.h"
#include "madX/mad_cmdpar.h"
#include "madX/mad_cmd.h"
#include "madX/mad_elem.h"
#include "madX/mad_node.h"
#include "madX/mad_seq.h"
#include "madX/mad_var.h"
#include "madX/mad_gvar.h"
#include "madX/mad_api.h"
#include "madX/mad_core.h"
#include "madX/mad_str.h"
#include "madX/mad_eval.h"
#include "madX/mad_parse.h"
#include "madX/madx.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _abs64(value)
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */

static PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "cpymad/libmadx.pyx",
};

/*--- Type declarations ---*/

/* "cpymad/clibmadx.pxd":101
 *         command_parameter** parameters
 * 
 * cdef enum:             # <<<<<<<<<<<<<<
 *     PARAM_TYPE_LOGICAL = 0
 *     PARAM_TYPE_INTEGER = 1
 */
enum  {
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_LOGICAL = 0,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_INTEGER = 1,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE = 2,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_STRING = 3,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_CONSTRAINT = 4,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_LOGICAL_ARRAY = 10,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_INTEGER_ARRAY = 11,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE_ARRAY = 12,
  __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_STRING_ARRAY = 13
};

/* "cpymad/clibmadx.pxd":112
 *     PARAM_TYPE_STRING_ARRAY = 13
 * 
 * cdef enum:             # <<<<<<<<<<<<<<
 *     CONSTR_TYPE_MIN = 1
 *     CONSTR_TYPE_MAX = 2
 */
enum  {
  __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_MIN = 1,
  __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_MAX = 2,
  __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_BOTH = 3,
  __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_VALUE = 4
};

/* "cpymad/clibmadx.pxd":179
 *         variable** vars             # variable pointer list
 * 
 * cdef enum:             # <<<<<<<<<<<<<<
 *     REF_EXIT = -1
 *     REF_CENTER = 0
 */
enum  {
  __pyx_e_6cpymad_8clibmadx_REF_EXIT = -1L,
  __pyx_e_6cpymad_8clibmadx_REF_CENTER = 0,
  __pyx_e_6cpymad_8clibmadx_REF_ENTRY = 1
};
struct __pyx_opt_args_6cpymad_7libmadx__expr;

/* "cpymad/libmadx.pyx":773
 * _expr_types = [bool, int, float]
 * 
 * cdef _expr(clib.expression* expr,             # <<<<<<<<<<<<<<
 *            double value,
 *            int typeid=clib.PARAM_TYPE_DOUBLE):
 */
struct __pyx_opt_args_6cpymad_7libmadx__expr {
  int __pyx_n;
  int typeid;
};

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyObjectGetAttrStr.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* GetModuleGlobalName.proto */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* PyThreadStateGet.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = PyThreadState_GET();
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#endif

/* SaveResetException.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* ListCompAppend.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* IncludeStringH.proto */
#include <string.h>

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* decode_c_string.proto */
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);


/* Module declarations from 'cpymad.clibmadx' */

/* Module declarations from 'cpymad.libmadx' */
static struct expression *__pyx_f_6cpymad_7libmadx__make_expr(PyObject *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__expr(struct expression *, double, struct __pyx_opt_args_6cpymad_7libmadx__expr *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__get_param_value(struct command_parameter *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__parse_command(struct command *); /*proto*/
static struct sequence *__pyx_f_6cpymad_7libmadx__find_sequence(PyObject *); /*proto*/
static struct table *__pyx_f_6cpymad_7libmadx__find_table(PyObject *); /*proto*/
static int __pyx_f_6cpymad_7libmadx__get_node_index(struct node **, int, struct node *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__split_header_line(PyObject *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__name_list(struct name_list *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__str(char const *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__cstr(PyObject *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__get_node(struct node *, int); /*proto*/
static double __pyx_f_6cpymad_7libmadx__get_node_entry_pos(struct node *, int); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__get_element(struct element *); /*proto*/
static PyObject *__pyx_f_6cpymad_7libmadx__get_table_row_name(struct table *, int); /*proto*/
static struct variable *__pyx_f_6cpymad_7libmadx__get_var(PyObject *); /*proto*/
#define __Pyx_MODULE_NAME "cpymad.libmadx"
int __pyx_module_is_main_cpymad__libmadx = 0;

/* Implementation of 'cpymad.libmadx' */
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_xrange;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_KeyError;
static const char __pyx_k_[] = " ";
static const char __pyx_k_S[] = "S";
static const char __pyx_k_V[] = "V";
static const char __pyx_k_d[] = "d";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_s[] = "s";
static const char __pyx_k_at[] = "at";
static const char __pyx_k_le[] = "%le";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_os[] = "os";
static const char __pyx_k__10[] = "";
static const char __pyx_k_all[] = "__all__";
static const char __pyx_k_cmd[] = "cmd";
static const char __pyx_k_max[] = "max";
static const char __pyx_k_min[] = "min";
static const char __pyx_k_seq[] = "seq";
static const char __pyx_k_val[] = "val";
static const char __pyx_k_var[] = "var";
static const char __pyx_k_addr[] = "addr";
static const char __pyx_k_elem[] = "elem";
static const char __pyx_k_expr[] = "expr";
static const char __pyx_k_info[] = "info";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "name";
static const char __pyx_k_seqs[] = "seqs";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_type[] = "type";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_chdir[] = "chdir";
static const char __pyx_k_cmd_2[] = "_cmd";
static const char __pyx_k_col_i[] = "col_i";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_elems[] = "elems";
static const char __pyx_k_i_beg[] = "i_beg";
static const char __pyx_k_i_end[] = "i_end";
static const char __pyx_k_index[] = "index";
static const char __pyx_k_input[] = "input";
static const char __pyx_k_lower[] = "lower";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_strip[] = "strip";
static const char __pyx_k_tab_i[] = "tab_i";
static const char __pyx_k_table[] = "table";
static const char __pyx_k_utf_8[] = "utf-8";
static const char __pyx_k_value[] = "value";
static const char __pyx_k_ctypes[] = "ctypes";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_finish[] = "finish";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_getcwd[] = "getcwd";
static const char __pyx_k_header[] = "header";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_inform[] = "inform";
static const char __pyx_k_name_2[] = "_name";
static const char __pyx_k_rsplit[] = "rsplit";
static const char __pyx_k_typeid[] = "typeid";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_xrange[] = "xrange";
static const char __pyx_k_get_var[] = "get_var";
static const char __pyx_k_indices[] = "indices";
static const char __pyx_k_set_var[] = "set_var";
static const char __pyx_k_table_2[] = "_table";
static const char __pyx_k_value_2[] = "_value";
static const char __pyx_k_KeyError[] = "KeyError";
static const char __pyx_k_as_array[] = "as_array";
static const char __pyx_k_c_double[] = "c_double";
static const char __pyx_k_char_tmp[] = "char_tmp";
static const char __pyx_k_col_name[] = "_col_name";
static const char __pyx_k_endswith[] = "endswith";
static const char __pyx_k_evaluate[] = "evaluate";
static const char __pyx_k_position[] = "position";
static const char __pyx_k_sentence[] = "sentence";
static const char __pyx_k_tab_name[] = "_tab_name";
static const char __pyx_k_val_type[] = "val_type";
static const char __pyx_k_var_type[] = "var_type";
static const char __pyx_k_ctypeslib[] = "ctypeslib";
static const char __pyx_k_Constraint[] = "Constraint";
static const char __pyx_k_Expression[] = "Expression";
static const char __pyx_k_IndexError[] = "IndexError";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_array_data[] = "array_data";
static const char __pyx_k_array_type[] = "array_type";
static const char __pyx_k_expr_types[] = "_expr_types";
static const char __pyx_k_expression[] = "expression";
static const char __pyx_k_is_started[] = "is_started";
static const char __pyx_k_position_2[] = "_position";
static const char __pyx_k_table_name[] = "table_name";
static const char __pyx_k_column_name[] = "column_name";
static const char __pyx_k_cpymad_util[] = "cpymad.util";
static const char __pyx_k_get_element[] = "get_element";
static const char __pyx_k_get_globals[] = "get_globals";
static const char __pyx_k_num_globals[] = "num_globals";
static const char __pyx_k_Invalid_node[] = "Invalid node!";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_cpymad_types[] = "cpymad.types";
static const char __pyx_k_element_name[] = "element_name";
static const char __pyx_k_from_address[] = "from_address";
static const char __pyx_k_get_var_type[] = "get_var_type";
static const char __pyx_k_madx_started[] = "_madx_started";
static const char __pyx_k_table_exists[] = "table_exists";
static const char __pyx_k_table_name_2[] = "_table_name";
static const char __pyx_k_element_index[] = "element_index";
static const char __pyx_k_sequence_name[] = "sequence_name";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_cpymad_libmadx[] = "cpymad.libmadx";
static const char __pyx_k_element_name_2[] = "_element_name";
static const char __pyx_k_Invalid_table_r[] = "Invalid table: {!r}";
static const char __pyx_k_get_table_count[] = "get_table_count";
static const char __pyx_k_get_table_names[] = "get_table_names";
static const char __pyx_k_sequence_exists[] = "sequence_exists";
static const char __pyx_k_Invalid_column_r[] = "Invalid column: {!r}";
static const char __pyx_k_Invalid_sequence[] = "Invalid sequence: {}";
static const char __pyx_k_get_table_column[] = "get_table_column";
static const char __pyx_k_get_version_date[] = "get_version_date";
static const char __pyx_k_name_to_internal[] = "name_to_internal";
static const char __pyx_k_Invalid_row_index[] = "Invalid row index: {}";
static const char __pyx_k_get_element_count[] = "get_element_count";
static const char __pyx_k_get_element_index[] = "get_element_index";
static const char __pyx_k_get_sequence_beam[] = "get_sequence_beam";
static const char __pyx_k_get_table_summary[] = "get_table_summary";
static const char __pyx_k_No_active_sequence[] = "No active sequence!";
static const char __pyx_k_get_global_element[] = "get_global_element";
static const char __pyx_k_get_rightmost_word[] = "_get_rightmost_word";
static const char __pyx_k_get_sequence_count[] = "get_sequence_count";
static const char __pyx_k_get_sequence_names[] = "get_sequence_names";
static const char __pyx_k_get_version_number[] = "get_version_number";
static const char __pyx_k_name_from_internal[] = "name_from_internal";
static const char __pyx_k_No_beam_attached_to[] = "No beam attached to {}";
static const char __pyx_k_TWISS_table_invalid[] = "TWISS table invalid.";
static const char __pyx_k_get_table_row_count[] = "get_table_row_count";
static const char __pyx_k_get_table_row_names[] = "get_table_row_names";
static const char __pyx_k_get_expanded_element[] = "get_expanded_element";
static const char __pyx_k_is_sequence_expanded[] = "is_sequence_expanded";
static const char __pyx_k_normalize_range_name[] = "normalize_range_name";
static const char __pyx_k_No_summary_for_table_r[] = "No summary for table: {!r}";
static const char __pyx_k_Unknown_parameter_type[] = "Unknown parameter type: {}";
static const char __pyx_k_Variable_not_defined_r[] = "Variable not defined: {!r}";
static const char __pyx_k_get_table_column_count[] = "get_table_column_count";
static const char __pyx_k_get_table_column_names[] = "get_table_column_names";
static const char __pyx_k_Unknown_column_format_r[] = "Unknown column format: {!r}";
static const char __pyx_k_get_global_element_name[] = "get_global_element_name";
static const char __pyx_k_Element_name_not_found_0[] = "Element name not found: {0}";
static const char __pyx_k_get_active_sequence_name[] = "get_active_sequence_name";
static const char __pyx_k_get_global_element_count[] = "get_global_element_count";
static const char __pyx_k_get_global_element_index[] = "get_global_element_index";
static const char __pyx_k_Column_r_is_not_in_table_r[] = "Column {!r} is not in table {!r}.";
static const char __pyx_k_get_expanded_element_count[] = "get_expanded_element_count";
static const char __pyx_k_get_expanded_element_index[] = "get_expanded_element_index";
static const char __pyx_k_get_table_column_names_all[] = "get_table_column_names_all";
static const char __pyx_k_get_element_index_by_position[] = "get_element_index_by_position";
static const char __pyx_k_get_sequence_twiss_table_name[] = "get_sequence_twiss_table_name";
static const char __pyx_k_No_element_found_at_position_0[] = "No element found at position: {0}";
static const char __pyx_k_Unknown_datatype_r_in_column_r[] = "Unknown datatype {!r} in column {!r}.";
static const char __pyx_k_Low_level_cython_binding_to_MAD[] = "\nLow level cython binding to MAD-X.\n\nCAUTION: Do not import this module directly! Use :class:`Madx` instead.\n\n- Importing this module means loading MAD-X directly into the process space.\n  This means that any crash in the (extremely fragile) MAD-X interpreter will\n  crash the importing process with it.\n- All functions in this module operate on a shared global state.\n- this module exposes a very C-ish API that is not convenient to work with.\n";
static const char __pyx_k_home_thomas_src_work_bundle_cpy[] = "/home/thomas/src/work/bundle/cpymad/cpymad/libmadx.pyx";
static const char __pyx_k_Empty_node_or_subsequence_Please[] = "Empty node or subsequence! Please report this incident!";
static const char __pyx_k_Index_out_of_range_0_element_cou[] = "Index out of range: {0} (element count is {1})";
static const char __pyx_k_get_expanded_element_index_by_po[] = "get_expanded_element_index_by_position";
static PyObject *__pyx_kp_s_;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_kp_s_Column_r_is_not_in_table_r;
static PyObject *__pyx_n_s_Constraint;
static PyObject *__pyx_kp_s_Element_name_not_found_0;
static PyObject *__pyx_kp_s_Empty_node_or_subsequence_Please;
static PyObject *__pyx_n_s_Expression;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_kp_s_Index_out_of_range_0_element_cou;
static PyObject *__pyx_kp_s_Invalid_column_r;
static PyObject *__pyx_kp_s_Invalid_node;
static PyObject *__pyx_kp_s_Invalid_row_index;
static PyObject *__pyx_kp_s_Invalid_sequence;
static PyObject *__pyx_kp_s_Invalid_table_r;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_kp_s_No_active_sequence;
static PyObject *__pyx_kp_s_No_beam_attached_to;
static PyObject *__pyx_kp_s_No_element_found_at_position_0;
static PyObject *__pyx_kp_s_No_summary_for_table_r;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_n_b_S;
static PyObject *__pyx_kp_s_TWISS_table_invalid;
static PyObject *__pyx_kp_s_Unknown_column_format_r;
static PyObject *__pyx_kp_s_Unknown_datatype_r_in_column_r;
static PyObject *__pyx_kp_s_Unknown_parameter_type;
static PyObject *__pyx_n_b_V;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s_Variable_not_defined_r;
static PyObject *__pyx_kp_b__10;
static PyObject *__pyx_kp_s__10;
static PyObject *__pyx_n_s_addr;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_array_data;
static PyObject *__pyx_n_s_array_type;
static PyObject *__pyx_n_s_as_array;
static PyObject *__pyx_n_s_at;
static PyObject *__pyx_n_s_c_double;
static PyObject *__pyx_n_s_char_tmp;
static PyObject *__pyx_n_s_chdir;
static PyObject *__pyx_n_s_cmd;
static PyObject *__pyx_n_s_cmd_2;
static PyObject *__pyx_n_s_col_i;
static PyObject *__pyx_n_s_col_name;
static PyObject *__pyx_n_s_column_name;
static PyObject *__pyx_n_s_cpymad_libmadx;
static PyObject *__pyx_n_s_cpymad_types;
static PyObject *__pyx_n_s_cpymad_util;
static PyObject *__pyx_n_s_ctypes;
static PyObject *__pyx_n_s_ctypeslib;
static PyObject *__pyx_n_b_d;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_elem;
static PyObject *__pyx_n_s_element_index;
static PyObject *__pyx_n_s_element_name;
static PyObject *__pyx_n_s_element_name_2;
static PyObject *__pyx_n_s_elems;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_endswith;
static PyObject *__pyx_n_s_evaluate;
static PyObject *__pyx_n_s_expr;
static PyObject *__pyx_n_s_expr_types;
static PyObject *__pyx_n_s_expression;
static PyObject *__pyx_n_s_finish;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_from_address;
static PyObject *__pyx_n_s_get_active_sequence_name;
static PyObject *__pyx_n_s_get_element;
static PyObject *__pyx_n_s_get_element_count;
static PyObject *__pyx_n_s_get_element_index;
static PyObject *__pyx_n_s_get_element_index_by_position;
static PyObject *__pyx_n_s_get_expanded_element;
static PyObject *__pyx_n_s_get_expanded_element_count;
static PyObject *__pyx_n_s_get_expanded_element_index;
static PyObject *__pyx_n_s_get_expanded_element_index_by_po;
static PyObject *__pyx_n_s_get_global_element;
static PyObject *__pyx_n_s_get_global_element_count;
static PyObject *__pyx_n_s_get_global_element_index;
static PyObject *__pyx_n_s_get_global_element_name;
static PyObject *__pyx_n_s_get_globals;
static PyObject *__pyx_n_s_get_rightmost_word;
static PyObject *__pyx_n_s_get_sequence_beam;
static PyObject *__pyx_n_s_get_sequence_count;
static PyObject *__pyx_n_s_get_sequence_names;
static PyObject *__pyx_n_s_get_sequence_twiss_table_name;
static PyObject *__pyx_n_s_get_table_column;
static PyObject *__pyx_n_s_get_table_column_count;
static PyObject *__pyx_n_s_get_table_column_names;
static PyObject *__pyx_n_s_get_table_column_names_all;
static PyObject *__pyx_n_s_get_table_count;
static PyObject *__pyx_n_s_get_table_names;
static PyObject *__pyx_n_s_get_table_row_count;
static PyObject *__pyx_n_s_get_table_row_names;
static PyObject *__pyx_n_s_get_table_summary;
static PyObject *__pyx_n_s_get_var;
static PyObject *__pyx_n_s_get_var_type;
static PyObject *__pyx_n_s_get_version_date;
static PyObject *__pyx_n_s_get_version_number;
static PyObject *__pyx_n_s_getcwd;
static PyObject *__pyx_n_s_header;
static PyObject *__pyx_kp_s_home_thomas_src_work_bundle_cpy;
static PyObject *__pyx_n_b_i;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_i_beg;
static PyObject *__pyx_n_s_i_end;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_index;
static PyObject *__pyx_n_s_indices;
static PyObject *__pyx_n_s_info;
static PyObject *__pyx_n_s_inform;
static PyObject *__pyx_n_s_input;
static PyObject *__pyx_n_s_is_sequence_expanded;
static PyObject *__pyx_n_s_is_started;
static PyObject *__pyx_kp_s_le;
static PyObject *__pyx_n_s_lower;
static PyObject *__pyx_n_s_madx_started;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_name_2;
static PyObject *__pyx_n_s_name_from_internal;
static PyObject *__pyx_n_s_name_to_internal;
static PyObject *__pyx_n_s_normalize_range_name;
static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_num_globals;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_position;
static PyObject *__pyx_n_s_position_2;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rsplit;
static PyObject *__pyx_n_s_s;
static PyObject *__pyx_n_s_sentence;
static PyObject *__pyx_n_s_seq;
static PyObject *__pyx_n_s_seqs;
static PyObject *__pyx_n_s_sequence_exists;
static PyObject *__pyx_n_s_sequence_name;
static PyObject *__pyx_n_s_set_var;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_strip;
static PyObject *__pyx_n_s_tab_i;
static PyObject *__pyx_n_s_tab_name;
static PyObject *__pyx_n_s_table;
static PyObject *__pyx_n_s_table_2;
static PyObject *__pyx_n_s_table_exists;
static PyObject *__pyx_n_s_table_name;
static PyObject *__pyx_n_s_table_name_2;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_type;
static PyObject *__pyx_n_s_typeid;
static PyObject *__pyx_n_s_update;
static PyObject *__pyx_kp_s_utf_8;
static PyObject *__pyx_n_s_val;
static PyObject *__pyx_n_s_val_type;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_s_value_2;
static PyObject *__pyx_n_s_var;
static PyObject *__pyx_n_s_var_type;
static PyObject *__pyx_n_s_xrange;
static PyObject *__pyx_pf_6cpymad_7libmadx__get_rightmost_word(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sentence); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_2get_version_number(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_4get_version_date(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_6is_started(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_8start(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_10finish(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_12input(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cmd); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_14get_var(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_16get_var_type(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_18set_var(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_20num_globals(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_22get_globals(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_24sequence_exists(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_26get_sequence_twiss_table_name(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_28get_sequence_beam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_30get_active_sequence_name(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_32get_sequence_names(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_34get_sequence_count(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_36table_exists(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_38get_table_names(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_40get_table_count(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_42get_table_summary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_44get_table_column_names(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_46get_table_column_names_all(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_48get_table_column_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_50get_table_column(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name, PyObject *__pyx_v_column_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_52get_table_row_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_54get_table_row_names(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name, PyObject *__pyx_v_indices); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_56get_element(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_index); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_58get_element_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_60get_element_index_by_position(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_position); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_62get_element_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_64get_expanded_element(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_index); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_66get_expanded_element_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_68get_expanded_element_index_by_position(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_position); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_70get_expanded_element_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_72get_global_element(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_element_index); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_74get_global_element_name(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_element_index); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_76get_global_element_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_element_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_78get_global_element_count(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_80is_sequence_expanded(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /* proto */
static PyObject *__pyx_pf_6cpymad_7libmadx_82evaluate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_expression); /* proto */
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_neg_1;
static int __pyx_k__5;
static PyObject *__pyx_slice__9;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__75;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_tuple__82;
static PyObject *__pyx_tuple__84;
static PyObject *__pyx_codeobj__14;
static PyObject *__pyx_codeobj__15;
static PyObject *__pyx_codeobj__16;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__18;
static PyObject *__pyx_codeobj__19;
static PyObject *__pyx_codeobj__21;
static PyObject *__pyx_codeobj__23;
static PyObject *__pyx_codeobj__25;
static PyObject *__pyx_codeobj__27;
static PyObject *__pyx_codeobj__28;
static PyObject *__pyx_codeobj__29;
static PyObject *__pyx_codeobj__31;
static PyObject *__pyx_codeobj__33;
static PyObject *__pyx_codeobj__35;
static PyObject *__pyx_codeobj__36;
static PyObject *__pyx_codeobj__38;
static PyObject *__pyx_codeobj__39;
static PyObject *__pyx_codeobj__41;
static PyObject *__pyx_codeobj__43;
static PyObject *__pyx_codeobj__44;
static PyObject *__pyx_codeobj__46;
static PyObject *__pyx_codeobj__48;
static PyObject *__pyx_codeobj__50;
static PyObject *__pyx_codeobj__52;
static PyObject *__pyx_codeobj__54;
static PyObject *__pyx_codeobj__56;
static PyObject *__pyx_codeobj__58;
static PyObject *__pyx_codeobj__60;
static PyObject *__pyx_codeobj__62;
static PyObject *__pyx_codeobj__64;
static PyObject *__pyx_codeobj__66;
static PyObject *__pyx_codeobj__68;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_codeobj__72;
static PyObject *__pyx_codeobj__74;
static PyObject *__pyx_codeobj__76;
static PyObject *__pyx_codeobj__78;
static PyObject *__pyx_codeobj__80;
static PyObject *__pyx_codeobj__81;
static PyObject *__pyx_codeobj__83;
static PyObject *__pyx_codeobj__85;

/* "cpymad/libmadx.pyx":101
 * 
 * 
 * def _get_rightmost_word(sentence):             # <<<<<<<<<<<<<<
 *     """Get the work right of the rightmost space character."""
 *     return sentence.rsplit(' ', 1)[-1]
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_1_get_rightmost_word(PyObject *__pyx_self, PyObject *__pyx_v_sentence); /*proto*/
static char __pyx_doc_6cpymad_7libmadx__get_rightmost_word[] = "_get_rightmost_word(sentence)\nGet the work right of the rightmost space character.";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_1_get_rightmost_word = {"_get_rightmost_word", (PyCFunction)__pyx_pw_6cpymad_7libmadx_1_get_rightmost_word, METH_O, __pyx_doc_6cpymad_7libmadx__get_rightmost_word};
static PyObject *__pyx_pw_6cpymad_7libmadx_1_get_rightmost_word(PyObject *__pyx_self, PyObject *__pyx_v_sentence) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_rightmost_word (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx__get_rightmost_word(__pyx_self, ((PyObject *)__pyx_v_sentence));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx__get_rightmost_word(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sentence) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("_get_rightmost_word", 0);

  /* "cpymad/libmadx.pyx":103
 * def _get_rightmost_word(sentence):
 *     """Get the work right of the rightmost space character."""
 *     return sentence.rsplit(' ', 1)[-1]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_sentence, __pyx_n_s_rsplit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":101
 * 
 * 
 * def _get_rightmost_word(sentence):             # <<<<<<<<<<<<<<
 *     """Get the work right of the rightmost space character."""
 *     return sentence.rsplit(' ', 1)[-1]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx._get_rightmost_word", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":106
 * 
 * 
 * def get_version_number():             # <<<<<<<<<<<<<<
 *     """
 *     Get the version number of loaded MAD-X interpreter.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_3get_version_number(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_2get_version_number[] = "get_version_number()\n\n    Get the version number of loaded MAD-X interpreter.\n\n    :returns: full version number\n    :rtype: str\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_3get_version_number = {"get_version_number", (PyCFunction)__pyx_pw_6cpymad_7libmadx_3get_version_number, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_2get_version_number};
static PyObject *__pyx_pw_6cpymad_7libmadx_3get_version_number(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_version_number (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_2get_version_number(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_2get_version_number(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("get_version_number", 0);

  /* "cpymad/libmadx.pyx":113
 *     :rtype: str
 *     """
 *     return _get_rightmost_word(_str(clib.version_name))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_rightmost_word); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__str(version_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 113, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":106
 * 
 * 
 * def get_version_number():             # <<<<<<<<<<<<<<
 *     """
 *     Get the version number of loaded MAD-X interpreter.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cpymad.libmadx.get_version_number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":116
 * 
 * 
 * def get_version_date():             # <<<<<<<<<<<<<<
 *     """
 *     Get the release date of loaded MAD-X interpreter.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_5get_version_date(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_4get_version_date[] = "get_version_date()\n\n    Get the release date of loaded MAD-X interpreter.\n\n    :returns: release date in YYYY.MM.DD format\n    :rtype: str\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_5get_version_date = {"get_version_date", (PyCFunction)__pyx_pw_6cpymad_7libmadx_5get_version_date, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_4get_version_date};
static PyObject *__pyx_pw_6cpymad_7libmadx_5get_version_date(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_version_date (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_4get_version_date(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_4get_version_date(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("get_version_date", 0);

  /* "cpymad/libmadx.pyx":123
 *     :rtype: str
 *     """
 *     return _get_rightmost_word(_str(clib.version_date))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_rightmost_word); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__str(version_date); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":116
 * 
 * 
 * def get_version_date():             # <<<<<<<<<<<<<<
 *     """
 *     Get the release date of loaded MAD-X interpreter.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cpymad.libmadx.get_version_date", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":126
 * 
 * 
 * def is_started():             # <<<<<<<<<<<<<<
 *     """
 *     Check whether MAD-X has been initialized.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_7is_started(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_6is_started[] = "is_started()\n\n    Check whether MAD-X has been initialized.\n\n    :returns: whether :func:`start` was called without matching :func:`finish`\n    :rtype: bool\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_7is_started = {"is_started", (PyCFunction)__pyx_pw_6cpymad_7libmadx_7is_started, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_6is_started};
static PyObject *__pyx_pw_6cpymad_7libmadx_7is_started(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_started (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_6is_started(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_6is_started(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("is_started", 0);

  /* "cpymad/libmadx.pyx":133
 *     :rtype: bool
 *     """
 *     return _madx_started             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_madx_started); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":126
 * 
 * 
 * def is_started():             # <<<<<<<<<<<<<<
 *     """
 *     Check whether MAD-X has been initialized.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.is_started", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":136
 * 
 * 
 * def start():             # <<<<<<<<<<<<<<
 *     """
 *     Initialize MAD-X.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_9start(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_8start[] = "start()\n\n    Initialize MAD-X.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_9start = {"start", (PyCFunction)__pyx_pw_6cpymad_7libmadx_9start, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_8start};
static PyObject *__pyx_pw_6cpymad_7libmadx_9start(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("start (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_8start(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_8start(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("start", 0);

  /* "cpymad/libmadx.pyx":140
 *     Initialize MAD-X.
 *     """
 *     clib.madx_start()             # <<<<<<<<<<<<<<
 *     global _madx_started
 *     _madx_started = True
 */
  madx_start();

  /* "cpymad/libmadx.pyx":142
 *     clib.madx_start()
 *     global _madx_started
 *     _madx_started = True             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_madx_started, Py_True) < 0) __PYX_ERR(0, 142, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":136
 * 
 * 
 * def start():             # <<<<<<<<<<<<<<
 *     """
 *     Initialize MAD-X.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpymad.libmadx.start", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":145
 * 
 * 
 * def finish():             # <<<<<<<<<<<<<<
 *     """
 *     Cleanup MAD-X.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_11finish(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_10finish[] = "finish()\n\n    Cleanup MAD-X.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_11finish = {"finish", (PyCFunction)__pyx_pw_6cpymad_7libmadx_11finish, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_10finish};
static PyObject *__pyx_pw_6cpymad_7libmadx_11finish(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("finish (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_10finish(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_10finish(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("finish", 0);

  /* "cpymad/libmadx.pyx":149
 *     Cleanup MAD-X.
 *     """
 *     clib.madx_finish()             # <<<<<<<<<<<<<<
 *     global _madx_started
 *     _madx_started = False
 */
  madx_finish();

  /* "cpymad/libmadx.pyx":151
 *     clib.madx_finish()
 *     global _madx_started
 *     _madx_started = False             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_madx_started, Py_False) < 0) __PYX_ERR(0, 151, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":145
 * 
 * 
 * def finish():             # <<<<<<<<<<<<<<
 *     """
 *     Cleanup MAD-X.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpymad.libmadx.finish", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":154
 * 
 * 
 * def input(cmd):             # <<<<<<<<<<<<<<
 *     """
 *     Pass one input command to MAD-X.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_13input(PyObject *__pyx_self, PyObject *__pyx_v_cmd); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_12input[] = "input(cmd)\n\n    Pass one input command to MAD-X.\n\n    :param str cmd: command to be executed by the MAD-X interpreter\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_13input = {"input", (PyCFunction)__pyx_pw_6cpymad_7libmadx_13input, METH_O, __pyx_doc_6cpymad_7libmadx_12input};
static PyObject *__pyx_pw_6cpymad_7libmadx_13input(PyObject *__pyx_self, PyObject *__pyx_v_cmd) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("input (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_12input(__pyx_self, ((PyObject *)__pyx_v_cmd));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_12input(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cmd) {
  PyObject *__pyx_v__cmd = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  __Pyx_RefNannySetupContext("input", 0);

  /* "cpymad/libmadx.pyx":160
 *     :param str cmd: command to be executed by the MAD-X interpreter
 *     """
 *     cdef bytes _cmd = _cstr(cmd)             # <<<<<<<<<<<<<<
 *     clib.stolower_nq(_cmd)
 *     clib.pro_input(_cmd)
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_cmd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__cmd = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":161
 *     """
 *     cdef bytes _cmd = _cstr(cmd)
 *     clib.stolower_nq(_cmd)             # <<<<<<<<<<<<<<
 *     clib.pro_input(_cmd)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__cmd); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 161, __pyx_L1_error)
  stolower_nq(__pyx_t_2);

  /* "cpymad/libmadx.pyx":162
 *     cdef bytes _cmd = _cstr(cmd)
 *     clib.stolower_nq(_cmd)
 *     clib.pro_input(_cmd)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__cmd); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 162, __pyx_L1_error)
  pro_input(__pyx_t_2);

  /* "cpymad/libmadx.pyx":154
 * 
 * 
 * def input(cmd):             # <<<<<<<<<<<<<<
 *     """
 *     Pass one input command to MAD-X.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.input", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__cmd);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":165
 * 
 * 
 * def get_var(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the value of a global variable.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_15get_var(PyObject *__pyx_self, PyObject *__pyx_v_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_14get_var[] = "get_var(name)\n\n    Get the value of a global variable.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_15get_var = {"get_var", (PyCFunction)__pyx_pw_6cpymad_7libmadx_15get_var, METH_O, __pyx_doc_6cpymad_7libmadx_14get_var};
static PyObject *__pyx_pw_6cpymad_7libmadx_15get_var(PyObject *__pyx_self, PyObject *__pyx_v_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_var (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_14get_var(__pyx_self, ((PyObject *)__pyx_v_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_14get_var(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name) {
  struct variable *__pyx_v_var;
  double __pyx_v_value;
  int __pyx_v_typeid;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct variable *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  struct __pyx_opt_args_6cpymad_7libmadx__expr __pyx_t_4;
  __Pyx_RefNannySetupContext("get_var", 0);

  /* "cpymad/libmadx.pyx":169
 *     Get the value of a global variable.
 *     """
 *     cdef clib.variable* var = _get_var(name)             # <<<<<<<<<<<<<<
 *     if var.type == 3:
 *         return _str(var.string)
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__get_var(__pyx_v_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 169, __pyx_L1_error)
  __pyx_v_var = __pyx_t_1;

  /* "cpymad/libmadx.pyx":170
 *     """
 *     cdef clib.variable* var = _get_var(name)
 *     if var.type == 3:             # <<<<<<<<<<<<<<
 *         return _str(var.string)
 *     cdef double value = clib.variable_value(var)
 */
  __pyx_t_2 = ((__pyx_v_var->type == 3) != 0);
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":171
 *     cdef clib.variable* var = _get_var(name)
 *     if var.type == 3:
 *         return _str(var.string)             # <<<<<<<<<<<<<<
 *     cdef double value = clib.variable_value(var)
 *     cdef int typeid
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __pyx_f_6cpymad_7libmadx__str(__pyx_v_var->string); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":170
 *     """
 *     cdef clib.variable* var = _get_var(name)
 *     if var.type == 3:             # <<<<<<<<<<<<<<
 *         return _str(var.string)
 *     cdef double value = clib.variable_value(var)
 */
  }

  /* "cpymad/libmadx.pyx":172
 *     if var.type == 3:
 *         return _str(var.string)
 *     cdef double value = clib.variable_value(var)             # <<<<<<<<<<<<<<
 *     cdef int typeid
 *     if var.val_type == 0:
 */
  __pyx_v_value = variable_value(__pyx_v_var);

  /* "cpymad/libmadx.pyx":174
 *     cdef double value = clib.variable_value(var)
 *     cdef int typeid
 *     if var.val_type == 0:             # <<<<<<<<<<<<<<
 *         typeid = clib.PARAM_TYPE_INTEGER
 *     else:
 */
  __pyx_t_2 = ((__pyx_v_var->val_type == 0) != 0);
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":175
 *     cdef int typeid
 *     if var.val_type == 0:
 *         typeid = clib.PARAM_TYPE_INTEGER             # <<<<<<<<<<<<<<
 *     else:
 *         typeid = clib.PARAM_TYPE_DOUBLE
 */
    __pyx_v_typeid = __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_INTEGER;

    /* "cpymad/libmadx.pyx":174
 *     cdef double value = clib.variable_value(var)
 *     cdef int typeid
 *     if var.val_type == 0:             # <<<<<<<<<<<<<<
 *         typeid = clib.PARAM_TYPE_INTEGER
 *     else:
 */
    goto __pyx_L4;
  }

  /* "cpymad/libmadx.pyx":177
 *         typeid = clib.PARAM_TYPE_INTEGER
 *     else:
 *         typeid = clib.PARAM_TYPE_DOUBLE             # <<<<<<<<<<<<<<
 *     return _expr(var.expr, value, typeid)
 * 
 */
  /*else*/ {
    __pyx_v_typeid = __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE;
  }
  __pyx_L4:;

  /* "cpymad/libmadx.pyx":178
 *     else:
 *         typeid = clib.PARAM_TYPE_DOUBLE
 *     return _expr(var.expr, value, typeid)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.typeid = __pyx_v_typeid;
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_var->expr, __pyx_v_value, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":165
 * 
 * 
 * def get_var(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the value of a global variable.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpymad.libmadx.get_var", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":181
 * 
 * 
 * def get_var_type(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the type of the variable:
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_17get_var_type(PyObject *__pyx_self, PyObject *__pyx_v_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_16get_var_type[] = "get_var_type(name)\n\n    Get the type of the variable:\n\n        0   constant\n        1   direct\n        2   deferred\n        3   string\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_17get_var_type = {"get_var_type", (PyCFunction)__pyx_pw_6cpymad_7libmadx_17get_var_type, METH_O, __pyx_doc_6cpymad_7libmadx_16get_var_type};
static PyObject *__pyx_pw_6cpymad_7libmadx_17get_var_type(PyObject *__pyx_self, PyObject *__pyx_v_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_var_type (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_16get_var_type(__pyx_self, ((PyObject *)__pyx_v_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_16get_var_type(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct variable *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_var_type", 0);

  /* "cpymad/libmadx.pyx":190
 *         3   string
 *     """
 *     return _get_var(name).type             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__get_var(__pyx_v_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 190, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1->type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":181
 * 
 * 
 * def get_var_type(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the type of the variable:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.get_var_type", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":193
 * 
 * 
 * def set_var(name, value):             # <<<<<<<<<<<<<<
 *     """
 *     Set the value of a global variable.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_19set_var(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_18set_var[] = "set_var(name, value)\n\n    Set the value of a global variable.\n\n    If the value is a string or :class:`Expression` set the variable as a\n    deferred expression.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_19set_var = {"set_var", (PyCFunction)__pyx_pw_6cpymad_7libmadx_19set_var, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_18set_var};
static PyObject *__pyx_pw_6cpymad_7libmadx_19set_var(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_name = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_var (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_value,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_var", 1, 2, 2, 1); __PYX_ERR(0, 193, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_var") < 0)) __PYX_ERR(0, 193, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_name = values[0];
    __pyx_v_value = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("set_var", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 193, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.set_var", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_18set_var(__pyx_self, __pyx_v_name, __pyx_v_value);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_18set_var(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name, PyObject *__pyx_v_value) {
  PyObject *__pyx_v__name = 0;
  double __pyx_v__value;
  int __pyx_v_var_type;
  int __pyx_v_val_type;
  struct expression *__pyx_v_expr;
  struct variable *__pyx_v_var;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  double __pyx_t_10;
  char *__pyx_t_11;
  __Pyx_RefNannySetupContext("set_var", 0);
  __Pyx_INCREF(__pyx_v_value);

  /* "cpymad/libmadx.pyx":200
 *     deferred expression.
 *     """
 *     cdef bytes _name = _cstr(name.lower())             # <<<<<<<<<<<<<<
 *     cdef double _value = 0
 *     cdef int var_type = 1       # 0: const, 1: direct, 2: deferred
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_name, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__name = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":201
 *     """
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef double _value = 0             # <<<<<<<<<<<<<<
 *     cdef int var_type = 1       # 0: const, 1: direct, 2: deferred
 *     cdef int val_type = 1       # 0: int, 1: double, 3: string
 */
  __pyx_v__value = 0.0;

  /* "cpymad/libmadx.pyx":202
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef double _value = 0
 *     cdef int var_type = 1       # 0: const, 1: direct, 2: deferred             # <<<<<<<<<<<<<<
 *     cdef int val_type = 1       # 0: int, 1: double, 3: string
 *     cdef clib.expression* expr = NULL
 */
  __pyx_v_var_type = 1;

  /* "cpymad/libmadx.pyx":203
 *     cdef double _value = 0
 *     cdef int var_type = 1       # 0: const, 1: direct, 2: deferred
 *     cdef int val_type = 1       # 0: int, 1: double, 3: string             # <<<<<<<<<<<<<<
 *     cdef clib.expression* expr = NULL
 *     cdef clib.variable* var
 */
  __pyx_v_val_type = 1;

  /* "cpymad/libmadx.pyx":204
 *     cdef int var_type = 1       # 0: const, 1: direct, 2: deferred
 *     cdef int val_type = 1       # 0: int, 1: double, 3: string
 *     cdef clib.expression* expr = NULL             # <<<<<<<<<<<<<<
 *     cdef clib.variable* var
 *     try:
 */
  __pyx_v_expr = NULL;

  /* "cpymad/libmadx.pyx":206
 *     cdef clib.expression* expr = NULL
 *     cdef clib.variable* var
 *     try:             # <<<<<<<<<<<<<<
 *         value = value.expr
 *     except AttributeError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
    __Pyx_XGOTREF(__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_5);
    __Pyx_XGOTREF(__pyx_t_6);
    /*try:*/ {

      /* "cpymad/libmadx.pyx":207
 *     cdef clib.variable* var
 *     try:
 *         value = value.expr             # <<<<<<<<<<<<<<
 *     except AttributeError:
 *         pass
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_expr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 207, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "cpymad/libmadx.pyx":206
 *     cdef clib.expression* expr = NULL
 *     cdef clib.variable* var
 *     try:             # <<<<<<<<<<<<<<
 *         value = value.expr
 *     except AttributeError:
 */
    }
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cpymad/libmadx.pyx":208
 *     try:
 *         value = value.expr
 *     except AttributeError:             # <<<<<<<<<<<<<<
 *         pass
 *     if isinstance(value, basestring):
 */
    __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_7) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "cpymad/libmadx.pyx":206
 *     cdef clib.expression* expr = NULL
 *     cdef clib.variable* var
 *     try:             # <<<<<<<<<<<<<<
 *         value = value.expr
 *     except AttributeError:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_XGIVEREF(__pyx_t_6);
    __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_XGIVEREF(__pyx_t_6);
    __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
    __pyx_L10_try_end:;
  }

  /* "cpymad/libmadx.pyx":210
 *     except AttributeError:
 *         pass
 *     if isinstance(value, basestring):             # <<<<<<<<<<<<<<
 *         var_type = 2            # deferred
 *         expr = _make_expr(value)
 */
  __pyx_t_8 = __Pyx_PyBaseString_Check(__pyx_v_value); 
  __pyx_t_9 = (__pyx_t_8 != 0);
  if (__pyx_t_9) {

    /* "cpymad/libmadx.pyx":211
 *         pass
 *     if isinstance(value, basestring):
 *         var_type = 2            # deferred             # <<<<<<<<<<<<<<
 *         expr = _make_expr(value)
 *     else:
 */
    __pyx_v_var_type = 2;

    /* "cpymad/libmadx.pyx":212
 *     if isinstance(value, basestring):
 *         var_type = 2            # deferred
 *         expr = _make_expr(value)             # <<<<<<<<<<<<<<
 *     else:
 *         _value = value
 */
    __pyx_v_expr = __pyx_f_6cpymad_7libmadx__make_expr(__pyx_v_value);

    /* "cpymad/libmadx.pyx":210
 *     except AttributeError:
 *         pass
 *     if isinstance(value, basestring):             # <<<<<<<<<<<<<<
 *         var_type = 2            # deferred
 *         expr = _make_expr(value)
 */
    goto __pyx_L11;
  }

  /* "cpymad/libmadx.pyx":214
 *         expr = _make_expr(value)
 *     else:
 *         _value = value             # <<<<<<<<<<<<<<
 *         if isinstance(value, int):
 *             val_type = 0        # int
 */
  /*else*/ {
    __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error)
    __pyx_v__value = __pyx_t_10;

    /* "cpymad/libmadx.pyx":215
 *     else:
 *         _value = value
 *         if isinstance(value, int):             # <<<<<<<<<<<<<<
 *             val_type = 0        # int
 *     var = clib.new_variable(_name, _value, val_type, var_type, expr, NULL)
 */
    __pyx_t_9 = PyInt_Check(__pyx_v_value); 
    __pyx_t_8 = (__pyx_t_9 != 0);
    if (__pyx_t_8) {

      /* "cpymad/libmadx.pyx":216
 *         _value = value
 *         if isinstance(value, int):
 *             val_type = 0        # int             # <<<<<<<<<<<<<<
 *     var = clib.new_variable(_name, _value, val_type, var_type, expr, NULL)
 *     clib.add_to_var_list(var, clib.variable_list, 1)
 */
      __pyx_v_val_type = 0;

      /* "cpymad/libmadx.pyx":215
 *     else:
 *         _value = value
 *         if isinstance(value, int):             # <<<<<<<<<<<<<<
 *             val_type = 0        # int
 *     var = clib.new_variable(_name, _value, val_type, var_type, expr, NULL)
 */
    }
  }
  __pyx_L11:;

  /* "cpymad/libmadx.pyx":217
 *         if isinstance(value, int):
 *             val_type = 0        # int
 *     var = clib.new_variable(_name, _value, val_type, var_type, expr, NULL)             # <<<<<<<<<<<<<<
 *     clib.add_to_var_list(var, clib.variable_list, 1)
 * 
 */
  __pyx_t_11 = __Pyx_PyObject_AsString(__pyx_v__name); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 217, __pyx_L1_error)
  __pyx_v_var = new_variable(__pyx_t_11, __pyx_v__value, __pyx_v_val_type, __pyx_v_var_type, __pyx_v_expr, NULL);

  /* "cpymad/libmadx.pyx":218
 *             val_type = 0        # int
 *     var = clib.new_variable(_name, _value, val_type, var_type, expr, NULL)
 *     clib.add_to_var_list(var, clib.variable_list, 1)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  add_to_var_list(__pyx_v_var, variable_list, 1);

  /* "cpymad/libmadx.pyx":193
 * 
 * 
 * def set_var(name, value):             # <<<<<<<<<<<<<<
 *     """
 *     Set the value of a global variable.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpymad.libmadx.set_var", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__name);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":221
 * 
 * 
 * def num_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Return the number of global variables.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_21num_globals(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_20num_globals[] = "num_globals()\n\n    Return the number of global variables.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_21num_globals = {"num_globals", (PyCFunction)__pyx_pw_6cpymad_7libmadx_21num_globals, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_20num_globals};
static PyObject *__pyx_pw_6cpymad_7libmadx_21num_globals(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("num_globals (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_20num_globals(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_20num_globals(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("num_globals", 0);

  /* "cpymad/libmadx.pyx":225
 *     Return the number of global variables.
 *     """
 *     return clib.variable_list.curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(variable_list->curr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":221
 * 
 * 
 * def num_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Return the number of global variables.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.num_globals", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":228
 * 
 * 
 * def get_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of names of all global variables.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_23get_globals(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_22get_globals[] = "get_globals()\n\n    Get a list of names of all global variables.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_23get_globals = {"get_globals", (PyCFunction)__pyx_pw_6cpymad_7libmadx_23get_globals, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_22get_globals};
static PyObject *__pyx_pw_6cpymad_7libmadx_23get_globals(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_globals (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_22get_globals(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_22get_globals(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_globals", 0);

  /* "cpymad/libmadx.pyx":232
 *     Get a list of names of all global variables.
 *     """
 *     return _name_list(clib.variable_list.list)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__name_list(variable_list->list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":228
 * 
 * 
 * def get_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of names of all global variables.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.get_globals", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":235
 * 
 * 
 * def sequence_exists(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the sequence exists.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_25sequence_exists(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_24sequence_exists[] = "sequence_exists(sequence_name)\n\n    Check if the sequence exists.\n\n    :param str sequence: sequence name\n    :returns: True if the sequence exists\n    :rtype: bool\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_25sequence_exists = {"sequence_exists", (PyCFunction)__pyx_pw_6cpymad_7libmadx_25sequence_exists, METH_O, __pyx_doc_6cpymad_7libmadx_24sequence_exists};
static PyObject *__pyx_pw_6cpymad_7libmadx_25sequence_exists(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sequence_exists (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_24sequence_exists(__pyx_self, ((PyObject *)__pyx_v_sequence_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_24sequence_exists(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  struct sequence *__pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("sequence_exists", 0);

  /* "cpymad/libmadx.pyx":243
 *     :rtype: bool
 *     """
 *     try:             # <<<<<<<<<<<<<<
 *         _find_sequence(sequence_name)
 *         return True
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "cpymad/libmadx.pyx":244
 *     """
 *     try:
 *         _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *         return True
 *     except ValueError:
 */
      __pyx_t_4 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_4 == NULL)) __PYX_ERR(0, 244, __pyx_L3_error)

      /* "cpymad/libmadx.pyx":245
 *     try:
 *         _find_sequence(sequence_name)
 *         return True             # <<<<<<<<<<<<<<
 *     except ValueError:
 *         return False
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_True);
      __pyx_r = Py_True;
      goto __pyx_L7_try_return;

      /* "cpymad/libmadx.pyx":243
 *     :rtype: bool
 *     """
 *     try:             # <<<<<<<<<<<<<<
 *         _find_sequence(sequence_name)
 *         return True
 */
    }
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign

    /* "cpymad/libmadx.pyx":246
 *         _find_sequence(sequence_name)
 *         return True
 *     except ValueError:             # <<<<<<<<<<<<<<
 *         return False
 * 
 */
    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_5) {
      __Pyx_AddTraceback("cpymad.libmadx.sequence_exists", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(0, 246, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GOTREF(__pyx_t_8);

      /* "cpymad/libmadx.pyx":247
 *         return True
 *     except ValueError:
 *         return False             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_False);
      __pyx_r = Py_False;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L6_except_return;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "cpymad/libmadx.pyx":243
 *     :rtype: bool
 *     """
 *     try:             # <<<<<<<<<<<<<<
 *         _find_sequence(sequence_name)
 *         return True
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
    __pyx_L6_except_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
  }

  /* "cpymad/libmadx.pyx":235
 * 
 * 
 * def sequence_exists(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the sequence exists.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("cpymad.libmadx.sequence_exists", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":250
 * 
 * 
 * def get_sequence_twiss_table_name(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the last calculated twiss table for the given sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_27get_sequence_twiss_table_name(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_26get_sequence_twiss_table_name[] = "get_sequence_twiss_table_name(sequence_name)\n\n    Get the last calculated twiss table for the given sequence.\n\n    :param str sequence_name: sequence name\n    :returns: twiss table name\n    :rtype: str\n    :raises ValueError: if the sequence name is invalid\n    :raises RuntimeError: if the twiss table is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_27get_sequence_twiss_table_name = {"get_sequence_twiss_table_name", (PyCFunction)__pyx_pw_6cpymad_7libmadx_27get_sequence_twiss_table_name, METH_O, __pyx_doc_6cpymad_7libmadx_26get_sequence_twiss_table_name};
static PyObject *__pyx_pw_6cpymad_7libmadx_27get_sequence_twiss_table_name(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_sequence_twiss_table_name (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_26get_sequence_twiss_table_name(__pyx_self, ((PyObject *)__pyx_v_sequence_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_26get_sequence_twiss_table_name(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("get_sequence_twiss_table_name", 0);

  /* "cpymad/libmadx.pyx":260
 *     :raises RuntimeError: if the twiss table is invalid
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     if not seq.tw_valid:
 *         raise RuntimeError("TWISS table invalid.")
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 260, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":261
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if not seq.tw_valid:             # <<<<<<<<<<<<<<
 *         raise RuntimeError("TWISS table invalid.")
 *     return _str(seq.tw_table.name)
 */
  __pyx_t_2 = ((!(__pyx_v_seq->tw_valid != 0)) != 0);
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":262
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if not seq.tw_valid:
 *         raise RuntimeError("TWISS table invalid.")             # <<<<<<<<<<<<<<
 *     return _str(seq.tw_table.name)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 262, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 262, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":261
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if not seq.tw_valid:             # <<<<<<<<<<<<<<
 *         raise RuntimeError("TWISS table invalid.")
 *     return _str(seq.tw_table.name)
 */
  }

  /* "cpymad/libmadx.pyx":263
 *     if not seq.tw_valid:
 *         raise RuntimeError("TWISS table invalid.")
 *     return _str(seq.tw_table.name)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__str(__pyx_v_seq->tw_table->name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":250
 * 
 * 
 * def get_sequence_twiss_table_name(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the last calculated twiss table for the given sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpymad.libmadx.get_sequence_twiss_table_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":266
 * 
 * 
 * def get_sequence_beam(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the beam associated to the sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_29get_sequence_beam(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_28get_sequence_beam[] = "get_sequence_beam(sequence_name)\n\n    Get the beam associated to the sequence.\n\n    :param str sequence_name: sequence name\n    :returns: beam properties as set with the BEAM command (and some more)\n    :rtype: dict\n    :raises ValueError: if the sequence name is invalid\n    :raises RuntimeError: if the sequence has no associated beam\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_29get_sequence_beam = {"get_sequence_beam", (PyCFunction)__pyx_pw_6cpymad_7libmadx_29get_sequence_beam, METH_O, __pyx_doc_6cpymad_7libmadx_28get_sequence_beam};
static PyObject *__pyx_pw_6cpymad_7libmadx_29get_sequence_beam(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_sequence_beam (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_28get_sequence_beam(__pyx_self, ((PyObject *)__pyx_v_sequence_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_28get_sequence_beam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("get_sequence_beam", 0);

  /* "cpymad/libmadx.pyx":276
 *     :raises RuntimeError: if the sequence has no associated beam
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     if seq.beam is NULL or not seq.beam.beam_def:
 *         raise RuntimeError("No beam attached to {}".format(sequence_name))
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 276, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":277
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if seq.beam is NULL or not seq.beam.beam_def:             # <<<<<<<<<<<<<<
 *         raise RuntimeError("No beam attached to {}".format(sequence_name))
 *     return _parse_command(seq.beam)
 */
  __pyx_t_3 = ((__pyx_v_seq->beam == NULL) != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = ((!(__pyx_v_seq->beam->beam_def != 0)) != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":278
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if seq.beam is NULL or not seq.beam.beam_def:
 *         raise RuntimeError("No beam attached to {}".format(sequence_name))             # <<<<<<<<<<<<<<
 *     return _parse_command(seq.beam)
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_No_beam_attached_to, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_sequence_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_sequence_name);
      __Pyx_GIVEREF(__pyx_v_sequence_name);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_sequence_name);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 278, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":277
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if seq.beam is NULL or not seq.beam.beam_def:             # <<<<<<<<<<<<<<
 *         raise RuntimeError("No beam attached to {}".format(sequence_name))
 *     return _parse_command(seq.beam)
 */
  }

  /* "cpymad/libmadx.pyx":279
 *     if seq.beam is NULL or not seq.beam.beam_def:
 *         raise RuntimeError("No beam attached to {}".format(sequence_name))
 *     return _parse_command(seq.beam)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __pyx_f_6cpymad_7libmadx__parse_command(__pyx_v_seq->beam); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 279, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":266
 * 
 * 
 * def get_sequence_beam(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the beam associated to the sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("cpymad.libmadx.get_sequence_beam", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":282
 * 
 * 
 * def get_active_sequence_name():             # <<<<<<<<<<<<<<
 *     """
 *     Get the name of the active sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_31get_active_sequence_name(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_30get_active_sequence_name[] = "get_active_sequence_name()\n\n    Get the name of the active sequence.\n\n    :returns: name of active sequence\n    :rtype: str\n    :raises RuntimeError: if no sequence is activated\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_31get_active_sequence_name = {"get_active_sequence_name", (PyCFunction)__pyx_pw_6cpymad_7libmadx_31get_active_sequence_name, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_30get_active_sequence_name};
static PyObject *__pyx_pw_6cpymad_7libmadx_31get_active_sequence_name(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_active_sequence_name (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_30get_active_sequence_name(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_30get_active_sequence_name(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_active_sequence_name", 0);

  /* "cpymad/libmadx.pyx":290
 *     :raises RuntimeError: if no sequence is activated
 *     """
 *     if clib.current_sequ is NULL:             # <<<<<<<<<<<<<<
 *         raise RuntimeError("No active sequence!")
 *     return _str(clib.current_sequ.name)
 */
  __pyx_t_1 = ((current_sequ == NULL) != 0);
  if (__pyx_t_1) {

    /* "cpymad/libmadx.pyx":291
 *     """
 *     if clib.current_sequ is NULL:
 *         raise RuntimeError("No active sequence!")             # <<<<<<<<<<<<<<
 *     return _str(clib.current_sequ.name)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 291, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":290
 *     :raises RuntimeError: if no sequence is activated
 *     """
 *     if clib.current_sequ is NULL:             # <<<<<<<<<<<<<<
 *         raise RuntimeError("No active sequence!")
 *     return _str(clib.current_sequ.name)
 */
  }

  /* "cpymad/libmadx.pyx":292
 *     if clib.current_sequ is NULL:
 *         raise RuntimeError("No active sequence!")
 *     return _str(clib.current_sequ.name)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_6cpymad_7libmadx__str(current_sequ->name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 292, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":282
 * 
 * 
 * def get_active_sequence_name():             # <<<<<<<<<<<<<<
 *     """
 *     Get the name of the active sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.get_active_sequence_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":295
 * 
 * 
 * def get_sequence_names():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all sequences currently in memory.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_33get_sequence_names(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_32get_sequence_names[] = "get_sequence_names()\n\n    Get a list of all sequences currently in memory.\n\n    :returns: sequence names\n    :rtype: list\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_33get_sequence_names = {"get_sequence_names", (PyCFunction)__pyx_pw_6cpymad_7libmadx_33get_sequence_names, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_32get_sequence_names};
static PyObject *__pyx_pw_6cpymad_7libmadx_33get_sequence_names(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_sequence_names (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_32get_sequence_names(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_32get_sequence_names(CYTHON_UNUSED PyObject *__pyx_self) {
  struct sequence_list *__pyx_v_seqs;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("get_sequence_names", 0);

  /* "cpymad/libmadx.pyx":302
 *     :rtype: list
 *     """
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()             # <<<<<<<<<<<<<<
 *     cdef int i
 *     return [_str(seqs.sequs[i].name)
 */
  __pyx_v_seqs = madextern_get_sequence_list();

  /* "cpymad/libmadx.pyx":304
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()
 *     cdef int i
 *     return [_str(seqs.sequs[i].name)             # <<<<<<<<<<<<<<
 *             for i in xrange(seqs.curr)]
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "cpymad/libmadx.pyx":305
 *     cdef int i
 *     return [_str(seqs.sequs[i].name)
 *             for i in xrange(seqs.curr)]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __pyx_v_seqs->curr;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "cpymad/libmadx.pyx":304
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()
 *     cdef int i
 *     return [_str(seqs.sequs[i].name)             # <<<<<<<<<<<<<<
 *             for i in xrange(seqs.curr)]
 * 
 */
    __pyx_t_4 = __pyx_f_6cpymad_7libmadx__str((__pyx_v_seqs->sequs[__pyx_v_i])->name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 304, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 304, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":295
 * 
 * 
 * def get_sequence_names():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all sequences currently in memory.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpymad.libmadx.get_sequence_names", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":308
 * 
 * 
 * def get_sequence_count():             # <<<<<<<<<<<<<<
 *     """
 *     Get the number of all sequences currently in memory.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_35get_sequence_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_34get_sequence_count[] = "get_sequence_count()\n\n    Get the number of all sequences currently in memory.\n\n    :returns: number of sequences\n    :rtype: int\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_35get_sequence_count = {"get_sequence_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_35get_sequence_count, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_34get_sequence_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_35get_sequence_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_sequence_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_34get_sequence_count(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_34get_sequence_count(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_sequence_count", 0);

  /* "cpymad/libmadx.pyx":315
 *     :rtype: int
 *     """
 *     return clib.madextern_get_sequence_list().curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(madextern_get_sequence_list()->curr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":308
 * 
 * 
 * def get_sequence_count():             # <<<<<<<<<<<<<<
 *     """
 *     Get the number of all sequences currently in memory.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.get_sequence_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":318
 * 
 * 
 * def table_exists(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the table exists.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_37table_exists(PyObject *__pyx_self, PyObject *__pyx_v_table_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_36table_exists[] = "table_exists(table_name)\n\n    Check if the table exists.\n\n    :param str table: table name\n    :returns: True if the table exists\n    :rtype: bool\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_37table_exists = {"table_exists", (PyCFunction)__pyx_pw_6cpymad_7libmadx_37table_exists, METH_O, __pyx_doc_6cpymad_7libmadx_36table_exists};
static PyObject *__pyx_pw_6cpymad_7libmadx_37table_exists(PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("table_exists (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_36table_exists(__pyx_self, ((PyObject *)__pyx_v_table_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_36table_exists(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_v__table_name = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("table_exists", 0);

  /* "cpymad/libmadx.pyx":326
 *     :rtype: bool
 *     """
 *     cdef bytes _table_name = _cstr(table_name)             # <<<<<<<<<<<<<<
 *     return bool(clib.table_exists(_table_name))
 * 
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 326, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__table_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":327
 *     """
 *     cdef bytes _table_name = _cstr(table_name)
 *     return bool(clib.table_exists(_table_name))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__table_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 327, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyInt_From_int(table_exists(__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 327, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_3))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":318
 * 
 * 
 * def table_exists(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the table exists.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.table_exists", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__table_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":330
 * 
 * 
 * def get_table_names():             # <<<<<<<<<<<<<<
 *     """
 *     Return list of all table names.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_39get_table_names(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_38get_table_names[] = "get_table_names()\n\n    Return list of all table names.\n\n    :returns: table names\n    :rtype: list\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_39get_table_names = {"get_table_names", (PyCFunction)__pyx_pw_6cpymad_7libmadx_39get_table_names, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_38get_table_names};
static PyObject *__pyx_pw_6cpymad_7libmadx_39get_table_names(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_names (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_38get_table_names(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_38get_table_names(CYTHON_UNUSED PyObject *__pyx_self) {
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("get_table_names", 0);

  /* "cpymad/libmadx.pyx":337
 *     :rtype: list
 *     """
 *     return [_str(clib.table_register.names.names[i])             # <<<<<<<<<<<<<<
 *             for i in xrange(clib.table_register.names.curr)]
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "cpymad/libmadx.pyx":338
 *     """
 *     return [_str(clib.table_register.names.names[i])
 *             for i in xrange(clib.table_register.names.curr)]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = table_register->names->curr;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "cpymad/libmadx.pyx":337
 *     :rtype: list
 *     """
 *     return [_str(clib.table_register.names.names[i])             # <<<<<<<<<<<<<<
 *             for i in xrange(clib.table_register.names.curr)]
 * 
 */
    __pyx_t_4 = __pyx_f_6cpymad_7libmadx__str((table_register->names->names[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 337, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":330
 * 
 * 
 * def get_table_names():             # <<<<<<<<<<<<<<
 *     """
 *     Return list of all table names.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_names", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":341
 * 
 * 
 * def get_table_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of existing tables.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_41get_table_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_40get_table_count[] = "get_table_count()\n\n    Return number of existing tables.\n\n    :returns: number of tables in memory\n    :rtype: int\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_41get_table_count = {"get_table_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_41get_table_count, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_40get_table_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_41get_table_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_40get_table_count(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_40get_table_count(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_table_count", 0);

  /* "cpymad/libmadx.pyx":348
 *     :rtype: int
 *     """
 *     return clib.table_register.names.curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(table_register->names->curr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":341
 * 
 * 
 * def get_table_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of existing tables.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":351
 * 
 * 
 * def get_table_summary(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get table summary.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_43get_table_summary(PyObject *__pyx_self, PyObject *__pyx_v_table_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_42get_table_summary[] = "get_table_summary(table_name)\n\n    Get table summary.\n\n    :param str table_name: table name\n    :returns: mapping of {column: value}\n    :rtype: dict\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_43get_table_summary = {"get_table_summary", (PyCFunction)__pyx_pw_6cpymad_7libmadx_43get_table_summary, METH_O, __pyx_doc_6cpymad_7libmadx_42get_table_summary};
static PyObject *__pyx_pw_6cpymad_7libmadx_43get_table_summary(PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_summary (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_42get_table_summary(__pyx_self, ((PyObject *)__pyx_v_table_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_42get_table_summary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_v__table_name = 0;
  struct char_p_array *__pyx_v_header;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("get_table_summary", 0);

  /* "cpymad/libmadx.pyx":359
 *     :rtype: dict
 *     """
 *     cdef bytes _table_name = _cstr(table_name)             # <<<<<<<<<<<<<<
 *     cdef clib.char_p_array* header = clib.table_get_header(_table_name)
 *     cdef int i
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__table_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":360
 *     """
 *     cdef bytes _table_name = _cstr(table_name)
 *     cdef clib.char_p_array* header = clib.table_get_header(_table_name)             # <<<<<<<<<<<<<<
 *     cdef int i
 *     if header is NULL:
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__table_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 360, __pyx_L1_error)
  __pyx_v_header = table_get_header(__pyx_t_2);

  /* "cpymad/libmadx.pyx":362
 *     cdef clib.char_p_array* header = clib.table_get_header(_table_name)
 *     cdef int i
 *     if header is NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError("No summary for table: {!r}".format(table_name))
 *     return dict([_split_header_line(header.p[i])
 */
  __pyx_t_3 = ((__pyx_v_header == NULL) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":363
 *     cdef int i
 *     if header is NULL:
 *         raise ValueError("No summary for table: {!r}".format(table_name))             # <<<<<<<<<<<<<<
 *     return dict([_split_header_line(header.p[i])
 *                  for i in xrange(header.curr)])
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_No_summary_for_table_r, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_table_name);
      __Pyx_GIVEREF(__pyx_v_table_name);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_table_name);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 363, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":362
 *     cdef clib.char_p_array* header = clib.table_get_header(_table_name)
 *     cdef int i
 *     if header is NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError("No summary for table: {!r}".format(table_name))
 *     return dict([_split_header_line(header.p[i])
 */
  }

  /* "cpymad/libmadx.pyx":364
 *     if header is NULL:
 *         raise ValueError("No summary for table: {!r}".format(table_name))
 *     return dict([_split_header_line(header.p[i])             # <<<<<<<<<<<<<<
 *                  for i in xrange(header.curr)])
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "cpymad/libmadx.pyx":365
 *         raise ValueError("No summary for table: {!r}".format(table_name))
 *     return dict([_split_header_line(header.p[i])
 *                  for i in xrange(header.curr)])             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_7 = __pyx_v_header->curr;
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "cpymad/libmadx.pyx":364
 *     if header is NULL:
 *         raise ValueError("No summary for table: {!r}".format(table_name))
 *     return dict([_split_header_line(header.p[i])             # <<<<<<<<<<<<<<
 *                  for i in xrange(header.curr)])
 * 
 */
    __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_header->p[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 364, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __pyx_f_6cpymad_7libmadx__split_header_line(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 364, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 364, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyDict_Type)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":351
 * 
 * 
 * def get_table_summary(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get table summary.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_summary", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__table_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":368
 * 
 * 
 * def get_table_column_names(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_45get_table_column_names(PyObject *__pyx_self, PyObject *__pyx_v_table_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_44get_table_column_names[] = "get_table_column_names(table_name)\n\n    Get a list of all column names in the table.\n\n    :param str table_name: table name\n    :returns: column names\n    :rtype: list\n    :raises ValueError: if the table name is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_45get_table_column_names = {"get_table_column_names", (PyCFunction)__pyx_pw_6cpymad_7libmadx_45get_table_column_names, METH_O, __pyx_doc_6cpymad_7libmadx_44get_table_column_names};
static PyObject *__pyx_pw_6cpymad_7libmadx_45get_table_column_names(PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_column_names (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_44get_table_column_names(__pyx_self, ((PyObject *)__pyx_v_table_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_44get_table_column_names(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  struct table *__pyx_v_table;
  PyObject *__pyx_v_indices = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct table *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  Py_ssize_t __pyx_t_7;
  __Pyx_RefNannySetupContext("get_table_column_names", 0);

  /* "cpymad/libmadx.pyx":377
 *     :raises ValueError: if the table name is invalid
 *     """
 *     cdef clib.table* table = _find_table(table_name)             # <<<<<<<<<<<<<<
 *     indices = [table.col_out.i[i] for i in xrange(table.col_out.curr)]
 *     # NOTE: we can't enforce lower-case on the column names here, since this
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_table(__pyx_v_table_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 377, __pyx_L1_error)
  __pyx_v_table = __pyx_t_1;

  /* "cpymad/libmadx.pyx":378
 *     """
 *     cdef clib.table* table = _find_table(table_name)
 *     indices = [table.col_out.i[i] for i in xrange(table.col_out.curr)]             # <<<<<<<<<<<<<<
 *     # NOTE: we can't enforce lower-case on the column names here, since this
 *     # breaks their usage with get_table_column():
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_table->col_out->curr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_xrange, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 378, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 378, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 378, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 378, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 378, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_table->col_out->i[__pyx_t_7])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_indices = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":381
 *     # NOTE: we can't enforce lower-case on the column names here, since this
 *     # breaks their usage with get_table_column():
 *     return [table.columns.names[i] for i in indices]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
  for (;;) {
    if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 381, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 381, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyBytes_FromString((__pyx_v_table->columns->names[__pyx_t_7])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 381, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":368
 * 
 * 
 * def get_table_column_names(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_column_names", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_indices);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":384
 * 
 * 
 * def get_table_column_names_all(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_47get_table_column_names_all(PyObject *__pyx_self, PyObject *__pyx_v_table_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_46get_table_column_names_all[] = "get_table_column_names_all(table_name)\n\n    Get a list of all column names in the table.\n\n    :param str table_name: table name\n    :returns: column names\n    :rtype: list\n    :raises ValueError: if the table name is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_47get_table_column_names_all = {"get_table_column_names_all", (PyCFunction)__pyx_pw_6cpymad_7libmadx_47get_table_column_names_all, METH_O, __pyx_doc_6cpymad_7libmadx_46get_table_column_names_all};
static PyObject *__pyx_pw_6cpymad_7libmadx_47get_table_column_names_all(PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_column_names_all (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_46get_table_column_names_all(__pyx_self, ((PyObject *)__pyx_v_table_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_46get_table_column_names_all(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  struct table *__pyx_v_table;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct table *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_table_column_names_all", 0);

  /* "cpymad/libmadx.pyx":393
 *     :raises ValueError: if the table name is invalid
 *     """
 *     cdef clib.table* table = _find_table(table_name)             # <<<<<<<<<<<<<<
 *     # NOTE: we can't enforce lower-case on the column names here, since this
 *     # breaks their usage with get_table_column():
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_table(__pyx_v_table_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 393, __pyx_L1_error)
  __pyx_v_table = __pyx_t_1;

  /* "cpymad/libmadx.pyx":396
 *     # NOTE: we can't enforce lower-case on the column names here, since this
 *     # breaks their usage with get_table_column():
 *     return _name_list(table.columns)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_6cpymad_7libmadx__name_list(__pyx_v_table->columns); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":384
 * 
 * 
 * def get_table_column_names_all(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_column_names_all", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":399
 * 
 * 
 * def get_table_column_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a number of columns in the table.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_49get_table_column_count(PyObject *__pyx_self, PyObject *__pyx_v_table_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_48get_table_column_count[] = "get_table_column_count(table_name)\n\n    Get a number of columns in the table.\n\n    :param str table_name: table name\n    :returns: number of columns\n    :rtype: int\n    :raises ValueError: if the table name is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_49get_table_column_count = {"get_table_column_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_49get_table_column_count, METH_O, __pyx_doc_6cpymad_7libmadx_48get_table_column_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_49get_table_column_count(PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_column_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_48get_table_column_count(__pyx_self, ((PyObject *)__pyx_v_table_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_48get_table_column_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  struct table *__pyx_v_table;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct table *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_table_column_count", 0);

  /* "cpymad/libmadx.pyx":408
 *     :raises ValueError: if the table name is invalid
 *     """
 *     cdef clib.table* table = _find_table(table_name)             # <<<<<<<<<<<<<<
 *     return table.columns.curr
 * 
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_table(__pyx_v_table_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 408, __pyx_L1_error)
  __pyx_v_table = __pyx_t_1;

  /* "cpymad/libmadx.pyx":409
 *     """
 *     cdef clib.table* table = _find_table(table_name)
 *     return table.columns.curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_table->columns->curr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 409, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":399
 * 
 * 
 * def get_table_column_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a number of columns in the table.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_column_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":412
 * 
 * 
 * def get_table_column(table_name, column_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get data from the specified table.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_51get_table_column(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_50get_table_column[] = "get_table_column(table_name, column_name)\n\n    Get data from the specified table.\n\n    :param str table_name: table name\n    :param str column_name: column name\n    :returns: the data in the requested column\n    :rtype: numpy.array\n    :raises ValueError: if the column cannot be found in the table\n    :raises RuntimeError: if the column has unknown type\n\n    CAUTION: Numeric data is wrapped in numpy arrays but not copied. Make\n    sure to copy all data before invoking any further MAD-X commands! This\n    is done automatically for you if using libmadx in a remote service\n    (pickle serialization effectively copies the data).\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_51get_table_column = {"get_table_column", (PyCFunction)__pyx_pw_6cpymad_7libmadx_51get_table_column, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_50get_table_column};
static PyObject *__pyx_pw_6cpymad_7libmadx_51get_table_column(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_table_name = 0;
  PyObject *__pyx_v_column_name = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_column (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_table_name,&__pyx_n_s_column_name,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_table_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_column_name)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_table_column", 1, 2, 2, 1); __PYX_ERR(0, 412, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_table_column") < 0)) __PYX_ERR(0, 412, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_table_name = values[0];
    __pyx_v_column_name = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_table_column", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 412, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_table_column", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_50get_table_column(__pyx_self, __pyx_v_table_name, __pyx_v_column_name);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_50get_table_column(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name, PyObject *__pyx_v_column_name) {
  char **__pyx_v_char_tmp;
  PyObject *__pyx_v__tab_name = 0;
  PyObject *__pyx_v__col_name = 0;
  struct column_info __pyx_v_info;
  int __pyx_v_tab_i;
  struct table *__pyx_v__table;
  int __pyx_v_col_i;
  int __pyx_v_inform;
  PyObject *__pyx_v_dtype = NULL;
  PyObject *__pyx_v_size = NULL;
  Py_intptr_t __pyx_v_addr;
  PyObject *__pyx_v_array_type = NULL;
  PyObject *__pyx_v_array_data = NULL;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  char const *__pyx_t_13;
  __Pyx_RefNannySetupContext("get_table_column", 0);

  /* "cpymad/libmadx.pyx":429
 *     """
 *     cdef char** char_tmp
 *     cdef bytes _tab_name = _cstr(table_name)             # <<<<<<<<<<<<<<
 *     cdef bytes _col_name = _cstr(column_name)
 *     cdef clib.column_info info
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 429, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__tab_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":430
 *     cdef char** char_tmp
 *     cdef bytes _tab_name = _cstr(table_name)
 *     cdef bytes _col_name = _cstr(column_name)             # <<<<<<<<<<<<<<
 *     cdef clib.column_info info
 *     # The following snippet imitates the table_get_column function from the
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_column_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 430, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__col_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":437
 *     # MAD-X before r4777. When this is not the case anymore, you should be
 *     # able to safely revert the commit that introduced this snippet:
 *     cdef int tab_i = clib.name_list_pos(_tab_name, clib.table_register.names)             # <<<<<<<<<<<<<<
 *     if tab_i == -1:
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__tab_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 437, __pyx_L1_error)
  __pyx_v_tab_i = name_list_pos(__pyx_t_2, table_register->names);

  /* "cpymad/libmadx.pyx":438
 *     # able to safely revert the commit that introduced this snippet:
 *     cdef int tab_i = clib.name_list_pos(_tab_name, clib.table_register.names)
 *     if tab_i == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]
 */
  __pyx_t_3 = ((__pyx_v_tab_i == -1L) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":439
 *     cdef int tab_i = clib.name_list_pos(_tab_name, clib.table_register.names)
 *     if tab_i == -1:
 *         raise ValueError("Invalid table: {!r}".format(table_name))             # <<<<<<<<<<<<<<
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]
 *     cdef int col_i = clib.name_list_pos(_col_name, _table.columns)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_table_r, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 439, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_table_name);
      __Pyx_GIVEREF(__pyx_v_table_name);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_table_name);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 439, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 439, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":438
 *     # able to safely revert the commit that introduced this snippet:
 *     cdef int tab_i = clib.name_list_pos(_tab_name, clib.table_register.names)
 *     if tab_i == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]
 */
  }

  /* "cpymad/libmadx.pyx":440
 *     if tab_i == -1:
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]             # <<<<<<<<<<<<<<
 *     cdef int col_i = clib.name_list_pos(_col_name, _table.columns)
 *     if col_i == -1:
 */
  __pyx_v__table = (table_register->tables[__pyx_v_tab_i]);

  /* "cpymad/libmadx.pyx":441
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]
 *     cdef int col_i = clib.name_list_pos(_col_name, _table.columns)             # <<<<<<<<<<<<<<
 *     if col_i == -1:
 *         raise ValueError("Invalid column: {!r}".format(column_name))
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__col_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L1_error)
  __pyx_v_col_i = name_list_pos(__pyx_t_2, __pyx_v__table->columns);

  /* "cpymad/libmadx.pyx":442
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]
 *     cdef int col_i = clib.name_list_pos(_col_name, _table.columns)
 *     if col_i == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid column: {!r}".format(column_name))
 *     info.length = _table.curr
 */
  __pyx_t_3 = ((__pyx_v_col_i == -1L) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":443
 *     cdef int col_i = clib.name_list_pos(_col_name, _table.columns)
 *     if col_i == -1:
 *         raise ValueError("Invalid column: {!r}".format(column_name))             # <<<<<<<<<<<<<<
 *     info.length = _table.curr
 *     cdef int inform = _table.columns.inform[col_i]
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_column_r, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 443, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_column_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_column_name);
      __Pyx_GIVEREF(__pyx_v_column_name);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_column_name);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 443, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 443, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":442
 *     cdef clib.table* _table = clib.table_register.tables[tab_i]
 *     cdef int col_i = clib.name_list_pos(_col_name, _table.columns)
 *     if col_i == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid column: {!r}".format(column_name))
 *     info.length = _table.curr
 */
  }

  /* "cpymad/libmadx.pyx":444
 *     if col_i == -1:
 *         raise ValueError("Invalid column: {!r}".format(column_name))
 *     info.length = _table.curr             # <<<<<<<<<<<<<<
 *     cdef int inform = _table.columns.inform[col_i]
 *     if inform == clib.PARAM_TYPE_INTEGER:
 */
  __pyx_t_7 = __pyx_v__table->curr;
  __pyx_v_info.length = __pyx_t_7;

  /* "cpymad/libmadx.pyx":445
 *         raise ValueError("Invalid column: {!r}".format(column_name))
 *     info.length = _table.curr
 *     cdef int inform = _table.columns.inform[col_i]             # <<<<<<<<<<<<<<
 *     if inform == clib.PARAM_TYPE_INTEGER:
 *         # YES, integers are internally stored as doubles in MAD-X:
 */
  __pyx_v_inform = (__pyx_v__table->columns->inform[__pyx_v_col_i]);

  /* "cpymad/libmadx.pyx":446
 *     info.length = _table.curr
 *     cdef int inform = _table.columns.inform[col_i]
 *     if inform == clib.PARAM_TYPE_INTEGER:             # <<<<<<<<<<<<<<
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         info.data = _table.d_cols[col_i]
 */
  switch (__pyx_v_inform) {
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_INTEGER:

    /* "cpymad/libmadx.pyx":448
 *     if inform == clib.PARAM_TYPE_INTEGER:
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         info.data = _table.d_cols[col_i]             # <<<<<<<<<<<<<<
 *         info.datatype = b'i'
 *     elif inform == clib.PARAM_TYPE_DOUBLE:
 */
    __pyx_v_info.data = (__pyx_v__table->d_cols[__pyx_v_col_i]);

    /* "cpymad/libmadx.pyx":449
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'i'             # <<<<<<<<<<<<<<
 *     elif inform == clib.PARAM_TYPE_DOUBLE:
 *         info.data = _table.d_cols[col_i]
 */
    __pyx_v_info.datatype = 'i';

    /* "cpymad/libmadx.pyx":446
 *     info.length = _table.curr
 *     cdef int inform = _table.columns.inform[col_i]
 *     if inform == clib.PARAM_TYPE_INTEGER:             # <<<<<<<<<<<<<<
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         info.data = _table.d_cols[col_i]
 */
    break;

    /* "cpymad/libmadx.pyx":450
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'i'
 *     elif inform == clib.PARAM_TYPE_DOUBLE:             # <<<<<<<<<<<<<<
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'd'
 */
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE:

    /* "cpymad/libmadx.pyx":451
 *         info.datatype = b'i'
 *     elif inform == clib.PARAM_TYPE_DOUBLE:
 *         info.data = _table.d_cols[col_i]             # <<<<<<<<<<<<<<
 *         info.datatype = b'd'
 *     elif inform == clib.PARAM_TYPE_STRING:
 */
    __pyx_v_info.data = (__pyx_v__table->d_cols[__pyx_v_col_i]);

    /* "cpymad/libmadx.pyx":452
 *     elif inform == clib.PARAM_TYPE_DOUBLE:
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'd'             # <<<<<<<<<<<<<<
 *     elif inform == clib.PARAM_TYPE_STRING:
 *         info.data = _table.s_cols[col_i]
 */
    __pyx_v_info.datatype = 'd';

    /* "cpymad/libmadx.pyx":450
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'i'
 *     elif inform == clib.PARAM_TYPE_DOUBLE:             # <<<<<<<<<<<<<<
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'd'
 */
    break;

    /* "cpymad/libmadx.pyx":453
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'd'
 *     elif inform == clib.PARAM_TYPE_STRING:             # <<<<<<<<<<<<<<
 *         info.data = _table.s_cols[col_i]
 *         info.datatype = b'S'
 */
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_STRING:

    /* "cpymad/libmadx.pyx":454
 *         info.datatype = b'd'
 *     elif inform == clib.PARAM_TYPE_STRING:
 *         info.data = _table.s_cols[col_i]             # <<<<<<<<<<<<<<
 *         info.datatype = b'S'
 *     else:
 */
    __pyx_v_info.data = (__pyx_v__table->s_cols[__pyx_v_col_i]);

    /* "cpymad/libmadx.pyx":455
 *     elif inform == clib.PARAM_TYPE_STRING:
 *         info.data = _table.s_cols[col_i]
 *         info.datatype = b'S'             # <<<<<<<<<<<<<<
 *     else:
 *         raise RuntimeError("Unknown column format: {!r}".format(inform))
 */
    __pyx_v_info.datatype = 'S';

    /* "cpymad/libmadx.pyx":453
 *         info.data = _table.d_cols[col_i]
 *         info.datatype = b'd'
 *     elif inform == clib.PARAM_TYPE_STRING:             # <<<<<<<<<<<<<<
 *         info.data = _table.s_cols[col_i]
 *         info.datatype = b'S'
 */
    break;
    default:

    /* "cpymad/libmadx.pyx":457
 *         info.datatype = b'S'
 *     else:
 *         raise RuntimeError("Unknown column format: {!r}".format(inform))             # <<<<<<<<<<<<<<
 *     # Although, we are using a custom replacement for table_get_column
 *     # above, we still try to be fully compatible with the real function from
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_column_format_r, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_inform); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 457, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 457, __pyx_L1_error)
    break;
  }

  /* "cpymad/libmadx.pyx":462
 *     # MAD-X below, so back-migration will be easier, when the time comes.
 *     # This is why the error and data type handling below is left untouched:
 *     dtype = <bytes> info.datatype             # <<<<<<<<<<<<<<
 *     size = <int> info.length
 *     addr = <Py_intptr_t> info.data
 */
  __pyx_t_1 = PyBytes_FromStringAndSize(&__pyx_v_info.datatype, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_dtype = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":463
 *     # This is why the error and data type handling below is left untouched:
 *     dtype = <bytes> info.datatype
 *     size = <int> info.length             # <<<<<<<<<<<<<<
 *     addr = <Py_intptr_t> info.data
 *     # double:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(((int)__pyx_v_info.length)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_size = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":464
 *     dtype = <bytes> info.datatype
 *     size = <int> info.length
 *     addr = <Py_intptr_t> info.data             # <<<<<<<<<<<<<<
 *     # double:
 *     if dtype == b'i' or dtype == b'd':
 */
  __pyx_v_addr = ((Py_intptr_t)__pyx_v_info.data);

  /* "cpymad/libmadx.pyx":466
 *     addr = <Py_intptr_t> info.data
 *     # double:
 *     if dtype == b'i' or dtype == b'd':             # <<<<<<<<<<<<<<
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         array_type = ctypes.c_double * size
 */
  __pyx_t_9 = (__Pyx_PyBytes_Equals(__pyx_v_dtype, __pyx_n_b_i, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 466, __pyx_L1_error)
  __pyx_t_10 = (__pyx_t_9 != 0);
  if (!__pyx_t_10) {
  } else {
    __pyx_t_3 = __pyx_t_10;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_10 = (__Pyx_PyBytes_Equals(__pyx_v_dtype, __pyx_n_b_d, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 466, __pyx_L1_error)
  __pyx_t_9 = (__pyx_t_10 != 0);
  __pyx_t_3 = __pyx_t_9;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":468
 *     if dtype == b'i' or dtype == b'd':
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         array_type = ctypes.c_double * size             # <<<<<<<<<<<<<<
 *         array_data = array_type.from_address(addr)
 *         return np.ctypeslib.as_array(array_data)
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_c_double); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 468, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_4, __pyx_v_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_array_type = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "cpymad/libmadx.pyx":469
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         array_type = ctypes.c_double * size
 *         array_data = array_type.from_address(addr)             # <<<<<<<<<<<<<<
 *         return np.ctypeslib.as_array(array_data)
 *     # string:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_array_type, __pyx_n_s_from_address); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyInt_From_Py_intptr_t(__pyx_v_addr); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 469, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_array_data = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "cpymad/libmadx.pyx":470
 *         array_type = ctypes.c_double * size
 *         array_data = array_type.from_address(addr)
 *         return np.ctypeslib.as_array(array_data)             # <<<<<<<<<<<<<<
 *     # string:
 *     elif dtype == b'S':
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 470, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ctypeslib); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 470, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_as_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 470, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_array_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_array_data);
      __Pyx_GIVEREF(__pyx_v_array_data);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_array_data);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":466
 *     addr = <Py_intptr_t> info.data
 *     # double:
 *     if dtype == b'i' or dtype == b'd':             # <<<<<<<<<<<<<<
 *         # YES, integers are internally stored as doubles in MAD-X:
 *         array_type = ctypes.c_double * size
 */
  }

  /* "cpymad/libmadx.pyx":472
 *         return np.ctypeslib.as_array(array_data)
 *     # string:
 *     elif dtype == b'S':             # <<<<<<<<<<<<<<
 *         char_tmp = <char**> info.data
 *         return np.array([char_tmp[i] for i in xrange(info.length)])
 */
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_v_dtype, __pyx_n_b_S, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 472, __pyx_L1_error)
  __pyx_t_9 = (__pyx_t_3 != 0);
  if (__pyx_t_9) {

    /* "cpymad/libmadx.pyx":473
 *     # string:
 *     elif dtype == b'S':
 *         char_tmp = <char**> info.data             # <<<<<<<<<<<<<<
 *         return np.array([char_tmp[i] for i in xrange(info.length)])
 *     # invalid:
 */
    __pyx_v_char_tmp = ((char **)__pyx_v_info.data);

    /* "cpymad/libmadx.pyx":474
 *     elif dtype == b'S':
 *         char_tmp = <char**> info.data
 *         return np.array([char_tmp[i] for i in xrange(info.length)])             # <<<<<<<<<<<<<<
 *     # invalid:
 *     elif dtype == b'V':
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __pyx_v_info.length;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_7; __pyx_t_11+=1) {
      __pyx_v_i = __pyx_t_11;
      __pyx_t_6 = __Pyx_PyBytes_FromString((__pyx_v_char_tmp[__pyx_v_i])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 474, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 474, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 474, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":472
 *         return np.ctypeslib.as_array(array_data)
 *     # string:
 *     elif dtype == b'S':             # <<<<<<<<<<<<<<
 *         char_tmp = <char**> info.data
 *         return np.array([char_tmp[i] for i in xrange(info.length)])
 */
  }

  /* "cpymad/libmadx.pyx":476
 *         return np.array([char_tmp[i] for i in xrange(info.length)])
 *     # invalid:
 *     elif dtype == b'V':             # <<<<<<<<<<<<<<
 *         raise ValueError("Column {!r} is not in table {!r}."
 *                          .format(column_name, table_name))
 */
  __pyx_t_9 = (__Pyx_PyBytes_Equals(__pyx_v_dtype, __pyx_n_b_V, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 476, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_9 != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":478
 *     elif dtype == b'V':
 *         raise ValueError("Column {!r} is not in table {!r}."
 *                          .format(column_name, table_name))             # <<<<<<<<<<<<<<
 *     # unknown:
 *     else:
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Column_r_is_not_in_table_r, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 478, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_12 = 1;
      }
    }
    __pyx_t_4 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 478, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(__pyx_v_column_name);
    __Pyx_GIVEREF(__pyx_v_column_name);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_12, __pyx_v_column_name);
    __Pyx_INCREF(__pyx_v_table_name);
    __Pyx_GIVEREF(__pyx_v_table_name);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_12, __pyx_v_table_name);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 478, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cpymad/libmadx.pyx":477
 *     # invalid:
 *     elif dtype == b'V':
 *         raise ValueError("Column {!r} is not in table {!r}."             # <<<<<<<<<<<<<<
 *                          .format(column_name, table_name))
 *     # unknown:
 */
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 477, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 477, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 477, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":476
 *         return np.array([char_tmp[i] for i in xrange(info.length)])
 *     # invalid:
 *     elif dtype == b'V':             # <<<<<<<<<<<<<<
 *         raise ValueError("Column {!r} is not in table {!r}."
 *                          .format(column_name, table_name))
 */
  }

  /* "cpymad/libmadx.pyx":481
 *     # unknown:
 *     else:
 *         raise RuntimeError("Unknown datatype {!r} in column {!r}."             # <<<<<<<<<<<<<<
 *                            .format(_str(dtype), column_name))
 * 
 */
  /*else*/ {

    /* "cpymad/libmadx.pyx":482
 *     else:
 *         raise RuntimeError("Unknown datatype {!r} in column {!r}."
 *                            .format(_str(dtype), column_name))             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_datatype_r_in_column_r, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_dtype); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 482, __pyx_L1_error)
    __pyx_t_4 = __pyx_f_6cpymad_7libmadx__str(__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_12 = 1;
      }
    }
    __pyx_t_6 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_12, __pyx_t_4);
    __Pyx_INCREF(__pyx_v_column_name);
    __Pyx_GIVEREF(__pyx_v_column_name);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_12, __pyx_v_column_name);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cpymad/libmadx.pyx":481
 *     # unknown:
 *     else:
 *         raise RuntimeError("Unknown datatype {!r} in column {!r}."             # <<<<<<<<<<<<<<
 *                            .format(_str(dtype), column_name))
 * 
 */
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 481, __pyx_L1_error)
  }

  /* "cpymad/libmadx.pyx":412
 * 
 * 
 * def get_table_column(table_name, column_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get data from the specified table.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_column", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__tab_name);
  __Pyx_XDECREF(__pyx_v__col_name);
  __Pyx_XDECREF(__pyx_v_dtype);
  __Pyx_XDECREF(__pyx_v_size);
  __Pyx_XDECREF(__pyx_v_array_type);
  __Pyx_XDECREF(__pyx_v_array_data);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":485
 * 
 * 
 * def get_table_row_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return total number of rows in the table.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_53get_table_row_count(PyObject *__pyx_self, PyObject *__pyx_v_table_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_52get_table_row_count[] = "get_table_row_count(table_name)\n\n    Return total number of rows in the table.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_53get_table_row_count = {"get_table_row_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_53get_table_row_count, METH_O, __pyx_doc_6cpymad_7libmadx_52get_table_row_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_53get_table_row_count(PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_row_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_52get_table_row_count(__pyx_self, ((PyObject *)__pyx_v_table_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_52get_table_row_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct table *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_table_row_count", 0);

  /* "cpymad/libmadx.pyx":489
 *     Return total number of rows in the table.
 *     """
 *     return _find_table(table_name).curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_table(__pyx_v_table_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 489, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1->curr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 489, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":485
 * 
 * 
 * def get_table_row_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return total number of rows in the table.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_row_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":492
 * 
 * 
 * def get_table_row_names(table_name, indices):             # <<<<<<<<<<<<<<
 *     """
 *     Return row names for every index (row number) in the list.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_55get_table_row_names(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_54get_table_row_names[] = "get_table_row_names(table_name, indices)\n\n    Return row names for every index (row number) in the list.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_55get_table_row_names = {"get_table_row_names", (PyCFunction)__pyx_pw_6cpymad_7libmadx_55get_table_row_names, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_54get_table_row_names};
static PyObject *__pyx_pw_6cpymad_7libmadx_55get_table_row_names(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_table_name = 0;
  PyObject *__pyx_v_indices = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_table_row_names (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_table_name,&__pyx_n_s_indices,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_table_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_indices)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_table_row_names", 1, 2, 2, 1); __PYX_ERR(0, 492, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_table_row_names") < 0)) __PYX_ERR(0, 492, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_table_name = values[0];
    __pyx_v_indices = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_table_row_names", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 492, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_table_row_names", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_54get_table_row_names(__pyx_self, __pyx_v_table_name, __pyx_v_indices);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_54get_table_row_names(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_name, PyObject *__pyx_v_indices) {
  struct table *__pyx_v_table;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct table *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("get_table_row_names", 0);

  /* "cpymad/libmadx.pyx":496
 *     Return row names for every index (row number) in the list.
 *     """
 *     cdef clib.table* table = _find_table(table_name)             # <<<<<<<<<<<<<<
 *     if isinstance(indices, int):
 *         return _get_table_row_name(table, indices)
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_table(__pyx_v_table_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 496, __pyx_L1_error)
  __pyx_v_table = __pyx_t_1;

  /* "cpymad/libmadx.pyx":497
 *     """
 *     cdef clib.table* table = _find_table(table_name)
 *     if isinstance(indices, int):             # <<<<<<<<<<<<<<
 *         return _get_table_row_name(table, indices)
 *     return [_get_table_row_name(table, i) for i in indices]
 */
  __pyx_t_2 = PyInt_Check(__pyx_v_indices); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":498
 *     cdef clib.table* table = _find_table(table_name)
 *     if isinstance(indices, int):
 *         return _get_table_row_name(table, indices)             # <<<<<<<<<<<<<<
 *     return [_get_table_row_name(table, i) for i in indices]
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_indices); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 498, __pyx_L1_error)
    __pyx_t_5 = __pyx_f_6cpymad_7libmadx__get_table_row_name(__pyx_v_table, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":497
 *     """
 *     cdef clib.table* table = _find_table(table_name)
 *     if isinstance(indices, int):             # <<<<<<<<<<<<<<
 *         return _get_table_row_name(table, indices)
 *     return [_get_table_row_name(table, i) for i in indices]
 */
  }

  /* "cpymad/libmadx.pyx":499
 *     if isinstance(indices, int):
 *         return _get_table_row_name(table, indices)
 *     return [_get_table_row_name(table, i) for i in indices]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 499, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) {
    __pyx_t_6 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_6); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 499, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_6))) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_6)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_9 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 499, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 499, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 499, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 499, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      }
    } else {
      __pyx_t_9 = __pyx_t_8(__pyx_t_6);
      if (unlikely(!__pyx_t_9)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 499, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_9);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_i); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 499, __pyx_L1_error)
    __pyx_t_9 = __pyx_f_6cpymad_7libmadx__get_table_row_name(__pyx_v_table, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":492
 * 
 * 
 * def get_table_row_names(table_name, indices):             # <<<<<<<<<<<<<<
 *     """
 *     Return row names for every index (row number) in the list.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cpymad.libmadx.get_table_row_names", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":502
 * 
 * 
 * def get_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the original sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_57get_element(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_56get_element[] = "get_element(sequence_name, element_index)\n\n    Return requested element in the original sequence.\n\n    :param str sequence_name: sequence name\n    :param int element_index: element index\n    :returns: the element with the specified index\n    :rtype: dict\n    :raises ValueError: if the sequence is invalid\n    :raises IndexError: if the index is out of range\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_57get_element = {"get_element", (PyCFunction)__pyx_pw_6cpymad_7libmadx_57get_element, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_56get_element};
static PyObject *__pyx_pw_6cpymad_7libmadx_57get_element(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sequence_name = 0;
  PyObject *__pyx_v_element_index = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_element (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence_name,&__pyx_n_s_element_index,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_element_index)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_element", 1, 2, 2, 1); __PYX_ERR(0, 502, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_element") < 0)) __PYX_ERR(0, 502, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_sequence_name = values[0];
    __pyx_v_element_index = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_element", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 502, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_element", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_56get_element(__pyx_self, __pyx_v_sequence_name, __pyx_v_element_index);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_56get_element(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_index) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("get_element", 0);

  /* "cpymad/libmadx.pyx":513
 *     :raises IndexError: if the index is out of range
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     if element_index < 0 or element_index >= seq.nodes.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 513, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":514
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if element_index < 0 or element_index >= seq.nodes.curr:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.nodes.curr))
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_element_index, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 514, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_seq->nodes->curr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyObject_RichCompare(__pyx_v_element_index, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 514, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":516
 *     if element_index < 0 or element_index >= seq.nodes.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.nodes.curr))             # <<<<<<<<<<<<<<
 *     return _get_node(seq.nodes.nodes[element_index], seq.ref_flag)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Index_out_of_range_0_element_cou, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_seq->nodes->curr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_8 = 1;
      }
    }
    __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (__pyx_t_7) {
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
    }
    __Pyx_INCREF(__pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_v_element_index);
    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "cpymad/libmadx.pyx":515
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if element_index < 0 or element_index >= seq.nodes.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"             # <<<<<<<<<<<<<<
 *                          .format(element_index, seq.nodes.curr))
 *     return _get_node(seq.nodes.nodes[element_index], seq.ref_flag)
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 515, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 515, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 515, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":514
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if element_index < 0 or element_index >= seq.nodes.curr:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.nodes.curr))
 */
  }

  /* "cpymad/libmadx.pyx":517
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.nodes.curr))
 *     return _get_node(seq.nodes.nodes[element_index], seq.ref_flag)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_element_index); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 517, __pyx_L1_error)
  __pyx_t_5 = __pyx_f_6cpymad_7libmadx__get_node((__pyx_v_seq->nodes->nodes[__pyx_t_8]), __pyx_v_seq->ref_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 517, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":502
 * 
 * 
 * def get_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the original sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cpymad.libmadx.get_element", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":520
 * 
 * 
 * def get_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the original sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_59get_element_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_58get_element_index[] = "get_element_index(sequence_name, element_name)\n\n    Return index of element with specified name in the original sequence.\n\n    :param str sequence_name: sequence name\n    :param str element_name: element index\n    :returns: the index of the specified element\n    :rtype: int\n    :raises ValueError: if the sequence or element name is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_59get_element_index = {"get_element_index", (PyCFunction)__pyx_pw_6cpymad_7libmadx_59get_element_index, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_58get_element_index};
static PyObject *__pyx_pw_6cpymad_7libmadx_59get_element_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sequence_name = 0;
  PyObject *__pyx_v_element_name = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_element_index (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence_name,&__pyx_n_s_element_name,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_element_name)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_element_index", 1, 2, 2, 1); __PYX_ERR(0, 520, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_element_index") < 0)) __PYX_ERR(0, 520, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_sequence_name = values[0];
    __pyx_v_element_name = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_element_index", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 520, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_element_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_58get_element_index(__pyx_self, __pyx_v_sequence_name, __pyx_v_element_name);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_58get_element_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_v__element_name = 0;
  int __pyx_v_index;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  char *__pyx_t_6;
  int __pyx_t_7;
  __Pyx_RefNannySetupContext("get_element_index", 0);

  /* "cpymad/libmadx.pyx":530
 *     :raises ValueError: if the sequence or element name is invalid
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))
 *     cdef int index = clib.name_list_pos(_element_name, seq.nodes.list)
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 530, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":531
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))             # <<<<<<<<<<<<<<
 *     cdef int index = clib.name_list_pos(_element_name, seq.nodes.list)
 *     if index == -1:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_name_to_internal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_element_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 531, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_INCREF(__pyx_v_element_name);
    __Pyx_GIVEREF(__pyx_v_element_name);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_element_name);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v__element_name = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "cpymad/libmadx.pyx":532
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))
 *     cdef int index = clib.name_list_pos(_element_name, seq.nodes.list)             # <<<<<<<<<<<<<<
 *     if index == -1:
 *         raise ValueError("Element name not found: {0}".format(element_name))
 */
  __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v__element_name); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 532, __pyx_L1_error)
  __pyx_v_index = name_list_pos(__pyx_t_6, __pyx_v_seq->nodes->list);

  /* "cpymad/libmadx.pyx":533
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))
 *     cdef int index = clib.name_list_pos(_element_name, seq.nodes.list)
 *     if index == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Element name not found: {0}".format(element_name))
 *     return index
 */
  __pyx_t_7 = ((__pyx_v_index == -1L) != 0);
  if (__pyx_t_7) {

    /* "cpymad/libmadx.pyx":534
 *     cdef int index = clib.name_list_pos(_element_name, seq.nodes.list)
 *     if index == -1:
 *         raise ValueError("Element name not found: {0}".format(element_name))             # <<<<<<<<<<<<<<
 *     return index
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Element_name_not_found_0, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_element_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 534, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_element_name);
      __Pyx_GIVEREF(__pyx_v_element_name);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_element_name);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 534, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":533
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))
 *     cdef int index = clib.name_list_pos(_element_name, seq.nodes.list)
 *     if index == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Element name not found: {0}".format(element_name))
 *     return index
 */
  }

  /* "cpymad/libmadx.pyx":535
 *     if index == -1:
 *         raise ValueError("Element name not found: {0}".format(element_name))
 *     return index             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 535, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":520
 * 
 * 
 * def get_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the original sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cpymad.libmadx.get_element_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__element_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":538
 * 
 * 
 * def get_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the original sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_61get_element_index_by_position(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_60get_element_index_by_position[] = "get_element_index_by_position(sequence_name, position)\n\n    Return index of element at specified position in the original sequence.\n\n    :param str sequence_name: sequence name\n    :param double position: position (S coordinate)\n    :returns: the index of an element at that position, -1 if not found\n    :rtype: int\n    :raises ValueError: if the sequence or element name is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_61get_element_index_by_position = {"get_element_index_by_position", (PyCFunction)__pyx_pw_6cpymad_7libmadx_61get_element_index_by_position, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_60get_element_index_by_position};
static PyObject *__pyx_pw_6cpymad_7libmadx_61get_element_index_by_position(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sequence_name = 0;
  PyObject *__pyx_v_position = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_element_index_by_position (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence_name,&__pyx_n_s_position,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_position)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_element_index_by_position", 1, 2, 2, 1); __PYX_ERR(0, 538, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_element_index_by_position") < 0)) __PYX_ERR(0, 538, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_sequence_name = values[0];
    __pyx_v_position = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_element_index_by_position", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 538, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_element_index_by_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_60get_element_index_by_position(__pyx_self, __pyx_v_sequence_name, __pyx_v_position);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_60get_element_index_by_position(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_position) {
  struct sequence *__pyx_v_seq;
  double __pyx_v__position;
  struct node *__pyx_v_elem;
  double __pyx_v_at;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  double __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_RefNannySetupContext("get_element_index_by_position", 0);

  /* "cpymad/libmadx.pyx":551
 *     # algorithm. If you want more, you need to copy the elements over and use
 *     # a suitable ordered data type.
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     cdef double _position = position
 *     cdef clib.node* elem
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 551, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":552
 *     # a suitable ordered data type.
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     cdef double _position = position             # <<<<<<<<<<<<<<
 *     cdef clib.node* elem
 *     cdef double at
 */
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_position); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 552, __pyx_L1_error)
  __pyx_v__position = __pyx_t_2;

  /* "cpymad/libmadx.pyx":555
 *     cdef clib.node* elem
 *     cdef double at
 *     for i in xrange(seq.nodes.curr):             # <<<<<<<<<<<<<<
 *         elem = seq.nodes.nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 */
  __pyx_t_3 = __pyx_v_seq->nodes->curr;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "cpymad/libmadx.pyx":556
 *     cdef double at
 *     for i in xrange(seq.nodes.curr):
 *         elem = seq.nodes.nodes[i]             # <<<<<<<<<<<<<<
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:
 */
    __pyx_v_elem = (__pyx_v_seq->nodes->nodes[__pyx_v_i]);

    /* "cpymad/libmadx.pyx":557
 *     for i in xrange(seq.nodes.curr):
 *         elem = seq.nodes.nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)             # <<<<<<<<<<<<<<
 *         if _position >= at and _position <= at+elem.length:
 *             return i
 */
    __pyx_v_at = __pyx_f_6cpymad_7libmadx__get_node_entry_pos(__pyx_v_elem, __pyx_v_seq->ref_flag);

    /* "cpymad/libmadx.pyx":558
 *         elem = seq.nodes.nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:             # <<<<<<<<<<<<<<
 *             return i
 *     raise ValueError("No element found at position: {0}".format(position))
 */
    __pyx_t_6 = ((__pyx_v__position >= __pyx_v_at) != 0);
    if (__pyx_t_6) {
    } else {
      __pyx_t_5 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v__position <= (__pyx_v_at + __pyx_v_elem->length)) != 0);
    __pyx_t_5 = __pyx_t_6;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_5) {

      /* "cpymad/libmadx.pyx":559
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:
 *             return i             # <<<<<<<<<<<<<<
 *     raise ValueError("No element found at position: {0}".format(position))
 * 
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":558
 *         elem = seq.nodes.nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:             # <<<<<<<<<<<<<<
 *             return i
 *     raise ValueError("No element found at position: {0}".format(position))
 */
    }
  }

  /* "cpymad/libmadx.pyx":560
 *         if _position >= at and _position <= at+elem.length:
 *             return i
 *     raise ValueError("No element found at position: {0}".format(position))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_No_element_found_at_position_0, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_position); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
  } else {
    __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
    __Pyx_INCREF(__pyx_v_position);
    __Pyx_GIVEREF(__pyx_v_position);
    PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_position);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_Raise(__pyx_t_7, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __PYX_ERR(0, 560, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":538
 * 
 * 
 * def get_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the original sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("cpymad.libmadx.get_element_index_by_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":563
 * 
 * 
 * def get_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the original sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_63get_element_count(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_62get_element_count[] = "get_element_count(sequence_name)\n\n    Return number of elements in the original sequence.\n\n    :param str sequence_name: sequence name\n    :returns: number of elements in the original sequence\n    :rtype: int\n    :raises ValueError: if the sequence is invalid.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_63get_element_count = {"get_element_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_63get_element_count, METH_O, __pyx_doc_6cpymad_7libmadx_62get_element_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_63get_element_count(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_element_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_62get_element_count(__pyx_self, ((PyObject *)__pyx_v_sequence_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_62get_element_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_element_count", 0);

  /* "cpymad/libmadx.pyx":572
 *     :raises ValueError: if the sequence is invalid.
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     return seq.nodes.curr
 * 
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 572, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":573
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     return seq.nodes.curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_seq->nodes->curr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":563
 * 
 * 
 * def get_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the original sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.get_element_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":576
 * 
 * 
 * def get_expanded_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_65get_expanded_element(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_64get_expanded_element[] = "get_expanded_element(sequence_name, element_index)\n\n    Return requested element in the expanded sequence.\n\n    :param str sequence_name: sequence name\n    :param int element_index: element index\n    :returns: the element with the specified index\n    :rtype: dict\n    :raises ValueError: if the sequence is invalid\n    :raises IndexError: if the index is out of range\n\n    NOTE: this function may currently return elements beyond the end of the\n    expanded sequence if requested to do so.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_65get_expanded_element = {"get_expanded_element", (PyCFunction)__pyx_pw_6cpymad_7libmadx_65get_expanded_element, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_64get_expanded_element};
static PyObject *__pyx_pw_6cpymad_7libmadx_65get_expanded_element(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sequence_name = 0;
  PyObject *__pyx_v_element_index = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_expanded_element (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence_name,&__pyx_n_s_element_index,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_element_index)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_expanded_element", 1, 2, 2, 1); __PYX_ERR(0, 576, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_expanded_element") < 0)) __PYX_ERR(0, 576, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_sequence_name = values[0];
    __pyx_v_element_index = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_expanded_element", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 576, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_64get_expanded_element(__pyx_self, __pyx_v_sequence_name, __pyx_v_element_index);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_64get_expanded_element(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_index) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("get_expanded_element", 0);

  /* "cpymad/libmadx.pyx":590
 *     expanded sequence if requested to do so.
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     # TODO: should check for get_expanded_element_count() instead of n_nodes?
 *     if element_index < 0 or element_index >= seq.n_nodes:
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 590, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":592
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     # TODO: should check for get_expanded_element_count() instead of n_nodes?
 *     if element_index < 0 or element_index >= seq.n_nodes:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.n_nodes))
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_element_index, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 592, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_seq->n_nodes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyObject_RichCompare(__pyx_v_element_index, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":594
 *     if element_index < 0 or element_index >= seq.n_nodes:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.n_nodes))             # <<<<<<<<<<<<<<
 *     return _get_node(seq.all_nodes[element_index], seq.ref_flag)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Index_out_of_range_0_element_cou, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_seq->n_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_8 = 1;
      }
    }
    __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (__pyx_t_7) {
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
    }
    __Pyx_INCREF(__pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_v_element_index);
    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "cpymad/libmadx.pyx":593
 *     # TODO: should check for get_expanded_element_count() instead of n_nodes?
 *     if element_index < 0 or element_index >= seq.n_nodes:
 *         raise IndexError("Index out of range: {0} (element count is {1})"             # <<<<<<<<<<<<<<
 *                          .format(element_index, seq.n_nodes))
 *     return _get_node(seq.all_nodes[element_index], seq.ref_flag)
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 593, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":592
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     # TODO: should check for get_expanded_element_count() instead of n_nodes?
 *     if element_index < 0 or element_index >= seq.n_nodes:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.n_nodes))
 */
  }

  /* "cpymad/libmadx.pyx":595
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, seq.n_nodes))
 *     return _get_node(seq.all_nodes[element_index], seq.ref_flag)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_element_index); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 595, __pyx_L1_error)
  __pyx_t_5 = __pyx_f_6cpymad_7libmadx__get_node((__pyx_v_seq->all_nodes[__pyx_t_8]), __pyx_v_seq->ref_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":576
 * 
 * 
 * def get_expanded_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":598
 * 
 * 
 * def get_expanded_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the expanded sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_67get_expanded_element_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_66get_expanded_element_index[] = "get_expanded_element_index(sequence_name, element_name)\n\n    Return index of element with specified name in the expanded sequence.\n\n    NOTE: this is the brute-force linear-time algorithm and therefore not\n    recommended for frequent execution.\n\n    :param str sequence_name: sequence name\n    :param str element_name: element index\n    :returns: the index of the specified element, -1 if not found\n    :rtype: int\n    :raises ValueError: if the sequence is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_67get_expanded_element_index = {"get_expanded_element_index", (PyCFunction)__pyx_pw_6cpymad_7libmadx_67get_expanded_element_index, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_66get_expanded_element_index};
static PyObject *__pyx_pw_6cpymad_7libmadx_67get_expanded_element_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sequence_name = 0;
  PyObject *__pyx_v_element_name = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_expanded_element_index (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence_name,&__pyx_n_s_element_name,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_element_name)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_expanded_element_index", 1, 2, 2, 1); __PYX_ERR(0, 598, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_expanded_element_index") < 0)) __PYX_ERR(0, 598, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_sequence_name = values[0];
    __pyx_v_element_name = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_expanded_element_index", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 598, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_66get_expanded_element_index(__pyx_self, __pyx_v_sequence_name, __pyx_v_element_name);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_66get_expanded_element_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_element_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_v__element_name = 0;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("get_expanded_element_index", 0);

  /* "cpymad/libmadx.pyx":613
 *     # Unfortunately, there is no name_list for the expanded list. Therefore,
 *     # Therefore, we can only provide a linear-time lookup.
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))
 *     # TODO: should use get_expanded_element_count() directly?
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 613, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":614
 *     # Therefore, we can only provide a linear-time lookup.
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))             # <<<<<<<<<<<<<<
 *     # TODO: should use get_expanded_element_count() directly?
 *     for i in xrange(seq.n_nodes):
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_name_to_internal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_element_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 614, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 614, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_INCREF(__pyx_v_element_name);
    __Pyx_GIVEREF(__pyx_v_element_name);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_element_name);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 614, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v__element_name = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "cpymad/libmadx.pyx":616
 *     cdef bytes _element_name = _cstr(name_to_internal(element_name))
 *     # TODO: should use get_expanded_element_count() directly?
 *     for i in xrange(seq.n_nodes):             # <<<<<<<<<<<<<<
 *         if seq.all_nodes[i].name == _element_name:
 *             return i
 */
  __pyx_t_6 = __pyx_v_seq->n_nodes;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "cpymad/libmadx.pyx":617
 *     # TODO: should use get_expanded_element_count() directly?
 *     for i in xrange(seq.n_nodes):
 *         if seq.all_nodes[i].name == _element_name:             # <<<<<<<<<<<<<<
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:
 */
    __pyx_t_3 = __Pyx_PyObject_FromString((__pyx_v_seq->all_nodes[__pyx_v_i])->name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 617, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_v__element_name, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 617, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_8) {

      /* "cpymad/libmadx.pyx":618
 *     for i in xrange(seq.n_nodes):
 *         if seq.all_nodes[i].name == _element_name:
 *             return i             # <<<<<<<<<<<<<<
 *         if seq.all_nodes[i] == seq.ex_end:
 *             break
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 618, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":617
 *     # TODO: should use get_expanded_element_count() directly?
 *     for i in xrange(seq.n_nodes):
 *         if seq.all_nodes[i].name == _element_name:             # <<<<<<<<<<<<<<
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:
 */
    }

    /* "cpymad/libmadx.pyx":619
 *         if seq.all_nodes[i].name == _element_name:
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:             # <<<<<<<<<<<<<<
 *             break
 *     raise ValueError("Element name not found: {0}".format(element_name))
 */
    __pyx_t_8 = (((__pyx_v_seq->all_nodes[__pyx_v_i]) == __pyx_v_seq->ex_end) != 0);
    if (__pyx_t_8) {

      /* "cpymad/libmadx.pyx":620
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:
 *             break             # <<<<<<<<<<<<<<
 *     raise ValueError("Element name not found: {0}".format(element_name))
 * 
 */
      goto __pyx_L4_break;

      /* "cpymad/libmadx.pyx":619
 *         if seq.all_nodes[i].name == _element_name:
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:             # <<<<<<<<<<<<<<
 *             break
 *     raise ValueError("Element name not found: {0}".format(element_name))
 */
    }
  }
  __pyx_L4_break:;

  /* "cpymad/libmadx.pyx":621
 *         if seq.all_nodes[i] == seq.ex_end:
 *             break
 *     raise ValueError("Element name not found: {0}".format(element_name))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Element_name_not_found_0, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_element_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
    __Pyx_INCREF(__pyx_v_element_name);
    __Pyx_GIVEREF(__pyx_v_element_name);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_element_name);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_Raise(__pyx_t_3, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __PYX_ERR(0, 621, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":598
 * 
 * 
 * def get_expanded_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the expanded sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__element_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":624
 * 
 * 
 * def get_expanded_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the expanded sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_69get_expanded_element_index_by_position(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_68get_expanded_element_index_by_position[] = "get_expanded_element_index_by_position(sequence_name, position)\n\n    Return index of element at specified position in the expanded sequence.\n\n    :param str sequence_name: sequence name\n    :param double position: position (S coordinate)\n    :returns: the index of an element at that position\n    :rtype: int\n    :raises ValueError: if the sequence or element name is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_69get_expanded_element_index_by_position = {"get_expanded_element_index_by_position", (PyCFunction)__pyx_pw_6cpymad_7libmadx_69get_expanded_element_index_by_position, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6cpymad_7libmadx_68get_expanded_element_index_by_position};
static PyObject *__pyx_pw_6cpymad_7libmadx_69get_expanded_element_index_by_position(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sequence_name = 0;
  PyObject *__pyx_v_position = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_expanded_element_index_by_position (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence_name,&__pyx_n_s_position,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_position)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_expanded_element_index_by_position", 1, 2, 2, 1); __PYX_ERR(0, 624, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_expanded_element_index_by_position") < 0)) __PYX_ERR(0, 624, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_sequence_name = values[0];
    __pyx_v_position = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_expanded_element_index_by_position", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 624, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element_index_by_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cpymad_7libmadx_68get_expanded_element_index_by_position(__pyx_self, __pyx_v_sequence_name, __pyx_v_position);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_68get_expanded_element_index_by_position(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name, PyObject *__pyx_v_position) {
  struct sequence *__pyx_v_seq;
  double __pyx_v__position;
  struct node *__pyx_v_elem;
  double __pyx_v_at;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  double __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_RefNannySetupContext("get_expanded_element_index_by_position", 0);

  /* "cpymad/libmadx.pyx":637
 *     # algorithm. If you want more, you need to copy the elements over and use
 *     # a suitable ordered data type.
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     cdef double _position = position
 *     cdef clib.node* elem
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 637, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":638
 *     # a suitable ordered data type.
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     cdef double _position = position             # <<<<<<<<<<<<<<
 *     cdef clib.node* elem
 *     cdef double at
 */
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_position); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 638, __pyx_L1_error)
  __pyx_v__position = __pyx_t_2;

  /* "cpymad/libmadx.pyx":642
 *     cdef double at
 *     # TODO: should use get_expanded_element_count() directly?
 *     for i in xrange(seq.n_nodes):             # <<<<<<<<<<<<<<
 *         elem = seq.all_nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 */
  __pyx_t_3 = __pyx_v_seq->n_nodes;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "cpymad/libmadx.pyx":643
 *     # TODO: should use get_expanded_element_count() directly?
 *     for i in xrange(seq.n_nodes):
 *         elem = seq.all_nodes[i]             # <<<<<<<<<<<<<<
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:
 */
    __pyx_v_elem = (__pyx_v_seq->all_nodes[__pyx_v_i]);

    /* "cpymad/libmadx.pyx":644
 *     for i in xrange(seq.n_nodes):
 *         elem = seq.all_nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)             # <<<<<<<<<<<<<<
 *         if _position >= at and _position <= at+elem.length:
 *             return i
 */
    __pyx_v_at = __pyx_f_6cpymad_7libmadx__get_node_entry_pos(__pyx_v_elem, __pyx_v_seq->ref_flag);

    /* "cpymad/libmadx.pyx":645
 *         elem = seq.all_nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:             # <<<<<<<<<<<<<<
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:
 */
    __pyx_t_6 = ((__pyx_v__position >= __pyx_v_at) != 0);
    if (__pyx_t_6) {
    } else {
      __pyx_t_5 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v__position <= (__pyx_v_at + __pyx_v_elem->length)) != 0);
    __pyx_t_5 = __pyx_t_6;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_5) {

      /* "cpymad/libmadx.pyx":646
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:
 *             return i             # <<<<<<<<<<<<<<
 *         if seq.all_nodes[i] == seq.ex_end:
 *             break
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 646, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":645
 *         elem = seq.all_nodes[i]
 *         at = _get_node_entry_pos(elem, seq.ref_flag)
 *         if _position >= at and _position <= at+elem.length:             # <<<<<<<<<<<<<<
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:
 */
    }

    /* "cpymad/libmadx.pyx":647
 *         if _position >= at and _position <= at+elem.length:
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:             # <<<<<<<<<<<<<<
 *             break
 *     raise ValueError("No element found at position: {0}".format(position))
 */
    __pyx_t_5 = (((__pyx_v_seq->all_nodes[__pyx_v_i]) == __pyx_v_seq->ex_end) != 0);
    if (__pyx_t_5) {

      /* "cpymad/libmadx.pyx":648
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:
 *             break             # <<<<<<<<<<<<<<
 *     raise ValueError("No element found at position: {0}".format(position))
 * 
 */
      goto __pyx_L4_break;

      /* "cpymad/libmadx.pyx":647
 *         if _position >= at and _position <= at+elem.length:
 *             return i
 *         if seq.all_nodes[i] == seq.ex_end:             # <<<<<<<<<<<<<<
 *             break
 *     raise ValueError("No element found at position: {0}".format(position))
 */
    }
  }
  __pyx_L4_break:;

  /* "cpymad/libmadx.pyx":649
 *         if seq.all_nodes[i] == seq.ex_end:
 *             break
 *     raise ValueError("No element found at position: {0}".format(position))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_No_element_found_at_position_0, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_position); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 649, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
  } else {
    __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 649, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
    __Pyx_INCREF(__pyx_v_position);
    __Pyx_GIVEREF(__pyx_v_position);
    PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_position);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 649, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_Raise(__pyx_t_7, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __PYX_ERR(0, 649, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":624
 * 
 * 
 * def get_expanded_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the expanded sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element_index_by_position", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":652
 * 
 * 
 * def get_expanded_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the expanded sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_71get_expanded_element_count(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_70get_expanded_element_count[] = "get_expanded_element_count(sequence_name)\n\n    Return number of elements in the expanded sequence.\n\n    :param str sequence_name: sequence name\n    :returns: number of elements in the expanded sequence\n    :rtype: int\n    :raises ValueError: if the sequence is invalid.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_71get_expanded_element_count = {"get_expanded_element_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_71get_expanded_element_count, METH_O, __pyx_doc_6cpymad_7libmadx_70get_expanded_element_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_71get_expanded_element_count(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_expanded_element_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_70get_expanded_element_count(__pyx_self, ((PyObject *)__pyx_v_sequence_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_70get_expanded_element_count(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_v_i_beg = NULL;
  PyObject *__pyx_v_i_end = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("get_expanded_element_count", 0);

  /* "cpymad/libmadx.pyx":661
 *     :raises ValueError: if the sequence is invalid.
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     # NOTE: seq.n_nodes is not necessarily the number of elements in the
 *     # expanded list. According to tests, some of the leading elements may be
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 661, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":665
 *     # expanded list. According to tests, some of the leading elements may be
 *     # appended after the final element of the expanded list. Reason unclear!
 *     i_beg = _get_node_index(seq.all_nodes, seq.n_nodes, seq.ex_start)             # <<<<<<<<<<<<<<
 *     i_end = _get_node_index(seq.all_nodes, seq.n_nodes, seq.ex_end)
 *     return i_end - i_beg + 1
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_6cpymad_7libmadx__get_node_index(__pyx_v_seq->all_nodes, __pyx_v_seq->n_nodes, __pyx_v_seq->ex_start)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 665, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_i_beg = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":666
 *     # appended after the final element of the expanded list. Reason unclear!
 *     i_beg = _get_node_index(seq.all_nodes, seq.n_nodes, seq.ex_start)
 *     i_end = _get_node_index(seq.all_nodes, seq.n_nodes, seq.ex_end)             # <<<<<<<<<<<<<<
 *     return i_end - i_beg + 1
 * 
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_6cpymad_7libmadx__get_node_index(__pyx_v_seq->all_nodes, __pyx_v_seq->n_nodes, __pyx_v_seq->ex_end)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_i_end = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":667
 *     i_beg = _get_node_index(seq.all_nodes, seq.n_nodes, seq.ex_start)
 *     i_end = _get_node_index(seq.all_nodes, seq.n_nodes, seq.ex_end)
 *     return i_end - i_beg + 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyNumber_Subtract(__pyx_v_i_end, __pyx_v_i_beg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":652
 * 
 * 
 * def get_expanded_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the expanded sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpymad.libmadx.get_expanded_element_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_i_beg);
  __Pyx_XDECREF(__pyx_v_i_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":670
 * 
 * 
 * def get_global_element(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_73get_global_element(PyObject *__pyx_self, PyObject *__pyx_v_element_index); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_72get_global_element[] = "get_global_element(element_index)\n\n    Return requested element in the expanded sequence.\n\n    :param int element_index: element index\n    :returns: the element with the specified index\n    :rtype: dict\n    :raises IndexError: if the index is out of range\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_73get_global_element = {"get_global_element", (PyCFunction)__pyx_pw_6cpymad_7libmadx_73get_global_element, METH_O, __pyx_doc_6cpymad_7libmadx_72get_global_element};
static PyObject *__pyx_pw_6cpymad_7libmadx_73get_global_element(PyObject *__pyx_self, PyObject *__pyx_v_element_index) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_global_element (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_72get_global_element(__pyx_self, ((PyObject *)__pyx_v_element_index));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_72get_global_element(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_element_index) {
  struct el_list *__pyx_v_elems;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("get_global_element", 0);

  /* "cpymad/libmadx.pyx":679
 *     :raises IndexError: if the index is out of range
 *     """
 *     cdef clib.el_list* elems = clib.element_list             # <<<<<<<<<<<<<<
 *     if element_index < 0 or element_index >= elems.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 */
  __pyx_v_elems = element_list;

  /* "cpymad/libmadx.pyx":680
 *     """
 *     cdef clib.el_list* elems = clib.element_list
 *     if element_index < 0 or element_index >= elems.curr:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_element_index, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 680, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 680, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_elems->curr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 680, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_RichCompare(__pyx_v_element_index, __pyx_t_2, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 680, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 680, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "cpymad/libmadx.pyx":682
 *     if element_index < 0 or element_index >= elems.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))             # <<<<<<<<<<<<<<
 *     return _get_element(elems.elem[element_index])
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Index_out_of_range_0_element_cou, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_elems->curr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_7 = 1;
      }
    }
    __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_v_element_index);
    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cpymad/libmadx.pyx":681
 *     cdef clib.el_list* elems = clib.element_list
 *     if element_index < 0 or element_index >= elems.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"             # <<<<<<<<<<<<<<
 *                          .format(element_index, elems.curr))
 *     return _get_element(elems.elem[element_index])
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 681, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":680
 *     """
 *     cdef clib.el_list* elems = clib.element_list
 *     if element_index < 0 or element_index >= elems.curr:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))
 */
  }

  /* "cpymad/libmadx.pyx":683
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))
 *     return _get_element(elems.elem[element_index])             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_element_index); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 683, __pyx_L1_error)
  __pyx_t_4 = __pyx_f_6cpymad_7libmadx__get_element((__pyx_v_elems->elem[__pyx_t_7])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 683, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":670
 * 
 * 
 * def get_global_element(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("cpymad.libmadx.get_global_element", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":686
 * 
 * 
 * def get_global_element_name(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return name of element.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_75get_global_element_name(PyObject *__pyx_self, PyObject *__pyx_v_element_index); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_74get_global_element_name[] = "get_global_element_name(element_index)\n\n    Return name of element.\n\n    :param int element_index: element index\n    :returns: element name\n    :rtype: str\n    :raises IndexError: if the index is out of range\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_75get_global_element_name = {"get_global_element_name", (PyCFunction)__pyx_pw_6cpymad_7libmadx_75get_global_element_name, METH_O, __pyx_doc_6cpymad_7libmadx_74get_global_element_name};
static PyObject *__pyx_pw_6cpymad_7libmadx_75get_global_element_name(PyObject *__pyx_self, PyObject *__pyx_v_element_index) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_global_element_name (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_74get_global_element_name(__pyx_self, ((PyObject *)__pyx_v_element_index));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_74get_global_element_name(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_element_index) {
  struct el_list *__pyx_v_elems;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("get_global_element_name", 0);

  /* "cpymad/libmadx.pyx":695
 *     :raises IndexError: if the index is out of range
 *     """
 *     cdef clib.el_list* elems = clib.element_list             # <<<<<<<<<<<<<<
 *     if element_index < 0 or element_index >= elems.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 */
  __pyx_v_elems = element_list;

  /* "cpymad/libmadx.pyx":696
 *     """
 *     cdef clib.el_list* elems = clib.element_list
 *     if element_index < 0 or element_index >= elems.curr:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_element_index, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 696, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 696, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_elems->curr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_RichCompare(__pyx_v_element_index, __pyx_t_2, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 696, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 696, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "cpymad/libmadx.pyx":698
 *     if element_index < 0 or element_index >= elems.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))             # <<<<<<<<<<<<<<
 *     return _str(elems.list.names[element_index])
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Index_out_of_range_0_element_cou, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_elems->curr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_7 = 1;
      }
    }
    __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_v_element_index);
    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_element_index);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cpymad/libmadx.pyx":697
 *     cdef clib.el_list* elems = clib.element_list
 *     if element_index < 0 or element_index >= elems.curr:
 *         raise IndexError("Index out of range: {0} (element count is {1})"             # <<<<<<<<<<<<<<
 *                          .format(element_index, elems.curr))
 *     return _str(elems.list.names[element_index])
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 697, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 697, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 697, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":696
 *     """
 *     cdef clib.el_list* elems = clib.element_list
 *     if element_index < 0 or element_index >= elems.curr:             # <<<<<<<<<<<<<<
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))
 */
  }

  /* "cpymad/libmadx.pyx":699
 *         raise IndexError("Index out of range: {0} (element count is {1})"
 *                          .format(element_index, elems.curr))
 *     return _str(elems.list.names[element_index])             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_element_index); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 699, __pyx_L1_error)
  __pyx_t_4 = __pyx_f_6cpymad_7libmadx__str((__pyx_v_elems->list->names[__pyx_t_7])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":686
 * 
 * 
 * def get_global_element_name(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return name of element.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("cpymad.libmadx.get_global_element_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":702
 * 
 * 
 * def get_global_element_index(element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the global element list.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_77get_global_element_index(PyObject *__pyx_self, PyObject *__pyx_v_element_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_76get_global_element_index[] = "get_global_element_index(element_name)\n\n    Return index of element with specified name in the global element list.\n\n    :param str element_name: element index\n    :returns: the index of the specified element, -1 if not found\n    :rtype: int\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_77get_global_element_index = {"get_global_element_index", (PyCFunction)__pyx_pw_6cpymad_7libmadx_77get_global_element_index, METH_O, __pyx_doc_6cpymad_7libmadx_76get_global_element_index};
static PyObject *__pyx_pw_6cpymad_7libmadx_77get_global_element_index(PyObject *__pyx_self, PyObject *__pyx_v_element_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_global_element_index (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_76get_global_element_index(__pyx_self, ((PyObject *)__pyx_v_element_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_76get_global_element_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_element_name) {
  PyObject *__pyx_v__element_name = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  __Pyx_RefNannySetupContext("get_global_element_index", 0);

  /* "cpymad/libmadx.pyx":710
 *     :rtype: int
 *     """
 *     cdef bytes _element_name = _cstr(element_name)             # <<<<<<<<<<<<<<
 *     return clib.name_list_pos(_element_name, clib.element_list.list)
 * 
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_element_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 710, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__element_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":711
 *     """
 *     cdef bytes _element_name = _cstr(element_name)
 *     return clib.name_list_pos(_element_name, clib.element_list.list)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__element_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 711, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyInt_From_int(name_list_pos(__pyx_t_2, element_list->list)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":702
 * 
 * 
 * def get_global_element_index(element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the global element list.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.get_global_element_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__element_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":714
 * 
 * 
 * def get_global_element_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of globally visible elements.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_79get_global_element_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_78get_global_element_count[] = "get_global_element_count()\n\n    Return number of globally visible elements.\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_79get_global_element_count = {"get_global_element_count", (PyCFunction)__pyx_pw_6cpymad_7libmadx_79get_global_element_count, METH_NOARGS, __pyx_doc_6cpymad_7libmadx_78get_global_element_count};
static PyObject *__pyx_pw_6cpymad_7libmadx_79get_global_element_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_global_element_count (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_78get_global_element_count(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_78get_global_element_count(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_global_element_count", 0);

  /* "cpymad/libmadx.pyx":718
 *     Return number of globally visible elements.
 *     """
 *     return clib.element_list.curr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(element_list->curr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":714
 * 
 * 
 * def get_global_element_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of globally visible elements.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.get_global_element_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":721
 * 
 * 
 * def is_sequence_expanded(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check whether a sequence has already been expanded.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_81is_sequence_expanded(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_80is_sequence_expanded[] = "is_sequence_expanded(sequence_name)\n\n    Check whether a sequence has already been expanded.\n\n    :param str sequence_name: sequence name\n    :returns: expanded state of the sequence\n    :rtype: bool\n    :raises ValueError: if the sequence is invalid\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_81is_sequence_expanded = {"is_sequence_expanded", (PyCFunction)__pyx_pw_6cpymad_7libmadx_81is_sequence_expanded, METH_O, __pyx_doc_6cpymad_7libmadx_80is_sequence_expanded};
static PyObject *__pyx_pw_6cpymad_7libmadx_81is_sequence_expanded(PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_sequence_expanded (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_80is_sequence_expanded(__pyx_self, ((PyObject *)__pyx_v_sequence_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_80is_sequence_expanded(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sequence_name) {
  struct sequence *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct sequence *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("is_sequence_expanded", 0);

  /* "cpymad/libmadx.pyx":730
 *     :raises ValueError: if the sequence is invalid
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)             # <<<<<<<<<<<<<<
 *     return seq.n_nodes > 0
 * 
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__find_sequence(__pyx_v_sequence_name); if (unlikely(__pyx_t_1 == NULL)) __PYX_ERR(0, 730, __pyx_L1_error)
  __pyx_v_seq = __pyx_t_1;

  /* "cpymad/libmadx.pyx":731
 *     """
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     return seq.n_nodes > 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong((__pyx_v_seq->n_nodes > 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":721
 * 
 * 
 * def is_sequence_expanded(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check whether a sequence has already been expanded.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx.is_sequence_expanded", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":734
 * 
 * 
 * def evaluate(expression):             # <<<<<<<<<<<<<<
 *     """
 *     Evaluates an expression and returns the result as double.
 */

/* Python wrapper */
static PyObject *__pyx_pw_6cpymad_7libmadx_83evaluate(PyObject *__pyx_self, PyObject *__pyx_v_expression); /*proto*/
static char __pyx_doc_6cpymad_7libmadx_82evaluate[] = "evaluate(expression)\n\n    Evaluates an expression and returns the result as double.\n\n    :param str expression: symbolic expression to evaluate\n    :returns: numeric value of the expression\n    :rtype: float\n    ";
static PyMethodDef __pyx_mdef_6cpymad_7libmadx_83evaluate = {"evaluate", (PyCFunction)__pyx_pw_6cpymad_7libmadx_83evaluate, METH_O, __pyx_doc_6cpymad_7libmadx_82evaluate};
static PyObject *__pyx_pw_6cpymad_7libmadx_83evaluate(PyObject *__pyx_self, PyObject *__pyx_v_expression) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("evaluate (wrapper)", 0);
  __pyx_r = __pyx_pf_6cpymad_7libmadx_82evaluate(__pyx_self, ((PyObject *)__pyx_v_expression));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6cpymad_7libmadx_82evaluate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_expression) {
  struct expression *__pyx_v_expr;
  double __pyx_v_value;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("evaluate", 0);

  /* "cpymad/libmadx.pyx":742
 *     :rtype: float
 *     """
 *     cdef clib.expression* expr = _make_expr(expression)             # <<<<<<<<<<<<<<
 *     value = clib.expression_value(expr, 2)
 *     clib.delete_expression(expr)
 */
  __pyx_v_expr = __pyx_f_6cpymad_7libmadx__make_expr(__pyx_v_expression);

  /* "cpymad/libmadx.pyx":743
 *     """
 *     cdef clib.expression* expr = _make_expr(expression)
 *     value = clib.expression_value(expr, 2)             # <<<<<<<<<<<<<<
 *     clib.delete_expression(expr)
 *     return value
 */
  __pyx_v_value = expression_value(__pyx_v_expr, 2);

  /* "cpymad/libmadx.pyx":744
 *     cdef clib.expression* expr = _make_expr(expression)
 *     value = clib.expression_value(expr, 2)
 *     clib.delete_expression(expr)             # <<<<<<<<<<<<<<
 *     return value
 * 
 */
  delete_expression(__pyx_v_expr);

  /* "cpymad/libmadx.pyx":745
 *     value = clib.expression_value(expr, 2)
 *     clib.delete_expression(expr)
 *     return value             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":734
 * 
 * 
 * def evaluate(expression):             # <<<<<<<<<<<<<<
 *     """
 *     Evaluates an expression and returns the result as double.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":748
 * 
 * 
 * cdef clib.expression* _make_expr(expression):             # <<<<<<<<<<<<<<
 *     # TODO: This function uses global variables as temporaries - which is in
 *     # general an *extremely* bad design choice. Even though MAD-X uses global
 */

static struct expression *__pyx_f_6cpymad_7libmadx__make_expr(PyObject *__pyx_v_expression) {
  PyObject *__pyx_v__expr = 0;
  struct expression *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  char *__pyx_t_8;
  __Pyx_RefNannySetupContext("_make_expr", 0);
  __Pyx_INCREF(__pyx_v_expression);

  /* "cpymad/libmadx.pyx":753
 *     # variables internally anyway, this is no excuse for cpymad to copy that
 *     # behaviour.
 *     try:             # <<<<<<<<<<<<<<
 *         # handle instance of type Expression:
 *         expression = expression.expr
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "cpymad/libmadx.pyx":755
 *     try:
 *         # handle instance of type Expression:
 *         expression = expression.expr             # <<<<<<<<<<<<<<
 *     except AttributeError:
 *         pass
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_expression, __pyx_n_s_expr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF_SET(__pyx_v_expression, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "cpymad/libmadx.pyx":753
 *     # variables internally anyway, this is no excuse for cpymad to copy that
 *     # behaviour.
 *     try:             # <<<<<<<<<<<<<<
 *         # handle instance of type Expression:
 *         expression = expression.expr
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "cpymad/libmadx.pyx":756
 *         # handle instance of type Expression:
 *         expression = expression.expr
 *     except AttributeError:             # <<<<<<<<<<<<<<
 *         pass
 *     # TODO: not sure about the flags (the magic constants 0, 2)
 */
    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_5) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "cpymad/libmadx.pyx":753
 *     # variables internally anyway, this is no excuse for cpymad to copy that
 *     # behaviour.
 *     try:             # <<<<<<<<<<<<<<
 *         # handle instance of type Expression:
 *         expression = expression.expr
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L10_try_end:;
  }

  /* "cpymad/libmadx.pyx":759
 *         pass
 *     # TODO: not sure about the flags (the magic constants 0, 2)
 *     cdef bytes _expr = _cstr(expression.lower())             # <<<<<<<<<<<<<<
 *     clib.pre_split(_expr, clib.c_dum, 0)
 *     clib.mysplit(clib.c_dum.c, clib.tmp_p_array)
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_expression, __pyx_n_s_lower); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_7) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 759, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 759, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v__expr = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "cpymad/libmadx.pyx":760
 *     # TODO: not sure about the flags (the magic constants 0, 2)
 *     cdef bytes _expr = _cstr(expression.lower())
 *     clib.pre_split(_expr, clib.c_dum, 0)             # <<<<<<<<<<<<<<
 *     clib.mysplit(clib.c_dum.c, clib.tmp_p_array)
 *     return clib.make_expression(clib.tmp_p_array.curr, clib.tmp_p_array.p)
 */
  __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v__expr); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 760, __pyx_L1_error)
  pre_split(__pyx_t_8, c_dum, 0);

  /* "cpymad/libmadx.pyx":761
 *     cdef bytes _expr = _cstr(expression.lower())
 *     clib.pre_split(_expr, clib.c_dum, 0)
 *     clib.mysplit(clib.c_dum.c, clib.tmp_p_array)             # <<<<<<<<<<<<<<
 *     return clib.make_expression(clib.tmp_p_array.curr, clib.tmp_p_array.p)
 * 
 */
  mysplit(c_dum->c, tmp_p_array);

  /* "cpymad/libmadx.pyx":762
 *     clib.pre_split(_expr, clib.c_dum, 0)
 *     clib.mysplit(clib.c_dum.c, clib.tmp_p_array)
 *     return clib.make_expression(clib.tmp_p_array.curr, clib.tmp_p_array.p)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = make_expression(tmp_p_array->curr, tmp_p_array->p);
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":748
 * 
 * 
 * cdef clib.expression* _make_expr(expression):             # <<<<<<<<<<<<<<
 *     # TODO: This function uses global variables as temporaries - which is in
 *     # general an *extremely* bad design choice. Even though MAD-X uses global
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_WriteUnraisable("cpymad.libmadx._make_expr", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__expr);
  __Pyx_XDECREF(__pyx_v_expression);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":773
 * _expr_types = [bool, int, float]
 * 
 * cdef _expr(clib.expression* expr,             # <<<<<<<<<<<<<<
 *            double value,
 *            int typeid=clib.PARAM_TYPE_DOUBLE):
 */

static PyObject *__pyx_f_6cpymad_7libmadx__expr(struct expression *__pyx_v_expr, double __pyx_v_value, struct __pyx_opt_args_6cpymad_7libmadx__expr *__pyx_optional_args) {
  int __pyx_v_typeid = __pyx_k__5;
  PyObject *__pyx_v__type = NULL;
  PyObject *__pyx_v__value = NULL;
  PyObject *__pyx_v__expr = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  Py_ssize_t __pyx_t_14;
  __Pyx_RefNannySetupContext("_expr", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_typeid = __pyx_optional_args->typeid;
    }
  }

  /* "cpymad/libmadx.pyx":777
 *            int typeid=clib.PARAM_TYPE_DOUBLE):
 *     """Return a parameter value with an appropriate type."""
 *     _type = _expr_types[typeid]             # <<<<<<<<<<<<<<
 *     _value = _type(value)
 *     if expr is NULL or expr.string is NULL:
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_expr_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_typeid, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__type = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":778
 *     """Return a parameter value with an appropriate type."""
 *     _type = _expr_types[typeid]
 *     _value = _type(value)             # <<<<<<<<<<<<<<
 *     if expr is NULL or expr.string is NULL:
 *         return _value
 */
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v__type);
  __pyx_t_3 = __pyx_v__type; __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v__value = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":779
 *     _type = _expr_types[typeid]
 *     _value = _type(value)
 *     if expr is NULL or expr.string is NULL:             # <<<<<<<<<<<<<<
 *         return _value
 *     _expr = _str(expr.string).strip()
 */
  __pyx_t_7 = ((__pyx_v_expr == NULL) != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_6 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_7 = ((__pyx_v_expr->string == NULL) != 0);
  __pyx_t_6 = __pyx_t_7;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_6) {

    /* "cpymad/libmadx.pyx":780
 *     _value = _type(value)
 *     if expr is NULL or expr.string is NULL:
 *         return _value             # <<<<<<<<<<<<<<
 *     _expr = _str(expr.string).strip()
 *     if not _expr:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v__value);
    __pyx_r = __pyx_v__value;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":779
 *     _type = _expr_types[typeid]
 *     _value = _type(value)
 *     if expr is NULL or expr.string is NULL:             # <<<<<<<<<<<<<<
 *         return _value
 *     _expr = _str(expr.string).strip()
 */
  }

  /* "cpymad/libmadx.pyx":781
 *     if expr is NULL or expr.string is NULL:
 *         return _value
 *     _expr = _str(expr.string).strip()             # <<<<<<<<<<<<<<
 *     if not _expr:
 *         return _value
 */
  __pyx_t_3 = __pyx_f_6cpymad_7libmadx__str(__pyx_v_expr->string); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 781, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_strip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 781, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 781, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 781, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v__expr = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":782
 *         return _value
 *     _expr = _str(expr.string).strip()
 *     if not _expr:             # <<<<<<<<<<<<<<
 *         return _value
 *     try:
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v__expr); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 782, __pyx_L1_error)
  __pyx_t_7 = ((!__pyx_t_6) != 0);
  if (__pyx_t_7) {

    /* "cpymad/libmadx.pyx":783
 *     _expr = _str(expr.string).strip()
 *     if not _expr:
 *         return _value             # <<<<<<<<<<<<<<
 *     try:
 *         return _type(float(_expr))
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v__value);
    __pyx_r = __pyx_v__value;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":782
 *         return _value
 *     _expr = _str(expr.string).strip()
 *     if not _expr:             # <<<<<<<<<<<<<<
 *         return _value
 *     try:
 */
  }

  /* "cpymad/libmadx.pyx":784
 *     if not _expr:
 *         return _value
 *     try:             # <<<<<<<<<<<<<<
 *         return _type(float(_expr))
 *     except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_8);
    __Pyx_XGOTREF(__pyx_t_9);
    __Pyx_XGOTREF(__pyx_t_10);
    /*try:*/ {

      /* "cpymad/libmadx.pyx":785
 *         return _value
 *     try:
 *         return _type(float(_expr))             # <<<<<<<<<<<<<<
 *     except ValueError:
 *         pass
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = __Pyx_PyNumber_Float(__pyx_v__expr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 785, __pyx_L7_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v__type);
      __pyx_t_3 = __pyx_v__type; __pyx_t_1 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 785, __pyx_L7_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 785, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
        __pyx_t_5 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 785, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L11_try_return;

      /* "cpymad/libmadx.pyx":784
 *     if not _expr:
 *         return _value
 *     try:             # <<<<<<<<<<<<<<
 *         return _type(float(_expr))
 *     except ValueError:
 */
    }
    __pyx_L7_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cpymad/libmadx.pyx":786
 *     try:
 *         return _type(float(_expr))
 *     except ValueError:             # <<<<<<<<<<<<<<
 *         pass
 *     value = clib.expression_value(expr, 2)
 */
    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_11) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L8_exception_handled;
    }
    goto __pyx_L9_except_error;
    __pyx_L9_except_error:;

    /* "cpymad/libmadx.pyx":784
 *     if not _expr:
 *         return _value
 *     try:             # <<<<<<<<<<<<<<
 *         return _type(float(_expr))
 *     except ValueError:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L1_error;
    __pyx_L11_try_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L0;
    __pyx_L8_exception_handled:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
  }

  /* "cpymad/libmadx.pyx":788
 *     except ValueError:
 *         pass
 *     value = clib.expression_value(expr, 2)             # <<<<<<<<<<<<<<
 *     return Expression(_expr, _type(value), _type)
 * 
 */
  __pyx_v_value = expression_value(__pyx_v_expr, 2);

  /* "cpymad/libmadx.pyx":789
 *         pass
 *     value = clib.expression_value(expr, 2)
 *     return Expression(_expr, _type(value), _type)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_Expression); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 789, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 789, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v__type);
  __pyx_t_1 = __pyx_v__type; __pyx_t_12 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_12) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 789, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else {
    __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL;
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  __pyx_t_14 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_14 = 1;
    }
  }
  __pyx_t_13 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 789, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  if (__pyx_t_1) {
    __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); __pyx_t_1 = NULL;
  }
  __Pyx_INCREF(__pyx_v__expr);
  __Pyx_GIVEREF(__pyx_v__expr);
  PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_14, __pyx_v__expr);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_14, __pyx_t_4);
  __Pyx_INCREF(__pyx_v__type);
  __Pyx_GIVEREF(__pyx_v__type);
  PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_14, __pyx_v__type);
  __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 789, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":773
 * _expr_types = [bool, int, float]
 * 
 * cdef _expr(clib.expression* expr,             # <<<<<<<<<<<<<<
 *            double value,
 *            int typeid=clib.PARAM_TYPE_DOUBLE):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("cpymad.libmadx._expr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__type);
  __Pyx_XDECREF(__pyx_v__value);
  __Pyx_XDECREF(__pyx_v__expr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":792
 * 
 * 
 * cdef _get_param_value(clib.command_parameter* par):             # <<<<<<<<<<<<<<
 * 
 *     """
 */

static PyObject *__pyx_f_6cpymad_7libmadx__get_param_value(struct command_parameter *__pyx_v_par) {
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_6cpymad_7libmadx__expr __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  void *__pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_RefNannySetupContext("_get_param_value", 0);

  /* "cpymad/libmadx.pyx":802
 *     """
 * 
 *     if par.type in (clib.PARAM_TYPE_LOGICAL,             # <<<<<<<<<<<<<<
 *                     clib.PARAM_TYPE_INTEGER,
 *                     clib.PARAM_TYPE_DOUBLE):
 */
  switch (__pyx_v_par->type) {
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_LOGICAL:

    /* "cpymad/libmadx.pyx":803
 * 
 *     if par.type in (clib.PARAM_TYPE_LOGICAL,
 *                     clib.PARAM_TYPE_INTEGER,             # <<<<<<<<<<<<<<
 *                     clib.PARAM_TYPE_DOUBLE):
 *         return _expr(par.expr, par.double_value, par.type)
 */
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_INTEGER:

    /* "cpymad/libmadx.pyx":804
 *     if par.type in (clib.PARAM_TYPE_LOGICAL,
 *                     clib.PARAM_TYPE_INTEGER,
 *                     clib.PARAM_TYPE_DOUBLE):             # <<<<<<<<<<<<<<
 *         return _expr(par.expr, par.double_value, par.type)
 * 
 */
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE:

    /* "cpymad/libmadx.pyx":805
 *                     clib.PARAM_TYPE_INTEGER,
 *                     clib.PARAM_TYPE_DOUBLE):
 *         return _expr(par.expr, par.double_value, par.type)             # <<<<<<<<<<<<<<
 * 
 *     if par.type == clib.PARAM_TYPE_STRING:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2.__pyx_n = 1;
    __pyx_t_2.typeid = __pyx_v_par->type;
    __pyx_t_1 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_par->expr, __pyx_v_par->double_value, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":802
 *     """
 * 
 *     if par.type in (clib.PARAM_TYPE_LOGICAL,             # <<<<<<<<<<<<<<
 *                     clib.PARAM_TYPE_INTEGER,
 *                     clib.PARAM_TYPE_DOUBLE):
 */
    break;
    default: break;
  }

  /* "cpymad/libmadx.pyx":807
 *         return _expr(par.expr, par.double_value, par.type)
 * 
 *     if par.type == clib.PARAM_TYPE_STRING:             # <<<<<<<<<<<<<<
 *         return _str(par.string)
 * 
 */
  __pyx_t_3 = ((__pyx_v_par->type == __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_STRING) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":808
 * 
 *     if par.type == clib.PARAM_TYPE_STRING:
 *         return _str(par.string)             # <<<<<<<<<<<<<<
 * 
 *     if par.type == clib.PARAM_TYPE_CONSTRAINT:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __pyx_f_6cpymad_7libmadx__str(__pyx_v_par->string); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":807
 *         return _expr(par.expr, par.double_value, par.type)
 * 
 *     if par.type == clib.PARAM_TYPE_STRING:             # <<<<<<<<<<<<<<
 *         return _str(par.string)
 * 
 */
  }

  /* "cpymad/libmadx.pyx":810
 *         return _str(par.string)
 * 
 *     if par.type == clib.PARAM_TYPE_CONSTRAINT:             # <<<<<<<<<<<<<<
 *         if par.c_type == clib.CONSTR_TYPE_MIN:
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 */
  __pyx_t_3 = ((__pyx_v_par->type == __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_CONSTRAINT) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":811
 * 
 *     if par.type == clib.PARAM_TYPE_CONSTRAINT:
 *         if par.c_type == clib.CONSTR_TYPE_MIN:             # <<<<<<<<<<<<<<
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 *         if par.c_type == clib.CONSTR_TYPE_MAX:
 */
    __pyx_t_3 = ((__pyx_v_par->c_type == __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_MIN) != 0);
    if (__pyx_t_3) {

      /* "cpymad/libmadx.pyx":812
 *     if par.type == clib.PARAM_TYPE_CONSTRAINT:
 *         if par.c_type == clib.CONSTR_TYPE_MIN:
 *             return Constraint(min=_expr(par.min_expr, par.c_min))             # <<<<<<<<<<<<<<
 *         if par.c_type == clib.CONSTR_TYPE_MAX:
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Constraint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 812, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_par->min_expr, __pyx_v_par->c_min, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 812, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_min, __pyx_t_5) < 0) __PYX_ERR(0, 812, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 812, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":811
 * 
 *     if par.type == clib.PARAM_TYPE_CONSTRAINT:
 *         if par.c_type == clib.CONSTR_TYPE_MIN:             # <<<<<<<<<<<<<<
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 *         if par.c_type == clib.CONSTR_TYPE_MAX:
 */
    }

    /* "cpymad/libmadx.pyx":813
 *         if par.c_type == clib.CONSTR_TYPE_MIN:
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 *         if par.c_type == clib.CONSTR_TYPE_MAX:             # <<<<<<<<<<<<<<
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:
 */
    __pyx_t_3 = ((__pyx_v_par->c_type == __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_MAX) != 0);
    if (__pyx_t_3) {

      /* "cpymad/libmadx.pyx":814
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 *         if par.c_type == clib.CONSTR_TYPE_MAX:
 *             return Constraint(max=_expr(par.max_expr, par.c_max))             # <<<<<<<<<<<<<<
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:
 *             return Constraint(min=_expr(par.min_expr, par.c_min),
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_Constraint); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_par->max_expr, __pyx_v_par->c_max, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_max, __pyx_t_1) < 0) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":813
 *         if par.c_type == clib.CONSTR_TYPE_MIN:
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 *         if par.c_type == clib.CONSTR_TYPE_MAX:             # <<<<<<<<<<<<<<
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:
 */
    }

    /* "cpymad/libmadx.pyx":815
 *         if par.c_type == clib.CONSTR_TYPE_MAX:
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:             # <<<<<<<<<<<<<<
 *             return Constraint(min=_expr(par.min_expr, par.c_min),
 *                               max=_expr(par.max_expr, par.c_max))
 */
    __pyx_t_3 = ((__pyx_v_par->c_type == __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_BOTH) != 0);
    if (__pyx_t_3) {

      /* "cpymad/libmadx.pyx":816
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:
 *             return Constraint(min=_expr(par.min_expr, par.c_min),             # <<<<<<<<<<<<<<
 *                               max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_VALUE:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Constraint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 816, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 816, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_par->min_expr, __pyx_v_par->c_min, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 816, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_min, __pyx_t_5) < 0) __PYX_ERR(0, 816, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "cpymad/libmadx.pyx":817
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:
 *             return Constraint(min=_expr(par.min_expr, par.c_min),
 *                               max=_expr(par.max_expr, par.c_max))             # <<<<<<<<<<<<<<
 *         if par.c_type == clib.CONSTR_TYPE_VALUE:
 *             return Constraint(val=_expr(par.expr, par.double_value))
 */
      __pyx_t_5 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_par->max_expr, __pyx_v_par->c_max, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 817, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_max, __pyx_t_5) < 0) __PYX_ERR(0, 816, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "cpymad/libmadx.pyx":816
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:
 *             return Constraint(min=_expr(par.min_expr, par.c_min),             # <<<<<<<<<<<<<<
 *                               max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_VALUE:
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 816, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":815
 *         if par.c_type == clib.CONSTR_TYPE_MAX:
 *             return Constraint(max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_BOTH:             # <<<<<<<<<<<<<<
 *             return Constraint(min=_expr(par.min_expr, par.c_min),
 *                               max=_expr(par.max_expr, par.c_max))
 */
    }

    /* "cpymad/libmadx.pyx":818
 *             return Constraint(min=_expr(par.min_expr, par.c_min),
 *                               max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_VALUE:             # <<<<<<<<<<<<<<
 *             return Constraint(val=_expr(par.expr, par.double_value))
 * 
 */
    __pyx_t_3 = ((__pyx_v_par->c_type == __pyx_e_6cpymad_8clibmadx_CONSTR_TYPE_VALUE) != 0);
    if (__pyx_t_3) {

      /* "cpymad/libmadx.pyx":819
 *                               max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_VALUE:
 *             return Constraint(val=_expr(par.expr, par.double_value))             # <<<<<<<<<<<<<<
 * 
 *     if par.type in (clib.PARAM_TYPE_INTEGER_ARRAY, clib.PARAM_TYPE_DOUBLE_ARRAY):
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_Constraint); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 819, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 819, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __pyx_f_6cpymad_7libmadx__expr(__pyx_v_par->expr, __pyx_v_par->double_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 819, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_val, __pyx_t_1) < 0) __PYX_ERR(0, 819, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 819, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":818
 *             return Constraint(min=_expr(par.min_expr, par.c_min),
 *                               max=_expr(par.max_expr, par.c_max))
 *         if par.c_type == clib.CONSTR_TYPE_VALUE:             # <<<<<<<<<<<<<<
 *             return Constraint(val=_expr(par.expr, par.double_value))
 * 
 */
    }

    /* "cpymad/libmadx.pyx":810
 *         return _str(par.string)
 * 
 *     if par.type == clib.PARAM_TYPE_CONSTRAINT:             # <<<<<<<<<<<<<<
 *         if par.c_type == clib.CONSTR_TYPE_MIN:
 *             return Constraint(min=_expr(par.min_expr, par.c_min))
 */
  }

  /* "cpymad/libmadx.pyx":821
 *             return Constraint(val=_expr(par.expr, par.double_value))
 * 
 *     if par.type in (clib.PARAM_TYPE_INTEGER_ARRAY, clib.PARAM_TYPE_DOUBLE_ARRAY):             # <<<<<<<<<<<<<<
 *         return [
 *             _expr(NULL if par.expr_list is NULL else par.expr_list.list[i],
 */
  switch (__pyx_v_par->type) {
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_INTEGER_ARRAY:
    case __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE_ARRAY:

    /* "cpymad/libmadx.pyx":822
 * 
 *     if par.type in (clib.PARAM_TYPE_INTEGER_ARRAY, clib.PARAM_TYPE_DOUBLE_ARRAY):
 *         return [             # <<<<<<<<<<<<<<
 *             _expr(NULL if par.expr_list is NULL else par.expr_list.list[i],
 *                   par.double_array.a[i],
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 822, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "cpymad/libmadx.pyx":826
 *                   par.double_array.a[i],
 *                   par.type - clib.PARAM_TYPE_LOGICAL_ARRAY)
 *             for i in xrange(par.double_array.curr)             # <<<<<<<<<<<<<<
 *         ]
 * 
 */
    __pyx_t_6 = __pyx_v_par->double_array->curr;
    for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
      __pyx_v_i = __pyx_t_7;

      /* "cpymad/libmadx.pyx":823
 *     if par.type in (clib.PARAM_TYPE_INTEGER_ARRAY, clib.PARAM_TYPE_DOUBLE_ARRAY):
 *         return [
 *             _expr(NULL if par.expr_list is NULL else par.expr_list.list[i],             # <<<<<<<<<<<<<<
 *                   par.double_array.a[i],
 *                   par.type - clib.PARAM_TYPE_LOGICAL_ARRAY)
 */
      if (((__pyx_v_par->expr_list == NULL) != 0)) {
        __pyx_t_8 = NULL;
      } else {
        __pyx_t_8 = (__pyx_v_par->expr_list->list[__pyx_v_i]);
      }

      /* "cpymad/libmadx.pyx":825
 *             _expr(NULL if par.expr_list is NULL else par.expr_list.list[i],
 *                   par.double_array.a[i],
 *                   par.type - clib.PARAM_TYPE_LOGICAL_ARRAY)             # <<<<<<<<<<<<<<
 *             for i in xrange(par.double_array.curr)
 *         ]
 */
      __pyx_t_2.__pyx_n = 1;
      __pyx_t_2.typeid = (__pyx_v_par->type - __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_LOGICAL_ARRAY);
      __pyx_t_4 = __pyx_f_6cpymad_7libmadx__expr(__pyx_t_8, (__pyx_v_par->double_array->a[__pyx_v_i]), &__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 823, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 822, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":821
 *             return Constraint(val=_expr(par.expr, par.double_value))
 * 
 *     if par.type in (clib.PARAM_TYPE_INTEGER_ARRAY, clib.PARAM_TYPE_DOUBLE_ARRAY):             # <<<<<<<<<<<<<<
 *         return [
 *             _expr(NULL if par.expr_list is NULL else par.expr_list.list[i],
 */
    break;
    default: break;
  }

  /* "cpymad/libmadx.pyx":829
 *         ]
 * 
 *     if par.type == clib.PARAM_TYPE_STRING_ARRAY:             # <<<<<<<<<<<<<<
 *         return [_str(par.m_string.p[i])
 *                 for i in xrange(par.m_string.curr)]
 */
  __pyx_t_3 = ((__pyx_v_par->type == __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_STRING_ARRAY) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":830
 * 
 *     if par.type == clib.PARAM_TYPE_STRING_ARRAY:
 *         return [_str(par.m_string.p[i])             # <<<<<<<<<<<<<<
 *                 for i in xrange(par.m_string.curr)]
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "cpymad/libmadx.pyx":831
 *     if par.type == clib.PARAM_TYPE_STRING_ARRAY:
 *         return [_str(par.m_string.p[i])
 *                 for i in xrange(par.m_string.curr)]             # <<<<<<<<<<<<<<
 * 
 *     raise ValueError("Unknown parameter type: {}".format(par.type))
 */
    __pyx_t_6 = __pyx_v_par->m_string->curr;
    for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
      __pyx_v_i = __pyx_t_7;

      /* "cpymad/libmadx.pyx":830
 * 
 *     if par.type == clib.PARAM_TYPE_STRING_ARRAY:
 *         return [_str(par.m_string.p[i])             # <<<<<<<<<<<<<<
 *                 for i in xrange(par.m_string.curr)]
 * 
 */
      __pyx_t_4 = __pyx_f_6cpymad_7libmadx__str((__pyx_v_par->m_string->p[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 830, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 830, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":829
 *         ]
 * 
 *     if par.type == clib.PARAM_TYPE_STRING_ARRAY:             # <<<<<<<<<<<<<<
 *         return [_str(par.m_string.p[i])
 *                 for i in xrange(par.m_string.curr)]
 */
  }

  /* "cpymad/libmadx.pyx":833
 *                 for i in xrange(par.m_string.curr)]
 * 
 *     raise ValueError("Unknown parameter type: {}".format(par.type))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_parameter_type, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 833, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_par->type); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 833, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_9 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 833, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 833, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 833, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 833, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 833, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 833, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":792
 * 
 * 
 * cdef _get_param_value(clib.command_parameter* par):             # <<<<<<<<<<<<<<
 * 
 *     """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("cpymad.libmadx._get_param_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":836
 * 
 * 
 * cdef _parse_command(clib.command* cmd):             # <<<<<<<<<<<<<<
 *     """
 *     Get the values of all parameters of a command.
 */

static PyObject *__pyx_f_6cpymad_7libmadx__parse_command(struct command *__pyx_v_cmd) {
  PyObject *__pyx_v_res = NULL;
  int __pyx_v_i;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("_parse_command", 0);

  /* "cpymad/libmadx.pyx":845
 *     # generator expressions are not yet supported in cdef functions, so
 *     # let's do it the hard way:
 *     res = {}             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i in xrange(cmd.par.curr):
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 845, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_res = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":847
 *     res = {}
 *     cdef int i
 *     for i in xrange(cmd.par.curr):             # <<<<<<<<<<<<<<
 *         # enforce lower-case keys:
 *         name = _str(cmd.par.parameters[i].name).lower()
 */
  __pyx_t_2 = __pyx_v_cmd->par->curr;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "cpymad/libmadx.pyx":849
 *     for i in xrange(cmd.par.curr):
 *         # enforce lower-case keys:
 *         name = _str(cmd.par.parameters[i].name).lower()             # <<<<<<<<<<<<<<
 *         res[name] = _get_param_value(cmd.par.parameters[i])
 *     return res
 */
    __pyx_t_4 = __pyx_f_6cpymad_7libmadx__str((__pyx_v_cmd->par->parameters[__pyx_v_i])->name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_lower); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (__pyx_t_4) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "cpymad/libmadx.pyx":850
 *         # enforce lower-case keys:
 *         name = _str(cmd.par.parameters[i].name).lower()
 *         res[name] = _get_param_value(cmd.par.parameters[i])             # <<<<<<<<<<<<<<
 *     return res
 * 
 */
    __pyx_t_1 = __pyx_f_6cpymad_7libmadx__get_param_value((__pyx_v_cmd->par->parameters[__pyx_v_i])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(PyDict_SetItem(__pyx_v_res, __pyx_v_name, __pyx_t_1) < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "cpymad/libmadx.pyx":851
 *         name = _str(cmd.par.parameters[i].name).lower()
 *         res[name] = _get_param_value(cmd.par.parameters[i])
 *     return res             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_res);
  __pyx_r = __pyx_v_res;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":836
 * 
 * 
 * cdef _parse_command(clib.command* cmd):             # <<<<<<<<<<<<<<
 *     """
 *     Get the values of all parameters of a command.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cpymad.libmadx._parse_command", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_res);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":857
 * # functions with C return values, see:
 * # http://docs.cython.org/src/userguide/language_basics.html#error-return-values
 * cdef clib.sequence* _find_sequence(sequence_name) except NULL:             # <<<<<<<<<<<<<<
 *     """
 *     Get pointer to the C sequence struct of the specified sequence or NULL.
 */

static struct sequence *__pyx_f_6cpymad_7libmadx__find_sequence(PyObject *__pyx_v_sequence_name) {
  PyObject *__pyx_v__sequence_name = 0;
  struct sequence_list *__pyx_v_seqs;
  int __pyx_v_index;
  struct sequence *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("_find_sequence", 0);

  /* "cpymad/libmadx.pyx":864
 *     :raises ValueError: if the sequence can not be found
 *     """
 *     cdef bytes _sequence_name = _cstr(sequence_name)             # <<<<<<<<<<<<<<
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()
 *     cdef int index = clib.name_list_pos(_sequence_name, seqs.list)
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_sequence_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 864, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__sequence_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":865
 *     """
 *     cdef bytes _sequence_name = _cstr(sequence_name)
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()             # <<<<<<<<<<<<<<
 *     cdef int index = clib.name_list_pos(_sequence_name, seqs.list)
 *     if index == -1:
 */
  __pyx_v_seqs = madextern_get_sequence_list();

  /* "cpymad/libmadx.pyx":866
 *     cdef bytes _sequence_name = _cstr(sequence_name)
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()
 *     cdef int index = clib.name_list_pos(_sequence_name, seqs.list)             # <<<<<<<<<<<<<<
 *     if index == -1:
 *         raise ValueError("Invalid sequence: {}".format(sequence_name))
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__sequence_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 866, __pyx_L1_error)
  __pyx_v_index = name_list_pos(__pyx_t_2, __pyx_v_seqs->list);

  /* "cpymad/libmadx.pyx":867
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()
 *     cdef int index = clib.name_list_pos(_sequence_name, seqs.list)
 *     if index == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid sequence: {}".format(sequence_name))
 *     return seqs.sequs[index]
 */
  __pyx_t_3 = ((__pyx_v_index == -1L) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":868
 *     cdef int index = clib.name_list_pos(_sequence_name, seqs.list)
 *     if index == -1:
 *         raise ValueError("Invalid sequence: {}".format(sequence_name))             # <<<<<<<<<<<<<<
 *     return seqs.sequs[index]
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_sequence, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 868, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_sequence_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 868, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 868, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_sequence_name);
      __Pyx_GIVEREF(__pyx_v_sequence_name);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_sequence_name);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 868, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 868, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 868, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 868, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":867
 *     cdef clib.sequence_list* seqs = clib.madextern_get_sequence_list()
 *     cdef int index = clib.name_list_pos(_sequence_name, seqs.list)
 *     if index == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid sequence: {}".format(sequence_name))
 *     return seqs.sequs[index]
 */
  }

  /* "cpymad/libmadx.pyx":869
 *     if index == -1:
 *         raise ValueError("Invalid sequence: {}".format(sequence_name))
 *     return seqs.sequs[index]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = (__pyx_v_seqs->sequs[__pyx_v_index]);
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":857
 * # functions with C return values, see:
 * # http://docs.cython.org/src/userguide/language_basics.html#error-return-values
 * cdef clib.sequence* _find_sequence(sequence_name) except NULL:             # <<<<<<<<<<<<<<
 *     """
 *     Get pointer to the C sequence struct of the specified sequence or NULL.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("cpymad.libmadx._find_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__sequence_name);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":872
 * 
 * 
 * cdef clib.table* _find_table(table_name) except NULL:             # <<<<<<<<<<<<<<
 *     cdef bytes _table_name = _cstr(table_name)
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)
 */

static struct table *__pyx_f_6cpymad_7libmadx__find_table(PyObject *__pyx_v_table_name) {
  PyObject *__pyx_v__table_name = 0;
  int __pyx_v_index;
  struct table *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("_find_table", 0);

  /* "cpymad/libmadx.pyx":873
 * 
 * cdef clib.table* _find_table(table_name) except NULL:
 *     cdef bytes _table_name = _cstr(table_name)             # <<<<<<<<<<<<<<
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)
 *     if index == -1:
 */
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__table_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":874
 * cdef clib.table* _find_table(table_name) except NULL:
 *     cdef bytes _table_name = _cstr(table_name)
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)             # <<<<<<<<<<<<<<
 *     if index == -1:
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v__table_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 874, __pyx_L1_error)
  __pyx_v_index = name_list_pos(__pyx_t_2, table_register->names);

  /* "cpymad/libmadx.pyx":875
 *     cdef bytes _table_name = _cstr(table_name)
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)
 *     if index == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     return clib.table_register.tables[index]
 */
  __pyx_t_3 = ((__pyx_v_index == -1L) != 0);
  if (__pyx_t_3) {

    /* "cpymad/libmadx.pyx":876
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)
 *     if index == -1:
 *         raise ValueError("Invalid table: {!r}".format(table_name))             # <<<<<<<<<<<<<<
 *     return clib.table_register.tables[index]
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_table_r, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_table_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 876, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 876, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_table_name);
      __Pyx_GIVEREF(__pyx_v_table_name);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_table_name);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 876, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 876, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":875
 *     cdef bytes _table_name = _cstr(table_name)
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)
 *     if index == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     return clib.table_register.tables[index]
 */
  }

  /* "cpymad/libmadx.pyx":877
 *     if index == -1:
 *         raise ValueError("Invalid table: {!r}".format(table_name))
 *     return clib.table_register.tables[index]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = (table_register->tables[__pyx_v_index]);
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":872
 * 
 * 
 * cdef clib.table* _find_table(table_name) except NULL:             # <<<<<<<<<<<<<<
 *     cdef bytes _table_name = _cstr(table_name)
 *     cdef int index = clib.name_list_pos(_table_name, clib.table_register.names)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("cpymad.libmadx._find_table", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__table_name);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":880
 * 
 * 
 * cdef int _get_node_index(clib.node** all_nodes, int n_nodes, clib.node* find):             # <<<<<<<<<<<<<<
 *     cdef int i = 0
 *     for i in range(n_nodes):
 */

static int __pyx_f_6cpymad_7libmadx__get_node_index(struct node **__pyx_v_all_nodes, int __pyx_v_n_nodes, struct node *__pyx_v_find) {
  int __pyx_v_i;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("_get_node_index", 0);

  /* "cpymad/libmadx.pyx":881
 * 
 * cdef int _get_node_index(clib.node** all_nodes, int n_nodes, clib.node* find):
 *     cdef int i = 0             # <<<<<<<<<<<<<<
 *     for i in range(n_nodes):
 *         if all_nodes[i] == find:
 */
  __pyx_v_i = 0;

  /* "cpymad/libmadx.pyx":882
 * cdef int _get_node_index(clib.node** all_nodes, int n_nodes, clib.node* find):
 *     cdef int i = 0
 *     for i in range(n_nodes):             # <<<<<<<<<<<<<<
 *         if all_nodes[i] == find:
 *             return i
 */
  __pyx_t_1 = __pyx_v_n_nodes;
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_i = __pyx_t_2;

    /* "cpymad/libmadx.pyx":883
 *     cdef int i = 0
 *     for i in range(n_nodes):
 *         if all_nodes[i] == find:             # <<<<<<<<<<<<<<
 *             return i
 *     raise ValueError("Invalid node!")
 */
    __pyx_t_3 = (((__pyx_v_all_nodes[__pyx_v_i]) == __pyx_v_find) != 0);
    if (__pyx_t_3) {

      /* "cpymad/libmadx.pyx":884
 *     for i in range(n_nodes):
 *         if all_nodes[i] == find:
 *             return i             # <<<<<<<<<<<<<<
 *     raise ValueError("Invalid node!")
 * 
 */
      __pyx_r = __pyx_v_i;
      goto __pyx_L0;

      /* "cpymad/libmadx.pyx":883
 *     cdef int i = 0
 *     for i in range(n_nodes):
 *         if all_nodes[i] == find:             # <<<<<<<<<<<<<<
 *             return i
 *     raise ValueError("Invalid node!")
 */
    }
  }

  /* "cpymad/libmadx.pyx":885
 *         if all_nodes[i] == find:
 *             return i
 *     raise ValueError("Invalid node!")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 885, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_Raise(__pyx_t_4, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __PYX_ERR(0, 885, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":880
 * 
 * 
 * cdef int _get_node_index(clib.node** all_nodes, int n_nodes, clib.node* find):             # <<<<<<<<<<<<<<
 *     cdef int i = 0
 *     for i in range(n_nodes):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("cpymad.libmadx._get_node_index", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":888
 * 
 * 
 * cdef _split_header_line(header_line):             # <<<<<<<<<<<<<<
 *     """Parse a table header value."""
 *     _, key, kind, value = _str(header_line).split(None, 3)
 */

static PyObject *__pyx_f_6cpymad_7libmadx__split_header_line(PyObject *__pyx_v_header_line) {
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_kind = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  char const *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  __Pyx_RefNannySetupContext("_split_header_line", 0);

  /* "cpymad/libmadx.pyx":890
 * cdef _split_header_line(header_line):
 *     """Parse a table header value."""
 *     _, key, kind, value = _str(header_line).split(None, 3)             # <<<<<<<<<<<<<<
 *     key = key.lower()
 *     if kind == "%le":
 */
  __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_header_line); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 890, __pyx_L1_error)
  __pyx_t_2 = __pyx_f_6cpymad_7libmadx__str(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 890, __pyx_L1_error)
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_6);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_3,&__pyx_t_4,&__pyx_t_5,&__pyx_t_6};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 890, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_3,&__pyx_t_4,&__pyx_t_5,&__pyx_t_6};
    __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 890, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_8(__pyx_t_7); if (unlikely(!item)) goto __pyx_L3_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 4) < 0) __PYX_ERR(0, 890, __pyx_L1_error)
    __pyx_t_8 = NULL;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 890, __pyx_L1_error)
    __pyx_L4_unpacking_done:;
  }
  __pyx_v__ = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_key = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_kind = __pyx_t_5;
  __pyx_t_5 = 0;
  __pyx_v_value = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "cpymad/libmadx.pyx":891
 *     """Parse a table header value."""
 *     _, key, kind, value = _str(header_line).split(None, 3)
 *     key = key.lower()             # <<<<<<<<<<<<<<
 *     if kind == "%le":
 *         return key, float(value)    # convert to number
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_lower); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 891, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 891, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 891, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":892
 *     _, key, kind, value = _str(header_line).split(None, 3)
 *     key = key.lower()
 *     if kind == "%le":             # <<<<<<<<<<<<<<
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):
 */
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_kind, __pyx_kp_s_le, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 892, __pyx_L1_error)
  if (__pyx_t_9) {

    /* "cpymad/libmadx.pyx":893
 *     key = key.lower()
 *     if kind == "%le":
 *         return key, float(value)    # convert to number             # <<<<<<<<<<<<<<
 *     elif kind.endswith('s'):
 *         return key, value[1:-1]     # strip quotes from string
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 893, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 893, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":892
 *     _, key, kind, value = _str(header_line).split(None, 3)
 *     key = key.lower()
 *     if kind == "%le":             # <<<<<<<<<<<<<<
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):
 */
  }

  /* "cpymad/libmadx.pyx":894
 *     if kind == "%le":
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):             # <<<<<<<<<<<<<<
 *         return key, value[1:-1]     # strip quotes from string
 *     else:
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_kind, __pyx_n_s_endswith); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_9) {

    /* "cpymad/libmadx.pyx":895
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):
 *         return key, value[1:-1]     # strip quotes from string             # <<<<<<<<<<<<<<
 *     else:
 *         return key, value           #
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_value, 1, -1L, NULL, NULL, &__pyx_slice__9, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":894
 *     if kind == "%le":
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):             # <<<<<<<<<<<<<<
 *         return key, value[1:-1]     # strip quotes from string
 *     else:
 */
  }

  /* "cpymad/libmadx.pyx":897
 *         return key, value[1:-1]     # strip quotes from string
 *     else:
 *         return key, value           #             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 897, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_value);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }

  /* "cpymad/libmadx.pyx":888
 * 
 * 
 * cdef _split_header_line(header_line):             # <<<<<<<<<<<<<<
 *     """Parse a table header value."""
 *     _, key, kind, value = _str(header_line).split(None, 3)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("cpymad.libmadx._split_header_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_kind);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":900
 * 
 * 
 * cdef _name_list(clib.name_list* names):             # <<<<<<<<<<<<<<
 *     """Return a python list of names for the name_list."""
 *     cdef int i
 */

static PyObject *__pyx_f_6cpymad_7libmadx__name_list(struct name_list *__pyx_v_names) {
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("_name_list", 0);

  /* "cpymad/libmadx.pyx":903
 *     """Return a python list of names for the name_list."""
 *     cdef int i
 *     return [names.names[i] for i in xrange(names.curr)]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_names->curr;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;
    __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_names->names[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":900
 * 
 * 
 * cdef _name_list(clib.name_list* names):             # <<<<<<<<<<<<<<
 *     """Return a python list of names for the name_list."""
 *     cdef int i
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpymad.libmadx._name_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":906
 * 
 * 
 * cdef _str(const char* s):             # <<<<<<<<<<<<<<
 *     """Decode C string to python string."""
 *     if s is NULL:
 */

static PyObject *__pyx_f_6cpymad_7libmadx__str(char const *__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("_str", 0);

  /* "cpymad/libmadx.pyx":908
 * cdef _str(const char* s):
 *     """Decode C string to python string."""
 *     if s is NULL:             # <<<<<<<<<<<<<<
 *         # Returning an empty string will make the type of the parameter
 *         # transparent to the inspecting code:
 */
  __pyx_t_1 = ((__pyx_v_s == NULL) != 0);
  if (__pyx_t_1) {

    /* "cpymad/libmadx.pyx":911
 *         # Returning an empty string will make the type of the parameter
 *         # transparent to the inspecting code:
 *         return ""             # <<<<<<<<<<<<<<
 *     return s.decode('utf-8')
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_s__10);
    __pyx_r = __pyx_kp_s__10;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":908
 * cdef _str(const char* s):
 *     """Decode C string to python string."""
 *     if s is NULL:             # <<<<<<<<<<<<<<
 *         # Returning an empty string will make the type of the parameter
 *         # transparent to the inspecting code:
 */
  }

  /* "cpymad/libmadx.pyx":912
 *         # transparent to the inspecting code:
 *         return ""
 *     return s.decode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_s, 0, strlen(__pyx_v_s), NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":906
 * 
 * 
 * cdef _str(const char* s):             # <<<<<<<<<<<<<<
 *     """Decode C string to python string."""
 *     if s is NULL:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpymad.libmadx._str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":915
 * 
 * 
 * cdef bytes _cstr(s):             # <<<<<<<<<<<<<<
 *     """Encode python string to C string."""
 *     if s is None:
 */

static PyObject *__pyx_f_6cpymad_7libmadx__cstr(PyObject *__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("_cstr", 0);

  /* "cpymad/libmadx.pyx":917
 * cdef bytes _cstr(s):
 *     """Encode python string to C string."""
 *     if s is None:             # <<<<<<<<<<<<<<
 *         return b""
 *     return <bytes> s.encode('utf-8')
 */
  __pyx_t_1 = (__pyx_v_s == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "cpymad/libmadx.pyx":918
 *     """Encode python string to C string."""
 *     if s is None:
 *         return b""             # <<<<<<<<<<<<<<
 *     return <bytes> s.encode('utf-8')
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_b__10);
    __pyx_r = __pyx_kp_b__10;
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":917
 * cdef bytes _cstr(s):
 *     """Encode python string to C string."""
 *     if s is None:             # <<<<<<<<<<<<<<
 *         return b""
 *     return <bytes> s.encode('utf-8')
 */
  }

  /* "cpymad/libmadx.pyx":919
 *     if s is None:
 *         return b""
 *     return <bytes> s.encode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_INCREF(((PyObject*)__pyx_t_4));
  __pyx_r = ((PyObject*)__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":915
 * 
 * 
 * cdef bytes _cstr(s):             # <<<<<<<<<<<<<<
 *     """Encode python string to C string."""
 *     if s is None:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpymad.libmadx._cstr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":922
 * 
 * 
 * cdef _get_node(clib.node* node, int ref_flag):             # <<<<<<<<<<<<<<
 *     """Return dictionary with node + element attributes."""
 *     if node.p_elem is NULL:
 */

static PyObject *__pyx_f_6cpymad_7libmadx__get_node(struct node *__pyx_v_node, int __pyx_v_ref_flag) {
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("_get_node", 0);

  /* "cpymad/libmadx.pyx":924
 * cdef _get_node(clib.node* node, int ref_flag):
 *     """Return dictionary with node + element attributes."""
 *     if node.p_elem is NULL:             # <<<<<<<<<<<<<<
 *         # Maybe this is a valid case, but better detect it with boom!
 *         raise RuntimeError("Empty node or subsequence! Please report this incident!")
 */
  __pyx_t_1 = ((__pyx_v_node->p_elem == NULL) != 0);
  if (__pyx_t_1) {

    /* "cpymad/libmadx.pyx":926
 *     if node.p_elem is NULL:
 *         # Maybe this is a valid case, but better detect it with boom!
 *         raise RuntimeError("Empty node or subsequence! Please report this incident!")             # <<<<<<<<<<<<<<
 *     data = _get_element(node.p_elem)
 *     data.update({'name': name_from_internal(_str(node.name)),
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 926, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 926, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":924
 * cdef _get_node(clib.node* node, int ref_flag):
 *     """Return dictionary with node + element attributes."""
 *     if node.p_elem is NULL:             # <<<<<<<<<<<<<<
 *         # Maybe this is a valid case, but better detect it with boom!
 *         raise RuntimeError("Empty node or subsequence! Please report this incident!")
 */
  }

  /* "cpymad/libmadx.pyx":927
 *         # Maybe this is a valid case, but better detect it with boom!
 *         raise RuntimeError("Empty node or subsequence! Please report this incident!")
 *     data = _get_element(node.p_elem)             # <<<<<<<<<<<<<<
 *     data.update({'name': name_from_internal(_str(node.name)),
 *                  'type': _str(node.base_name),
 */
  __pyx_t_2 = __pyx_f_6cpymad_7libmadx__get_element(__pyx_v_node->p_elem); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 927, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_data = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":928
 *         raise RuntimeError("Empty node or subsequence! Please report this incident!")
 *     data = _get_element(node.p_elem)
 *     data.update({'name': name_from_internal(_str(node.name)),             # <<<<<<<<<<<<<<
 *                  'type': _str(node.base_name),
 *                  'at': _get_node_entry_pos(node, ref_flag)})
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s_update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_name_from_internal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __pyx_f_6cpymad_7libmadx__str(__pyx_v_node->name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (!__pyx_t_8) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_name, __pyx_t_5) < 0) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "cpymad/libmadx.pyx":929
 *     data = _get_element(node.p_elem)
 *     data.update({'name': name_from_internal(_str(node.name)),
 *                  'type': _str(node.base_name),             # <<<<<<<<<<<<<<
 *                  'at': _get_node_entry_pos(node, ref_flag)})
 *     return data
 */
  __pyx_t_5 = __pyx_f_6cpymad_7libmadx__str(__pyx_v_node->base_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 929, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_type, __pyx_t_5) < 0) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "cpymad/libmadx.pyx":930
 *     data.update({'name': name_from_internal(_str(node.name)),
 *                  'type': _str(node.base_name),
 *                  'at': _get_node_entry_pos(node, ref_flag)})             # <<<<<<<<<<<<<<
 *     return data
 * 
 */
  __pyx_t_5 = PyFloat_FromDouble(__pyx_f_6cpymad_7libmadx__get_node_entry_pos(__pyx_v_node, __pyx_v_ref_flag)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_at, __pyx_t_5) < 0) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":931
 *                  'type': _str(node.base_name),
 *                  'at': _get_node_entry_pos(node, ref_flag)})
 *     return data             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_data);
  __pyx_r = __pyx_v_data;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":922
 * 
 * 
 * cdef _get_node(clib.node* node, int ref_flag):             # <<<<<<<<<<<<<<
 *     """Return dictionary with node + element attributes."""
 *     if node.p_elem is NULL:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cpymad.libmadx._get_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":934
 * 
 * 
 * cdef double _get_node_entry_pos(clib.node* node, int ref_flag):             # <<<<<<<<<<<<<<
 *     """Normalize 'at' value to node entry."""
 *     if ref_flag == clib.REF_CENTER:
 */

static double __pyx_f_6cpymad_7libmadx__get_node_entry_pos(struct node *__pyx_v_node, int __pyx_v_ref_flag) {
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_node_entry_pos", 0);

  /* "cpymad/libmadx.pyx":936
 * cdef double _get_node_entry_pos(clib.node* node, int ref_flag):
 *     """Normalize 'at' value to node entry."""
 *     if ref_flag == clib.REF_CENTER:             # <<<<<<<<<<<<<<
 *         return node.at_value - node.length / 2
 *     elif ref_flag == clib.REF_EXIT:
 */
  switch (__pyx_v_ref_flag) {
    case __pyx_e_6cpymad_8clibmadx_REF_CENTER:

    /* "cpymad/libmadx.pyx":937
 *     """Normalize 'at' value to node entry."""
 *     if ref_flag == clib.REF_CENTER:
 *         return node.at_value - node.length / 2             # <<<<<<<<<<<<<<
 *     elif ref_flag == clib.REF_EXIT:
 *         return node.at_value - node.length
 */
    __pyx_r = (__pyx_v_node->at_value - (__pyx_v_node->length / 2.0));
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":936
 * cdef double _get_node_entry_pos(clib.node* node, int ref_flag):
 *     """Normalize 'at' value to node entry."""
 *     if ref_flag == clib.REF_CENTER:             # <<<<<<<<<<<<<<
 *         return node.at_value - node.length / 2
 *     elif ref_flag == clib.REF_EXIT:
 */
    break;

    /* "cpymad/libmadx.pyx":938
 *     if ref_flag == clib.REF_CENTER:
 *         return node.at_value - node.length / 2
 *     elif ref_flag == clib.REF_EXIT:             # <<<<<<<<<<<<<<
 *         return node.at_value - node.length
 *     else:
 */
    case __pyx_e_6cpymad_8clibmadx_REF_EXIT:

    /* "cpymad/libmadx.pyx":939
 *         return node.at_value - node.length / 2
 *     elif ref_flag == clib.REF_EXIT:
 *         return node.at_value - node.length             # <<<<<<<<<<<<<<
 *     else:
 *         return node.at_value
 */
    __pyx_r = (__pyx_v_node->at_value - __pyx_v_node->length);
    goto __pyx_L0;

    /* "cpymad/libmadx.pyx":938
 *     if ref_flag == clib.REF_CENTER:
 *         return node.at_value - node.length / 2
 *     elif ref_flag == clib.REF_EXIT:             # <<<<<<<<<<<<<<
 *         return node.at_value - node.length
 *     else:
 */
    break;
    default:

    /* "cpymad/libmadx.pyx":941
 *         return node.at_value - node.length
 *     else:
 *         return node.at_value             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_r = __pyx_v_node->at_value;
    goto __pyx_L0;
    break;
  }

  /* "cpymad/libmadx.pyx":934
 * 
 * 
 * cdef double _get_node_entry_pos(clib.node* node, int ref_flag):             # <<<<<<<<<<<<<<
 *     """Normalize 'at' value to node entry."""
 *     if ref_flag == clib.REF_CENTER:
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":944
 * 
 * 
 * cdef _get_element(clib.element* elem):             # <<<<<<<<<<<<<<
 *     """Return dictionary with element attributes."""
 *     return _parse_command(elem.def_)
 */

static PyObject *__pyx_f_6cpymad_7libmadx__get_element(struct element *__pyx_v_elem) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("_get_element", 0);

  /* "cpymad/libmadx.pyx":946
 * cdef _get_element(clib.element* elem):
 *     """Return dictionary with element attributes."""
 *     return _parse_command(elem.def_)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_6cpymad_7libmadx__parse_command(__pyx_v_elem->def); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 946, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":944
 * 
 * 
 * cdef _get_element(clib.element* elem):             # <<<<<<<<<<<<<<
 *     """Return dictionary with element attributes."""
 *     return _parse_command(elem.def_)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpymad.libmadx._get_element", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":949
 * 
 * 
 * cdef _get_table_row_name(clib.table* table, int index):             # <<<<<<<<<<<<<<
 *     if index < 0 or index >= table.curr:
 *         raise ValueError("Invalid row index: {}".format(index))
 */

static PyObject *__pyx_f_6cpymad_7libmadx__get_table_row_name(struct table *__pyx_v_table, int __pyx_v_index) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("_get_table_row_name", 0);

  /* "cpymad/libmadx.pyx":950
 * 
 * cdef _get_table_row_name(clib.table* table, int index):
 *     if index < 0 or index >= table.curr:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid row index: {}".format(index))
 *     return normalize_range_name(name_from_internal(_str(
 */
  __pyx_t_2 = ((__pyx_v_index < 0) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_index >= __pyx_v_table->curr) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "cpymad/libmadx.pyx":951
 * cdef _get_table_row_name(clib.table* table, int index):
 *     if index < 0 or index >= table.curr:
 *         raise ValueError("Invalid row index: {}".format(index))             # <<<<<<<<<<<<<<
 *     return normalize_range_name(name_from_internal(_str(
 *         table.node_nm.p[index]
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_row_index, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 951, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 951, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 951, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 951, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":950
 * 
 * cdef _get_table_row_name(clib.table* table, int index):
 *     if index < 0 or index >= table.curr:             # <<<<<<<<<<<<<<
 *         raise ValueError("Invalid row index: {}".format(index))
 *     return normalize_range_name(name_from_internal(_str(
 */
  }

  /* "cpymad/libmadx.pyx":952
 *     if index < 0 or index >= table.curr:
 *         raise ValueError("Invalid row index: {}".format(index))
 *     return normalize_range_name(name_from_internal(_str(             # <<<<<<<<<<<<<<
 *         table.node_nm.p[index]
 *     )))
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_normalize_range_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_name_from_internal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "cpymad/libmadx.pyx":953
 *         raise ValueError("Invalid row index: {}".format(index))
 *     return normalize_range_name(name_from_internal(_str(
 *         table.node_nm.p[index]             # <<<<<<<<<<<<<<
 *     )))
 * 
 */
  __pyx_t_6 = __pyx_f_6cpymad_7libmadx__str((__pyx_v_table->node_nm->p[__pyx_v_index])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_8) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_7);
  } else {
    __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":949
 * 
 * 
 * cdef _get_table_row_name(clib.table* table, int index):             # <<<<<<<<<<<<<<
 *     if index < 0 or index >= table.curr:
 *         raise ValueError("Invalid row index: {}".format(index))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cpymad.libmadx._get_table_row_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpymad/libmadx.pyx":957
 * 
 * 
 * cdef clib.variable* _get_var(name) except NULL:             # <<<<<<<<<<<<<<
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)
 */

static struct variable *__pyx_f_6cpymad_7libmadx__get_var(PyObject *__pyx_v_name) {
  PyObject *__pyx_v__name = 0;
  struct variable *__pyx_v_var;
  struct variable *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("_get_var", 0);

  /* "cpymad/libmadx.pyx":958
 * 
 * cdef clib.variable* _get_var(name) except NULL:
 *     cdef bytes _name = _cstr(name.lower())             # <<<<<<<<<<<<<<
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)
 *     if var is NULL:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_name, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 958, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 958, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 958, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_f_6cpymad_7libmadx__cstr(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 958, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v__name = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":959
 * cdef clib.variable* _get_var(name) except NULL:
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)             # <<<<<<<<<<<<<<
 *     if var is NULL:
 *         raise KeyError("Variable not defined: {!r}".format(name))
 */
  __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v__name); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 959, __pyx_L1_error)
  __pyx_v_var = find_variable(__pyx_t_4, variable_list);

  /* "cpymad/libmadx.pyx":960
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)
 *     if var is NULL:             # <<<<<<<<<<<<<<
 *         raise KeyError("Variable not defined: {!r}".format(name))
 *     return var
 */
  __pyx_t_5 = ((__pyx_v_var == NULL) != 0);
  if (__pyx_t_5) {

    /* "cpymad/libmadx.pyx":961
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)
 *     if var is NULL:
 *         raise KeyError("Variable not defined: {!r}".format(name))             # <<<<<<<<<<<<<<
 *     return var
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Variable_not_defined_r, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 961, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_name);
      __Pyx_GIVEREF(__pyx_v_name);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_name);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 961, __pyx_L1_error)

    /* "cpymad/libmadx.pyx":960
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)
 *     if var is NULL:             # <<<<<<<<<<<<<<
 *         raise KeyError("Variable not defined: {!r}".format(name))
 *     return var
 */
  }

  /* "cpymad/libmadx.pyx":962
 *     if var is NULL:
 *         raise KeyError("Variable not defined: {!r}".format(name))
 *     return var             # <<<<<<<<<<<<<<
 */
  __pyx_r = __pyx_v_var;
  goto __pyx_L0;

  /* "cpymad/libmadx.pyx":957
 * 
 * 
 * cdef clib.variable* _get_var(name) except NULL:             # <<<<<<<<<<<<<<
 *     cdef bytes _name = _cstr(name.lower())
 *     cdef clib.variable* var = clib.find_variable(_name, clib.variable_list)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("cpymad.libmadx._get_var", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__name);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "libmadx",
    __pyx_k_Low_level_cython_binding_to_MAD, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 1, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_kp_s_Column_r_is_not_in_table_r, __pyx_k_Column_r_is_not_in_table_r, sizeof(__pyx_k_Column_r_is_not_in_table_r), 0, 0, 1, 0},
  {&__pyx_n_s_Constraint, __pyx_k_Constraint, sizeof(__pyx_k_Constraint), 0, 0, 1, 1},
  {&__pyx_kp_s_Element_name_not_found_0, __pyx_k_Element_name_not_found_0, sizeof(__pyx_k_Element_name_not_found_0), 0, 0, 1, 0},
  {&__pyx_kp_s_Empty_node_or_subsequence_Please, __pyx_k_Empty_node_or_subsequence_Please, sizeof(__pyx_k_Empty_node_or_subsequence_Please), 0, 0, 1, 0},
  {&__pyx_n_s_Expression, __pyx_k_Expression, sizeof(__pyx_k_Expression), 0, 0, 1, 1},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_kp_s_Index_out_of_range_0_element_cou, __pyx_k_Index_out_of_range_0_element_cou, sizeof(__pyx_k_Index_out_of_range_0_element_cou), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_column_r, __pyx_k_Invalid_column_r, sizeof(__pyx_k_Invalid_column_r), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_node, __pyx_k_Invalid_node, sizeof(__pyx_k_Invalid_node), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_row_index, __pyx_k_Invalid_row_index, sizeof(__pyx_k_Invalid_row_index), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_sequence, __pyx_k_Invalid_sequence, sizeof(__pyx_k_Invalid_sequence), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_table_r, __pyx_k_Invalid_table_r, sizeof(__pyx_k_Invalid_table_r), 0, 0, 1, 0},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_kp_s_No_active_sequence, __pyx_k_No_active_sequence, sizeof(__pyx_k_No_active_sequence), 0, 0, 1, 0},
  {&__pyx_kp_s_No_beam_attached_to, __pyx_k_No_beam_attached_to, sizeof(__pyx_k_No_beam_attached_to), 0, 0, 1, 0},
  {&__pyx_kp_s_No_element_found_at_position_0, __pyx_k_No_element_found_at_position_0, sizeof(__pyx_k_No_element_found_at_position_0), 0, 0, 1, 0},
  {&__pyx_kp_s_No_summary_for_table_r, __pyx_k_No_summary_for_table_r, sizeof(__pyx_k_No_summary_for_table_r), 0, 0, 1, 0},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_b_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 0, 1},
  {&__pyx_kp_s_TWISS_table_invalid, __pyx_k_TWISS_table_invalid, sizeof(__pyx_k_TWISS_table_invalid), 0, 0, 1, 0},
  {&__pyx_kp_s_Unknown_column_format_r, __pyx_k_Unknown_column_format_r, sizeof(__pyx_k_Unknown_column_format_r), 0, 0, 1, 0},
  {&__pyx_kp_s_Unknown_datatype_r_in_column_r, __pyx_k_Unknown_datatype_r_in_column_r, sizeof(__pyx_k_Unknown_datatype_r_in_column_r), 0, 0, 1, 0},
  {&__pyx_kp_s_Unknown_parameter_type, __pyx_k_Unknown_parameter_type, sizeof(__pyx_k_Unknown_parameter_type), 0, 0, 1, 0},
  {&__pyx_n_b_V, __pyx_k_V, sizeof(__pyx_k_V), 0, 0, 0, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s_Variable_not_defined_r, __pyx_k_Variable_not_defined_r, sizeof(__pyx_k_Variable_not_defined_r), 0, 0, 1, 0},
  {&__pyx_kp_b__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 0, 0},
  {&__pyx_kp_s__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 1, 0},
  {&__pyx_n_s_addr, __pyx_k_addr, sizeof(__pyx_k_addr), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_array_data, __pyx_k_array_data, sizeof(__pyx_k_array_data), 0, 0, 1, 1},
  {&__pyx_n_s_array_type, __pyx_k_array_type, sizeof(__pyx_k_array_type), 0, 0, 1, 1},
  {&__pyx_n_s_as_array, __pyx_k_as_array, sizeof(__pyx_k_as_array), 0, 0, 1, 1},
  {&__pyx_n_s_at, __pyx_k_at, sizeof(__pyx_k_at), 0, 0, 1, 1},
  {&__pyx_n_s_c_double, __pyx_k_c_double, sizeof(__pyx_k_c_double), 0, 0, 1, 1},
  {&__pyx_n_s_char_tmp, __pyx_k_char_tmp, sizeof(__pyx_k_char_tmp), 0, 0, 1, 1},
  {&__pyx_n_s_chdir, __pyx_k_chdir, sizeof(__pyx_k_chdir), 0, 0, 1, 1},
  {&__pyx_n_s_cmd, __pyx_k_cmd, sizeof(__pyx_k_cmd), 0, 0, 1, 1},
  {&__pyx_n_s_cmd_2, __pyx_k_cmd_2, sizeof(__pyx_k_cmd_2), 0, 0, 1, 1},
  {&__pyx_n_s_col_i, __pyx_k_col_i, sizeof(__pyx_k_col_i), 0, 0, 1, 1},
  {&__pyx_n_s_col_name, __pyx_k_col_name, sizeof(__pyx_k_col_name), 0, 0, 1, 1},
  {&__pyx_n_s_column_name, __pyx_k_column_name, sizeof(__pyx_k_column_name), 0, 0, 1, 1},
  {&__pyx_n_s_cpymad_libmadx, __pyx_k_cpymad_libmadx, sizeof(__pyx_k_cpymad_libmadx), 0, 0, 1, 1},
  {&__pyx_n_s_cpymad_types, __pyx_k_cpymad_types, sizeof(__pyx_k_cpymad_types), 0, 0, 1, 1},
  {&__pyx_n_s_cpymad_util, __pyx_k_cpymad_util, sizeof(__pyx_k_cpymad_util), 0, 0, 1, 1},
  {&__pyx_n_s_ctypes, __pyx_k_ctypes, sizeof(__pyx_k_ctypes), 0, 0, 1, 1},
  {&__pyx_n_s_ctypeslib, __pyx_k_ctypeslib, sizeof(__pyx_k_ctypeslib), 0, 0, 1, 1},
  {&__pyx_n_b_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 0, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_elem, __pyx_k_elem, sizeof(__pyx_k_elem), 0, 0, 1, 1},
  {&__pyx_n_s_element_index, __pyx_k_element_index, sizeof(__pyx_k_element_index), 0, 0, 1, 1},
  {&__pyx_n_s_element_name, __pyx_k_element_name, sizeof(__pyx_k_element_name), 0, 0, 1, 1},
  {&__pyx_n_s_element_name_2, __pyx_k_element_name_2, sizeof(__pyx_k_element_name_2), 0, 0, 1, 1},
  {&__pyx_n_s_elems, __pyx_k_elems, sizeof(__pyx_k_elems), 0, 0, 1, 1},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_endswith, __pyx_k_endswith, sizeof(__pyx_k_endswith), 0, 0, 1, 1},
  {&__pyx_n_s_evaluate, __pyx_k_evaluate, sizeof(__pyx_k_evaluate), 0, 0, 1, 1},
  {&__pyx_n_s_expr, __pyx_k_expr, sizeof(__pyx_k_expr), 0, 0, 1, 1},
  {&__pyx_n_s_expr_types, __pyx_k_expr_types, sizeof(__pyx_k_expr_types), 0, 0, 1, 1},
  {&__pyx_n_s_expression, __pyx_k_expression, sizeof(__pyx_k_expression), 0, 0, 1, 1},
  {&__pyx_n_s_finish, __pyx_k_finish, sizeof(__pyx_k_finish), 0, 0, 1, 1},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_from_address, __pyx_k_from_address, sizeof(__pyx_k_from_address), 0, 0, 1, 1},
  {&__pyx_n_s_get_active_sequence_name, __pyx_k_get_active_sequence_name, sizeof(__pyx_k_get_active_sequence_name), 0, 0, 1, 1},
  {&__pyx_n_s_get_element, __pyx_k_get_element, sizeof(__pyx_k_get_element), 0, 0, 1, 1},
  {&__pyx_n_s_get_element_count, __pyx_k_get_element_count, sizeof(__pyx_k_get_element_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_element_index, __pyx_k_get_element_index, sizeof(__pyx_k_get_element_index), 0, 0, 1, 1},
  {&__pyx_n_s_get_element_index_by_position, __pyx_k_get_element_index_by_position, sizeof(__pyx_k_get_element_index_by_position), 0, 0, 1, 1},
  {&__pyx_n_s_get_expanded_element, __pyx_k_get_expanded_element, sizeof(__pyx_k_get_expanded_element), 0, 0, 1, 1},
  {&__pyx_n_s_get_expanded_element_count, __pyx_k_get_expanded_element_count, sizeof(__pyx_k_get_expanded_element_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_expanded_element_index, __pyx_k_get_expanded_element_index, sizeof(__pyx_k_get_expanded_element_index), 0, 0, 1, 1},
  {&__pyx_n_s_get_expanded_element_index_by_po, __pyx_k_get_expanded_element_index_by_po, sizeof(__pyx_k_get_expanded_element_index_by_po), 0, 0, 1, 1},
  {&__pyx_n_s_get_global_element, __pyx_k_get_global_element, sizeof(__pyx_k_get_global_element), 0, 0, 1, 1},
  {&__pyx_n_s_get_global_element_count, __pyx_k_get_global_element_count, sizeof(__pyx_k_get_global_element_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_global_element_index, __pyx_k_get_global_element_index, sizeof(__pyx_k_get_global_element_index), 0, 0, 1, 1},
  {&__pyx_n_s_get_global_element_name, __pyx_k_get_global_element_name, sizeof(__pyx_k_get_global_element_name), 0, 0, 1, 1},
  {&__pyx_n_s_get_globals, __pyx_k_get_globals, sizeof(__pyx_k_get_globals), 0, 0, 1, 1},
  {&__pyx_n_s_get_rightmost_word, __pyx_k_get_rightmost_word, sizeof(__pyx_k_get_rightmost_word), 0, 0, 1, 1},
  {&__pyx_n_s_get_sequence_beam, __pyx_k_get_sequence_beam, sizeof(__pyx_k_get_sequence_beam), 0, 0, 1, 1},
  {&__pyx_n_s_get_sequence_count, __pyx_k_get_sequence_count, sizeof(__pyx_k_get_sequence_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_sequence_names, __pyx_k_get_sequence_names, sizeof(__pyx_k_get_sequence_names), 0, 0, 1, 1},
  {&__pyx_n_s_get_sequence_twiss_table_name, __pyx_k_get_sequence_twiss_table_name, sizeof(__pyx_k_get_sequence_twiss_table_name), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_column, __pyx_k_get_table_column, sizeof(__pyx_k_get_table_column), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_column_count, __pyx_k_get_table_column_count, sizeof(__pyx_k_get_table_column_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_column_names, __pyx_k_get_table_column_names, sizeof(__pyx_k_get_table_column_names), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_column_names_all, __pyx_k_get_table_column_names_all, sizeof(__pyx_k_get_table_column_names_all), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_count, __pyx_k_get_table_count, sizeof(__pyx_k_get_table_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_names, __pyx_k_get_table_names, sizeof(__pyx_k_get_table_names), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_row_count, __pyx_k_get_table_row_count, sizeof(__pyx_k_get_table_row_count), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_row_names, __pyx_k_get_table_row_names, sizeof(__pyx_k_get_table_row_names), 0, 0, 1, 1},
  {&__pyx_n_s_get_table_summary, __pyx_k_get_table_summary, sizeof(__pyx_k_get_table_summary), 0, 0, 1, 1},
  {&__pyx_n_s_get_var, __pyx_k_get_var, sizeof(__pyx_k_get_var), 0, 0, 1, 1},
  {&__pyx_n_s_get_var_type, __pyx_k_get_var_type, sizeof(__pyx_k_get_var_type), 0, 0, 1, 1},
  {&__pyx_n_s_get_version_date, __pyx_k_get_version_date, sizeof(__pyx_k_get_version_date), 0, 0, 1, 1},
  {&__pyx_n_s_get_version_number, __pyx_k_get_version_number, sizeof(__pyx_k_get_version_number), 0, 0, 1, 1},
  {&__pyx_n_s_getcwd, __pyx_k_getcwd, sizeof(__pyx_k_getcwd), 0, 0, 1, 1},
  {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1},
  {&__pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_k_home_thomas_src_work_bundle_cpy, sizeof(__pyx_k_home_thomas_src_work_bundle_cpy), 0, 0, 1, 0},
  {&__pyx_n_b_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 0, 1},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_s_i_beg, __pyx_k_i_beg, sizeof(__pyx_k_i_beg), 0, 0, 1, 1},
  {&__pyx_n_s_i_end, __pyx_k_i_end, sizeof(__pyx_k_i_end), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1},
  {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1},
  {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1},
  {&__pyx_n_s_inform, __pyx_k_inform, sizeof(__pyx_k_inform), 0, 0, 1, 1},
  {&__pyx_n_s_input, __pyx_k_input, sizeof(__pyx_k_input), 0, 0, 1, 1},
  {&__pyx_n_s_is_sequence_expanded, __pyx_k_is_sequence_expanded, sizeof(__pyx_k_is_sequence_expanded), 0, 0, 1, 1},
  {&__pyx_n_s_is_started, __pyx_k_is_started, sizeof(__pyx_k_is_started), 0, 0, 1, 1},
  {&__pyx_kp_s_le, __pyx_k_le, sizeof(__pyx_k_le), 0, 0, 1, 0},
  {&__pyx_n_s_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 0, 0, 1, 1},
  {&__pyx_n_s_madx_started, __pyx_k_madx_started, sizeof(__pyx_k_madx_started), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
  {&__pyx_n_s_name_from_internal, __pyx_k_name_from_internal, sizeof(__pyx_k_name_from_internal), 0, 0, 1, 1},
  {&__pyx_n_s_name_to_internal, __pyx_k_name_to_internal, sizeof(__pyx_k_name_to_internal), 0, 0, 1, 1},
  {&__pyx_n_s_normalize_range_name, __pyx_k_normalize_range_name, sizeof(__pyx_k_normalize_range_name), 0, 0, 1, 1},
  {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1},
  {&__pyx_n_s_num_globals, __pyx_k_num_globals, sizeof(__pyx_k_num_globals), 0, 0, 1, 1},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_position, __pyx_k_position, sizeof(__pyx_k_position), 0, 0, 1, 1},
  {&__pyx_n_s_position_2, __pyx_k_position_2, sizeof(__pyx_k_position_2), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rsplit, __pyx_k_rsplit, sizeof(__pyx_k_rsplit), 0, 0, 1, 1},
  {&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1},
  {&__pyx_n_s_sentence, __pyx_k_sentence, sizeof(__pyx_k_sentence), 0, 0, 1, 1},
  {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
  {&__pyx_n_s_seqs, __pyx_k_seqs, sizeof(__pyx_k_seqs), 0, 0, 1, 1},
  {&__pyx_n_s_sequence_exists, __pyx_k_sequence_exists, sizeof(__pyx_k_sequence_exists), 0, 0, 1, 1},
  {&__pyx_n_s_sequence_name, __pyx_k_sequence_name, sizeof(__pyx_k_sequence_name), 0, 0, 1, 1},
  {&__pyx_n_s_set_var, __pyx_k_set_var, sizeof(__pyx_k_set_var), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1},
  {&__pyx_n_s_tab_i, __pyx_k_tab_i, sizeof(__pyx_k_tab_i), 0, 0, 1, 1},
  {&__pyx_n_s_tab_name, __pyx_k_tab_name, sizeof(__pyx_k_tab_name), 0, 0, 1, 1},
  {&__pyx_n_s_table, __pyx_k_table, sizeof(__pyx_k_table), 0, 0, 1, 1},
  {&__pyx_n_s_table_2, __pyx_k_table_2, sizeof(__pyx_k_table_2), 0, 0, 1, 1},
  {&__pyx_n_s_table_exists, __pyx_k_table_exists, sizeof(__pyx_k_table_exists), 0, 0, 1, 1},
  {&__pyx_n_s_table_name, __pyx_k_table_name, sizeof(__pyx_k_table_name), 0, 0, 1, 1},
  {&__pyx_n_s_table_name_2, __pyx_k_table_name_2, sizeof(__pyx_k_table_name_2), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1},
  {&__pyx_n_s_typeid, __pyx_k_typeid, sizeof(__pyx_k_typeid), 0, 0, 1, 1},
  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
  {&__pyx_kp_s_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 0, 1, 0},
  {&__pyx_n_s_val, __pyx_k_val, sizeof(__pyx_k_val), 0, 0, 1, 1},
  {&__pyx_n_s_val_type, __pyx_k_val_type, sizeof(__pyx_k_val_type), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_s_value_2, __pyx_k_value_2, sizeof(__pyx_k_value_2), 0, 0, 1, 1},
  {&__pyx_n_s_var, __pyx_k_var, sizeof(__pyx_k_var), 0, 0, 1, 1},
  {&__pyx_n_s_var_type, __pyx_k_var_type, sizeof(__pyx_k_var_type), 0, 0, 1, 1},
  {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 208, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 246, __pyx_L1_error)
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 262, __pyx_L1_error)
  #if PY_MAJOR_VERSION >= 3
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 305, __pyx_L1_error)
  #else
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 305, __pyx_L1_error)
  #endif
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 515, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 882, __pyx_L1_error)
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 961, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "cpymad/libmadx.pyx":103
 * def _get_rightmost_word(sentence):
 *     """Get the work right of the rightmost space character."""
 *     return sentence.rsplit(' ', 1)[-1]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__2 = PyTuple_Pack(2, __pyx_kp_s_, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "cpymad/libmadx.pyx":262
 *     cdef clib.sequence* seq = _find_sequence(sequence_name)
 *     if not seq.tw_valid:
 *         raise RuntimeError("TWISS table invalid.")             # <<<<<<<<<<<<<<
 *     return _str(seq.tw_table.name)
 * 
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_TWISS_table_invalid); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 262, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "cpymad/libmadx.pyx":291
 *     """
 *     if clib.current_sequ is NULL:
 *         raise RuntimeError("No active sequence!")             # <<<<<<<<<<<<<<
 *     return _str(clib.current_sequ.name)
 * 
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_No_active_sequence); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "cpymad/libmadx.pyx":885
 *         if all_nodes[i] == find:
 *             return i
 *     raise ValueError("Invalid node!")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_Invalid_node); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 885, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "cpymad/libmadx.pyx":890
 * cdef _split_header_line(header_line):
 *     """Parse a table header value."""
 *     _, key, kind, value = _str(header_line).split(None, 3)             # <<<<<<<<<<<<<<
 *     key = key.lower()
 *     if kind == "%le":
 */
  __pyx_tuple__7 = PyTuple_Pack(2, Py_None, __pyx_int_3); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "cpymad/libmadx.pyx":894
 *     if kind == "%le":
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):             # <<<<<<<<<<<<<<
 *         return key, value[1:-1]     # strip quotes from string
 *     else:
 */
  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_n_s_s); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "cpymad/libmadx.pyx":895
 *         return key, float(value)    # convert to number
 *     elif kind.endswith('s'):
 *         return key, value[1:-1]     # strip quotes from string             # <<<<<<<<<<<<<<
 *     else:
 *         return key, value           #
 */
  __pyx_slice__9 = PySlice_New(__pyx_int_1, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__9)) __PYX_ERR(0, 895, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__9);
  __Pyx_GIVEREF(__pyx_slice__9);

  /* "cpymad/libmadx.pyx":919
 *     if s is None:
 *         return b""
 *     return <bytes> s.encode('utf-8')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_utf_8); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "cpymad/libmadx.pyx":926
 *     if node.p_elem is NULL:
 *         # Maybe this is a valid case, but better detect it with boom!
 *         raise RuntimeError("Empty node or subsequence! Please report this incident!")             # <<<<<<<<<<<<<<
 *     data = _get_element(node.p_elem)
 *     data.update({'name': name_from_internal(_str(node.name)),
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_Empty_node_or_subsequence_Please); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "cpymad/libmadx.pyx":101
 * 
 * 
 * def _get_rightmost_word(sentence):             # <<<<<<<<<<<<<<
 *     """Get the work right of the rightmost space character."""
 *     return sentence.rsplit(' ', 1)[-1]
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_n_s_sentence); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);
  __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_rightmost_word, 101, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 101, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":106
 * 
 * 
 * def get_version_number():             # <<<<<<<<<<<<<<
 *     """
 *     Get the version number of loaded MAD-X interpreter.
 */
  __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_version_number, 106, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 106, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":116
 * 
 * 
 * def get_version_date():             # <<<<<<<<<<<<<<
 *     """
 *     Get the release date of loaded MAD-X interpreter.
 */
  __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_version_date, 116, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 116, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":126
 * 
 * 
 * def is_started():             # <<<<<<<<<<<<<<
 *     """
 *     Check whether MAD-X has been initialized.
 */
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_is_started, 126, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 126, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":136
 * 
 * 
 * def start():             # <<<<<<<<<<<<<<
 *     """
 *     Initialize MAD-X.
 */
  __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_start, 136, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 136, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":145
 * 
 * 
 * def finish():             # <<<<<<<<<<<<<<
 *     """
 *     Cleanup MAD-X.
 */
  __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_finish, 145, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 145, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":154
 * 
 * 
 * def input(cmd):             # <<<<<<<<<<<<<<
 *     """
 *     Pass one input command to MAD-X.
 */
  __pyx_tuple__20 = PyTuple_Pack(2, __pyx_n_s_cmd, __pyx_n_s_cmd_2); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);
  __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_input, 154, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 154, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":165
 * 
 * 
 * def get_var(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the value of a global variable.
 */
  __pyx_tuple__22 = PyTuple_Pack(4, __pyx_n_s_name, __pyx_n_s_var, __pyx_n_s_value, __pyx_n_s_typeid); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);
  __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_var, 165, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 165, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":181
 * 
 * 
 * def get_var_type(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the type of the variable:
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_n_s_name); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);
  __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_var_type, 181, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 181, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":193
 * 
 * 
 * def set_var(name, value):             # <<<<<<<<<<<<<<
 *     """
 *     Set the value of a global variable.
 */
  __pyx_tuple__26 = PyTuple_Pack(8, __pyx_n_s_name, __pyx_n_s_value, __pyx_n_s_name_2, __pyx_n_s_value_2, __pyx_n_s_var_type, __pyx_n_s_val_type, __pyx_n_s_expr, __pyx_n_s_var); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);
  __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_set_var, 193, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 193, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":221
 * 
 * 
 * def num_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Return the number of global variables.
 */
  __pyx_codeobj__28 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_num_globals, 221, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__28)) __PYX_ERR(0, 221, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":228
 * 
 * 
 * def get_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of names of all global variables.
 */
  __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_globals, 228, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 228, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":235
 * 
 * 
 * def sequence_exists(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the sequence exists.
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_n_s_sequence_name); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);
  __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_sequence_exists, 235, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 235, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":250
 * 
 * 
 * def get_sequence_twiss_table_name(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the last calculated twiss table for the given sequence.
 */
  __pyx_tuple__32 = PyTuple_Pack(2, __pyx_n_s_sequence_name, __pyx_n_s_seq); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);
  __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_sequence_twiss_table_name, 250, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 250, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":266
 * 
 * 
 * def get_sequence_beam(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the beam associated to the sequence.
 */
  __pyx_tuple__34 = PyTuple_Pack(2, __pyx_n_s_sequence_name, __pyx_n_s_seq); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);
  __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_sequence_beam, 266, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 266, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":282
 * 
 * 
 * def get_active_sequence_name():             # <<<<<<<<<<<<<<
 *     """
 *     Get the name of the active sequence.
 */
  __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_active_sequence_name, 282, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 282, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":295
 * 
 * 
 * def get_sequence_names():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all sequences currently in memory.
 */
  __pyx_tuple__37 = PyTuple_Pack(2, __pyx_n_s_seqs, __pyx_n_s_i); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);
  __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_sequence_names, 295, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 295, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":308
 * 
 * 
 * def get_sequence_count():             # <<<<<<<<<<<<<<
 *     """
 *     Get the number of all sequences currently in memory.
 */
  __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_sequence_count, 308, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 308, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":318
 * 
 * 
 * def table_exists(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the table exists.
 */
  __pyx_tuple__40 = PyTuple_Pack(2, __pyx_n_s_table_name, __pyx_n_s_table_name_2); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 318, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);
  __pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__40, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_table_exists, 318, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(0, 318, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":330
 * 
 * 
 * def get_table_names():             # <<<<<<<<<<<<<<
 *     """
 *     Return list of all table names.
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_n_s_i); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 330, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);
  __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(0, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__42, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_names, 330, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 330, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":341
 * 
 * 
 * def get_table_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of existing tables.
 */
  __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_count, 341, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 341, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":351
 * 
 * 
 * def get_table_summary(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get table summary.
 */
  __pyx_tuple__45 = PyTuple_Pack(4, __pyx_n_s_table_name, __pyx_n_s_table_name_2, __pyx_n_s_header, __pyx_n_s_i); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);
  __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_summary, 351, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 351, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":368
 * 
 * 
 * def get_table_column_names(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */
  __pyx_tuple__47 = PyTuple_Pack(4, __pyx_n_s_table_name, __pyx_n_s_table, __pyx_n_s_indices, __pyx_n_s_i); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);
  __pyx_codeobj__48 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_column_names, 368, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__48)) __PYX_ERR(0, 368, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":384
 * 
 * 
 * def get_table_column_names_all(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */
  __pyx_tuple__49 = PyTuple_Pack(2, __pyx_n_s_table_name, __pyx_n_s_table); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 384, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);
  __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_column_names_all, 384, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 384, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":399
 * 
 * 
 * def get_table_column_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a number of columns in the table.
 */
  __pyx_tuple__51 = PyTuple_Pack(2, __pyx_n_s_table_name, __pyx_n_s_table); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);
  __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_column_count, 399, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 399, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":412
 * 
 * 
 * def get_table_column(table_name, column_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get data from the specified table.
 */
  __pyx_tuple__53 = PyTuple_Pack(16, __pyx_n_s_table_name, __pyx_n_s_column_name, __pyx_n_s_char_tmp, __pyx_n_s_tab_name, __pyx_n_s_col_name, __pyx_n_s_info, __pyx_n_s_tab_i, __pyx_n_s_table_2, __pyx_n_s_col_i, __pyx_n_s_inform, __pyx_n_s_dtype, __pyx_n_s_size, __pyx_n_s_addr, __pyx_n_s_array_type, __pyx_n_s_array_data, __pyx_n_s_i); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 412, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);
  __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(2, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_column, 412, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 412, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":485
 * 
 * 
 * def get_table_row_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return total number of rows in the table.
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_n_s_table_name); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);
  __pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_row_count, 485, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) __PYX_ERR(0, 485, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":492
 * 
 * 
 * def get_table_row_names(table_name, indices):             # <<<<<<<<<<<<<<
 *     """
 *     Return row names for every index (row number) in the list.
 */
  __pyx_tuple__57 = PyTuple_Pack(4, __pyx_n_s_table_name, __pyx_n_s_indices, __pyx_n_s_table, __pyx_n_s_i); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);
  __pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_table_row_names, 492, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) __PYX_ERR(0, 492, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":502
 * 
 * 
 * def get_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the original sequence.
 */
  __pyx_tuple__59 = PyTuple_Pack(3, __pyx_n_s_sequence_name, __pyx_n_s_element_index, __pyx_n_s_seq); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 502, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);
  __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_element, 502, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(0, 502, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":520
 * 
 * 
 * def get_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the original sequence.
 */
  __pyx_tuple__61 = PyTuple_Pack(5, __pyx_n_s_sequence_name, __pyx_n_s_element_name, __pyx_n_s_seq, __pyx_n_s_element_name_2, __pyx_n_s_index); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);
  __pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_element_index, 520, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) __PYX_ERR(0, 520, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":538
 * 
 * 
 * def get_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the original sequence.
 */
  __pyx_tuple__63 = PyTuple_Pack(7, __pyx_n_s_sequence_name, __pyx_n_s_position, __pyx_n_s_seq, __pyx_n_s_position_2, __pyx_n_s_elem, __pyx_n_s_at, __pyx_n_s_i); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 538, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);
  __pyx_codeobj__64 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_element_index_by_position, 538, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__64)) __PYX_ERR(0, 538, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":563
 * 
 * 
 * def get_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the original sequence.
 */
  __pyx_tuple__65 = PyTuple_Pack(2, __pyx_n_s_sequence_name, __pyx_n_s_seq); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);
  __pyx_codeobj__66 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__65, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_element_count, 563, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__66)) __PYX_ERR(0, 563, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":576
 * 
 * 
 * def get_expanded_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */
  __pyx_tuple__67 = PyTuple_Pack(3, __pyx_n_s_sequence_name, __pyx_n_s_element_index, __pyx_n_s_seq); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);
  __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_expanded_element, 576, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 576, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":598
 * 
 * 
 * def get_expanded_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the expanded sequence.
 */
  __pyx_tuple__69 = PyTuple_Pack(5, __pyx_n_s_sequence_name, __pyx_n_s_element_name, __pyx_n_s_seq, __pyx_n_s_element_name_2, __pyx_n_s_i); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_expanded_element_index, 598, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 598, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":624
 * 
 * 
 * def get_expanded_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the expanded sequence.
 */
  __pyx_tuple__71 = PyTuple_Pack(7, __pyx_n_s_sequence_name, __pyx_n_s_position, __pyx_n_s_seq, __pyx_n_s_position_2, __pyx_n_s_elem, __pyx_n_s_at, __pyx_n_s_i); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_expanded_element_index_by_po, 624, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 624, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":652
 * 
 * 
 * def get_expanded_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the expanded sequence.
 */
  __pyx_tuple__73 = PyTuple_Pack(4, __pyx_n_s_sequence_name, __pyx_n_s_seq, __pyx_n_s_i_beg, __pyx_n_s_i_end); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 652, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);
  __pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_expanded_element_count, 652, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) __PYX_ERR(0, 652, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":670
 * 
 * 
 * def get_global_element(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */
  __pyx_tuple__75 = PyTuple_Pack(2, __pyx_n_s_element_index, __pyx_n_s_elems); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);
  __pyx_codeobj__76 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__75, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_global_element, 670, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__76)) __PYX_ERR(0, 670, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":686
 * 
 * 
 * def get_global_element_name(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return name of element.
 */
  __pyx_tuple__77 = PyTuple_Pack(2, __pyx_n_s_element_index, __pyx_n_s_elems); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 686, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);
  __pyx_codeobj__78 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__77, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_global_element_name, 686, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__78)) __PYX_ERR(0, 686, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":702
 * 
 * 
 * def get_global_element_index(element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the global element list.
 */
  __pyx_tuple__79 = PyTuple_Pack(2, __pyx_n_s_element_name, __pyx_n_s_element_name_2); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);
  __pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__79, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_global_element_index, 702, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) __PYX_ERR(0, 702, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":714
 * 
 * 
 * def get_global_element_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of globally visible elements.
 */
  __pyx_codeobj__81 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_get_global_element_count, 714, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__81)) __PYX_ERR(0, 714, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":721
 * 
 * 
 * def is_sequence_expanded(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check whether a sequence has already been expanded.
 */
  __pyx_tuple__82 = PyTuple_Pack(2, __pyx_n_s_sequence_name, __pyx_n_s_seq); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 721, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);
  __pyx_codeobj__83 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__82, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_is_sequence_expanded, 721, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__83)) __PYX_ERR(0, 721, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":734
 * 
 * 
 * def evaluate(expression):             # <<<<<<<<<<<<<<
 *     """
 *     Evaluates an expression and returns the result as double.
 */
  __pyx_tuple__84 = PyTuple_Pack(3, __pyx_n_s_expression, __pyx_n_s_expr, __pyx_n_s_value); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);
  __pyx_codeobj__85 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__84, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_thomas_src_work_bundle_cpy, __pyx_n_s_evaluate, 734, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__85)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initlibmadx(void); /*proto*/
PyMODINIT_FUNC initlibmadx(void)
#else
PyMODINIT_FUNC PyInit_libmadx(void); /*proto*/
PyMODINIT_FUNC PyInit_libmadx(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_libmadx(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("libmadx", __pyx_methods, __pyx_k_Low_level_cython_binding_to_MAD, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_cpymad__libmadx) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "cpymad.libmadx")) {
      if (unlikely(PyDict_SetItemString(modules, "cpymad.libmadx", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "cpymad/libmadx.pyx":14
 * """
 * 
 * from os import chdir, getcwd             # <<<<<<<<<<<<<<
 * 
 * import ctypes
 */
  __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_chdir);
  __Pyx_GIVEREF(__pyx_n_s_chdir);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_chdir);
  __Pyx_INCREF(__pyx_n_s_getcwd);
  __Pyx_GIVEREF(__pyx_n_s_getcwd);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_getcwd);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_os, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_chdir); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_chdir, __pyx_t_1) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_getcwd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_getcwd, __pyx_t_1) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":16
 * from os import chdir, getcwd
 * 
 * import ctypes             # <<<<<<<<<<<<<<
 * import numpy as np      # Import the Python-level symbols of numpy
 * 
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_ctypes, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctypes, __pyx_t_2) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":17
 * 
 * import ctypes
 * import numpy as np      # Import the Python-level symbols of numpy             # <<<<<<<<<<<<<<
 * 
 * # Import a large-enough integer type to hold pointer, see also:
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_2) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":24
 *     ctypedef int Py_intptr_t
 * 
 * from cpymad.types import Constraint, Expression             # <<<<<<<<<<<<<<
 * from cpymad.util import name_to_internal, name_from_internal, normalize_range_name
 * cimport cpymad.clibmadx as clib
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_Constraint);
  __Pyx_GIVEREF(__pyx_n_s_Constraint);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Constraint);
  __Pyx_INCREF(__pyx_n_s_Expression);
  __Pyx_GIVEREF(__pyx_n_s_Expression);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_Expression);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_cpymad_types, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Constraint); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Constraint, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Expression); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Expression, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cpymad/libmadx.pyx":25
 * 
 * from cpymad.types import Constraint, Expression
 * from cpymad.util import name_to_internal, name_from_internal, normalize_range_name             # <<<<<<<<<<<<<<
 * cimport cpymad.clibmadx as clib
 * 
 */
  __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_name_to_internal);
  __Pyx_GIVEREF(__pyx_n_s_name_to_internal);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_name_to_internal);
  __Pyx_INCREF(__pyx_n_s_name_from_internal);
  __Pyx_GIVEREF(__pyx_n_s_name_from_internal);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_name_from_internal);
  __Pyx_INCREF(__pyx_n_s_normalize_range_name);
  __Pyx_GIVEREF(__pyx_n_s_normalize_range_name);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_normalize_range_name);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_cpymad_util, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_name_to_internal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_name_to_internal, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_name_from_internal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_name_from_internal, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_normalize_range_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_normalize_range_name, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":30
 * 
 * # Remember whether start() was called
 * _madx_started = False             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_madx_started, Py_False) < 0) __PYX_ERR(0, 30, __pyx_L1_error)

  /* "cpymad/libmadx.pyx":34
 * 
 * # Python-level binding to libmadx:
 * __all__ = [             # <<<<<<<<<<<<<<
 *     # MAD-X version
 *     'get_version_number',
 */
  __pyx_t_2 = PyList_New(41); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_get_version_number);
  __Pyx_GIVEREF(__pyx_n_s_get_version_number);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_get_version_number);
  __Pyx_INCREF(__pyx_n_s_get_version_date);
  __Pyx_GIVEREF(__pyx_n_s_get_version_date);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_get_version_date);
  __Pyx_INCREF(__pyx_n_s_is_started);
  __Pyx_GIVEREF(__pyx_n_s_is_started);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_is_started);
  __Pyx_INCREF(__pyx_n_s_start);
  __Pyx_GIVEREF(__pyx_n_s_start);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_start);
  __Pyx_INCREF(__pyx_n_s_finish);
  __Pyx_GIVEREF(__pyx_n_s_finish);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_n_s_finish);
  __Pyx_INCREF(__pyx_n_s_input);
  __Pyx_GIVEREF(__pyx_n_s_input);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_n_s_input);
  __Pyx_INCREF(__pyx_n_s_evaluate);
  __Pyx_GIVEREF(__pyx_n_s_evaluate);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_n_s_evaluate);
  __Pyx_INCREF(__pyx_n_s_get_var);
  __Pyx_GIVEREF(__pyx_n_s_get_var);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_n_s_get_var);
  __Pyx_INCREF(__pyx_n_s_set_var);
  __Pyx_GIVEREF(__pyx_n_s_set_var);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_n_s_set_var);
  __Pyx_INCREF(__pyx_n_s_num_globals);
  __Pyx_GIVEREF(__pyx_n_s_num_globals);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_n_s_num_globals);
  __Pyx_INCREF(__pyx_n_s_get_globals);
  __Pyx_GIVEREF(__pyx_n_s_get_globals);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_n_s_get_globals);
  __Pyx_INCREF(__pyx_n_s_get_var_type);
  __Pyx_GIVEREF(__pyx_n_s_get_var_type);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_n_s_get_var_type);
  __Pyx_INCREF(__pyx_n_s_sequence_exists);
  __Pyx_GIVEREF(__pyx_n_s_sequence_exists);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_n_s_sequence_exists);
  __Pyx_INCREF(__pyx_n_s_get_sequence_names);
  __Pyx_GIVEREF(__pyx_n_s_get_sequence_names);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_n_s_get_sequence_names);
  __Pyx_INCREF(__pyx_n_s_get_sequence_count);
  __Pyx_GIVEREF(__pyx_n_s_get_sequence_count);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_n_s_get_sequence_count);
  __Pyx_INCREF(__pyx_n_s_get_active_sequence_name);
  __Pyx_GIVEREF(__pyx_n_s_get_active_sequence_name);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_n_s_get_active_sequence_name);
  __Pyx_INCREF(__pyx_n_s_get_sequence_twiss_table_name);
  __Pyx_GIVEREF(__pyx_n_s_get_sequence_twiss_table_name);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_n_s_get_sequence_twiss_table_name);
  __Pyx_INCREF(__pyx_n_s_get_sequence_beam);
  __Pyx_GIVEREF(__pyx_n_s_get_sequence_beam);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_n_s_get_sequence_beam);
  __Pyx_INCREF(__pyx_n_s_is_sequence_expanded);
  __Pyx_GIVEREF(__pyx_n_s_is_sequence_expanded);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_n_s_is_sequence_expanded);
  __Pyx_INCREF(__pyx_n_s_table_exists);
  __Pyx_GIVEREF(__pyx_n_s_table_exists);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_n_s_table_exists);
  __Pyx_INCREF(__pyx_n_s_get_table_names);
  __Pyx_GIVEREF(__pyx_n_s_get_table_names);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_n_s_get_table_names);
  __Pyx_INCREF(__pyx_n_s_get_table_count);
  __Pyx_GIVEREF(__pyx_n_s_get_table_count);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_n_s_get_table_count);
  __Pyx_INCREF(__pyx_n_s_get_table_summary);
  __Pyx_GIVEREF(__pyx_n_s_get_table_summary);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_n_s_get_table_summary);
  __Pyx_INCREF(__pyx_n_s_get_table_column_names);
  __Pyx_GIVEREF(__pyx_n_s_get_table_column_names);
  PyList_SET_ITEM(__pyx_t_2, 23, __pyx_n_s_get_table_column_names);
  __Pyx_INCREF(__pyx_n_s_get_table_column_names_all);
  __Pyx_GIVEREF(__pyx_n_s_get_table_column_names_all);
  PyList_SET_ITEM(__pyx_t_2, 24, __pyx_n_s_get_table_column_names_all);
  __Pyx_INCREF(__pyx_n_s_get_table_column);
  __Pyx_GIVEREF(__pyx_n_s_get_table_column);
  PyList_SET_ITEM(__pyx_t_2, 25, __pyx_n_s_get_table_column);
  __Pyx_INCREF(__pyx_n_s_get_table_row_count);
  __Pyx_GIVEREF(__pyx_n_s_get_table_row_count);
  PyList_SET_ITEM(__pyx_t_2, 26, __pyx_n_s_get_table_row_count);
  __Pyx_INCREF(__pyx_n_s_get_table_row_names);
  __Pyx_GIVEREF(__pyx_n_s_get_table_row_names);
  PyList_SET_ITEM(__pyx_t_2, 27, __pyx_n_s_get_table_row_names);
  __Pyx_INCREF(__pyx_n_s_get_element);
  __Pyx_GIVEREF(__pyx_n_s_get_element);
  PyList_SET_ITEM(__pyx_t_2, 28, __pyx_n_s_get_element);
  __Pyx_INCREF(__pyx_n_s_get_element_index);
  __Pyx_GIVEREF(__pyx_n_s_get_element_index);
  PyList_SET_ITEM(__pyx_t_2, 29, __pyx_n_s_get_element_index);
  __Pyx_INCREF(__pyx_n_s_get_element_index_by_position);
  __Pyx_GIVEREF(__pyx_n_s_get_element_index_by_position);
  PyList_SET_ITEM(__pyx_t_2, 30, __pyx_n_s_get_element_index_by_position);
  __Pyx_INCREF(__pyx_n_s_get_element_count);
  __Pyx_GIVEREF(__pyx_n_s_get_element_count);
  PyList_SET_ITEM(__pyx_t_2, 31, __pyx_n_s_get_element_count);
  __Pyx_INCREF(__pyx_n_s_get_expanded_element);
  __Pyx_GIVEREF(__pyx_n_s_get_expanded_element);
  PyList_SET_ITEM(__pyx_t_2, 32, __pyx_n_s_get_expanded_element);
  __Pyx_INCREF(__pyx_n_s_get_expanded_element_index);
  __Pyx_GIVEREF(__pyx_n_s_get_expanded_element_index);
  PyList_SET_ITEM(__pyx_t_2, 33, __pyx_n_s_get_expanded_element_index);
  __Pyx_INCREF(__pyx_n_s_get_expanded_element_index_by_po);
  __Pyx_GIVEREF(__pyx_n_s_get_expanded_element_index_by_po);
  PyList_SET_ITEM(__pyx_t_2, 34, __pyx_n_s_get_expanded_element_index_by_po);
  __Pyx_INCREF(__pyx_n_s_get_expanded_element_count);
  __Pyx_GIVEREF(__pyx_n_s_get_expanded_element_count);
  PyList_SET_ITEM(__pyx_t_2, 35, __pyx_n_s_get_expanded_element_count);
  __Pyx_INCREF(__pyx_n_s_get_global_element);
  __Pyx_GIVEREF(__pyx_n_s_get_global_element);
  PyList_SET_ITEM(__pyx_t_2, 36, __pyx_n_s_get_global_element);
  __Pyx_INCREF(__pyx_n_s_get_global_element_index);
  __Pyx_GIVEREF(__pyx_n_s_get_global_element_index);
  PyList_SET_ITEM(__pyx_t_2, 37, __pyx_n_s_get_global_element_index);
  __Pyx_INCREF(__pyx_n_s_get_global_element_count);
  __Pyx_GIVEREF(__pyx_n_s_get_global_element_count);
  PyList_SET_ITEM(__pyx_t_2, 38, __pyx_n_s_get_global_element_count);
  __Pyx_INCREF(__pyx_n_s_chdir);
  __Pyx_GIVEREF(__pyx_n_s_chdir);
  PyList_SET_ITEM(__pyx_t_2, 39, __pyx_n_s_chdir);
  __Pyx_INCREF(__pyx_n_s_getcwd);
  __Pyx_GIVEREF(__pyx_n_s_getcwd);
  PyList_SET_ITEM(__pyx_t_2, 40, __pyx_n_s_getcwd);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":101
 * 
 * 
 * def _get_rightmost_word(sentence):             # <<<<<<<<<<<<<<
 *     """Get the work right of the rightmost space character."""
 *     return sentence.rsplit(' ', 1)[-1]
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_1_get_rightmost_word, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_rightmost_word, __pyx_t_2) < 0) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":106
 * 
 * 
 * def get_version_number():             # <<<<<<<<<<<<<<
 *     """
 *     Get the version number of loaded MAD-X interpreter.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_3get_version_number, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_version_number, __pyx_t_2) < 0) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":116
 * 
 * 
 * def get_version_date():             # <<<<<<<<<<<<<<
 *     """
 *     Get the release date of loaded MAD-X interpreter.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_5get_version_date, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_version_date, __pyx_t_2) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":126
 * 
 * 
 * def is_started():             # <<<<<<<<<<<<<<
 *     """
 *     Check whether MAD-X has been initialized.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_7is_started, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_started, __pyx_t_2) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":136
 * 
 * 
 * def start():             # <<<<<<<<<<<<<<
 *     """
 *     Initialize MAD-X.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_9start, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_start, __pyx_t_2) < 0) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":145
 * 
 * 
 * def finish():             # <<<<<<<<<<<<<<
 *     """
 *     Cleanup MAD-X.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_11finish, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 145, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_finish, __pyx_t_2) < 0) __PYX_ERR(0, 145, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":154
 * 
 * 
 * def input(cmd):             # <<<<<<<<<<<<<<
 *     """
 *     Pass one input command to MAD-X.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_13input, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_input, __pyx_t_2) < 0) __PYX_ERR(0, 154, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":165
 * 
 * 
 * def get_var(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the value of a global variable.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_15get_var, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_var, __pyx_t_2) < 0) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":181
 * 
 * 
 * def get_var_type(name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the type of the variable:
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_17get_var_type, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_var_type, __pyx_t_2) < 0) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":193
 * 
 * 
 * def set_var(name, value):             # <<<<<<<<<<<<<<
 *     """
 *     Set the value of a global variable.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_19set_var, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_var, __pyx_t_2) < 0) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":221
 * 
 * 
 * def num_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Return the number of global variables.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_21num_globals, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_num_globals, __pyx_t_2) < 0) __PYX_ERR(0, 221, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":228
 * 
 * 
 * def get_globals():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of names of all global variables.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_23get_globals, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_globals, __pyx_t_2) < 0) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":235
 * 
 * 
 * def sequence_exists(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the sequence exists.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_25sequence_exists, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sequence_exists, __pyx_t_2) < 0) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":250
 * 
 * 
 * def get_sequence_twiss_table_name(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the last calculated twiss table for the given sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_27get_sequence_twiss_table_name, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_sequence_twiss_table_name, __pyx_t_2) < 0) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":266
 * 
 * 
 * def get_sequence_beam(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get the beam associated to the sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_29get_sequence_beam, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_sequence_beam, __pyx_t_2) < 0) __PYX_ERR(0, 266, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":282
 * 
 * 
 * def get_active_sequence_name():             # <<<<<<<<<<<<<<
 *     """
 *     Get the name of the active sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_31get_active_sequence_name, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_active_sequence_name, __pyx_t_2) < 0) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":295
 * 
 * 
 * def get_sequence_names():             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all sequences currently in memory.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_33get_sequence_names, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_sequence_names, __pyx_t_2) < 0) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":308
 * 
 * 
 * def get_sequence_count():             # <<<<<<<<<<<<<<
 *     """
 *     Get the number of all sequences currently in memory.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_35get_sequence_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_sequence_count, __pyx_t_2) < 0) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":318
 * 
 * 
 * def table_exists(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check if the table exists.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_37table_exists, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_table_exists, __pyx_t_2) < 0) __PYX_ERR(0, 318, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":330
 * 
 * 
 * def get_table_names():             # <<<<<<<<<<<<<<
 *     """
 *     Return list of all table names.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_39get_table_names, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 330, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_names, __pyx_t_2) < 0) __PYX_ERR(0, 330, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":341
 * 
 * 
 * def get_table_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of existing tables.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_41get_table_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_count, __pyx_t_2) < 0) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":351
 * 
 * 
 * def get_table_summary(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get table summary.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_43get_table_summary, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_summary, __pyx_t_2) < 0) __PYX_ERR(0, 351, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":368
 * 
 * 
 * def get_table_column_names(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_45get_table_column_names, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_column_names, __pyx_t_2) < 0) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":384
 * 
 * 
 * def get_table_column_names_all(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a list of all column names in the table.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_47get_table_column_names_all, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_column_names_all, __pyx_t_2) < 0) __PYX_ERR(0, 384, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":399
 * 
 * 
 * def get_table_column_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get a number of columns in the table.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_49get_table_column_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_column_count, __pyx_t_2) < 0) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":412
 * 
 * 
 * def get_table_column(table_name, column_name):             # <<<<<<<<<<<<<<
 *     """
 *     Get data from the specified table.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_51get_table_column, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 412, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_column, __pyx_t_2) < 0) __PYX_ERR(0, 412, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":485
 * 
 * 
 * def get_table_row_count(table_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return total number of rows in the table.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_53get_table_row_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_row_count, __pyx_t_2) < 0) __PYX_ERR(0, 485, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":492
 * 
 * 
 * def get_table_row_names(table_name, indices):             # <<<<<<<<<<<<<<
 *     """
 *     Return row names for every index (row number) in the list.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_55get_table_row_names, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_table_row_names, __pyx_t_2) < 0) __PYX_ERR(0, 492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":502
 * 
 * 
 * def get_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the original sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_57get_element, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 502, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_element, __pyx_t_2) < 0) __PYX_ERR(0, 502, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":520
 * 
 * 
 * def get_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the original sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_59get_element_index, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_element_index, __pyx_t_2) < 0) __PYX_ERR(0, 520, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":538
 * 
 * 
 * def get_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the original sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_61get_element_index_by_position, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 538, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_element_index_by_position, __pyx_t_2) < 0) __PYX_ERR(0, 538, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":563
 * 
 * 
 * def get_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the original sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_63get_element_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_element_count, __pyx_t_2) < 0) __PYX_ERR(0, 563, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":576
 * 
 * 
 * def get_expanded_element(sequence_name, element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_65get_expanded_element, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_expanded_element, __pyx_t_2) < 0) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":598
 * 
 * 
 * def get_expanded_element_index(sequence_name, element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the expanded sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_67get_expanded_element_index, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_expanded_element_index, __pyx_t_2) < 0) __PYX_ERR(0, 598, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":624
 * 
 * 
 * def get_expanded_element_index_by_position(sequence_name, position):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element at specified position in the expanded sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_69get_expanded_element_index_by_position, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_expanded_element_index_by_po, __pyx_t_2) < 0) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":652
 * 
 * 
 * def get_expanded_element_count(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return number of elements in the expanded sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_71get_expanded_element_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 652, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_expanded_element_count, __pyx_t_2) < 0) __PYX_ERR(0, 652, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":670
 * 
 * 
 * def get_global_element(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return requested element in the expanded sequence.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_73get_global_element, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_global_element, __pyx_t_2) < 0) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":686
 * 
 * 
 * def get_global_element_name(element_index):             # <<<<<<<<<<<<<<
 *     """
 *     Return name of element.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_75get_global_element_name, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 686, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_global_element_name, __pyx_t_2) < 0) __PYX_ERR(0, 686, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":702
 * 
 * 
 * def get_global_element_index(element_name):             # <<<<<<<<<<<<<<
 *     """
 *     Return index of element with specified name in the global element list.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_77get_global_element_index, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_global_element_index, __pyx_t_2) < 0) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":714
 * 
 * 
 * def get_global_element_count():             # <<<<<<<<<<<<<<
 *     """
 *     Return number of globally visible elements.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_79get_global_element_count, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 714, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_global_element_count, __pyx_t_2) < 0) __PYX_ERR(0, 714, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":721
 * 
 * 
 * def is_sequence_expanded(sequence_name):             # <<<<<<<<<<<<<<
 *     """
 *     Check whether a sequence has already been expanded.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_81is_sequence_expanded, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 721, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_sequence_expanded, __pyx_t_2) < 0) __PYX_ERR(0, 721, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":734
 * 
 * 
 * def evaluate(expression):             # <<<<<<<<<<<<<<
 *     """
 *     Evaluates an expression and returns the result as double.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6cpymad_7libmadx_83evaluate, NULL, __pyx_n_s_cpymad_libmadx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_evaluate, __pyx_t_2) < 0) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":771
 * # we want to pass parameters or return values with a pure C type.
 * 
 * _expr_types = [bool, int, float]             # <<<<<<<<<<<<<<
 * 
 * cdef _expr(clib.expression* expr,
 */
  __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject*)&PyBool_Type));
  __Pyx_GIVEREF(((PyObject*)&PyBool_Type));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject*)&PyBool_Type));
  __Pyx_INCREF(((PyObject *)(&PyInt_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyInt_Type)));
  PyList_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type)));
  __Pyx_INCREF(((PyObject *)(&PyFloat_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyFloat_Type)));
  PyList_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyFloat_Type)));
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_expr_types, __pyx_t_2) < 0) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cpymad/libmadx.pyx":775
 * cdef _expr(clib.expression* expr,
 *            double value,
 *            int typeid=clib.PARAM_TYPE_DOUBLE):             # <<<<<<<<<<<<<<
 *     """Return a parameter value with an appropriate type."""
 *     _type = _expr_types[typeid]
 */
  __pyx_k__5 = __pyx_e_6cpymad_8clibmadx_PARAM_TYPE_DOUBLE;

  /* "cpymad/libmadx.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * """
 * Low level cython binding to MAD-X.
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init cpymad.libmadx", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init cpymad.libmadx");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* GetItemInt */
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* GetModuleGlobalName */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

/* PyObjectCallMethO */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
  #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* RaiseArgTupleInvalid */
    static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
    static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
    static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* PyObjectCallNoArg */
    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* SaveResetException */
      #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* PyErrExceptionMatches */
      #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    return PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* PyErrFetchRestore */
      #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* GetException */
      #if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* RaiseException */
        #if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* BytesEquals */
          static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* PyIntBinop */
          #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* WriteUnraisableException */
          static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* RaiseTooManyValuesToUnpack */
          static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
          static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
          static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
          static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* UnicodeEquals */
          static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* SliceObject */
          static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* decode_c_string */
          static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        size_t slen = strlen(cstring);
        if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
            PyErr_SetString(PyExc_OverflowError,
                            "c-string too long to convert to Python");
            return NULL;
        }
        length = (Py_ssize_t) slen;
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    length = stop - start;
    if (unlikely(length <= 0))
        return PyUnicode_FromUnicode(NULL, 0);
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

/* Import */
          static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
          static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CodeObjectCache */
          static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
          #include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntFromPyVerify */
          #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value) {
    const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = (Py_intptr_t) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(Py_intptr_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(Py_intptr_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(Py_intptr_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(Py_intptr_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(Py_intptr_t),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
          static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
          static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CheckBinaryVersion */
          static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* InitStrings */
          static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
