gd_entry(3)

NAME
gd_entry — retrieve a dirfile field's metadata

SYNOPSIS
#include <getdata.h>

int gd_entry(DIRFILE *dirfile, const char *field_code, gd_entry_t *entry);

DESCRIPTION
The gd_entry() function queries a dirfile(5) database specified by dirfile and returns the metadata associated with the field specified by field_code. If field_code contains a valid representation suffix, the suffix will be ignored. The dirfile argument must point to a valid DIRFILE object previously created by a call to gd_open(3). The entry will be stored in the gd_entry_t structure indicated by the entry argument, which must be allocated by the caller. Members available in this structure depend on the field type of the field queried. See below for a complete description of this data type. Strings members in entry filled by this function (variously, depending on field type: field, the elements of the in_fields[] array, table; see below) will by dynamically allocated by gd_entry() and should not point to allocated memory locations before calling this function. Only strings provided by the gd_entry_t for the particular field type described will be allocated. These strings should be de-allocated with free(3) by the caller once they are no longer needed. The gd_free_entry_strings(3) function is provided as a convenience to do this. The returned entry structure, including strings and their pointers may be freely modified by the caller.

RETURN VALUE
Upon successful completion, gd_entry() returns zero, and writes the field metadata in the supplied gd_entry_t buffer. On error, the supplied gd_entry_t buffer is not modified. In this case, gd_entry() returns -1 and sets the dirfile error to a non-zero error value. Possible error values are:

GD_E_BAD_CODE
    The field specified by field_code was not found in the database.

GD_E_BAD_DIRFILE
    The supplied dirfile was invalid.

GD_E_BAD_REPR
    The representation suffix specified in field_code was not recognised.

GD_E_BAD_SCALAR
    A scalar parameter used in the definition of the field was invalid.

The dirfile error may be retrieved by calling gd_error(3). A descriptive error string for the last error encountered can be obtained from a call to gd_error_string(3).

THE ENTRY TYPE
Members available in the gd_entry_t structure depend on the field type described. All gd_entry_t objects are guaranteed to have at least:

typedef struct {
  ...
  const char  *field;          /* field code */
  gd_entype_t  field_type;     /* field type */
  int          fragment_index; /* format fragment index */
  ...
} gd_entry_t;

The field member is the field code of the entry (i.e. its string name). If the call to gd_entry(3) is successful, this will be the field name specified as part of the field_code argument.

The field_type member indicates the field type of the entry. This is an integer type equal to one of the following symbols:

    GD_BIT_ENTRY, GD_CARRAY_ENTRY, GD_CONST_ENTRY, GD_DIVIDE_ENTRY, GD_INDEX_ENTRY, GD_LINCOM_ENTRY, GD_LINTERP_ENTRY, GD_MULTIPLY_ENTRY, GD_PHASE_ENTRY, GD_POLYNOM_ENTRY, GD_RAW_ENTRY, GD_RECIP_ENTRY, GD_SBIT_ENTRY, GD_STRING_ENTRY.

GD_INDEX_ENTRY is a special field type used only for the implicit INDEX field. The meaning of the other symbols should be self-explanatory.

The fragment_index member indicates the format specification fragment in which this field is defined. This is an integer index to the Dirfile's list of parsed format specification fragments. The name of the file corresponding to fragment_index may be obtained by calling gd_fragmentname(3). A value of zero for this field indicates that the field is defined in the primary fragment, the file called format in the root dirfile directory (see dirfile(5)).

Remaining fields in the gd_entry_t structure depend on the value of field_type. Callers are advised to check field_type before attempting to access the remaining members. Members for different field types may be stored in the same physical location in core. Accordingly, attempting to access a member not declared for the appropriate field type will have unspecified results.

  Scalar Parameter Members
A gd_entry_t describing any field type which permits non-literal scalar field parameters (BIT, LINCOM, PHASE, POLYNOM, RECIP, RAW, or SBIT) will also provide:

typedef struct {
  ...
  const char *scalar[GD_MAX_POLY_ORD + 1];     /* param. fields */
  int         scalar_ind[GD_MAX_POLY_ORD + 1]; /* CARRAY indices */
  ...
} gd_entry_t;

Only certain elements of these arrays will be initialised:

•   For BIT and SBIT fields, the first element corresponds to bitnum and the second to numbits. The remainder are uninitialised.

•   For LINCOM fields, the first GD_MAX_LINCOM elements correspond to the slopes (cm) and the next GD_MAX_LINCOM elements correspond to the offsets (cb). Only the first n_fields elements of these two sets are initialised. Notably, this means for n_fields < GD_MAX_LINCOM, there will be uninitialised elements in the middle of these arrays between the element corresponding to cm[n_fields - 1] and the element corresponding to cb[0].

•   For PHASE fields, the first element corresponds to shift. The remainder are unitialised.

•   For POLYNOM fields, these arrays correspond with the co-efficients ca. Only the first poly_ord + 1 elements are initialised.

•   For RECIP fields, the first element corresponds to cdividend. The remainder are unitialised.

•   For RAW fields, the first element corresponds to spf. The remainder are unitialised.

The scalar parameters are NULL if a literal parameter was used, or else a field code specifying the scalar parameters.

If an element of scalar specifies a CARRAY field, the corresponding scalar_ind will indicate the element of the CARRAY used. For CONST fields, scalar_ind will be -1.

  BIT and SBIT Members
A gd_entry_t describing a BIT or SBIT entry, will also provide:

typedef struct {
  ...
  const char *in_fields[1];     /* input field code */
  gd_bit_t    bitnum;           /* first bit */
  gd_bit_t    numbits;          /* bit length */
  ...
} gd_entry_t;

The in_fields member is an array of length one containing the input field code.

The bitnum member indicates the number of the first bit (counted from zero) extracted from the input. The gd_bit_t type is a signed 16-bit integer type. If this value was specified as a scalar field code, this will be the numerical value of that field, and scalar[0] will contain the field code itself, otherwise scalar[0] will be NULL.

The numbits member indicates the number of bits which are extracted from the input. If this value was specified as a scalar field code, this will be the numerical value of that field, and scalar[1] will contain the field code itself, otherwise scalar[1] will be NULL.

  CARRAY Members
A gd_entry_t describing a CARRAY entry, will also provide:

typedef struct {
  ...
  gd_type_t   const_type;     /* data type in format specification */
  size_t      array_len;      /* length of array data */
  ...
} gd_entry_t;

The const_type member indicates the data type of the constant value stored in the format file metadata. See gd_getdata(3) for a list of valid values that a variable of type gd_type_t may take.

The array_len member gives the number of elements in the array.

  CONST Members
A gd_entry_t describing a CONST entry, will also provide:

typedef struct {
  ...
  gd_type_t   const_type;     /* data type in format specification */
  ...
} gd_entry_t;

The const_type member indicates the data type of the constant value stored in the format file metadata. See gd_getdata(3) for a list of valid values that a variable of type gd_type_t may take.

  INDEX Members
A gd_entry_t describing an INDEX entry, which is used only for the implicit INDEX field, provides no additional data.

  LINCOM Members
A gd_entry_t describing a LINCOM entry, will also provide:

typedef struct {
  ...
  int            n_fields;                  /* # of input fields */
  int            comp_scal;                 /* complex scalar flag */
  const char    *in_fields[GD_MAX_LINCOM];  /* input field code(s) */
  double complex cm[GD_MAX_LINCOM];         /* scale factor(s) */
  double         m[GD_MAX_LINCOM];          /* scale factor(s) */
  double complex cb[GD_MAX_LINCOM];         /* offset terms(s) */
  double         b[GD_MAX_LINCOM];          /* offset terms(s) */
  ...
} gd_entry_t;

The n_fields member indicates the number of input fields. It will be between one and GD_MAX_LINCOM inclusive, which is defined in getdata.h to the maximum number of input fields permitted by a LINCOM.

The comp_scal member is non-zero if any of the scale factors or offset terms have a non-zero imaginary part. (That is, if comp_scal is zero, the elements of cm and cb equal the corresponding elements of m and b.) members.)

The in_fields member is an array of length GD_MAX_LINCOM containing the input field code(s). Only the first n_fields elements of this array are initialised. The remaining elements contain uninitialised data.

The cm and cb members are arrays of the scale factor(s) and offset term(s) for the LINCOM. Only the first n_fields elements of these array contain meaningful data. If any of these values were specified as a scalar field code, this will be the numerical value of that field. The field code corresponding to cm[i] will be stored in scalar[i] and the field code associated with cb[i] will be stored in scalar[i + GD_MAX_LINCOM]. Otherwise the corresponding scalar member will be NULL. See NOTES below on changes to the declaration of cm and cb when using the C89 GetData API.

The elements of m and b are the real parts of the corresponding elements of cm and cb.

  LINTERP Members
A gd_entry_t describing a LINTERP entry, will also provide:

typedef struct {
  ...
  const char *table             /* linterp table filename */
  const char *in_fields[1];     /* input field code */
  ...
} gd_entry_t;

The table member is the pathname to the look up table on disk.

The in_fields member is an array of length one containing the input field code.

  MULTIPLY and DIVIDE Members
A gd_entry_t describing a MULTIPLY or DIVIDE entry, will also provide:

typedef struct {
  ...
  const char *in_fields[2];     /* input field codes */
  ...
} gd_entry_t;

The in_fields member is an array of length two containing the input field codes.

  PHASE Members
A gd_entry_t describing a PHASE entry, will also provide:

typedef struct {
  ...
  const char *in_fields[1];     /* input field code */
  gd_shift_t  shift;            /* phase shift */
  ...
} gd_entry_t;

The in_fields member is an array of length one containing the input field code.

The shift member indicates the shift in samples. The gd_shift_t type is a 64-bit signed integer type. A positive value indicates a shift forward in time (towards larger frame numbers). If this value was specified as a scalar field code, this will be the numerical value of that field, and scalar[0] will contain the field code itself, otherwise scalar[0] will be NULL.

  POLYNOM Members
A gd_entry_t describing a POLYNOM entry, will also provide:

typedef struct {
  ...
  int            poly_ord;                  /* polynomial order */
  int            comp_scal;                 /* complex scalar flag */
  const char    *in_fields[1];              /* input field code(s) */
  double complex ca[GD_MAX_POLY_ORD + 1];   /* co-efficients(s) */
  double         a[GD_MAX_POLY_ORD + 1];    /* co-efficients(s) */
  ...
} gd_entry_t;

The poly_ord member indicates the order of the polynomial. It will be between one and GD_MAX_POLY_ORD inclusive, which is defined in getdata.h to the maximum order of polynomial permitted by a POLYNOM.

The comp_scal member is non-zero if any of the co-efficients have a non-zero imaginary part. (That is, if comp_scal is zero, the elements of ca equal the corresponding elements of a.)

The in_fields member is an array of length one containing the input field code.

The ca members are arrays of the co-efficient(s) for the POLYNOM. Only the first poly_ord + 1 elements of this array contains meaningful data. If any of these values were specified as a scalar field code, this will be the numerical value of that field. The field code corresponding to ca[i] will be stored in scalar[i]. Otherwise the corresponding scalar member will be NULL. See NOTES below on changes to the declaration of ca when using the C89 GetData API.

The elements of a are the real parts of the corresponding elements of ca.

  RECIP Members
A gd_entry_t describing a RECIP entry, will also provide:

typedef struct {
  ...
  int            comp_scal;            /* complex scalar flag */
  const char    *in_fields[1];         /* input field code */
  double complex cdividend;            /* scalar dividend */
  double         dividend;             /* scalar dividend */
  ...
} gd_entry_t;

The comp_scal member is non-zero if any of the co-efficients have a non-zero imaginary part. (That is, if comp_scal is zero, cdividend equals dividend.)

The in_fields member is an array of length one containing the input field code.

The cdividend member provides the constant dividend of the computed division. If this value was specified as a scalar field code, this will be the numerical value of that field, and scalar[0] will contain the field code itself, otherwise scalar[0] will be NULL. The dividend member contains the real part of cdividend.

  RAW Members
A gd_entry_t describing a RAW entry, will also provide:

typedef struct {
  ...
  gd_spf_t      spf;          /* samples per frame on disk */
  gd_type_t     data_type;    /* data type on disk */
  ...
} gd_entry_t;

The spf member contains the samples per frame of the binary data on disk. The gd_spf_t type is an unsigned 16-bit integer type. If this value was specified as a scalar field code, this will be the numerical value of that field, and scalar[0] will contain the field code itself, otherwise scalar[0] will be NULL.

The data_type member indicates the data type of the binary data on disk. See gd_getdata(3) for a list of valid values that a variable of type gd_type_t may take.

  STRING Members
A gd_entry_t describing a STRING entry provides no additional data.

NOTES
When using the C89 GetData API (by defining GD_C89_API before including getdata.h), the data types and names of several of the entry parameters are different. The following table lists the correspondences between members in the C99 and C89 APIs.
C99 API | C89 API
gd_spf_t | spf | gd_spf_t | u.raw.spf
gd_type_t | data_type | gd_type_t | u.raw.data_type
int | n_fields | int | u.lincom.n_fields
double compex | cm[3] | double | u.lincom.cm[3][2]
double | m[3] | double | u.lincom.m[3]
double compex | cb[3] | double | u.lincom.cb[3][2]
double | b[3] | double | u.lincom.b[3]
int | poly_ord | int | u.polynom.poly_ord
double compex | ca[3] | double | u.polynom.ca[3][2]
double | a[3] | double | u.polynom.a[3]
const char* | table | const char* | u.linterp.table
gd_bit_t | bitnum | gd_bit_t | u.bit.bitnum
gd_bit_t | numbits | gd_bit_t | u.bit.numbits
gd_shift_t | shift | gd_shift_t | u.phase.shift
double compex | cdividend | double | u.recip.cdividend[2]
double | dividend | double | u.recip.dividend
gd_type_t | const_type | gd_type_t | u.scalar.const_type
size_t | array_len | size_t | u.scalar.array_len

In the case of complex valued data in the C89 API, the first element of the two element array is the real part of the complex number, and the second element is the imaginary part.

SEE ALSO
dirfile(5), gd_free_entry_strings(3), gd_cbopen(3), gd_error(3), gd_error_string(3), gd_field_list(3), gd_fragmentname(3), gd_getdata(3), gd_raw_filename(3)