/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include<dlfcn.h>
#include<array.h>

typedef int (*func1_t)();
typedef array double func2_t(int a, int b) [2][3];
int func1(int a, int b) {
   return a+b;
}
array double func2(int a, int b) [2][3]{
   double a[2][3];
   return a;
}


int chvastart(double a[3][4], double d1, func1_t f1, func2_t f2, 
              array double b[30][40], int n, double c[n], double d[n]) {
  void *handle, *fptr;
  int retval;

  handle = dlopen("libch.dl", RTLD_LAZY);
  if(handle == NULL) {
     printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
     return -1;
  }

  fptr = dlsym(handle, "chvastart_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
     return -1;
  }

  dlrunfun(fptr, &retval, NULL, a, d1, f1, f2, b, n, c, d);

  if(dlclose(handle)!=0) {
     printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
     return -1;
  }
  return retval;
}

int main() {
  double a[3][4];
  array double b[30][40];
  int n = 5;
  double c[5], d[n];

  chvastart(a, 2.0, func1, func2, b, n, c, d);
  return 0;
}
