I have this function in this module
require 'dl'
require 'dl/import'
module LibCalendars
extend DL::Importer
dlload './cal2jd.o'
extern 'int iauCal2jd(int, int, int, double *, double *)'
end
How to set this in a module to access pointers?
What do I need in part there? I'm just not sure. How is this done correctly? The exact code is at http://www.iausofa.org/2013_1202_C/sofa/cal2jd.c
I need to know how to access these address pointers. Validation testing here http://www.iausofa.org/2013_1202_C/sofa/t_sofa_c.c
An almost equivalent core C would look something like this following code. I just made a copy of cal2jd.c and applied the main function at the bottom.
#include <stdio.h>
int
main()
{
int y = 2003, m = 6, d = 1;
int j;
double djm0, djm;
double *pdjm0 = &djm0;
double *pdjm = &djm;
printf("values are: y == %d, m == %d, d == %d\n", y, m, d);
j = iauCal2jd(y, m, d, &djm0, &djm);
printf("j == %d\n", j);
printf("address of &djm0 == %p, size of pointer == %d\n", &djm0, sizeof(*pdjm0));
printf("address of &djm == %p, size of pointer == %d\n", &djm, sizeof(*pdjm0));
printf("value from &djm0 == %.20g, size of djm0 == %d\n", *pdjm0, sizeof(djm0));
printf("value from &djm == %.20g, size of djm == %d\n", *pdjm, sizeof(djm));
printf("value from &djm0 == %.3f\n", (float)*pdjm0);
printf("value from &djm == %.3f\n", (float)*pdjm);
return 0;
}
I will compile it with> gcc -o cal2jd cal2jd.c
Here is my conclusion
$ cal2jd
values are: y == 2003, m == 6, d == 1
j == 0
address of &djm0 == 0022FF30, size of pointer == 8
address of &djm == 0022FF28, size of pointer == 8
value from &djm0 == 2400000.5, size of djm0 == 8
value from &djm == 52791, size of djm == 8
value from &djm0 == 2400000.500
value from &djm == 52791.000
, djm0 sofam.h 2400000.5
, .
, djm.
.
C SOFA Ruby. ( , JRuby). C, DL FFI .
ffi.
.
require 'ffi'
module MyLibrary
extend FFI::Library
ffi_lib "cal2jd.so"
attach_function :iauCal2jd, [:int, :int, :int, :pointer, :pointer], :int
end
JRuby.
, .
?
.