/* file: dbf.c G. Moody 23 August 1995 Last revised: 15 April 1997 Fortran wrappers for the DB library functions Copyright (C) Massachusetts Institute of Technology 1997. All rights reserved. General notes on using the wrapper functions Wrappers are provided below for all of the DB library functions except setmsheader. See the sample program (example.f, in this directory) to see how the wrappers are used. Include the statements implicit integer(a-z) real aduphys, getbasecount, getcfreq, sampfreq (or the equivalent for your dialect of Fortran) in your Fortran program to ensure that these functions (except for the four listed in the second statement) will be understood to return integer*4 values (equivalent to C `long' values). Note that Fortran arrays are 1-based, and C arrays are 0-based. Signal and annotator numbers passed to these functions must be 0-based. If you are using a UNIX Fortran compiler, or a Fortran-to-C translator, note that the trailing `_' in these function names should *not* appear in your Fortran program; thus, for example, `annopen1_' should be invoked as `annopen1'. UNIX Fortran compilers and translators append a `_' to the names of all external symbols referenced in Fortran source files when generating object files. Thus the linker can recognize that annopen1_ (defined below) is the function required by a Fortran program that invokes `annopen1'; if the Fortran program were to invoke `annopen1_', the linker would search (unsuccessfully) for a function named `annopen1__'. If you are using a Fortran compiler that does not follow this convention, you are on your own. */ #include #include #ifndef BSD # include #else /* for Berkeley UNIX only */ # include #endif /* If a DB_Sample is the same size as a long (true except for MS-DOS PCs and a few less common systems), considerable efficiency gains are possible. Otherwise, define REPACK below to compile the code needed to repack arrays of DB_Samples into long arrays. */ /* #define REPACK */ /* If Fortran strings are terminated by spaces rather than by null characters, define FIXSTRINGS. */ /* #define FIXSTRINGS */ #ifdef FIXSTRINGS fcstring(s) /* change final space to null */ char *s; { while (*s && *s != ' ') s++; *s = '\0'; } cfstring(s) /* change final null to space */ char *s; { while (*s) s++; *s = ' '; } #else #define fcstring(s) #define cfstring(s) #endif /* Static data shared by the wrapper functions. Since Fortran does not support composite data types (such as C `struct' types), these are defined here, and functions for setting and retrieving data from these structures are provided below. */ static DB_Siginfo sinfo[DB_MAXSIG]; static DB_Calinfo cinfo; static DB_Anninfo ainfo[DB_MAXANN*2]; /* The functions setanninfo_, setsiginfo_, and getsiginfo_ do not have direct equivalents in the DB library; they are provided in order to permit Fortran programs to read and write data structures passed to and from several of the DB library functions. Since the contents of these structures are directly accessible by C programs, these functions are not needed in the C library. */ long setanninfo_(a, name, stat) long *a; char *name; long *stat; { if (0 <= *a && *a < DB_MAXANN*2) { fcstring(name); ainfo[*a].name = name; ainfo[*a].stat = *stat; return (0L); } else return (-1L); } long getsiginfo_(s, fname, desc, units, gain, initval, group, fmt, spf, bsize, adcres, adczero, baseline, nsamp, cksum) long *s; char *fname, *desc, *units; double *gain; long *initval, *group, *fmt, *spf, *bsize, *adcres, *adczero, *baseline, *nsamp, *cksum; { if (0 <= *s && *s < DB_MAXSIG) { fname = sinfo[*s].fname; desc = sinfo[*s].desc; units = sinfo[*s].units; *gain = sinfo[*s].gain; *initval = sinfo[*s].initval; *group = sinfo[*s].group; *fmt = sinfo[*s].fmt; *spf = sinfo[*s].spf; *bsize = sinfo[*s].bsize; *adcres = sinfo[*s].adcres; *adczero = sinfo[*s].adczero; *baseline = sinfo[*s].baseline; *nsamp = sinfo[*s].nsamp; *cksum = sinfo[*s].cksum; return (0L); } else return (-1L); } long setsiginfo_(s, fname, desc, units, gain, initval, group, fmt, spf, bsize, adcres, adczero, baseline, nsamp, cksum) long *s; char *fname, *desc, *units; double *gain; long *initval, *group, *fmt, *spf, *bsize, *adcres, *adczero, *baseline, *nsamp, *cksum; { if (0 <= *s && *s < DB_MAXSIG) { sinfo[*s].fname = fname; sinfo[*s].desc = desc; sinfo[*s].units = units; sinfo[*s].gain = *gain; sinfo[*s].initval = *initval; sinfo[*s].group = *group; sinfo[*s].fmt = *fmt; sinfo[*s].spf = *spf; sinfo[*s].bsize = *bsize; sinfo[*s].adcres = *adcres; sinfo[*s].adczero = *adczero; sinfo[*s].baseline = *baseline; sinfo[*s].nsamp = *nsamp; sinfo[*s].cksum = *cksum; return (0L); } else return (-1L); } /* Before using annopen_, set up the annotation information structures using setanninfo_. */ long annopen_(record, nann) char *record; long *nann; { fcstring(record); return (annopen(record, ainfo, (unsigned int)(*nann))); } /* After using isigopen_ or osigopen_, use getsiginfo_ to obtain the contents of the signal information structures if necessary. */ long isigopen_(record, nsig) char *record; long *nsig; { fcstring(record); return (isigopen(record, sinfo, (unsigned int)(*nsig))); } long osigopen_(record, nsig) char *record; long *nsig; { int i; fcstring(record); return (osigopen(record, sinfo, (unsigned int)(*nsig))); } /* Before using osigfopen_, use setsiginfo to set the contents of the signal information structures. */ long osigfopen_(nsig) long *nsig; { return (osigfopen(sinfo, (unsigned int)(*nsig))); } /* Before using dbinit_, use setanninfo and setsiginfo to set the contents of the annotation and signal information structures. */ long dbinit_(record, nann, nsig) char *record; long *nann, *nsig; { fcstring(record); return (dbinit(record, ainfo, (unsigned int)(*nann), sinfo, (unsigned int)(*nsig))); } long setgvmode_(mode) long *mode; { setgvmode((int)(*mode)); return (0L); } long getspf_(void) { return (getspf()); } long getvec_(long_vector) long *long_vector; { #ifndef REPACK return (getvec((DB_Sample *)long_vector)); #else DB_Sample v[DB_MAXSIG]; int i, j; i = getvec(v); for (j = 0; j < i; j++) long_vector[i] = v[i]; return (i); #endif } long getframe_(long_vector) long *long_vector; { #ifndef REPACK return (getframe((DB_Sample *)long_vector)); #else DB_Sample v[DB_MAXSIG*DB_MAXSPF]; int i, j, k; i = getframe(v); for (j = 0; j < i; j += k) for (k = 0; k < sinfo[i].spf; k++) long_vector[j+k] = v[j+k]; return (i); #endif } long putvec_(long_vector) long *long_vector; { #ifndef REPACK return (putvec((DB_Sample *)long_vector)); #else DB_Sample v[DB_MAXSIG*DB_MAXSPF]; int i; for (i = 0; i < DB_MAXSIG*DB_MAXSPF; i++) v[i] = long_vector[i]; return (putvec(v)); #endif } long getann_(annotator, time, anntyp, subtyp, chan, num, aux) long *annotator, *time, *anntyp, *subtyp, *chan, *num; char *aux; { static DB_Annotation iann; int i, j; i = getann((DB_Annotator)(*annotator), &iann); if (i == 0) { *time = iann.time; *anntyp = iann.anntyp; *subtyp = iann.subtyp; *chan = iann.chan; *num = iann.num; aux = iann.aux; } return (i); } long ungetann_(annotator, time, anntyp, subtyp, chan, num, aux) long *annotator, *time, *anntyp, *subtyp, *chan, *num; char *aux; { static DB_Annotation oann; int i, j; oann.time = *time; oann.anntyp = *anntyp; oann.subtyp = *subtyp; oann.chan = *chan; oann.num = *num; oann.aux = aux; return (ungetann((DB_Annotator)(*annotator), &oann)); } long putann_(annotator, time, anntyp, subtyp, chan, num, aux) long *annotator, *time, *anntyp, *subtyp, *chan, *num; char *aux; { static DB_Annotation oann; int i, j; oann.time = *time; oann.anntyp = *anntyp; oann.subtyp = *subtyp; oann.chan = *chan; oann.num = *num; oann.aux = aux; return (putann((DB_Annotator)(*annotator), &oann)); } long isigsetttime_(time) long *time; { return (isigsettime((DB_Time)(*time))); } long isgsetttime_(group, time) long *group, *time; { return (isgsettime((DB_Group)(*group), (DB_Time)(*time))); } long ecgstr_(code, string) long *code; char *string; { strcpy(string, ecgstr((int)(*code))); cfstring(string); return (0L); } long strecg_(string) char *string; { fcstring(string); return (strecg(string)); } long setecgstr_(code, string) long *code; char *string; { fcstring(string); return (setecgstr((int)(*code), string)); } long annstr_(code, string) long *code; char *string; { strcpy(string, annstr((int)(*code))); cfstring(string); return (0L); } long strann_(string) char *string; { fcstring(string); return (strann(string)); } long setannstr_(code, string) long *code; char *string; { fcstring(string) return (setannstr((int)(*code), string)); } long anndesc_(code, string) long *code; char *string; { strcpy(string, anndesc((int)(*code))); cfstring(string); return (0L); } long setanndesc_(code, string) long *code; char *string; { fcstring(string); return (setanndesc((int)(*code), string)); } long iannclose_(annotator) long *annotator; { iannclose((DB_Annotator)(*annotator)); return (0L); } long oannclose_(annotator) long *annotator; { oannclose((DB_Annotator)(*annotator)); return (0L); } long timstr_(time, string) long *time; char *string; { strcpy(string, timstr((DB_Time)(*time))); cfstring(string); return (0L); } long mstimstr_(time, string) long *time; char *string; { strcpy(string, mstimstr((DB_Time)(*time))); cfstring(string); return (0L); } long strtim_(string) char *string; { fcstring(string); return (strtim(string)); } long datstr_(date, string) long *date; char *string; { strcpy(string, datstr((DB_Date)(*date))); cfstring(string); return (0L); } long strdat_(string) char *string; { fcstring(string); return (strdat(string)); } long adumuv_(signal, ampl) long *signal, *ampl; { return (adumuv((DB_Signal)(*signal), (DB_Sample)(*ampl))); } long muvadu_(signal, microvolts) long *signal, *microvolts; { return (muvadu((DB_Signal)(*signal), (int)(*microvolts))); } double aduphys_(signal, ampl) long *signal, *ampl; { return (aduphys((DB_Signal)(*signal), (DB_Sample)(*ampl))); } long physadu_(signal, v) long *signal; double *v; { return (physadu((DB_Signal)(*signal), *v)); } long calopen_(calibration_filename) char *calibration_filename; { fcstring(calibration_filename); return (calopen(calibration_filename)); } long getcal_(description, units, low, high, scale, caltype) char *description, *units; double *low, *high, *scale; long *caltype; { fcstring(description); fcstring(units); if (getcal(description, units, &cinfo) == 0) { *low = cinfo.low; *high = cinfo.high; *scale = cinfo.scale; *caltype = cinfo.caltype; return (0L); } else return (-1L); } long putcal_(description, units, low, high, scale, caltype) char *description, *units; double *low, *high, *scale; long *caltype; { fcstring(description); fcstring(units); cinfo.sigtype = description; cinfo.units = units; cinfo.low = *low; cinfo.high = *high; cinfo.scale = *scale; cinfo.caltype = *caltype; return (putcal(&cinfo)); } long newcal_(calibration_filename) char *calibration_filename; { fcstring(calibration_filename); return (newcal(calibration_filename)); } long flushcal_(dummy) long *dummy; { flushcal(); return (0L); } long getinfo_(record, string) char *record, *string; { fcstring(record); strcpy(string, getinfo(record)); cfstring(string); return (0L); } long putinfo_(string) char *string; { fcstring(string); return (putinfo(string)); } long newheader_(record) char *record; { fcstring(record); return (newheader(record)); } /* Before using setheader_, use setsiginfo to set the contents of the signal information structures. */ long setheader_(record, nsig) char *record; long *nsig; { fcstring(record); return (setheader(record, sinfo, (unsigned int)(*nsig))); } /* No wrapper is provided for setmsheader. */ long dbgetskew_(s) long *s; { return (dbgetskew((DB_Signal)(*s))); } long dbsetskew_(s, skew) long *s, *skew; { dbsetskew((DB_Signal)(*s), (int)(*skew)); return (0L); } long dbgetstart_(s) long *s; { return (dbgetstart((DB_Signal)(*s))); } long dbsetstart_(s, bytes) long *s, *bytes; { dbsetstart((DB_Signal)(*s), *bytes); return (0L); } long dbquit_(dummy) long *dummy; { dbquit(); return (0L); } double sampfreq_(record) char *record; { fcstring(record); return (sampfreq(record)); } long setsampfreq_(frequency) double *frequency; { return (setsampfreq((DB_Frequency)(*frequency))); } double getcfreq_(dummy) long *dummy; { return (getcfreq()); } long setcfreq_(frequency) double *frequency; { setcfreq((DB_Frequency)(*frequency)); return (0L); } double getbasecount_(dummy) long *dummy; { return (getbasecount()); } long setbasecount_(count) double *count; { setbasecount(*count); return (0L); } long setbasetime_(string) char *string; { fcstring(string); return (setbasetime(string)); } long dbquiet_(dummy) long *dummy; { dbquiet(); return (0L); } long dbverbose_(dummy) long *dummy; { dbverbose(); return (0L); } long dberror_(string) char *string; { strcpy(string, dberror()); cfstring(string); return (0L); } long setdb_(string) char *string; { fcstring(string); setdb(string); return (0L); } long getdb_(string) char *string; { strcpy(string, getdb()); cfstring(string); return (0L); } long setibsize_(input_buffer_size) long *input_buffer_size; { return (setibsize((int)(*input_buffer_size))); } long setobsize_(output_buffer_size) long *output_buffer_size; { return (setobsize((int)(*output_buffer_size))); } long dbfile_(file_type, record, pathname) char *file_type, *record, *pathname; { fcstring(file_type); fcstring(record); strcpy(pathname, dbfile(file_type, record)); cfstring(pathname); return (0L); } long dbflush_(dummy) long *dummy; { dbflush(); return (0L); }