/*
 * This file was generated automatically by xsubpp version 1.937 from the 
 * contents of Examples.xs. Do not edit this file, edit Examples.xs instead.
 *
 *	ANY CHANGES MADE HERE WILL BE LOST! 
 *
 */


/* 
   Examples.xs - simple examples module

*/

#include "EXTERN.h"   /* std perl include */
#include "perl.h"     /* std perl include */
#include "XSUB.h"     /* XSUB include */

#include "pdl.h"      /* Data structure declarations */
#include "pdlcore.h"  /* Core declarations */

#include "pdlexamples.h"  /* Local decs */

/* Return a integer or numeric scalar as approroate */

#define SET_RETVAL_NV x.datatype<PDL_F ? (RETVAL=newSViv( (IV)result )) : (RETVAL=newSVnv( result ))

static Core* PDL; /* Structure hold core C functions */
SV* CoreSV;       /* Get's pointer to perl var holding core structure */

XS(XS_PDL__Examples_fibonacci)
{
    dXSARGS;
    if (items != 1)
	croak("Usage: PDL::Examples::fibonacci(x)");
    {
	pdl*	x = PDL->SvPDLV(ST(0));
	SV *	RETVAL;
    pdl* y;
    if (x->ndims != 1) 
       croak("Array is not 1D");

    RETVAL = PDL->copy(x,"");   /* Init y value to return as copy of x */
    y = PDL->SvPDLV(RETVAL);    /* Map */

    pdl_fibonacci( y->data, y->datatype, y->nvals );     /* Do it */

	ST(0) = RETVAL;
	if (SvREFCNT(ST(0))) sv_2mortal(ST(0));
    }
    XSRETURN(1);
}

XS(XS_PDL__Examples_cc8compt)
{
    dXSARGS;
    if (items != 1)
	croak("Usage: PDL::Examples::cc8compt(x)");
    {
	pdl*	x = PDL->SvPDLV(ST(0));
	SV *	RETVAL;
    pdl* y;
    int* dims    = x->dims;
    int nx, ny;

    RETVAL = PDL->copy(x,""); /* Init y value to return as copy of x */
    y = PDL->SvPDLV(RETVAL);         /* Map */

    nx = *(y->dims); ny = y->ndims==2 ? *(y->dims+1) : 1; 

    /* Note: PDL->twod(pdl) returns void** ptr to 1D or 2D array */

    pdl_cc8compt( PDL->twod(y), y->datatype, nx, ny); /* do it */

	ST(0) = RETVAL;
	if (SvREFCNT(ST(0))) sv_2mortal(ST(0));
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_PDL__Examples)
{
    dXSARGS;
    char* file = __FILE__;

    XS_VERSION_BOOTCHECK ;

        newXS("PDL::Examples::fibonacci", XS_PDL__Examples_fibonacci, file);
        newXS("PDL::Examples::cc8compt", XS_PDL__Examples_cc8compt, file);

    /* Initialisation Section */


   /* Get pointer to structure of core shared C routines */

   CoreSV = perl_get_sv("PDL::SHARE",FALSE);  /* SV* value */
   if (CoreSV==NULL)
      croak("This module requires use of PDL::Core first");

   PDL = (Core*) (void*) SvIV( CoreSV );  /* Core* value */


    /* End of Initialisation Section */

    ST(0) = &sv_yes;
    XSRETURN(1);
}