/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
#include<stdio.h>
#include<ch.h>

int cfun3(ChInterp_t interp, void *chfunptr){
   int dim, ext1, ext2, ext3;
   int sum_ret;
   int aa1[3][4] = { 1, 2, 3, 4,
                     5, 6, 7, 8,
                     9, 10, 11, 12};

   int aa2[2][3][4] = { 1, 2, 3, 4,
                        5, 6, 7, 8,
                        9, 10, 11, 12,

                        1, 2, 3, 4,
                        5, 6, 7, 8,
                        9, 10, 11, 12};

   dim = 2; ext1 = 3; ext2 = 4; /* dimension and extents of aa1 */
   Ch_CallFuncByAddr(interp, chfunptr, &sum_ret, aa1, dim, ext1, ext2);
   printf("sumNd has been called from C space and returned %d\n\n", sum_ret);

   dim = 3; ext1 = 2; ext2 = 3; ext3 = 4; /* dimension and extents of aa2 */
   Ch_CallFuncByAddr(interp, chfunptr, &sum_ret, aa2, dim, ext1, ext2, ext3);
   printf("sumNd has been called from C space and returned %d\n", sum_ret);

   return 0;
}

EXPORTCH int  callchvla_Nd_chdl(void *varg) {
  ChInterp_t interp;
  ChVaList_t ap;
  int retval;
  void *sumNd_ch_fun;

  Ch_VaStart(interp, ap, varg);
  sumNd_ch_fun = Ch_VaArg(interp, ap, void *);

  retval = cfun3(interp, sumNd_ch_fun);
  Ch_VaEnd(interp, ap);
  return retval; 
}
