A colleague has produced a geochemical data analysis package, which has been developed in Java. He can provide a link / hook to my multivariate software for my in-house use, but the link will be via C.
I know nothing about JAVA, and not a lot about c.
Can you access Salford Fortran directly from JAVA?
I've had a quick look at the Salford manuals, but couldn't find any explicit examples of interfacing Fortran and c. I've reached that age in (semi-)retirement where cutting-and-pasting is much more efficient than starting from scratch.
So I'm pasting a simple example, in the hope that there is some kind soul out there who can spend a few minutes making the necessary changes to show me how to get the code to run.
program test_wrapper
dimension xxx(10), yyy(10)
npt = 10
do ip = 1, npt
xxx(ip) = ip
yyy(ip) = 1.
end do
xv1 = 20.
yv1 = 30.
itt = 6
call wrap_c_to_Fortran ( itt, npt, xxx, yyy, xpr,
1 xv1, yv1, pv1 )
stop
end
c I would like to be able to replace this subroutine c by C code (see my first try below)
c and make whatever changes are necessary to the remaining Fortran c and modified c code to have the example compile and run
subroutine wrap_c_to_Fortran ( itt, npt, xxx, yyy, xpr,
1 xv1, yv1, pv1 )
dimension xxx(*), yyy(*)
c write data
write (itt,'(/ '' XXX '')' )
write (itt,'( 10g12.4 )') (xxx(ip),ip=1,npt)
do ip = 1, npt
write (itt,'(/ '' XXX(i) '', g12.4 )') xxx(ip)
end do
write (itt,'(/ '' YYY '')' )
write (itt,'( 10g12.4 )') (yyy(ip),ip=1,npt)
do ip = 1, npt
write (itt,'(/ '' YYY(i) '', g12.4 )') yyy(ip)
end do
write (itt,'(/ '' XV1 '', g12.4 )') xv1
write (itt,'(/ '' YV1 '', g12.4 )') yv1
call calc_prod ( npt, xxx, yyy, xpr, xv1, yv1, pv1 )
write (itt,'(/ '' XXX * YYY = '', g12.4 )') xpr
write (itt,'(/ '' XV1 * YV1 = '', g12.4 )') pv1
return
end
subroutine calc_prod ( npt, xxx, yyy, xpr, xv1, yv1, pv1 )
dimension xxx(*), yyy(*)
xpr = 0.
do ip = 1, npt
xpr = xpr + xxx(ip) * yyy(ip)
end do
pv1 = xv1 * yv1
return
end
#include <stdio.h>
extern int calc_prod ( long, long, double *, double *, double, double, double, double );
int wrap_c_to_Fortran ( long itt, long npt, // number of observations double *xxx, double *yyy, double xpr, double xv1, double yv1, double pv1 )
// xxx(ip) = ip yyy(ip) = 1. xpr = xpr + xxx(ip) * yyy(ip); ip = 1, npt
// xv1 = 20. yv1 = 30. pv1 = xv1 * yv1
{ short ip;
long npv1;
for(ip=1;ip<=npt;ip++)
printf( '%12.4lf ', xxx[ip] );
for(ip=1;ip<=npt;ip++)
printf( '%12.4lf ', yyy[ip] );
printf( '%12.4lf ', xv1 );
printf( '%12.4lf ', yv1 );
calc_prod ( npt, xxx, yyy, xpr, xv1, yv1, pv1 );
printf( '%12.4lf ', xpr );
printf( '%12.4lf ', pv1 );
// sprintf(szBuff, '\n\nC V means - C V %3ld vs C V %ld', ncvY, ncvX); // write (itt,'(/ '' XXX * YYY = '', g12.4 )') xpr // write (itt,'(/ '' XV1 * YV1 = '', g12.4 )') pv1
npv1 = pv1;
return npv1;
}