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

static void *FUNC_chdl_funptr;
EXPORTCH int chvla_chdl(void *varg) {
  ChInterp_t interp;
  ChVaList_t ap;
  double *a;
  int elementtype, d_a, ext_a_1, ext_a_2;
  int arg_count, funarg_count, retval;
  double d1;

  Ch_VaStart(interp, ap, varg);

  /* Number of arguments passed from Ch space*/
  arg_count = Ch_VaCount(interp, ap); 
  printf("Number of arguments before first calling of Ch_VaArg() is %d\n", arg_count);

  /* Data type of 1st argument */
  elementtype = Ch_VaDataType(interp, ap); 
  if(elementtype == CH_INTTYPE) {
    printf("Element data type of the 1st argument is int\n");
  }
  /* Dimension of 1st argument */
  d_a = Ch_VaArrayDim(interp, ap);        
  printf("Dimension of the 1st argument is = %d\n", d_a);
  /* Number of elements in the 1st dimension of the 1st argument */ 
  ext_a_1 = Ch_VaArrayExtent(interp, ap, 0);
  printf("Extent of the 1st dimension of the 1st argument is = %d\n", ext_a_1);
  /* Number of elements in the 2nd dimension of the 1st argument */ 
  ext_a_2 = Ch_VaArrayExtent(interp, ap, 1);
  printf("Extent of the 2nd dimension of the 1st argument is = %d\n", ext_a_2);

  /* Return the 1st argument, and step to the next argument */
  a = Ch_VaArg(interp, ap, double*);  

  /* Number of the rest of arguments */
  arg_count = Ch_VaCount(interp, ap); 
  printf("\nNumber of the rest of arguments after the 1st calling of \
Ch_VaArg() is %d\n", arg_count);

  /* Data type of 2nd argument */
  elementtype = Ch_VaDataType(interp, ap); 
  if(elementtype == CH_DOUBLETYPE) {
    printf("Element data type of the 2nd argument is double\n");
  } 

  /* Return the 2nd argument, and step to the next argument */
  d1 = Ch_VaArg(interp, ap, double);

  /* Number of the rest of arguments */
  arg_count = Ch_VaCount(interp, ap);
  printf("\nNumber of the rest of arguments after the 2nd calling of \
Ch_VaArg() is %d\n", arg_count);

  funarg_count = Ch_VaFuncArgNum(interp, ap);
  printf("Number of arguments of the function pointed to by the 3nd \
argument is %d\n", funarg_count);

  /* Return the 3rd argument */
  FUNC_chdl_funptr = Ch_VaArg(interp, ap, void*);

  Ch_VaEnd(interp, ap);
  return retval;
}
