#include <stddef.h>
#include <stdlib.h>
#include <libvhcall.h>
#include <stdio.h>
#define MAXLEN 100
#define N 3
const char *msg = "Hello, This is VE";
int main() {
int ret=1;
uint64_t len = MAXLEN;
char buf[MAXLEN];
double a[N][N];
int64_t symid;
vhcall_handle handle;
uint64_t retval = -1;
int i,j;
printf("Test for Fortran library\n");
if (handle == (vhcall_handle)-1) {
perror("vhcall_install");
goto ret;
}
printf("\nInvoke function passing string\n");
if (symid == -1 ) {
perror("vhcall_find");
goto ret3;
}
memcpy(buf, msg, strlen(msg));
memset(buf+strlen(msg)+1, '\0', MAXLEN-strlen(msg));
if (ret) {
perror("vhcall_args_set_pointer");
goto ret3;
}
if (ret) {
perror("vhcall_args_set_pointer");
goto ret3;
}
if (ret) {
perror("vhcall_invoke_with_args");
goto ret3;
}
if (retval != 999) {
printf("VH function returns unexpected value(%ld)\n", retval);
goto ret3;
}
printf("\nInvoke subroutine passing matrix of double\n");
if (symid == -1 ) {
perror("vhcall_find");
goto ret3;
}
for(i=0;i<N;i++)for(j=0;j<N;j++)
a[i][j]=10*i+j;
len = N;
if (ret) {
perror("vhcall_args_set_pointer");
goto ret3;
}
for(i=0;i<N;i++)for(j=0;j<N;j++)
printf("[VE] a[%d][%d]=%.16f\n", i,j,a[i][j]);
if (ret) {
perror("vhcall_invoke_with_args");
goto ret3;
}
ret3:
ret2:
perror("vhcall_uninstall");
ret:
return ret;
}