/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* File name: arrmul.ch */
#include<dlfcn.h>
#include<array.h>
int arrmul(array double a[:][:], array double b[:][:], array double c[:][:]) {
  void *handle, *fptr;
  int retval;

  handle = dlopen("libvlaarg.dl", RTLD_LAZY);
  if(handle == NULL) {
     printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
     return -1;
  }
  fptr = dlsym(handle, "arrmul_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
     return -1;
  }
  dlrunfun(fptr, &retval, arrmul, a, b, c);
  if(dlclose(handle)!=0) {
     printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
     return -1;
  }
  return retval;
}

int main() {
  array double a1[2][3] = { 1, 5, 3,
                            5, 6, 7};
  double b1[3][2] = { 1, 5, 
                      5, 6,
                      3, 7};
  array double c1[2][2];
  array double a2[3][4] = { 1, 5, 3, 7,
                            5, 6, 7, 3,
                            1, 2, 6, 8};
  double b2[4][3] = { 1, 5, 4, 
                      5, 6, 9,
                      3, 7, 5,
                      2, 3, 4};
  array double c2[3][3];

  arrmul(a1, b1, c1);
  printf("c1 = \n%f\n", c1);
  arrmul(a2, b2, c2);
  printf("c2 = \n%f", c2);

  return 0;
}
