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

typedef int (*func_t)(int, int);
int func1(int a, int b)
{
   return a+b;
}

int chvla(double a[3][4], double d1, func_t f1) {
  void *handle, *fptr;
  int retval;

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

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

  dlrunfun(fptr, &retval, NULL, a, d1, f1);

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

int main() {
  double a[3][4];

  chvla(a, 2.0, func1);
  return 0;
}
