Adding a Routine to SDSSMATH
The most common change to SDSSMATH is to add a C binding (and possibly
DERVISH-based C and TCL bindings) for a routine which is part of a library
which is already partially supported in SDSSMATH.
This expains how to do so. As an example, we will add C, DERVISH-based C,
and DERVISH-based TCL bindings for the SLALIB routine:
sla_DTF2R(IHOUR, IMIN, SEC, DAYS, J)
Straight C Binding
The straight C bindings (independent of DERVISH) for a given library are
prototyped in the file "include/library_c.h", and defined in the
file "src/library_c.c" (replace library in the file names
with the name of your library; in our case, with slalib. For the
example, add the following line to "include/slalib_c.h":
void sla_dtf2r_(int *hour, int *min, double *sec, double *radian, int *jflag);
and add the following lines to "src/slalib_c.c":
void sl_dtf2r_(int *hour, int *min, double *sec, double *radian, int *jflag);
void sla_dtf2r(int *hour, int *min, double *sec, double *radian, int *jflag)
{ sla_dtf2r_(hour, min, sec, radian, jflag); }
The first line in the source file declares the Fortran prototype, and the
second line defines the C binding, using the usual rules for calling a
Fortran routine from C.
DERVISH-based C Binding
The DERVISH_based C bindings for a given library are
prototyped in the file "include/library.h", and defined in the
file "src/library.c". For the
example, add the following line to "include/slalib.h":
double slRadFromHMS(char *string);
and add the following lines to "src/slalib.c":
double slRadFromHMS(char *string) {
int nstrt, hour, min;
double sec, radian;
int hourFlag, minFlag, secFlag, jflag;
nstrt = 1; sla_intin(string, &nstrt, &hour, &hourFlag);
nstrt++; sla_intin(string, &nstrt, &min, &minFlag);
nstrt++; sla_dfltin(string, &nstrt, &sec, &secFlag);
if ( (hourFlag==0) && (minFlag==0) && (secFlag==0) ) {
sla_dtf2r(&hour, &min, &sec, &radian, &jflag);
} else {
radian = -10.0;
}
return radian;
}