Hi,

I am receiving a "parse" error when I try to declare an array of doubles.
However, I don't see a problem with my syntax.

Is something special required to create arrays with Inline ?

My code is shown below...

Thanks in advance
Brady Cannon


#!/usr/local/bin/perl 

package mlGraphics;
use strict;
require Exporter;

@mlGraphics::ISA = qw(Exporter);
@mlGraphics::EXPORT = qw(&printSVasMxArray);

use Inline (C => DATA =>
        NAME => 'mlGraphics',
        MYEXTLIB => ["/r1u3/matlab/extern/lib/sol2/libmmfile.so",
                     "/r1u3/matlab/extern/lib/sol2/libmwsglm.so"],
        INC      => ["-I/r1u3/matlab/toolbox/compiler/bundles/",
                     "-I/r1u3/matlab/bin/sol2/",                     
                     "-I/r1u3/matlab/extern/include/",
                     "-I/home/bbcannon/shell/perl/MATLAB/mccfiles/"],
        DIRECTORY => "/home/bbcannon/shell/perl/MATLAB/_Inline/"
       );
#
sub printNumArray {
#  my ($x,$y)

   my $x = [1,4,2,23,23];

   cPrintNumArrayRef($x);
}

#
#
#doesn't work yet
sub printSVasMxArray {
   my $arr = [2,6,5,7.5,8];
   
   #my $arr_ref = \@arr;
   cPrintSVasMxArray($arr);
   
}

       
1;

__DATA__
__C__
#include <libmmfile.h>
#include "libmwsglm.h"
#include "matlab.h"

/*cPrintNumArrayRef() prints the contents of an array of numbers
 *   THIS WORKS. 
 */
void cPrintNumArrayRef(SV* x)    
{
   int i, maxIndex;
   SV* tmpX;
   double tmpXN;
   
   AV *arr = (AV*) SvRV(x);
   
   maxIndex = av_len(arr);
   for (i=0; i<=maxIndex; i++) {
      tmpX = av_shift(arr);
      tmpXN = SvNV(tmpX);
      printf("%3d  %g\n", i, tmpXN);
   }   

}

/* mPrintNum() prints the preset matrix of numbers
 *  This WORKS.
 */
void mPrintNum() {
   double data[] = { 1, 4, 2, 5, 3, 6 };
   mxArray *A = NULL;
   mlfAssign(&A, mlfDoubleMatrix(2, 3, data, 0));
   mlfPrintMatrix(A);
   mxDestroyArray(A);
}

/* cPrintSVasMxArray()
 *
 */
void cPrintSVasMxArray(SV* x) {

   int i;
   int maxIndex;
   int numElements;
   SV* tmpX;
   double tmpXN;
   
   //dereference SV* and cast to AV*
   AV *arr = (AV*) SvRV(x);
   
   maxIndex = av_len(arr);
   numElements = maxIndex + 1;
printf("maxind= %d numEl= %d\n",maxIndex, numElements);   // this prints the
correct values...
   /* initialize a double array with enough spaces to hold all array items
*/
   double data[numElements]; // this is where the parse error is pointed.
   
   for (i=0; i<=5; i++) {
   
      //pull first element off array
      tmpX = av_shift(arr);

      //Convert the SV element to a double
      tmpXN = SvNV(tmpX);
      data[i] = tmpXN;
      
      printf("%g\n", data[i]);
   }   
   
   //Create a mxArray using the data stored in a[]
 //  mxArray *A = NULL;
 //  mlfAssign(&A, mlfDoubleMatrix(2, 3, a, 0));   
 //  mlfPrintMatrix(A);
 //  mxDestroyArray(A);

}


Reply via email to