/* --------------------------------------------------- */
/* Automatically generated by mwrap                    */
/* --------------------------------------------------- */

/* Code generated by mwrap 1.1 */
/*
  Copyright statement for mwrap:

  mwrap -- MEX file generation for MATLAB and Octave
  Copyright (c) 2007-2008 David Bindel

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  You may distribute a work that contains part or all of the source code
  generated by mwrap under the terms of your choice.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/

#include <stdio.h>
#include <string.h>
#include <stddef.h>

#include <mex.h>

#if MX_HAS_INTERLEAVED_COMPLEX
#include <matrix.h>
#endif


/*
 * Records for call profile.
 */
int* mexprofrecord_= NULL;


/*
 * Support routines for copying data into and out of the MEX stubs, R2018a
 */

#if MX_HAS_INTERLEAVED_COMPLEX

void* mxWrapGetP(const mxArray* a, const char* fmt, const char** e)
{
    void* p = NULL;
#ifdef R2008OO
    mxArray* ap;
#endif
    if (mxGetClassID(a) == mxDOUBLE_CLASS && mxIsComplex(a) )
    {
        if( mxGetM(a)*mxGetN(a) == 1 && (*mxGetComplexDoubles(a)).real == 0 )
        return NULL;
    }
    if (mxGetClassID(a) == mxDOUBLE_CLASS && !mxIsComplex(a) )
    {
        if( mxGetM(a)*mxGetN(a) == 1 && *mxGetDoubles(a) == 0)
        return NULL;
    }
    if (mxIsChar(a)) {
        char pbuf[128];
        mxGetString(a, pbuf, sizeof(pbuf));
        sscanf(pbuf, fmt, &p);
    } 
#ifdef R2008OO
    else if (ap = mxGetProperty(a, 0, "mwptr")) {
        return mxWrapGetP(ap, fmt, e);
    }
#endif
    if (p == 0)
        *e = "Invalid pointer";
    return p;
}

mxArray* mxWrapCreateP(void* p, const char* fmt)
{
    if (p == 0) {
        mxArray* z = mxCreateDoubleMatrix(1,1, mxREAL);
        *mxGetDoubles(z) = 0;
        return z;
    } else {
        char pbuf[128];
        sprintf(pbuf, fmt, p);
        return mxCreateString(pbuf);
    }
}

mxArray* mxWrapStrncpy(const char* s)
{
    if (s) {
        return mxCreateString(s);
    } else {
        mxArray* z = mxCreateDoubleMatrix(1,1, mxREAL);
        *mxGetDoubles(z) = 0;
        return z;
    }
}

char* mxWrapGetString(const mxArray* a, const char** e)
{
    char* s;
    mwSize slen;
    if (!a || (!mxIsChar(a) && mxGetM(a)*mxGetN(a) > 0)) {
        *e = "Invalid string argument";
        return NULL;
    }
    slen = mxGetM(a)*mxGetN(a) + 1;
    s = (char*) mxMalloc(slen);
    if (mxGetM(a)*mxGetN(a) == 0)
        *s = 0;
    else
        mxGetString(a, s, slen);
    return s;
}


double mxWrapGetScalar(const mxArray* a, const char** e)
{
    if (!a || mxGetClassID(a) != mxDOUBLE_CLASS || mxGetM(a)*mxGetN(a) != 1) {
        *e = "Invalid scalar argument";
        return 0;
    }
    if( mxIsComplex(a) )
      return (double) (*mxGetComplexDoubles(a)).real;
    else
      return (double) (*mxGetDoubles(a));
}

#define mxWrapGetArrayDef(func, T) \
T* func(const mxArray* a, const char** e)     \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    double* q; \
    mxComplexDouble* z; \
    if (!a || mxGetClassID(a) != mxDOUBLE_CLASS) { \
        *e = "Invalid array argument, mxDOUBLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexDoubles(a);	   \
	for (i = 0; i < arraylen; ++i)		\
	  *p++ = (T) (*z++).real;			\
      } \
    else \
      {				   \
	q = mxGetDoubles(a);	   \
	for (i = 0; i < arraylen; ++i)		\
	  *p++ = (T) (*q++);			\
      } \
    return array; \
}


#define mxWrapCopyDef(func, T) \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    double* p;	\
    mxComplexDouble* z; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexDoubles(a);	   \
	for (i = 0; i < n; ++i)		\
	  (*z++).real = (double) *q++;	\
	  (*z++).imag = 0;	\
      } \
    else \
      {				   \
	p = mxGetDoubles(a);	   \
	for (i = 0; i < n; ++i)		\
	  *p++ = (double) *q++;		\
      } \
}


#define mxWrapReturnDef(func, T) \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    double* p; \
    if (!q) { \
        return mxCreateDoubleMatrix(0,0, mxREAL); \
    } else { \
        mxArray* a = mxCreateDoubleMatrix(m,n, mxREAL); \
        p = mxGetDoubles(a); \
        for (i = 0; i < m*n; ++i) \
	  *p++ = (double) *q++;	  \
        return a; \
    } \
}


#define mxWrapGetScalarZDef(func, T, ZT, setz)	\
void func(T* z, const mxArray* a) \
{ \
    if( mxIsComplex(a) ) \
      { \
  setz(z, (ZT) (*mxGetComplexDoubles(a)).real, (ZT) (*mxGetComplexDoubles(a)).imag); \
      } \
    else \
      {				   \
  setz(z, (ZT) (*mxGetComplexDoubles(a)).real, (ZT) 0);	\
      } \
}


#define mxWrapGetArrayZDef(func, T, ZT, setz)      \
T* func(const mxArray* a, const char** e)     \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    double* q; \
    mxComplexDouble* z; \
    if (!a || mxGetClassID(a) != mxDOUBLE_CLASS) { \
        *e = "Invalid array argument, mxDOUBLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexDoubles(a);	   \
	for (i = 0; i < arraylen; ++i) {	\
	  setz(p, (ZT) (*z).real, (ZT) (*z).imag);	\
  	  ++p; ++z; }					\
      } \
    else \
      {				   \
	q = mxGetDoubles(a);	   \
	for (i = 0; i < arraylen; ++i)	{	\
	  setz(p, (ZT) (*q), (ZT) 0 );		\
          ++p; ++q; }			\
      }						\
    return array; \
}


#define mxWrapCopyZDef(func, T, freal, fimag)	    \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    double* p;	\
    mxComplexDouble* z; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexDoubles(a);	   \
	for (i = 0; i < n; ++i)	{		\
          (*z).real = freal(*q);			\
	  (*z).imag = fimag(*q);			\
	  ++z; ++q; 	}			\
      } \
    else \
      {				   \
	p = mxGetDoubles(a);	   \
	for (i = 0; i < n; ++i)		\
	  *p++ = freal(*q++);		\
      } \
}


#define mxWrapReturnZDef(func, T, freal, fimag)	      \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    mxComplexDouble* p; \
    if (!q) { \
        return mxCreateDoubleMatrix(0,0, mxCOMPLEX); \
    } else { \
        mxArray* a = mxCreateDoubleMatrix(m,n, mxCOMPLEX); \
        p = mxGetComplexDoubles(a); \
        for (i = 0; i < m*n; ++i) {	  \
          (*p).real = freal(*q);			\
	  (*p).imag = fimag(*q);			\
	  ++p; ++q; 	}			\
        return a; \
    } \
}






void* mxWrapGetP_single(const mxArray* a, const char* fmt, const char** e)
{
    void* p = NULL;
#ifdef R2008OO
    mxArray* ap;
#endif
    if (mxGetClassID(a) == mxSINGLE_CLASS && mxIsComplex(a) )
    {
        if( mxGetM(a)*mxGetN(a) == 1 && (*mxGetComplexSingles(a)).real == 0 )
        return NULL;
    }
    if (mxGetClassID(a) == mxSINGLE_CLASS && !mxIsComplex(a) )
    {
        if( mxGetM(a)*mxGetN(a) == 1 && *mxGetSingles(a) == 0)
        return NULL;
    }
    if (mxIsChar(a)) {
        char pbuf[128];
        mxGetString(a, pbuf, sizeof(pbuf));
        sscanf(pbuf, fmt, &p);
    } 
#ifdef R2008OO
    else if (ap = mxGetProperty(a, 0, "mwptr")) {
        return mxWrapGetP(ap, fmt, e);
    }
#endif
    if (p == 0)
        *e = "Invalid pointer";
    return p;
}

mxArray* mxWrapCreateP_single(void* p, const char* fmt)
{
    if (p == 0) {
        mxArray* z = mxCreateNumericMatrix(1,1, mxSINGLE_CLASS, mxREAL);
        *mxGetSingles(z) = 0;
        return z;
    } else {
        char pbuf[128];
        sprintf(pbuf, fmt, p);
        return mxCreateString(pbuf);
    }
}

mxArray* mxWrapStrncpy_single(const char* s)
{
    if (s) {
        return mxCreateString(s);
    } else {
        mxArray* z = mxCreateNumericMatrix(1,1, mxSINGLE_CLASS, mxREAL);
        *mxGetSingles(z) = 0;
        return z;
    }
}

char* mxWrapGetString_single(const mxArray* a, const char** e)
{
    char* s;
    mwSize slen;
    if (!a || (!mxIsChar(a) && mxGetM(a)*mxGetN(a) > 0)) {
        *e = "Invalid string argument";
        return NULL;
    }
    slen = mxGetM(a)*mxGetN(a) + 1;
    s = (char*) mxMalloc(slen);
    if (mxGetM(a)*mxGetN(a) == 0)
        *s = 0;
    else
        mxGetString(a, s, slen);
    return s;
}


float mxWrapGetScalar_single(const mxArray* a, const char** e)
{
    if (!a || mxGetClassID(a) != mxSINGLE_CLASS || mxGetM(a)*mxGetN(a) != 1) {
        *e = "Invalid scalar argument";
        return 0;
    }
    if( mxIsComplex(a) )
      return (float) (*mxGetComplexSingles(a)).real;
    else
      return (float) (*mxGetSingles(a));
}

#define mxWrapGetArrayDef_single(func, T) \
T* func(const mxArray* a, const char** e)     \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    float* q; \
    mxComplexSingle* z; \
    if (!a || mxGetClassID(a) != mxSINGLE_CLASS) { \
        *e = "Invalid array argument, mxSINGLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexSingles(a);	   \
	for (i = 0; i < arraylen; ++i)		\
	  *p++ = (T) (*z++).real;			\
      } \
    else \
      {				   \
	q = mxGetSingles(a);	   \
	for (i = 0; i < arraylen; ++i)		\
	  *p++ = (T) (*q++);			\
      } \
    return array; \
}


#define mxWrapCopyDef_single(func, T) \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    float* p;	\
    mxComplexSingle* z; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexSingles(a);	   \
	for (i = 0; i < n; ++i)		\
	  (*z++).real = (float) *q++;	\
	  (*z++).imag = 0;	\
      } \
    else \
      {				   \
	p = mxGetSingles(a);	   \
	for (i = 0; i < n; ++i)		\
	  *p++ = (float) *q++;		\
      } \
}


#define mxWrapReturnDef_single(func, T) \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    float* p; \
    if (!q) { \
        return mxCreateNumericMatrix(0,0, mxSINGLE_CLASS, mxREAL); \
    } else { \
        mxArray* a = mxCreateNumericMatrix(m,n, mxSINGLE_CLASS, mxREAL); \
        p = mxGetSingles(a); \
        for (i = 0; i < m*n; ++i) \
	  *p++ = (float) *q++;	  \
        return a; \
    } \
}


#define mxWrapGetScalarZDef_single(func, T, ZT, setz)	\
void func(T* z, const mxArray* a) \
{ \
    if( mxIsComplex(a) ) \
      { \
  setz(z, (ZT) (*mxGetComplexSingles(a)).real, (ZT) (*mxGetComplexSingles(a)).imag); \
      } \
    else \
      {				   \
  setz(z, (ZT) (*mxGetComplexSingles(a)).real, (ZT) 0);	\
      } \
}


#define mxWrapGetArrayZDef_single(func, T, ZT, setz)      \
T* func(const mxArray* a, const char** e)     \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    float* q; \
    mxComplexSingle* z; \
    if (!a || mxGetClassID(a) != mxSINGLE_CLASS) { \
        *e = "Invalid array argument, mxSINGLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexSingles(a);	   \
	for (i = 0; i < arraylen; ++i) {	\
	  setz(p, (ZT) (*z).real, (ZT) (*z).imag);	\
  	  ++p; ++z; }					\
      } \
    else \
      {				   \
	q = mxGetSingles(a);	   \
	for (i = 0; i < arraylen; ++i)	{	\
	  setz(p, (ZT) (*q), (ZT) 0 );		\
          ++p; ++q; }			\
      }						\
    return array; \
}


#define mxWrapCopyZDef_single(func, T, freal, fimag)	    \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    float* p;	\
    mxComplexSingle* z; \
    if( mxIsComplex(a) ) \
      { \
	z = mxGetComplexSingles(a);	   \
	for (i = 0; i < n; ++i)	{		\
          (*z).real = freal(*q);			\
	  (*z).imag = fimag(*q);			\
	  ++z; ++q; 	}			\
      } \
    else \
      {				   \
	p = mxGetSingles(a);	   \
	for (i = 0; i < n; ++i)		\
	  *p++ = freal(*q++);		\
      } \
}


#define mxWrapReturnZDef_single(func, T, freal, fimag)	      \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    mxComplexSingle* p; \
    if (!q) { \
        return mxCreateNumericMatrix(0,0, mxSINGLE_CLASS, mxCOMPLEX); \
    } else { \
        mxArray* a = mxCreateNumericMatrix(m,n, mxSINGLE_CLASS, mxCOMPLEX); \
        p = mxGetComplexSingles(a); \
        for (i = 0; i < m*n; ++i) {	  \
          (*p).real = freal(*q);			\
	  (*p).imag = fimag(*q);			\
	  ++p; ++q; 	}			\
        return a; \
    } \
}



#else

/*
 * Support routines for copying data into and out of the MEX stubs, -R2017b
 */

void* mxWrapGetP(const mxArray* a, const char* fmt, const char** e)
{
    void* p = 0;
#ifdef R2008OO
    mxArray* ap;
#endif
    if (mxGetClassID(a) == mxDOUBLE_CLASS && 
        mxGetM(a)*mxGetN(a) == 1 && *mxGetPr(a) == 0)
        return p;
    if (mxIsChar(a)) {
        char pbuf[128];
        mxGetString(a, pbuf, sizeof(pbuf));
        sscanf(pbuf, fmt, &p);
    } 
#ifdef R2008OO
    else if (ap = mxGetProperty(a, 0, "mwptr")) {
        return mxWrapGetP(ap, fmt, e);
    }
#endif
    if (p == 0)
        *e = "Invalid pointer";
    return p;
}

mxArray* mxWrapCreateP(void* p, const char* fmt)
{
    if (p == 0) {
        mxArray* z = mxCreateDoubleMatrix(1,1, mxREAL);
        *mxGetPr(z) = 0;
        return z;
    } else {
        char pbuf[128];
        sprintf(pbuf, fmt, p);
        return mxCreateString(pbuf);
    }
}

mxArray* mxWrapStrncpy(const char* s)
{
    if (s) {
        return mxCreateString(s);
    } else {
        mxArray* z = mxCreateDoubleMatrix(1,1, mxREAL);
        *mxGetPr(z) = 0;
        return z;
    }
}

double mxWrapGetScalar(const mxArray* a, const char** e)
{
    if (!a || mxGetClassID(a) != mxDOUBLE_CLASS || mxGetM(a)*mxGetN(a) != 1) {
        *e = "Invalid scalar argument";
        return 0;
    }
    return *mxGetPr(a);
}

char* mxWrapGetString(const mxArray* a, const char** e)
{
    char* s;
    mwSize slen;
    if (!a || (!mxIsChar(a) && mxGetM(a)*mxGetN(a) > 0)) {
        *e = "Invalid string argument";
        return NULL;
    }
    slen = mxGetM(a)*mxGetN(a) + 1;
    s = (char*) mxMalloc(slen);
    if (mxGetM(a)*mxGetN(a) == 0)
        *s = 0;
    else
        mxGetString(a, s, slen);
    return s;
}


#define mxWrapGetArrayDef(func, T) \
T* func(const mxArray* a, const char** e)     \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    double* q; \
    if (!a || mxGetClassID(a) != mxDOUBLE_CLASS) { \
        *e = "Invalid array argument, mxDOUBLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    q = mxGetPr(a); \
    for (i = 0; i < arraylen; ++i) \
        *p++ = (T) (*q++); \
    return array; \
}


#define mxWrapCopyDef(func, T) \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    double* p = mxGetPr(a); \
    for (i = 0; i < n; ++i) \
        *p++ = *q++; \
}


#define mxWrapReturnDef(func, T) \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    double* p; \
    if (!q) { \
        return mxCreateDoubleMatrix(0,0, mxREAL); \
    } else { \
        mxArray* a = mxCreateDoubleMatrix(m,n, mxREAL); \
        p = mxGetPr(a); \
        for (i = 0; i < m*n; ++i) \
            *p++ = *q++; \
        return a; \
    } \
}


#define mxWrapGetScalarZDef(func, T, ZT, setz) \
void func(T* z, const mxArray* a) \
{ \
    double* pr = mxGetPr(a); \
    double* pi = mxGetPi(a); \
    setz(z, (ZT) *pr, (pi ? (ZT) *pi : (ZT) 0)); \
}


#define mxWrapGetArrayZDef(func, T, ZT, setz) \
T* func(const mxArray* a, const char** e) \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    double* qr; \
    double* qi; \
    if (!a || mxGetClassID(a) != mxDOUBLE_CLASS) { \
        *e = "Invalid array argument, mxDOUBLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    qr = mxGetPr(a); \
    qi = mxGetPi(a); \
    for (i = 0; i < arraylen; ++i) { \
        ZT val_qr = *qr++; \
        ZT val_qi = (qi ? (ZT) *qi++ : (ZT) 0); \
        setz(p, val_qr, val_qi); \
        ++p; \
    } \
    return array; \
}


#define mxWrapCopyZDef(func, T, real, imag) \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    double* pr = mxGetPr(a); \
    double* pi = mxGetPi(a); \
    for (i = 0; i < n; ++i) { \
        *pr++ = real(*q); \
        *pi++ = imag(*q); \
        ++q; \
    } \
}


#define mxWrapReturnZDef(func, T, real, imag) \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    double* pr; \
    double* pi; \
    if (!q) { \
        return mxCreateDoubleMatrix(0,0, mxCOMPLEX); \
    } else { \
        mxArray* a = mxCreateDoubleMatrix(m,n, mxCOMPLEX); \
        pr = mxGetPr(a); \
        pi = mxGetPi(a); \
        for (i = 0; i < m*n; ++i) { \
            *pr++ = real(*q); \
            *pi++ = imag(*q); \
            ++q; \
        } \
        return a; \
    } \
}






void* mxWrapGetP_single(const mxArray* a, const char* fmt, const char** e)
{
    void* p = 0;
#ifdef R2008OO
    mxArray* ap;
#endif
    if (mxGetClassID(a) == mxSINGLE_CLASS && 
        mxGetM(a)*mxGetN(a) == 1 && *((float*)mxGetData(a)) == 0)
        return p;
    if (mxIsChar(a)) {
        char pbuf[128];
        mxGetString(a, pbuf, sizeof(pbuf));
        sscanf(pbuf, fmt, &p);
    } 
#ifdef R2008OO
    else if (ap = mxGetProperty(a, 0, "mwptr")) {
        return mxWrapGetP(ap, fmt, e);
    }
#endif
    if (p == 0)
        *e = "Invalid pointer";
    return p;
}

mxArray* mxWrapCreateP_single(void* p, const char* fmt)
{
    if (p == 0) {
        mxArray* z = mxCreateNumericMatrix(1,1, mxSINGLE_CLASS, mxREAL);
        *((float*)mxGetData(z)) = 0;
        return z;
    } else {
        char pbuf[128];
        sprintf(pbuf, fmt, p);
        return mxCreateString(pbuf);
    }
}
mxArray* mxWrapStrncpy_single(const char* s)
{
    if (s) {
        return mxCreateString(s);
    } else {
        mxArray* z = mxCreateNumericMatrix(1,1, mxSINGLE_CLASS, mxREAL);
        *((float*)mxGetData(z)) = 0;
        return z;
    }
}

float mxWrapGetScalar_single(const mxArray* a, const char** e)
{
    if (!a || mxGetClassID(a) != mxSINGLE_CLASS || mxGetM(a)*mxGetN(a) != 1) {
        *e = "Invalid scalar argument";
        return 0;
    }
    return *((float*)mxGetData(a));
}

char* mxWrapGetString_single(const mxArray* a, const char** e)
{
    char* s;
    mwSize slen;
    if (!a || (!mxIsChar(a) && mxGetM(a)*mxGetN(a) > 0)) {
        *e = "Invalid string argument, mxSINGLE_CLASS expected";
        return NULL;
    }
    slen = mxGetM(a)*mxGetN(a) + 1;
    s = (char*) mxMalloc(slen);
    if (mxGetM(a)*mxGetN(a) == 0)
        *s = 0;
    else
        mxGetString(a, s, slen);
    return s;
}


#define mxWrapGetArrayDef_single(func, T) \
T* func(const mxArray* a, const char** e)     \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    float* q; \
    if (!a || mxGetClassID(a) != mxSINGLE_CLASS) { \
        *e = "Invalid array argument, mxSINGLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    q = (float*) mxGetData(a);	   \
    for (i = 0; i < arraylen; ++i) \
        *p++ = (T) (*q++); \
    return array; \
}


#define mxWrapCopyDef_single(func, T) \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    float* p = (float*) mxGetData(a);		\
    for (i = 0; i < n; ++i) \
        *p++ = *q++; \
}


#define mxWrapReturnDef_single(func, T) \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    float* p; \
    if (!q) { \
      return mxCreateNumericMatrix(0,0, mxSINGLE_CLASS, mxREAL); \
    } else { \
        mxArray* a = mxCreateNumericMatrix(m,n, mxSINGLE_CLASS, mxREAL);\
        p = (float*) mxGetData(a);				\
        for (i = 0; i < m*n; ++i) \
            *p++ = *q++; \
        return a; \
    } \
}


#define mxWrapGetScalarZDef_single(func, T, ZT, setz) \
void func(T* z, const mxArray* a) \
{ \
    float* pr = (float*) mxGetData(a);		\
    float* pi = (float*) mxGetImagData(a);		 \
    setz(z, (ZT) *pr, (pi ? (ZT) *pi : (ZT) 0)); \
}


#define mxWrapGetArrayZDef_single(func, T, ZT, setz) \
T* func(const mxArray* a, const char** e) \
{ \
    T* array; \
    mwSize arraylen; \
    mwIndex i; \
    T* p; \
    float* qr; \
    float* qi; \
    if (!a || mxGetClassID(a) != mxSINGLE_CLASS) { \
        *e = "Invalid array argument, mxSINGLE_CLASS expected"; \
        return 0; \
    } \
    arraylen = mxGetM(a)*mxGetN(a); \
    array = (T*) mxMalloc(mxGetM(a)*mxGetN(a) * sizeof(T)); \
    p = array; \
    qr = (float*) mxGetData(a);			\
    qi = (float*) mxGetImagData(a);			\
    for (i = 0; i < arraylen; ++i) { \
        ZT val_qr = *qr++; \
        ZT val_qi = (qi ? (ZT) *qi++ : (ZT) 0); \
        setz(p, val_qr, val_qi); \
        ++p; \
    } \
    return array; \
}


#define mxWrapCopyZDef_single(func, T, real, imag) \
void func(mxArray* a, const T* q, mwSize n) \
{ \
    mwIndex i; \
    float* pr = (float*) mxGetData(a);		\
    float* pi = (float*) mxGetImagData(a);		\
    for (i = 0; i < n; ++i) { \
        *pr++ = real(*q); \
        *pi++ = imag(*q); \
        ++q; \
    } \
}


#define mxWrapReturnZDef_single(func, T, real, imag) \
mxArray* func(const T* q, mwSize m, mwSize n) \
{ \
    mwIndex i; \
    float* pr; \
    float* pi; \
    if (!q) { \
      return mxCreateNumericMatrix(0,0, mxSINGLE_CLASS, mxCOMPLEX); \
    } else { \
        mxArray* a = mxCreateNumericMatrix(m,n, mxSINGLE_CLASS, mxCOMPLEX);\
        pr = (float*) mxGetData(a);					\
        pi = (float*) mxGetImagData(a);					\
        for (i = 0; i < m*n; ++i) { \
            *pr++ = real(*q); \
            *pi++ = imag(*q); \
            ++q; \
        } \
        return a; \
    } \
}





#endif

#include <complex.h>

typedef _Complex double dcomplex;
#define real_dcomplex(z) creal(z)
#define imag_dcomplex(z) cimag(z)
#define setz_dcomplex(z,r,i)  *z = r + i*_Complex_I

typedef _Complex float fcomplex;
#define real_fcomplex(z) crealf(z)
#define imag_fcomplex(z) cimagf(z)
#define setz_fcomplex(z,r,i)  *z = r + i*_Complex_I




/* Array copier definitions */
mxWrapGetArrayDef(mxWrapGetArray_bool, bool)
mxWrapCopyDef    (mxWrapCopy_bool,     bool)
mxWrapReturnDef  (mxWrapReturn_bool,   bool)
mxWrapGetArrayDef_single(mxWrapGetArray_single_bool, bool)
mxWrapCopyDef_single    (mxWrapCopy_single_bool,     bool)
mxWrapReturnDef_single  (mxWrapReturn_single_bool,   bool)
mxWrapGetArrayDef(mxWrapGetArray_char, char)
mxWrapCopyDef    (mxWrapCopy_char,     char)
mxWrapReturnDef  (mxWrapReturn_char,   char)
mxWrapGetArrayDef_single(mxWrapGetArray_single_char, char)
mxWrapCopyDef_single    (mxWrapCopy_single_char,     char)
mxWrapReturnDef_single  (mxWrapReturn_single_char,   char)
mxWrapGetArrayDef(mxWrapGetArray_double, double)
mxWrapCopyDef    (mxWrapCopy_double,     double)
mxWrapReturnDef  (mxWrapReturn_double,   double)
mxWrapGetArrayDef_single(mxWrapGetArray_single_double, double)
mxWrapCopyDef_single    (mxWrapCopy_single_double,     double)
mxWrapReturnDef_single  (mxWrapReturn_single_double,   double)
mxWrapGetArrayDef(mxWrapGetArray_float, float)
mxWrapCopyDef    (mxWrapCopy_float,     float)
mxWrapReturnDef  (mxWrapReturn_float,   float)
mxWrapGetArrayDef_single(mxWrapGetArray_single_float, float)
mxWrapCopyDef_single    (mxWrapCopy_single_float,     float)
mxWrapReturnDef_single  (mxWrapReturn_single_float,   float)
mxWrapGetArrayDef(mxWrapGetArray_int, int)
mxWrapCopyDef    (mxWrapCopy_int,     int)
mxWrapReturnDef  (mxWrapReturn_int,   int)
mxWrapGetArrayDef_single(mxWrapGetArray_single_int, int)
mxWrapCopyDef_single    (mxWrapCopy_single_int,     int)
mxWrapReturnDef_single  (mxWrapReturn_single_int,   int)
mxWrapGetArrayDef(mxWrapGetArray_int64_t, int64_t)
mxWrapCopyDef    (mxWrapCopy_int64_t,     int64_t)
mxWrapReturnDef  (mxWrapReturn_int64_t,   int64_t)
mxWrapGetArrayDef_single(mxWrapGetArray_single_int64_t, int64_t)
mxWrapCopyDef_single    (mxWrapCopy_single_int64_t,     int64_t)
mxWrapReturnDef_single  (mxWrapReturn_single_int64_t,   int64_t)
mxWrapGetArrayDef(mxWrapGetArray_long, long)
mxWrapCopyDef    (mxWrapCopy_long,     long)
mxWrapReturnDef  (mxWrapReturn_long,   long)
mxWrapGetArrayDef_single(mxWrapGetArray_single_long, long)
mxWrapCopyDef_single    (mxWrapCopy_single_long,     long)
mxWrapReturnDef_single  (mxWrapReturn_single_long,   long)
mxWrapGetArrayDef(mxWrapGetArray_ptrdiff_t, ptrdiff_t)
mxWrapCopyDef    (mxWrapCopy_ptrdiff_t,     ptrdiff_t)
mxWrapReturnDef  (mxWrapReturn_ptrdiff_t,   ptrdiff_t)
mxWrapGetArrayDef_single(mxWrapGetArray_single_ptrdiff_t, ptrdiff_t)
mxWrapCopyDef_single    (mxWrapCopy_single_ptrdiff_t,     ptrdiff_t)
mxWrapReturnDef_single  (mxWrapReturn_single_ptrdiff_t,   ptrdiff_t)
mxWrapGetArrayDef(mxWrapGetArray_short, short)
mxWrapCopyDef    (mxWrapCopy_short,     short)
mxWrapReturnDef  (mxWrapReturn_short,   short)
mxWrapGetArrayDef_single(mxWrapGetArray_single_short, short)
mxWrapCopyDef_single    (mxWrapCopy_single_short,     short)
mxWrapReturnDef_single  (mxWrapReturn_single_short,   short)
mxWrapGetArrayDef(mxWrapGetArray_size_t, size_t)
mxWrapCopyDef    (mxWrapCopy_size_t,     size_t)
mxWrapReturnDef  (mxWrapReturn_size_t,   size_t)
mxWrapGetArrayDef_single(mxWrapGetArray_single_size_t, size_t)
mxWrapCopyDef_single    (mxWrapCopy_single_size_t,     size_t)
mxWrapReturnDef_single  (mxWrapReturn_single_size_t,   size_t)
mxWrapGetScalarZDef(mxWrapGetScalar_fcomplex, fcomplex,
                    float, setz_fcomplex)
mxWrapGetArrayZDef (mxWrapGetArray_fcomplex, fcomplex,
                    float, setz_fcomplex)
mxWrapCopyZDef     (mxWrapCopy_fcomplex, fcomplex,
                    real_fcomplex, imag_fcomplex)
mxWrapReturnZDef   (mxWrapReturn_fcomplex, fcomplex,
                    real_fcomplex, imag_fcomplex)
mxWrapGetScalarZDef_single(mxWrapGetScalar_single_fcomplex, fcomplex,
                    float, setz_fcomplex)
mxWrapGetArrayZDef_single (mxWrapGetArray_single_fcomplex, fcomplex,
                    float, setz_fcomplex)
mxWrapCopyZDef_single     (mxWrapCopy_single_fcomplex, fcomplex,
                    real_fcomplex, imag_fcomplex)
mxWrapReturnZDef_single   (mxWrapReturn_single_fcomplex, fcomplex,
                    real_fcomplex, imag_fcomplex)
mxWrapGetScalarZDef(mxWrapGetScalar_dcomplex, dcomplex,
                    double, setz_dcomplex)
mxWrapGetArrayZDef (mxWrapGetArray_dcomplex, dcomplex,
                    double, setz_dcomplex)
mxWrapCopyZDef     (mxWrapCopy_dcomplex, dcomplex,
                    real_dcomplex, imag_dcomplex)
mxWrapReturnZDef   (mxWrapReturn_dcomplex, dcomplex,
                    real_dcomplex, imag_dcomplex)
mxWrapGetScalarZDef_single(mxWrapGetScalar_single_dcomplex, dcomplex,
                    double, setz_dcomplex)
mxWrapGetArrayZDef_single (mxWrapGetArray_single_dcomplex, dcomplex,
                    double, setz_dcomplex)
mxWrapCopyZDef_single     (mxWrapCopy_single_dcomplex, dcomplex,
                    real_dcomplex, imag_dcomplex)
mxWrapReturnZDef_single   (mxWrapReturn_single_dcomplex, dcomplex,
                    real_dcomplex, imag_dcomplex)

#if defined(MWF77_CAPS)
#define MWF77_hfmm3dpartself HFMM3DPARTSELF
#define MWF77_hfmm3dparttarg HFMM3DPARTTARG
#define MWF77_h3dpartdirect H3DPARTDIRECT
#define MWF77_lfmm3dpartself LFMM3DPARTSELF
#define MWF77_lfmm3dparttarg LFMM3DPARTTARG
#define MWF77_l3dpartdirect L3DPARTDIRECT
#elif defined(MWF77_UNDERSCORE1)
#define MWF77_hfmm3dpartself hfmm3dpartself_
#define MWF77_hfmm3dparttarg hfmm3dparttarg_
#define MWF77_h3dpartdirect h3dpartdirect_
#define MWF77_lfmm3dpartself lfmm3dpartself_
#define MWF77_lfmm3dparttarg lfmm3dparttarg_
#define MWF77_l3dpartdirect l3dpartdirect_
#elif defined(MWF77_UNDERSCORE0)
#define MWF77_hfmm3dpartself hfmm3dpartself
#define MWF77_hfmm3dparttarg hfmm3dparttarg
#define MWF77_h3dpartdirect h3dpartdirect
#define MWF77_lfmm3dpartself lfmm3dpartself
#define MWF77_lfmm3dparttarg lfmm3dparttarg
#define MWF77_l3dpartdirect l3dpartdirect
#else /* f2c convention */
#define MWF77_hfmm3dpartself hfmm3dpartself_
#define MWF77_hfmm3dparttarg hfmm3dparttarg_
#define MWF77_h3dpartdirect h3dpartdirect_
#define MWF77_lfmm3dpartself lfmm3dpartself_
#define MWF77_lfmm3dparttarg lfmm3dparttarg_
#define MWF77_l3dpartdirect l3dpartdirect_
#endif

#ifdef __cplusplus
extern "C" { /* Prevent C++ name mangling */
#endif

#ifndef MWF77_RETURN
#define MWF77_RETURN int
#endif

MWF77_RETURN MWF77_hfmm3dpartself(int64_t*, int64_t*, dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*);
MWF77_RETURN MWF77_hfmm3dparttarg(int64_t*, int64_t*, dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*);
MWF77_RETURN MWF77_h3dpartdirect(dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*);
MWF77_RETURN MWF77_lfmm3dpartself(int64_t*, int64_t*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*);
MWF77_RETURN MWF77_lfmm3dparttarg(int64_t*, int64_t*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*);
MWF77_RETURN MWF77_l3dpartdirect(int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*, int64_t*, double*, int64_t*, dcomplex*, int64_t*, dcomplex*);

#ifdef __cplusplus
} /* end extern C */
#endif

/* ---- fmm3d_legacy.mw: 121 ----
 * hfmm3dpartself(inout int64_t[1] ier, int64_t[1] iprec, dcomplex[1] zk, int64_t[1] nsource, double[3, nsource] source, int64_t[1] ifcharge, dcomplex[] charge, int64_t[1] ifdipole, dcomplex[] dipstr, double[3, nsource] dipvec, int64_t[1] ifpot, inout dcomplex[] pot, int64_t[1] iffld, inout dcomplex[] fld);
 */
static const char* stubids1_ = "hfmm3dpartself(io int64_t[x], i int64_t[x], i dcomplex[x], i int64_t[x], i double[xx], i int64_t[x], i dcomplex[], i int64_t[x], i dcomplex[], i double[xx], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[])";

void mexStub1(int nlhs, mxArray* plhs[],
              int nrhs, const mxArray* prhs[])
{
    const char* mw_err_txt_ = 0;
    int64_t*    in0_ =0; /* ier        */
    int64_t*    in1_ =0; /* iprec      */
    dcomplex*   in2_ =0; /* zk         */
    int64_t*    in3_ =0; /* nsource    */
    double*     in4_ =0; /* source     */
    int64_t*    in5_ =0; /* ifcharge   */
    dcomplex*   in6_ =0; /* charge     */
    int64_t*    in7_ =0; /* ifdipole   */
    dcomplex*   in8_ =0; /* dipstr     */
    double*     in9_ =0; /* dipvec     */
    int64_t*    in10_ =0; /* ifpot      */
    dcomplex*   in11_ =0; /* pot        */
    int64_t*    in12_ =0; /* iffld      */
    dcomplex*   in13_ =0; /* fld        */
    mwSize      dim14_;   /* 1          */
    mwSize      dim15_;   /* 1          */
    mwSize      dim16_;   /* 1          */
    mwSize      dim17_;   /* 1          */
    mwSize      dim18_;   /* 3          */
    mwSize      dim19_;   /* nsource    */
    mwSize      dim20_;   /* 1          */
    mwSize      dim21_;   /* 1          */
    mwSize      dim22_;   /* 3          */
    mwSize      dim23_;   /* nsource    */
    mwSize      dim24_;   /* 1          */
    mwSize      dim25_;   /* 1          */

    dim14_ = (mwSize) mxWrapGetScalar(prhs[14], &mw_err_txt_);
    dim15_ = (mwSize) mxWrapGetScalar(prhs[15], &mw_err_txt_);
    dim16_ = (mwSize) mxWrapGetScalar(prhs[16], &mw_err_txt_);
    dim17_ = (mwSize) mxWrapGetScalar(prhs[17], &mw_err_txt_);
    dim18_ = (mwSize) mxWrapGetScalar(prhs[18], &mw_err_txt_);
    dim19_ = (mwSize) mxWrapGetScalar(prhs[19], &mw_err_txt_);
    dim20_ = (mwSize) mxWrapGetScalar(prhs[20], &mw_err_txt_);
    dim21_ = (mwSize) mxWrapGetScalar(prhs[21], &mw_err_txt_);
    dim22_ = (mwSize) mxWrapGetScalar(prhs[22], &mw_err_txt_);
    dim23_ = (mwSize) mxWrapGetScalar(prhs[23], &mw_err_txt_);
    dim24_ = (mwSize) mxWrapGetScalar(prhs[24], &mw_err_txt_);
    dim25_ = (mwSize) mxWrapGetScalar(prhs[25], &mw_err_txt_);

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != dim14_) {
        mw_err_txt_ = "Bad argument size: ier";        goto mw_err_label;
    }

    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != dim15_) {
        mw_err_txt_ = "Bad argument size: iprec";        goto mw_err_label;
    }

    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != dim16_) {
        mw_err_txt_ = "Bad argument size: zk";        goto mw_err_label;
    }

    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != dim17_) {
        mw_err_txt_ = "Bad argument size: nsource";        goto mw_err_label;
    }

    if (mxGetM(prhs[4]) != dim18_ ||
        mxGetN(prhs[4]) != dim19_) {
        mw_err_txt_ = "Bad argument size: source";
        goto mw_err_label;
    }

    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != dim20_) {
        mw_err_txt_ = "Bad argument size: ifcharge";        goto mw_err_label;
    }

    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != dim21_) {
        mw_err_txt_ = "Bad argument size: ifdipole";        goto mw_err_label;
    }

    if (mxGetM(prhs[9]) != dim22_ ||
        mxGetN(prhs[9]) != dim23_) {
        mw_err_txt_ = "Bad argument size: dipvec";
        goto mw_err_label;
    }

    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != dim24_) {
        mw_err_txt_ = "Bad argument size: ifpot";        goto mw_err_label;
    }

    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != dim25_) {
        mw_err_txt_ = "Bad argument size: iffld";        goto mw_err_label;
    }

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != 0) {
        in0_ = mxWrapGetArray_int64_t(prhs[0], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in0_ = NULL;
    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 0) {
        in1_ = mxWrapGetArray_int64_t(prhs[1], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in1_ = NULL;
    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != 0) {
        if( mxGetClassID(prhs[2]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in2_ = mxWrapGetArray_dcomplex(prhs[2], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in2_ = NULL;
    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 0) {
        in3_ = mxWrapGetArray_int64_t(prhs[3], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in3_ = NULL;
    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != 0) {
        if( mxGetClassID(prhs[4]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in4_ = mxGetDoubles(prhs[4]);
#else
        in4_ = mxGetPr(prhs[4]);
#endif
    } else
        in4_ = NULL;
    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != 0) {
        in5_ = mxWrapGetArray_int64_t(prhs[5], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in5_ = NULL;
    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != 0) {
        if( mxGetClassID(prhs[6]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in6_ = mxWrapGetArray_dcomplex(prhs[6], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in6_ = NULL;
    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != 0) {
        in7_ = mxWrapGetArray_int64_t(prhs[7], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in7_ = NULL;
    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != 0) {
        if( mxGetClassID(prhs[8]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in8_ = mxWrapGetArray_dcomplex(prhs[8], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in8_ = NULL;
    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != 0) {
        if( mxGetClassID(prhs[9]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in9_ = mxGetDoubles(prhs[9]);
#else
        in9_ = mxGetPr(prhs[9]);
#endif
    } else
        in9_ = NULL;
    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != 0) {
        in10_ = mxWrapGetArray_int64_t(prhs[10], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in10_ = NULL;
    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != 0) {
        if( mxGetClassID(prhs[11]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in11_ = mxWrapGetArray_dcomplex(prhs[11], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in11_ = NULL;
    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != 0) {
        in12_ = mxWrapGetArray_int64_t(prhs[12], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in12_ = NULL;
    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != 0) {
        if( mxGetClassID(prhs[13]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in13_ = mxWrapGetArray_dcomplex(prhs[13], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in13_ = NULL;
    if (mexprofrecord_)
        mexprofrecord_[1]++;
    MWF77_hfmm3dpartself(in0_, in1_, in2_, in3_, in4_, in5_, in6_, in7_, in8_, in9_, in10_, in11_, in12_, in13_);
    plhs[0] = mxCreateDoubleMatrix(dim14_, 1, mxREAL);
    mxWrapCopy_int64_t(plhs[0], in0_, dim14_);
    plhs[1] = mxCreateDoubleMatrix(mxGetM(prhs[11]), mxGetN(prhs[11]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[1], in11_, mxGetM(prhs[11])*mxGetN(prhs[11]));
    plhs[2] = mxCreateDoubleMatrix(mxGetM(prhs[13]), mxGetN(prhs[13]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[2], in13_, mxGetM(prhs[13])*mxGetN(prhs[13]));

mw_err_label:
    if (in0_)  mxFree(in0_);
    if (in1_)  mxFree(in1_);
    if (in2_)  mxFree(in2_);
    if (in3_)  mxFree(in3_);
    if (in5_)  mxFree(in5_);
    if (in6_)  mxFree(in6_);
    if (in7_)  mxFree(in7_);
    if (in8_)  mxFree(in8_);
    if (in10_)  mxFree(in10_);
    if (in11_)  mxFree(in11_);
    if (in12_)  mxFree(in12_);
    if (in13_)  mxFree(in13_);
    if (mw_err_txt_)
        mexErrMsgTxt(mw_err_txt_);
}

/* ---- fmm3d_legacy.mw: 123 ----
 * hfmm3dparttarg(inout int64_t[1] ier, int64_t[1] iprec, dcomplex[1] zk, int64_t[1] nsource, double[3, nsource] source, int64_t[1] ifcharge, dcomplex[] charge, int64_t[1] ifdipole, dcomplex[] dipstr, double[3, nsource] dipvec, int64_t[1] ifpot, inout dcomplex[] pot, int64_t[1] iffld, inout dcomplex[] fld, int64_t[1] ntarg, double[] targ, int64_t[1] ifpottarg, inout dcomplex[] pottarg, int64_t[1] iffldtarg, inout dcomplex[] fldtarg);
 */
static const char* stubids2_ = "hfmm3dparttarg(io int64_t[x], i int64_t[x], i dcomplex[x], i int64_t[x], i double[xx], i int64_t[x], i dcomplex[], i int64_t[x], i dcomplex[], i double[xx], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[], i int64_t[x], i double[], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[])";

void mexStub2(int nlhs, mxArray* plhs[],
              int nrhs, const mxArray* prhs[])
{
    const char* mw_err_txt_ = 0;
    int64_t*    in0_ =0; /* ier        */
    int64_t*    in1_ =0; /* iprec      */
    dcomplex*   in2_ =0; /* zk         */
    int64_t*    in3_ =0; /* nsource    */
    double*     in4_ =0; /* source     */
    int64_t*    in5_ =0; /* ifcharge   */
    dcomplex*   in6_ =0; /* charge     */
    int64_t*    in7_ =0; /* ifdipole   */
    dcomplex*   in8_ =0; /* dipstr     */
    double*     in9_ =0; /* dipvec     */
    int64_t*    in10_ =0; /* ifpot      */
    dcomplex*   in11_ =0; /* pot        */
    int64_t*    in12_ =0; /* iffld      */
    dcomplex*   in13_ =0; /* fld        */
    int64_t*    in14_ =0; /* ntarg      */
    double*     in15_ =0; /* targ       */
    int64_t*    in16_ =0; /* ifpottarg  */
    dcomplex*   in17_ =0; /* pottarg    */
    int64_t*    in18_ =0; /* iffldtarg  */
    dcomplex*   in19_ =0; /* fldtarg    */
    mwSize      dim20_;   /* 1          */
    mwSize      dim21_;   /* 1          */
    mwSize      dim22_;   /* 1          */
    mwSize      dim23_;   /* 1          */
    mwSize      dim24_;   /* 3          */
    mwSize      dim25_;   /* nsource    */
    mwSize      dim26_;   /* 1          */
    mwSize      dim27_;   /* 1          */
    mwSize      dim28_;   /* 3          */
    mwSize      dim29_;   /* nsource    */
    mwSize      dim30_;   /* 1          */
    mwSize      dim31_;   /* 1          */
    mwSize      dim32_;   /* 1          */
    mwSize      dim33_;   /* 1          */
    mwSize      dim34_;   /* 1          */

    dim20_ = (mwSize) mxWrapGetScalar(prhs[20], &mw_err_txt_);
    dim21_ = (mwSize) mxWrapGetScalar(prhs[21], &mw_err_txt_);
    dim22_ = (mwSize) mxWrapGetScalar(prhs[22], &mw_err_txt_);
    dim23_ = (mwSize) mxWrapGetScalar(prhs[23], &mw_err_txt_);
    dim24_ = (mwSize) mxWrapGetScalar(prhs[24], &mw_err_txt_);
    dim25_ = (mwSize) mxWrapGetScalar(prhs[25], &mw_err_txt_);
    dim26_ = (mwSize) mxWrapGetScalar(prhs[26], &mw_err_txt_);
    dim27_ = (mwSize) mxWrapGetScalar(prhs[27], &mw_err_txt_);
    dim28_ = (mwSize) mxWrapGetScalar(prhs[28], &mw_err_txt_);
    dim29_ = (mwSize) mxWrapGetScalar(prhs[29], &mw_err_txt_);
    dim30_ = (mwSize) mxWrapGetScalar(prhs[30], &mw_err_txt_);
    dim31_ = (mwSize) mxWrapGetScalar(prhs[31], &mw_err_txt_);
    dim32_ = (mwSize) mxWrapGetScalar(prhs[32], &mw_err_txt_);
    dim33_ = (mwSize) mxWrapGetScalar(prhs[33], &mw_err_txt_);
    dim34_ = (mwSize) mxWrapGetScalar(prhs[34], &mw_err_txt_);

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != dim20_) {
        mw_err_txt_ = "Bad argument size: ier";        goto mw_err_label;
    }

    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != dim21_) {
        mw_err_txt_ = "Bad argument size: iprec";        goto mw_err_label;
    }

    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != dim22_) {
        mw_err_txt_ = "Bad argument size: zk";        goto mw_err_label;
    }

    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != dim23_) {
        mw_err_txt_ = "Bad argument size: nsource";        goto mw_err_label;
    }

    if (mxGetM(prhs[4]) != dim24_ ||
        mxGetN(prhs[4]) != dim25_) {
        mw_err_txt_ = "Bad argument size: source";
        goto mw_err_label;
    }

    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != dim26_) {
        mw_err_txt_ = "Bad argument size: ifcharge";        goto mw_err_label;
    }

    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != dim27_) {
        mw_err_txt_ = "Bad argument size: ifdipole";        goto mw_err_label;
    }

    if (mxGetM(prhs[9]) != dim28_ ||
        mxGetN(prhs[9]) != dim29_) {
        mw_err_txt_ = "Bad argument size: dipvec";
        goto mw_err_label;
    }

    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != dim30_) {
        mw_err_txt_ = "Bad argument size: ifpot";        goto mw_err_label;
    }

    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != dim31_) {
        mw_err_txt_ = "Bad argument size: iffld";        goto mw_err_label;
    }

    if (mxGetM(prhs[14])*mxGetN(prhs[14]) != dim32_) {
        mw_err_txt_ = "Bad argument size: ntarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[16])*mxGetN(prhs[16]) != dim33_) {
        mw_err_txt_ = "Bad argument size: ifpottarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[18])*mxGetN(prhs[18]) != dim34_) {
        mw_err_txt_ = "Bad argument size: iffldtarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != 0) {
        in0_ = mxWrapGetArray_int64_t(prhs[0], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in0_ = NULL;
    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 0) {
        in1_ = mxWrapGetArray_int64_t(prhs[1], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in1_ = NULL;
    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != 0) {
        if( mxGetClassID(prhs[2]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in2_ = mxWrapGetArray_dcomplex(prhs[2], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in2_ = NULL;
    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 0) {
        in3_ = mxWrapGetArray_int64_t(prhs[3], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in3_ = NULL;
    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != 0) {
        if( mxGetClassID(prhs[4]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in4_ = mxGetDoubles(prhs[4]);
#else
        in4_ = mxGetPr(prhs[4]);
#endif
    } else
        in4_ = NULL;
    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != 0) {
        in5_ = mxWrapGetArray_int64_t(prhs[5], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in5_ = NULL;
    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != 0) {
        if( mxGetClassID(prhs[6]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in6_ = mxWrapGetArray_dcomplex(prhs[6], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in6_ = NULL;
    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != 0) {
        in7_ = mxWrapGetArray_int64_t(prhs[7], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in7_ = NULL;
    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != 0) {
        if( mxGetClassID(prhs[8]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in8_ = mxWrapGetArray_dcomplex(prhs[8], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in8_ = NULL;
    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != 0) {
        if( mxGetClassID(prhs[9]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in9_ = mxGetDoubles(prhs[9]);
#else
        in9_ = mxGetPr(prhs[9]);
#endif
    } else
        in9_ = NULL;
    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != 0) {
        in10_ = mxWrapGetArray_int64_t(prhs[10], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in10_ = NULL;
    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != 0) {
        if( mxGetClassID(prhs[11]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in11_ = mxWrapGetArray_dcomplex(prhs[11], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in11_ = NULL;
    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != 0) {
        in12_ = mxWrapGetArray_int64_t(prhs[12], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in12_ = NULL;
    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != 0) {
        if( mxGetClassID(prhs[13]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in13_ = mxWrapGetArray_dcomplex(prhs[13], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in13_ = NULL;
    if (mxGetM(prhs[14])*mxGetN(prhs[14]) != 0) {
        in14_ = mxWrapGetArray_int64_t(prhs[14], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in14_ = NULL;
    if (mxGetM(prhs[15])*mxGetN(prhs[15]) != 0) {
        if( mxGetClassID(prhs[15]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in15_ = mxGetDoubles(prhs[15]);
#else
        in15_ = mxGetPr(prhs[15]);
#endif
    } else
        in15_ = NULL;
    if (mxGetM(prhs[16])*mxGetN(prhs[16]) != 0) {
        in16_ = mxWrapGetArray_int64_t(prhs[16], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in16_ = NULL;
    if (mxGetM(prhs[17])*mxGetN(prhs[17]) != 0) {
        if( mxGetClassID(prhs[17]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in17_ = mxWrapGetArray_dcomplex(prhs[17], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in17_ = NULL;
    if (mxGetM(prhs[18])*mxGetN(prhs[18]) != 0) {
        in18_ = mxWrapGetArray_int64_t(prhs[18], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in18_ = NULL;
    if (mxGetM(prhs[19])*mxGetN(prhs[19]) != 0) {
        if( mxGetClassID(prhs[19]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in19_ = mxWrapGetArray_dcomplex(prhs[19], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in19_ = NULL;
    if (mexprofrecord_)
        mexprofrecord_[2]++;
    MWF77_hfmm3dparttarg(in0_, in1_, in2_, in3_, in4_, in5_, in6_, in7_, in8_, in9_, in10_, in11_, in12_, in13_, in14_, in15_, in16_, in17_, in18_, in19_);
    plhs[0] = mxCreateDoubleMatrix(dim20_, 1, mxREAL);
    mxWrapCopy_int64_t(plhs[0], in0_, dim20_);
    plhs[1] = mxCreateDoubleMatrix(mxGetM(prhs[11]), mxGetN(prhs[11]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[1], in11_, mxGetM(prhs[11])*mxGetN(prhs[11]));
    plhs[2] = mxCreateDoubleMatrix(mxGetM(prhs[13]), mxGetN(prhs[13]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[2], in13_, mxGetM(prhs[13])*mxGetN(prhs[13]));
    plhs[3] = mxCreateDoubleMatrix(mxGetM(prhs[17]), mxGetN(prhs[17]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[3], in17_, mxGetM(prhs[17])*mxGetN(prhs[17]));
    plhs[4] = mxCreateDoubleMatrix(mxGetM(prhs[19]), mxGetN(prhs[19]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[4], in19_, mxGetM(prhs[19])*mxGetN(prhs[19]));

mw_err_label:
    if (in0_)  mxFree(in0_);
    if (in1_)  mxFree(in1_);
    if (in2_)  mxFree(in2_);
    if (in3_)  mxFree(in3_);
    if (in5_)  mxFree(in5_);
    if (in6_)  mxFree(in6_);
    if (in7_)  mxFree(in7_);
    if (in8_)  mxFree(in8_);
    if (in10_)  mxFree(in10_);
    if (in11_)  mxFree(in11_);
    if (in12_)  mxFree(in12_);
    if (in13_)  mxFree(in13_);
    if (in14_)  mxFree(in14_);
    if (in16_)  mxFree(in16_);
    if (in17_)  mxFree(in17_);
    if (in18_)  mxFree(in18_);
    if (in19_)  mxFree(in19_);
    if (mw_err_txt_)
        mexErrMsgTxt(mw_err_txt_);
}

/* ---- fmm3d_legacy.mw: 241 ----
 * h3dpartdirect(dcomplex[1] zk, int64_t[1] nsource, double[3, nsource] source, int64_t[1] ifcharge, dcomplex[] charge, int64_t[1] ifdipole, dcomplex[] dipstr, double[3, nsource] dipvec, int64_t[1] ifpot, inout dcomplex[] pot, int64_t[1] iffld, inout dcomplex[] fld, int64_t[1] ntarg, double[] targ, int64_t[1] ifpottarg, inout dcomplex[] pottarg, int64_t[1] iffldtarg, inout dcomplex[] fldtarg);
 */
static const char* stubids3_ = "h3dpartdirect(i dcomplex[x], i int64_t[x], i double[xx], i int64_t[x], i dcomplex[], i int64_t[x], i dcomplex[], i double[xx], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[], i int64_t[x], i double[], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[])";

void mexStub3(int nlhs, mxArray* plhs[],
              int nrhs, const mxArray* prhs[])
{
    const char* mw_err_txt_ = 0;
    dcomplex*   in0_ =0; /* zk         */
    int64_t*    in1_ =0; /* nsource    */
    double*     in2_ =0; /* source     */
    int64_t*    in3_ =0; /* ifcharge   */
    dcomplex*   in4_ =0; /* charge     */
    int64_t*    in5_ =0; /* ifdipole   */
    dcomplex*   in6_ =0; /* dipstr     */
    double*     in7_ =0; /* dipvec     */
    int64_t*    in8_ =0; /* ifpot      */
    dcomplex*   in9_ =0; /* pot        */
    int64_t*    in10_ =0; /* iffld      */
    dcomplex*   in11_ =0; /* fld        */
    int64_t*    in12_ =0; /* ntarg      */
    double*     in13_ =0; /* targ       */
    int64_t*    in14_ =0; /* ifpottarg  */
    dcomplex*   in15_ =0; /* pottarg    */
    int64_t*    in16_ =0; /* iffldtarg  */
    dcomplex*   in17_ =0; /* fldtarg    */
    mwSize      dim18_;   /* 1          */
    mwSize      dim19_;   /* 1          */
    mwSize      dim20_;   /* 3          */
    mwSize      dim21_;   /* nsource    */
    mwSize      dim22_;   /* 1          */
    mwSize      dim23_;   /* 1          */
    mwSize      dim24_;   /* 3          */
    mwSize      dim25_;   /* nsource    */
    mwSize      dim26_;   /* 1          */
    mwSize      dim27_;   /* 1          */
    mwSize      dim28_;   /* 1          */
    mwSize      dim29_;   /* 1          */
    mwSize      dim30_;   /* 1          */

    dim18_ = (mwSize) mxWrapGetScalar(prhs[18], &mw_err_txt_);
    dim19_ = (mwSize) mxWrapGetScalar(prhs[19], &mw_err_txt_);
    dim20_ = (mwSize) mxWrapGetScalar(prhs[20], &mw_err_txt_);
    dim21_ = (mwSize) mxWrapGetScalar(prhs[21], &mw_err_txt_);
    dim22_ = (mwSize) mxWrapGetScalar(prhs[22], &mw_err_txt_);
    dim23_ = (mwSize) mxWrapGetScalar(prhs[23], &mw_err_txt_);
    dim24_ = (mwSize) mxWrapGetScalar(prhs[24], &mw_err_txt_);
    dim25_ = (mwSize) mxWrapGetScalar(prhs[25], &mw_err_txt_);
    dim26_ = (mwSize) mxWrapGetScalar(prhs[26], &mw_err_txt_);
    dim27_ = (mwSize) mxWrapGetScalar(prhs[27], &mw_err_txt_);
    dim28_ = (mwSize) mxWrapGetScalar(prhs[28], &mw_err_txt_);
    dim29_ = (mwSize) mxWrapGetScalar(prhs[29], &mw_err_txt_);
    dim30_ = (mwSize) mxWrapGetScalar(prhs[30], &mw_err_txt_);

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != dim18_) {
        mw_err_txt_ = "Bad argument size: zk";        goto mw_err_label;
    }

    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != dim19_) {
        mw_err_txt_ = "Bad argument size: nsource";        goto mw_err_label;
    }

    if (mxGetM(prhs[2]) != dim20_ ||
        mxGetN(prhs[2]) != dim21_) {
        mw_err_txt_ = "Bad argument size: source";
        goto mw_err_label;
    }

    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != dim22_) {
        mw_err_txt_ = "Bad argument size: ifcharge";        goto mw_err_label;
    }

    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != dim23_) {
        mw_err_txt_ = "Bad argument size: ifdipole";        goto mw_err_label;
    }

    if (mxGetM(prhs[7]) != dim24_ ||
        mxGetN(prhs[7]) != dim25_) {
        mw_err_txt_ = "Bad argument size: dipvec";
        goto mw_err_label;
    }

    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != dim26_) {
        mw_err_txt_ = "Bad argument size: ifpot";        goto mw_err_label;
    }

    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != dim27_) {
        mw_err_txt_ = "Bad argument size: iffld";        goto mw_err_label;
    }

    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != dim28_) {
        mw_err_txt_ = "Bad argument size: ntarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[14])*mxGetN(prhs[14]) != dim29_) {
        mw_err_txt_ = "Bad argument size: ifpottarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[16])*mxGetN(prhs[16]) != dim30_) {
        mw_err_txt_ = "Bad argument size: iffldtarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != 0) {
        if( mxGetClassID(prhs[0]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in0_ = mxWrapGetArray_dcomplex(prhs[0], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in0_ = NULL;
    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 0) {
        in1_ = mxWrapGetArray_int64_t(prhs[1], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in1_ = NULL;
    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != 0) {
        if( mxGetClassID(prhs[2]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in2_ = mxGetDoubles(prhs[2]);
#else
        in2_ = mxGetPr(prhs[2]);
#endif
    } else
        in2_ = NULL;
    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 0) {
        in3_ = mxWrapGetArray_int64_t(prhs[3], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in3_ = NULL;
    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != 0) {
        if( mxGetClassID(prhs[4]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in4_ = mxWrapGetArray_dcomplex(prhs[4], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in4_ = NULL;
    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != 0) {
        in5_ = mxWrapGetArray_int64_t(prhs[5], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in5_ = NULL;
    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != 0) {
        if( mxGetClassID(prhs[6]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in6_ = mxWrapGetArray_dcomplex(prhs[6], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in6_ = NULL;
    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != 0) {
        if( mxGetClassID(prhs[7]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in7_ = mxGetDoubles(prhs[7]);
#else
        in7_ = mxGetPr(prhs[7]);
#endif
    } else
        in7_ = NULL;
    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != 0) {
        in8_ = mxWrapGetArray_int64_t(prhs[8], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in8_ = NULL;
    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != 0) {
        if( mxGetClassID(prhs[9]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in9_ = mxWrapGetArray_dcomplex(prhs[9], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in9_ = NULL;
    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != 0) {
        in10_ = mxWrapGetArray_int64_t(prhs[10], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in10_ = NULL;
    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != 0) {
        if( mxGetClassID(prhs[11]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in11_ = mxWrapGetArray_dcomplex(prhs[11], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in11_ = NULL;
    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != 0) {
        in12_ = mxWrapGetArray_int64_t(prhs[12], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in12_ = NULL;
    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != 0) {
        if( mxGetClassID(prhs[13]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in13_ = mxGetDoubles(prhs[13]);
#else
        in13_ = mxGetPr(prhs[13]);
#endif
    } else
        in13_ = NULL;
    if (mxGetM(prhs[14])*mxGetN(prhs[14]) != 0) {
        in14_ = mxWrapGetArray_int64_t(prhs[14], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in14_ = NULL;
    if (mxGetM(prhs[15])*mxGetN(prhs[15]) != 0) {
        if( mxGetClassID(prhs[15]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in15_ = mxWrapGetArray_dcomplex(prhs[15], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in15_ = NULL;
    if (mxGetM(prhs[16])*mxGetN(prhs[16]) != 0) {
        in16_ = mxWrapGetArray_int64_t(prhs[16], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in16_ = NULL;
    if (mxGetM(prhs[17])*mxGetN(prhs[17]) != 0) {
        if( mxGetClassID(prhs[17]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in17_ = mxWrapGetArray_dcomplex(prhs[17], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in17_ = NULL;
    if (mexprofrecord_)
        mexprofrecord_[3]++;
    MWF77_h3dpartdirect(in0_, in1_, in2_, in3_, in4_, in5_, in6_, in7_, in8_, in9_, in10_, in11_, in12_, in13_, in14_, in15_, in16_, in17_);
    plhs[0] = mxCreateDoubleMatrix(mxGetM(prhs[9]), mxGetN(prhs[9]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[0], in9_, mxGetM(prhs[9])*mxGetN(prhs[9]));
    plhs[1] = mxCreateDoubleMatrix(mxGetM(prhs[11]), mxGetN(prhs[11]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[1], in11_, mxGetM(prhs[11])*mxGetN(prhs[11]));
    plhs[2] = mxCreateDoubleMatrix(mxGetM(prhs[15]), mxGetN(prhs[15]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[2], in15_, mxGetM(prhs[15])*mxGetN(prhs[15]));
    plhs[3] = mxCreateDoubleMatrix(mxGetM(prhs[17]), mxGetN(prhs[17]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[3], in17_, mxGetM(prhs[17])*mxGetN(prhs[17]));

mw_err_label:
    if (in0_)  mxFree(in0_);
    if (in1_)  mxFree(in1_);
    if (in3_)  mxFree(in3_);
    if (in4_)  mxFree(in4_);
    if (in5_)  mxFree(in5_);
    if (in6_)  mxFree(in6_);
    if (in8_)  mxFree(in8_);
    if (in9_)  mxFree(in9_);
    if (in10_)  mxFree(in10_);
    if (in11_)  mxFree(in11_);
    if (in12_)  mxFree(in12_);
    if (in14_)  mxFree(in14_);
    if (in15_)  mxFree(in15_);
    if (in16_)  mxFree(in16_);
    if (in17_)  mxFree(in17_);
    if (mw_err_txt_)
        mexErrMsgTxt(mw_err_txt_);
}

/* ---- fmm3d_legacy.mw: 372 ----
 * lfmm3dpartself(inout int64_t[1] ier, int64_t[1] iprec, int64_t[1] nsource, double[3, nsource] source, int64_t[1] ifcharge, dcomplex[] charge, int64_t[1] ifdipole, dcomplex[] dipstr, double[3, nsource] dipvec, int64_t[1] ifpot, inout dcomplex[] pot, int64_t[1] iffld, inout dcomplex[] fld);
 */
static const char* stubids4_ = "lfmm3dpartself(io int64_t[x], i int64_t[x], i int64_t[x], i double[xx], i int64_t[x], i dcomplex[], i int64_t[x], i dcomplex[], i double[xx], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[])";

void mexStub4(int nlhs, mxArray* plhs[],
              int nrhs, const mxArray* prhs[])
{
    const char* mw_err_txt_ = 0;
    int64_t*    in0_ =0; /* ier        */
    int64_t*    in1_ =0; /* iprec      */
    int64_t*    in2_ =0; /* nsource    */
    double*     in3_ =0; /* source     */
    int64_t*    in4_ =0; /* ifcharge   */
    dcomplex*   in5_ =0; /* charge     */
    int64_t*    in6_ =0; /* ifdipole   */
    dcomplex*   in7_ =0; /* dipstr     */
    double*     in8_ =0; /* dipvec     */
    int64_t*    in9_ =0; /* ifpot      */
    dcomplex*   in10_ =0; /* pot        */
    int64_t*    in11_ =0; /* iffld      */
    dcomplex*   in12_ =0; /* fld        */
    mwSize      dim13_;   /* 1          */
    mwSize      dim14_;   /* 1          */
    mwSize      dim15_;   /* 1          */
    mwSize      dim16_;   /* 3          */
    mwSize      dim17_;   /* nsource    */
    mwSize      dim18_;   /* 1          */
    mwSize      dim19_;   /* 1          */
    mwSize      dim20_;   /* 3          */
    mwSize      dim21_;   /* nsource    */
    mwSize      dim22_;   /* 1          */
    mwSize      dim23_;   /* 1          */

    dim13_ = (mwSize) mxWrapGetScalar(prhs[13], &mw_err_txt_);
    dim14_ = (mwSize) mxWrapGetScalar(prhs[14], &mw_err_txt_);
    dim15_ = (mwSize) mxWrapGetScalar(prhs[15], &mw_err_txt_);
    dim16_ = (mwSize) mxWrapGetScalar(prhs[16], &mw_err_txt_);
    dim17_ = (mwSize) mxWrapGetScalar(prhs[17], &mw_err_txt_);
    dim18_ = (mwSize) mxWrapGetScalar(prhs[18], &mw_err_txt_);
    dim19_ = (mwSize) mxWrapGetScalar(prhs[19], &mw_err_txt_);
    dim20_ = (mwSize) mxWrapGetScalar(prhs[20], &mw_err_txt_);
    dim21_ = (mwSize) mxWrapGetScalar(prhs[21], &mw_err_txt_);
    dim22_ = (mwSize) mxWrapGetScalar(prhs[22], &mw_err_txt_);
    dim23_ = (mwSize) mxWrapGetScalar(prhs[23], &mw_err_txt_);

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != dim13_) {
        mw_err_txt_ = "Bad argument size: ier";        goto mw_err_label;
    }

    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != dim14_) {
        mw_err_txt_ = "Bad argument size: iprec";        goto mw_err_label;
    }

    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != dim15_) {
        mw_err_txt_ = "Bad argument size: nsource";        goto mw_err_label;
    }

    if (mxGetM(prhs[3]) != dim16_ ||
        mxGetN(prhs[3]) != dim17_) {
        mw_err_txt_ = "Bad argument size: source";
        goto mw_err_label;
    }

    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != dim18_) {
        mw_err_txt_ = "Bad argument size: ifcharge";        goto mw_err_label;
    }

    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != dim19_) {
        mw_err_txt_ = "Bad argument size: ifdipole";        goto mw_err_label;
    }

    if (mxGetM(prhs[8]) != dim20_ ||
        mxGetN(prhs[8]) != dim21_) {
        mw_err_txt_ = "Bad argument size: dipvec";
        goto mw_err_label;
    }

    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != dim22_) {
        mw_err_txt_ = "Bad argument size: ifpot";        goto mw_err_label;
    }

    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != dim23_) {
        mw_err_txt_ = "Bad argument size: iffld";        goto mw_err_label;
    }

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != 0) {
        in0_ = mxWrapGetArray_int64_t(prhs[0], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in0_ = NULL;
    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 0) {
        in1_ = mxWrapGetArray_int64_t(prhs[1], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in1_ = NULL;
    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != 0) {
        in2_ = mxWrapGetArray_int64_t(prhs[2], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in2_ = NULL;
    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 0) {
        if( mxGetClassID(prhs[3]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in3_ = mxGetDoubles(prhs[3]);
#else
        in3_ = mxGetPr(prhs[3]);
#endif
    } else
        in3_ = NULL;
    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != 0) {
        in4_ = mxWrapGetArray_int64_t(prhs[4], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in4_ = NULL;
    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != 0) {
        if( mxGetClassID(prhs[5]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in5_ = mxWrapGetArray_dcomplex(prhs[5], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in5_ = NULL;
    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != 0) {
        in6_ = mxWrapGetArray_int64_t(prhs[6], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in6_ = NULL;
    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != 0) {
        if( mxGetClassID(prhs[7]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in7_ = mxWrapGetArray_dcomplex(prhs[7], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in7_ = NULL;
    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != 0) {
        if( mxGetClassID(prhs[8]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in8_ = mxGetDoubles(prhs[8]);
#else
        in8_ = mxGetPr(prhs[8]);
#endif
    } else
        in8_ = NULL;
    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != 0) {
        in9_ = mxWrapGetArray_int64_t(prhs[9], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in9_ = NULL;
    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != 0) {
        if( mxGetClassID(prhs[10]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in10_ = mxWrapGetArray_dcomplex(prhs[10], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in10_ = NULL;
    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != 0) {
        in11_ = mxWrapGetArray_int64_t(prhs[11], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in11_ = NULL;
    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != 0) {
        if( mxGetClassID(prhs[12]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in12_ = mxWrapGetArray_dcomplex(prhs[12], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in12_ = NULL;
    if (mexprofrecord_)
        mexprofrecord_[4]++;
    MWF77_lfmm3dpartself(in0_, in1_, in2_, in3_, in4_, in5_, in6_, in7_, in8_, in9_, in10_, in11_, in12_);
    plhs[0] = mxCreateDoubleMatrix(dim13_, 1, mxREAL);
    mxWrapCopy_int64_t(plhs[0], in0_, dim13_);
    plhs[1] = mxCreateDoubleMatrix(mxGetM(prhs[10]), mxGetN(prhs[10]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[1], in10_, mxGetM(prhs[10])*mxGetN(prhs[10]));
    plhs[2] = mxCreateDoubleMatrix(mxGetM(prhs[12]), mxGetN(prhs[12]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[2], in12_, mxGetM(prhs[12])*mxGetN(prhs[12]));

mw_err_label:
    if (in0_)  mxFree(in0_);
    if (in1_)  mxFree(in1_);
    if (in2_)  mxFree(in2_);
    if (in4_)  mxFree(in4_);
    if (in5_)  mxFree(in5_);
    if (in6_)  mxFree(in6_);
    if (in7_)  mxFree(in7_);
    if (in9_)  mxFree(in9_);
    if (in10_)  mxFree(in10_);
    if (in11_)  mxFree(in11_);
    if (in12_)  mxFree(in12_);
    if (mw_err_txt_)
        mexErrMsgTxt(mw_err_txt_);
}

/* ---- fmm3d_legacy.mw: 374 ----
 * lfmm3dparttarg(inout int64_t[1] ier, int64_t[1] iprec, int64_t[1] nsource, double[3, nsource] source, int64_t[1] ifcharge, dcomplex[] charge, int64_t[1] ifdipole, dcomplex[] dipstr, double[3, nsource] dipvec, int64_t[1] ifpot, inout dcomplex[] pot, int64_t[1] iffld, inout dcomplex[] fld, int64_t[1] ntarg, double[] targ, int64_t[1] ifpottarg, inout dcomplex[] pottarg, int64_t[1] iffldtarg, inout dcomplex[] fldtarg);
 */
static const char* stubids5_ = "lfmm3dparttarg(io int64_t[x], i int64_t[x], i int64_t[x], i double[xx], i int64_t[x], i dcomplex[], i int64_t[x], i dcomplex[], i double[xx], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[], i int64_t[x], i double[], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[])";

void mexStub5(int nlhs, mxArray* plhs[],
              int nrhs, const mxArray* prhs[])
{
    const char* mw_err_txt_ = 0;
    int64_t*    in0_ =0; /* ier        */
    int64_t*    in1_ =0; /* iprec      */
    int64_t*    in2_ =0; /* nsource    */
    double*     in3_ =0; /* source     */
    int64_t*    in4_ =0; /* ifcharge   */
    dcomplex*   in5_ =0; /* charge     */
    int64_t*    in6_ =0; /* ifdipole   */
    dcomplex*   in7_ =0; /* dipstr     */
    double*     in8_ =0; /* dipvec     */
    int64_t*    in9_ =0; /* ifpot      */
    dcomplex*   in10_ =0; /* pot        */
    int64_t*    in11_ =0; /* iffld      */
    dcomplex*   in12_ =0; /* fld        */
    int64_t*    in13_ =0; /* ntarg      */
    double*     in14_ =0; /* targ       */
    int64_t*    in15_ =0; /* ifpottarg  */
    dcomplex*   in16_ =0; /* pottarg    */
    int64_t*    in17_ =0; /* iffldtarg  */
    dcomplex*   in18_ =0; /* fldtarg    */
    mwSize      dim19_;   /* 1          */
    mwSize      dim20_;   /* 1          */
    mwSize      dim21_;   /* 1          */
    mwSize      dim22_;   /* 3          */
    mwSize      dim23_;   /* nsource    */
    mwSize      dim24_;   /* 1          */
    mwSize      dim25_;   /* 1          */
    mwSize      dim26_;   /* 3          */
    mwSize      dim27_;   /* nsource    */
    mwSize      dim28_;   /* 1          */
    mwSize      dim29_;   /* 1          */
    mwSize      dim30_;   /* 1          */
    mwSize      dim31_;   /* 1          */
    mwSize      dim32_;   /* 1          */

    dim19_ = (mwSize) mxWrapGetScalar(prhs[19], &mw_err_txt_);
    dim20_ = (mwSize) mxWrapGetScalar(prhs[20], &mw_err_txt_);
    dim21_ = (mwSize) mxWrapGetScalar(prhs[21], &mw_err_txt_);
    dim22_ = (mwSize) mxWrapGetScalar(prhs[22], &mw_err_txt_);
    dim23_ = (mwSize) mxWrapGetScalar(prhs[23], &mw_err_txt_);
    dim24_ = (mwSize) mxWrapGetScalar(prhs[24], &mw_err_txt_);
    dim25_ = (mwSize) mxWrapGetScalar(prhs[25], &mw_err_txt_);
    dim26_ = (mwSize) mxWrapGetScalar(prhs[26], &mw_err_txt_);
    dim27_ = (mwSize) mxWrapGetScalar(prhs[27], &mw_err_txt_);
    dim28_ = (mwSize) mxWrapGetScalar(prhs[28], &mw_err_txt_);
    dim29_ = (mwSize) mxWrapGetScalar(prhs[29], &mw_err_txt_);
    dim30_ = (mwSize) mxWrapGetScalar(prhs[30], &mw_err_txt_);
    dim31_ = (mwSize) mxWrapGetScalar(prhs[31], &mw_err_txt_);
    dim32_ = (mwSize) mxWrapGetScalar(prhs[32], &mw_err_txt_);

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != dim19_) {
        mw_err_txt_ = "Bad argument size: ier";        goto mw_err_label;
    }

    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != dim20_) {
        mw_err_txt_ = "Bad argument size: iprec";        goto mw_err_label;
    }

    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != dim21_) {
        mw_err_txt_ = "Bad argument size: nsource";        goto mw_err_label;
    }

    if (mxGetM(prhs[3]) != dim22_ ||
        mxGetN(prhs[3]) != dim23_) {
        mw_err_txt_ = "Bad argument size: source";
        goto mw_err_label;
    }

    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != dim24_) {
        mw_err_txt_ = "Bad argument size: ifcharge";        goto mw_err_label;
    }

    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != dim25_) {
        mw_err_txt_ = "Bad argument size: ifdipole";        goto mw_err_label;
    }

    if (mxGetM(prhs[8]) != dim26_ ||
        mxGetN(prhs[8]) != dim27_) {
        mw_err_txt_ = "Bad argument size: dipvec";
        goto mw_err_label;
    }

    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != dim28_) {
        mw_err_txt_ = "Bad argument size: ifpot";        goto mw_err_label;
    }

    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != dim29_) {
        mw_err_txt_ = "Bad argument size: iffld";        goto mw_err_label;
    }

    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != dim30_) {
        mw_err_txt_ = "Bad argument size: ntarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[15])*mxGetN(prhs[15]) != dim31_) {
        mw_err_txt_ = "Bad argument size: ifpottarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[17])*mxGetN(prhs[17]) != dim32_) {
        mw_err_txt_ = "Bad argument size: iffldtarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != 0) {
        in0_ = mxWrapGetArray_int64_t(prhs[0], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in0_ = NULL;
    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 0) {
        in1_ = mxWrapGetArray_int64_t(prhs[1], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in1_ = NULL;
    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != 0) {
        in2_ = mxWrapGetArray_int64_t(prhs[2], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in2_ = NULL;
    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 0) {
        if( mxGetClassID(prhs[3]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in3_ = mxGetDoubles(prhs[3]);
#else
        in3_ = mxGetPr(prhs[3]);
#endif
    } else
        in3_ = NULL;
    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != 0) {
        in4_ = mxWrapGetArray_int64_t(prhs[4], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in4_ = NULL;
    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != 0) {
        if( mxGetClassID(prhs[5]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in5_ = mxWrapGetArray_dcomplex(prhs[5], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in5_ = NULL;
    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != 0) {
        in6_ = mxWrapGetArray_int64_t(prhs[6], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in6_ = NULL;
    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != 0) {
        if( mxGetClassID(prhs[7]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in7_ = mxWrapGetArray_dcomplex(prhs[7], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in7_ = NULL;
    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != 0) {
        if( mxGetClassID(prhs[8]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in8_ = mxGetDoubles(prhs[8]);
#else
        in8_ = mxGetPr(prhs[8]);
#endif
    } else
        in8_ = NULL;
    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != 0) {
        in9_ = mxWrapGetArray_int64_t(prhs[9], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in9_ = NULL;
    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != 0) {
        if( mxGetClassID(prhs[10]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in10_ = mxWrapGetArray_dcomplex(prhs[10], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in10_ = NULL;
    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != 0) {
        in11_ = mxWrapGetArray_int64_t(prhs[11], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in11_ = NULL;
    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != 0) {
        if( mxGetClassID(prhs[12]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in12_ = mxWrapGetArray_dcomplex(prhs[12], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in12_ = NULL;
    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != 0) {
        in13_ = mxWrapGetArray_int64_t(prhs[13], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in13_ = NULL;
    if (mxGetM(prhs[14])*mxGetN(prhs[14]) != 0) {
        if( mxGetClassID(prhs[14]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in14_ = mxGetDoubles(prhs[14]);
#else
        in14_ = mxGetPr(prhs[14]);
#endif
    } else
        in14_ = NULL;
    if (mxGetM(prhs[15])*mxGetN(prhs[15]) != 0) {
        in15_ = mxWrapGetArray_int64_t(prhs[15], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in15_ = NULL;
    if (mxGetM(prhs[16])*mxGetN(prhs[16]) != 0) {
        if( mxGetClassID(prhs[16]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in16_ = mxWrapGetArray_dcomplex(prhs[16], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in16_ = NULL;
    if (mxGetM(prhs[17])*mxGetN(prhs[17]) != 0) {
        in17_ = mxWrapGetArray_int64_t(prhs[17], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in17_ = NULL;
    if (mxGetM(prhs[18])*mxGetN(prhs[18]) != 0) {
        if( mxGetClassID(prhs[18]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in18_ = mxWrapGetArray_dcomplex(prhs[18], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in18_ = NULL;
    if (mexprofrecord_)
        mexprofrecord_[5]++;
    MWF77_lfmm3dparttarg(in0_, in1_, in2_, in3_, in4_, in5_, in6_, in7_, in8_, in9_, in10_, in11_, in12_, in13_, in14_, in15_, in16_, in17_, in18_);
    plhs[0] = mxCreateDoubleMatrix(dim19_, 1, mxREAL);
    mxWrapCopy_int64_t(plhs[0], in0_, dim19_);
    plhs[1] = mxCreateDoubleMatrix(mxGetM(prhs[10]), mxGetN(prhs[10]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[1], in10_, mxGetM(prhs[10])*mxGetN(prhs[10]));
    plhs[2] = mxCreateDoubleMatrix(mxGetM(prhs[12]), mxGetN(prhs[12]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[2], in12_, mxGetM(prhs[12])*mxGetN(prhs[12]));
    plhs[3] = mxCreateDoubleMatrix(mxGetM(prhs[16]), mxGetN(prhs[16]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[3], in16_, mxGetM(prhs[16])*mxGetN(prhs[16]));
    plhs[4] = mxCreateDoubleMatrix(mxGetM(prhs[18]), mxGetN(prhs[18]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[4], in18_, mxGetM(prhs[18])*mxGetN(prhs[18]));

mw_err_label:
    if (in0_)  mxFree(in0_);
    if (in1_)  mxFree(in1_);
    if (in2_)  mxFree(in2_);
    if (in4_)  mxFree(in4_);
    if (in5_)  mxFree(in5_);
    if (in6_)  mxFree(in6_);
    if (in7_)  mxFree(in7_);
    if (in9_)  mxFree(in9_);
    if (in10_)  mxFree(in10_);
    if (in11_)  mxFree(in11_);
    if (in12_)  mxFree(in12_);
    if (in13_)  mxFree(in13_);
    if (in15_)  mxFree(in15_);
    if (in16_)  mxFree(in16_);
    if (in17_)  mxFree(in17_);
    if (in18_)  mxFree(in18_);
    if (mw_err_txt_)
        mexErrMsgTxt(mw_err_txt_);
}

/* ---- fmm3d_legacy.mw: 490 ----
 * l3dpartdirect(int64_t[1] nsource, double[3, nsource] source, int64_t[1] ifcharge, dcomplex[] charge, int64_t[1] ifdipole, dcomplex[] dipstr, double[3, nsource] dipvec, int64_t[1] ifpot, inout dcomplex[] pot, int64_t[1] iffld, inout dcomplex[] fld, int64_t[1] ntarg, double[] targ, int64_t[1] ifpottarg, inout dcomplex[] pottarg, int64_t[1] iffldtarg, inout dcomplex[] fldtarg);
 */
static const char* stubids6_ = "l3dpartdirect(i int64_t[x], i double[xx], i int64_t[x], i dcomplex[], i int64_t[x], i dcomplex[], i double[xx], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[], i int64_t[x], i double[], i int64_t[x], io dcomplex[], i int64_t[x], io dcomplex[])";

void mexStub6(int nlhs, mxArray* plhs[],
              int nrhs, const mxArray* prhs[])
{
    const char* mw_err_txt_ = 0;
    int64_t*    in0_ =0; /* nsource    */
    double*     in1_ =0; /* source     */
    int64_t*    in2_ =0; /* ifcharge   */
    dcomplex*   in3_ =0; /* charge     */
    int64_t*    in4_ =0; /* ifdipole   */
    dcomplex*   in5_ =0; /* dipstr     */
    double*     in6_ =0; /* dipvec     */
    int64_t*    in7_ =0; /* ifpot      */
    dcomplex*   in8_ =0; /* pot        */
    int64_t*    in9_ =0; /* iffld      */
    dcomplex*   in10_ =0; /* fld        */
    int64_t*    in11_ =0; /* ntarg      */
    double*     in12_ =0; /* targ       */
    int64_t*    in13_ =0; /* ifpottarg  */
    dcomplex*   in14_ =0; /* pottarg    */
    int64_t*    in15_ =0; /* iffldtarg  */
    dcomplex*   in16_ =0; /* fldtarg    */
    mwSize      dim17_;   /* 1          */
    mwSize      dim18_;   /* 3          */
    mwSize      dim19_;   /* nsource    */
    mwSize      dim20_;   /* 1          */
    mwSize      dim21_;   /* 1          */
    mwSize      dim22_;   /* 3          */
    mwSize      dim23_;   /* nsource    */
    mwSize      dim24_;   /* 1          */
    mwSize      dim25_;   /* 1          */
    mwSize      dim26_;   /* 1          */
    mwSize      dim27_;   /* 1          */
    mwSize      dim28_;   /* 1          */

    dim17_ = (mwSize) mxWrapGetScalar(prhs[17], &mw_err_txt_);
    dim18_ = (mwSize) mxWrapGetScalar(prhs[18], &mw_err_txt_);
    dim19_ = (mwSize) mxWrapGetScalar(prhs[19], &mw_err_txt_);
    dim20_ = (mwSize) mxWrapGetScalar(prhs[20], &mw_err_txt_);
    dim21_ = (mwSize) mxWrapGetScalar(prhs[21], &mw_err_txt_);
    dim22_ = (mwSize) mxWrapGetScalar(prhs[22], &mw_err_txt_);
    dim23_ = (mwSize) mxWrapGetScalar(prhs[23], &mw_err_txt_);
    dim24_ = (mwSize) mxWrapGetScalar(prhs[24], &mw_err_txt_);
    dim25_ = (mwSize) mxWrapGetScalar(prhs[25], &mw_err_txt_);
    dim26_ = (mwSize) mxWrapGetScalar(prhs[26], &mw_err_txt_);
    dim27_ = (mwSize) mxWrapGetScalar(prhs[27], &mw_err_txt_);
    dim28_ = (mwSize) mxWrapGetScalar(prhs[28], &mw_err_txt_);

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != dim17_) {
        mw_err_txt_ = "Bad argument size: nsource";        goto mw_err_label;
    }

    if (mxGetM(prhs[1]) != dim18_ ||
        mxGetN(prhs[1]) != dim19_) {
        mw_err_txt_ = "Bad argument size: source";
        goto mw_err_label;
    }

    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != dim20_) {
        mw_err_txt_ = "Bad argument size: ifcharge";        goto mw_err_label;
    }

    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != dim21_) {
        mw_err_txt_ = "Bad argument size: ifdipole";        goto mw_err_label;
    }

    if (mxGetM(prhs[6]) != dim22_ ||
        mxGetN(prhs[6]) != dim23_) {
        mw_err_txt_ = "Bad argument size: dipvec";
        goto mw_err_label;
    }

    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != dim24_) {
        mw_err_txt_ = "Bad argument size: ifpot";        goto mw_err_label;
    }

    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != dim25_) {
        mw_err_txt_ = "Bad argument size: iffld";        goto mw_err_label;
    }

    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != dim26_) {
        mw_err_txt_ = "Bad argument size: ntarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != dim27_) {
        mw_err_txt_ = "Bad argument size: ifpottarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[15])*mxGetN(prhs[15]) != dim28_) {
        mw_err_txt_ = "Bad argument size: iffldtarg";        goto mw_err_label;
    }

    if (mxGetM(prhs[0])*mxGetN(prhs[0]) != 0) {
        in0_ = mxWrapGetArray_int64_t(prhs[0], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in0_ = NULL;
    if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 0) {
        if( mxGetClassID(prhs[1]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in1_ = mxGetDoubles(prhs[1]);
#else
        in1_ = mxGetPr(prhs[1]);
#endif
    } else
        in1_ = NULL;
    if (mxGetM(prhs[2])*mxGetN(prhs[2]) != 0) {
        in2_ = mxWrapGetArray_int64_t(prhs[2], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in2_ = NULL;
    if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 0) {
        if( mxGetClassID(prhs[3]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in3_ = mxWrapGetArray_dcomplex(prhs[3], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in3_ = NULL;
    if (mxGetM(prhs[4])*mxGetN(prhs[4]) != 0) {
        in4_ = mxWrapGetArray_int64_t(prhs[4], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in4_ = NULL;
    if (mxGetM(prhs[5])*mxGetN(prhs[5]) != 0) {
        if( mxGetClassID(prhs[5]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in5_ = mxWrapGetArray_dcomplex(prhs[5], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in5_ = NULL;
    if (mxGetM(prhs[6])*mxGetN(prhs[6]) != 0) {
        if( mxGetClassID(prhs[6]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in6_ = mxGetDoubles(prhs[6]);
#else
        in6_ = mxGetPr(prhs[6]);
#endif
    } else
        in6_ = NULL;
    if (mxGetM(prhs[7])*mxGetN(prhs[7]) != 0) {
        in7_ = mxWrapGetArray_int64_t(prhs[7], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in7_ = NULL;
    if (mxGetM(prhs[8])*mxGetN(prhs[8]) != 0) {
        if( mxGetClassID(prhs[8]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in8_ = mxWrapGetArray_dcomplex(prhs[8], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in8_ = NULL;
    if (mxGetM(prhs[9])*mxGetN(prhs[9]) != 0) {
        in9_ = mxWrapGetArray_int64_t(prhs[9], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in9_ = NULL;
    if (mxGetM(prhs[10])*mxGetN(prhs[10]) != 0) {
        if( mxGetClassID(prhs[10]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in10_ = mxWrapGetArray_dcomplex(prhs[10], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in10_ = NULL;
    if (mxGetM(prhs[11])*mxGetN(prhs[11]) != 0) {
        in11_ = mxWrapGetArray_int64_t(prhs[11], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in11_ = NULL;
    if (mxGetM(prhs[12])*mxGetN(prhs[12]) != 0) {
        if( mxGetClassID(prhs[12]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
#if MX_HAS_INTERLEAVED_COMPLEX
        in12_ = mxGetDoubles(prhs[12]);
#else
        in12_ = mxGetPr(prhs[12]);
#endif
    } else
        in12_ = NULL;
    if (mxGetM(prhs[13])*mxGetN(prhs[13]) != 0) {
        in13_ = mxWrapGetArray_int64_t(prhs[13], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in13_ = NULL;
    if (mxGetM(prhs[14])*mxGetN(prhs[14]) != 0) {
        if( mxGetClassID(prhs[14]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in14_ = mxWrapGetArray_dcomplex(prhs[14], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in14_ = NULL;
    if (mxGetM(prhs[15])*mxGetN(prhs[15]) != 0) {
        in15_ = mxWrapGetArray_int64_t(prhs[15], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in15_ = NULL;
    if (mxGetM(prhs[16])*mxGetN(prhs[16]) != 0) {
        if( mxGetClassID(prhs[16]) != mxDOUBLE_CLASS )
            mw_err_txt_ = "Invalid array argument, mxDOUBLE_CLASS expected";
        if (mw_err_txt_) goto mw_err_label;
        in16_ = mxWrapGetArray_dcomplex(prhs[16], &mw_err_txt_);
        if (mw_err_txt_)
            goto mw_err_label;
    } else
        in16_ = NULL;
    if (mexprofrecord_)
        mexprofrecord_[6]++;
    MWF77_l3dpartdirect(in0_, in1_, in2_, in3_, in4_, in5_, in6_, in7_, in8_, in9_, in10_, in11_, in12_, in13_, in14_, in15_, in16_);
    plhs[0] = mxCreateDoubleMatrix(mxGetM(prhs[8]), mxGetN(prhs[8]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[0], in8_, mxGetM(prhs[8])*mxGetN(prhs[8]));
    plhs[1] = mxCreateDoubleMatrix(mxGetM(prhs[10]), mxGetN(prhs[10]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[1], in10_, mxGetM(prhs[10])*mxGetN(prhs[10]));
    plhs[2] = mxCreateDoubleMatrix(mxGetM(prhs[14]), mxGetN(prhs[14]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[2], in14_, mxGetM(prhs[14])*mxGetN(prhs[14]));
    plhs[3] = mxCreateDoubleMatrix(mxGetM(prhs[16]), mxGetN(prhs[16]), mxCOMPLEX);
    mxWrapCopy_dcomplex(plhs[3], in16_, mxGetM(prhs[16])*mxGetN(prhs[16]));

mw_err_label:
    if (in0_)  mxFree(in0_);
    if (in2_)  mxFree(in2_);
    if (in3_)  mxFree(in3_);
    if (in4_)  mxFree(in4_);
    if (in5_)  mxFree(in5_);
    if (in7_)  mxFree(in7_);
    if (in8_)  mxFree(in8_);
    if (in9_)  mxFree(in9_);
    if (in10_)  mxFree(in10_);
    if (in11_)  mxFree(in11_);
    if (in13_)  mxFree(in13_);
    if (in14_)  mxFree(in14_);
    if (in15_)  mxFree(in15_);
    if (in16_)  mxFree(in16_);
    if (mw_err_txt_)
        mexErrMsgTxt(mw_err_txt_);
}

/* ----
 */
void mexFunction(int nlhs, mxArray* plhs[],
                 int nrhs, const mxArray* prhs[])
{
    char id[512];
    if (nrhs == 0) {
        mexPrintf("Mex function installed\n");
        return;
    }

    if (mxGetString(prhs[0], id, sizeof(id)) != 0)
        mexErrMsgTxt("Identifier should be a string");
    else if (strcmp(id, stubids1_) == 0)
        mexStub1(nlhs,plhs, nrhs-1,prhs+1);
    else if (strcmp(id, stubids2_) == 0)
        mexStub2(nlhs,plhs, nrhs-1,prhs+1);
    else if (strcmp(id, stubids3_) == 0)
        mexStub3(nlhs,plhs, nrhs-1,prhs+1);
    else if (strcmp(id, stubids4_) == 0)
        mexStub4(nlhs,plhs, nrhs-1,prhs+1);
    else if (strcmp(id, stubids5_) == 0)
        mexStub5(nlhs,plhs, nrhs-1,prhs+1);
    else if (strcmp(id, stubids6_) == 0)
        mexStub6(nlhs,plhs, nrhs-1,prhs+1);
    else if (strcmp(id, "*profile on*") == 0) {
        if (!mexprofrecord_) {
            mexprofrecord_ = (int*) malloc(7 * sizeof(int));
            mexLock();
        }
        memset(mexprofrecord_, 0, 7 * sizeof(int));
    } else if (strcmp(id, "*profile off*") == 0) {
        if (mexprofrecord_) {
            free(mexprofrecord_);
            mexUnlock();
        }
        mexprofrecord_ = NULL;
    } else if (strcmp(id, "*profile report*") == 0) {
        if (!mexprofrecord_)
            mexPrintf("Profiler inactive\n");
        mexPrintf("%d calls to fmm3d_legacy.mw:121\n", mexprofrecord_[1]);
        mexPrintf("%d calls to fmm3d_legacy.mw:123\n", mexprofrecord_[2]);
        mexPrintf("%d calls to fmm3d_legacy.mw:241\n", mexprofrecord_[3]);
        mexPrintf("%d calls to fmm3d_legacy.mw:372\n", mexprofrecord_[4]);
        mexPrintf("%d calls to fmm3d_legacy.mw:374\n", mexprofrecord_[5]);
        mexPrintf("%d calls to fmm3d_legacy.mw:490\n", mexprofrecord_[6]);
    } else if (strcmp(id, "*profile log*") == 0) {
        FILE* logfp;
        if (nrhs != 2 || mxGetString(prhs[1], id, sizeof(id)) != 0)
            mexErrMsgTxt("Must have two string arguments");
        logfp = fopen(id, "w+");
        if (!logfp)
            mexErrMsgTxt("Cannot open log for output");
        if (!mexprofrecord_)
            fprintf(logfp, "Profiler inactive\n");
        fprintf(logfp, "%d calls to fmm3d_legacy.mw:121\n", mexprofrecord_[1]);
        fprintf(logfp, "%d calls to fmm3d_legacy.mw:123\n", mexprofrecord_[2]);
        fprintf(logfp, "%d calls to fmm3d_legacy.mw:241\n", mexprofrecord_[3]);
        fprintf(logfp, "%d calls to fmm3d_legacy.mw:372\n", mexprofrecord_[4]);
        fprintf(logfp, "%d calls to fmm3d_legacy.mw:374\n", mexprofrecord_[5]);
        fprintf(logfp, "%d calls to fmm3d_legacy.mw:490\n", mexprofrecord_[6]);
        fclose(logfp);
    } else
        mexErrMsgTxt("Unknown identifier");
}

