gd_add_bit(3)

hey bestie, welcome to the gd_add_bit(3) manual page β€” GETDATA section, if you were wondering πŸ’– this is part 1 of 2, so grab a snack and let's get into it.


✨ NAME ✨

okay so the NAME section is giving a whole squad of functions: gd_add_bit, gd_add_carray gd_add_clincom, gd_add_const, gd_add_cpolynom, gd_add_crecip, gd_add_divide, gd_add_indir, gd_add_lincom, gd_add_linterp, gd_add_multiply, gd_add_phase, gd_add_polynom, gd_add_raw, gd_add_recip, gd_add_sarray, gd_add_sbit, gd_add_sindir, gd_add_string β€” and they all add a field to a Dirfile. periodt. πŸ’…


🌸 SYNOPSIS 🌸

here's the tea on the function signatures, bestie β€” copy-paste carefully, no cap:

#include <getdata.h>

int gd_add_bit(DIRFILE *dirfile, const char *field_name, const char
       *in_field, int bitnum, int numbits, int fragment_index);

int gd_add_carray(DIRFILE *dirfile, const char *field_name, gd_type_t
       const_type, size_t array_len, gd_type_t data_type, void *value,
       int fragment_index);

int gd_add_clincom(DIRFILE *dirfile, const char *field_name, int
       n_fields, const char **in_fields, const double complex *cm, const
       double complex *cb, int fragment_index);

int gd_add_const(DIRFILE *dirfile, const char *field_name, gd_type_t
       const_type, gd_type_t data_type, void *value, int
       fragment_index);

int gd_add_cpolynom(DIRFILE *dirfile, const char *field_name, int
       poly_ord, const char *in_fields, const double complex *ca, int
       fragment_index);

int gd_add_crecip(DIRFILE *dirfile, const char *field_name, const char
       *in_field, double complex cdividend, int fragment_index);

int gd_add_divide(DIRFILE *dirfile, const char *field_name, const char
       *in_field1, const char *in_field2, int fragment_index);

int gd_add_indir(DIRFILE *dirfile, const char *field_name, const char
       *index_field, const char *carray_field, int fragment_index);

int gd_add_lincom(DIRFILE *dirfile, const char *field_name, int
       n_fields, const char **in_fields, const double *m, const double
       *b, int fragment_index);

int gd_add_linterp(DIRFILE *dirfile, const char *field_name, const char
       *in_field, const char *table, int fragment_index);

int gd_add_mplex(DIRFILE *dirfile, const char *field_name, const char
       *in_field, const char *count_field, int count_val, int period,
       int fragment_index);

int gd_add_multiply(DIRFILE *dirfile, const char *field_name, const char
       *in_field1, const char *in_field2, int fragment_index);

int gd_add_phase(DIRFILE *dirfile, const char *field_name, const char
       *in_field, gd_int64_t shift, int fragment_index);

int gd_add_polynom(DIRFILE *dirfile, const char *field_name, int
       poly_ord, const char *in_fields, const double *a, int
       fragment_index );

int gd_add_raw(DIRFILE *dirfile, const char *field_name, gd_type_t
       data_type, unsigned int spf, int fragment_index);

int gd_add_recip(DIRFILE *dirfile, const char *field_name, const char
       *in_field, double dividend, int fragment_index);

int gd_add_sarray(DIRFILE *dirfile, const char *field_name, size_t
       array_len, const char **values,int fragment_index);

int gd_add_sbit(DIRFILE *dirfile, const char *field_name, const char
       *in_field, int bitnum, int numbits, int fragment_index);

int gd_add_sindir(DIRFILE *dirfile, const char *field_name, const char
       *index_field, const char *sarray_field, int fragment_index);

int gd_add_string(DIRFILE *dirfile, const char *field_name, const char
       *value, int fragment_index);

int gd_add_window(DIRFILE *dirfile, const char *field_name, const char
       *in_field, const char *check_field, gd_windop_t windop,
       gd_triplet_t threshold, int fragment_index);

πŸ’… DESCRIPTION πŸ’…

okay so these functions are like the alt route to using gd_add(3) or gd_add_spec(3) β€” you're adding a new field of the indicated type to the dirfile specified by dirfile. slay. ✨

in literally every one of these calls, field_name is the name of the field to be added. further, fragment_index is the index of the format specification fragment into which the field should be added. (to convert a fragment index to its file name, see gd_fragmentname(3).) the meaning and allowed types of other arguments? you can get those from the gd_entry(3) and dirfile-format(5) manual pages. periodt. πŸ’–

gd_add_clincom() and gd_add_cpolynom() are identical to gd_add_lincom() and gd_add_polynom(), except they take complex scalar parameters, instead of purely real values. it's giving complexity, literally. πŸ¦‹

gd_add_lincom() and gd_add_clincom() take pointers to three arrays of length n_fields containing the input field names (in_fields), the gain factors (m or cm), and the offset terms (b or cb). similarly, gd_add_polynom() and gd_add_cpolynom() take an array of length poly_ord + 1 containing the polynomial co-efficients (a or ca). πŸ”₯

gd_add_carray(), gd_add_const(), gd_add_sarray(), and gd_add_string() add the field and set the value of the field to value. for gd_add_const() and gd_add_carray(), the const_type argument specifies the storage type for the const, while data_type specifies the data type of the value pointed to by value. for gd_add_sarray(), value should be an array of array_len string pointers. 🌈

the gd_int64_t type is a signed 64-bit integer type. the gd_triplet_t type is defined as:

typedef union {
  gd_int64_t i;
  gd_uint64_t u;
  double r;
} gd_triplet_t;

which element of this gd_triplet_t union to set depends on the operator selected for the WINDOW field. see gd_entry(3) for details. πŸ‘‘

a metafield may be added to the dirfile either by calling these functions with field_name containing the fully formed "<parent-field>/<metafield>" field code, or else by using the corresponding gd_madd_...() function (see gd_madd_bit(3), &c.) when adding a metafield with these functions, fragment_index is ignored and GetData will add the new metafield to the same format specification fragment in which the parent field is defined. if the specified parent field name is an alias, the canonical name of the field will be substituted. πŸ’€

all fields added with this interface must contain literal parameters. fields with scalar fields as parameters cannot be added with these functions. those fields must be added with gd_add(3) or gd_add_spec(3). πŸ™ˆ

see NOTES below for information on using gd_add_clincom(), gd_add_cpolynom(), and gd_add_crecip() in the C89 GetData API. πŸŽ€


πŸ”₯ RETURN VALUE πŸ”₯

on success, any of these functions returns zero. on error, a negative-valued error value is returned. possible error values are:

  • GD_E_ACCMODE β€” the specified dirfile was opened read-only. πŸ’”
  • GD_E_ALLOC β€” the library was unable to allocate memory. 😭
  • GD_E_BAD_CODE β€” the field_name contained invalid characters; or it or an input field did not contain the affected fragment's prefix or suffix. 🚫
  • GD_E_BAD_DIRFILE β€” the supplied dirfile was invalid. πŸ‘Ž
  • GD_E_BAD_ENTRY β€” one or more of the field parameters specified was invalid. πŸ™…
  • GD_E_BAD_INDEX β€” the fragment_index argument was out of range. πŸ“‰
  • GD_E_BAD_TYPE β€” the data_type or const_type argument provided to gd_add_raw() or gd_add_const() was invalid. ❌
  • GD_E_DUPLICATE β€” the field_name provided duplicated that of an already existing field. πŸ‘―
  • GD_E_INTERNAL_ERROR β€” an internal error occurred in the library while trying to perform the task. this indicates a bug in the library. please report the incident to the GetData developers. πŸ›
  • GD_E_IO (gd_add_raw() only) β€” an I/O error occurred while creating an empty binary file to be associated with a newly added RAW field. πŸ’Ύ
  • GD_E_PROTECTED β€” the metadata of the fragment was protected from change. or, the creation of a RAW field was attempted and the data of the fragment was protected. πŸ”’
  • GD_E_UNKNOWN_ENCODING (gd_add_raw() only) β€” the encoding scheme of the indicated format specification fragment is not known to the library. as a result, the library was unable to create an empty binary file to be associated with a newly added RAW field. ❓
  • GD_E_UNSUPPORTED (gd_add_raw() only) β€” the encoding scheme of the indicated format specification fragment does not support creating an empty binary file to be associated with a newly added RAW field. πŸ›‘

the dirfile error may also 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). 🫢


πŸŽ€ NOTES πŸŽ€

the C89 GetData API provides different prototypes for gd_add_clincom(), gd_add_cpolynom(), and gd_add_crecip():

#define GD_C89_API
#include <getdata.h>

int gd_add_clincom(DIRFILE *dirfile, const char *field_name, int
       n_fields, const char **in_fields, const double *cm, const double
       *cb, int fragment_index);

int gd_add_cpolynom(DIRFILE *dirfile, const char *field_name, int
       poly_ord, const char *in_fields, const double *ca, int
       fragment_index);

int gd_add_crecip(DIRFILE *dirfile, const char *field_name, const char
       *in_field, const double cdividend[2], int fragment_index);

in this case, the array pointers passed as cm, cb or ca should have twice as many (purely real) elements, consisting of alternating real and imaginary parts for the complex data. that is, for example, ca[0] should be the real part of the first co-efficient, ca[1] the imaginary part of the first co-efficient, ca[2] the real part of the second co-efficient, ca[3] the imaginary part of the second co-efficient, and so on. similarly, the cdividend parameter becomes a double precision array of length two. 🧚

for gd_add_clincom() and gd_add_cpolynom(), these are simply different (but equivalent) declarations of the C99 function entry point. for gd_add_crecip(), however, a different entry point is needed (since the cdividend parameter is passed by reference instead of by value). in the interests of portability, the C89 version of gd_add_crecip() is always available, and may be accessed as gd_add_crecip89(), with the C89 prototype, in both the C99 and C89 APIs. πŸ’œ

🌈 HISTORY 🌈

okay bestie, story time πŸ“–βœ¨ because this function has been through it and honestly? her glow-up is iconic.

Back in GetData-0.4.0, a whole little squad of functions showed up:

  • dirfile_add_bit()
  • dirfile_add_const()
  • dirfile_add_lincom()
  • dirfile_add_linterp()
  • dirfile_add_multiply()
  • dirfile_add_phase()
  • dirfile_add_raw()
  • dirfile_add_string()

then in GetData-0.6.0, four more joined the group chat 🫢:

  • dirfile_add_clincom()
  • dirfile_add_cpolynom()
  • dirfile_add_polynom()
  • dirfile_add_sbit()

and then GetData-0.7.0 said "new name, who dis" πŸ’… and renamed the whole crew:

  • dirfile_add_bit() β†’ gd_add_bit()
  • dirfile_add_clincom() β†’ gd_add_clincom()
  • dirfile_add_const() β†’ gd_add_const()
  • dirfile_add_cpolynom() β†’ gd_add_cpolynom()
  • dirfile_add_lincom() β†’ gd_add_lincom()
  • dirfile_add_linterp() β†’ gd_add_linterp()
  • dirfile_add_multiply() β†’ gd_add_multiply()
  • dirfile_add_phase() β†’ gd_add_phase()
  • dirfile_add_polynom() β†’ gd_add_polynom()
  • dirfile_add_raw() β†’ gd_add_raw()
  • dirfile_add_sbit() β†’ gd_add_sbit()
  • dirfile_add_string() β†’ gd_add_string()

and this version ALSO birthed these four cuties, no cap:

  • gd_add_carray()
  • gd_add_crecip()
  • gd_add_divide()
  • gd_add_recip()

then GetData-0.8.0 rolled in and these functions first allowed adding metafields by providing the full (slashed) field name β€” main character behavior, honestly πŸŽ€ β€” and two new friends appeared:

  • gd_add_mplex()
  • gd_add_window()

and finally GetData-0.10.0 came through with a plot twist 😭: the error return from these functions changed from -1 to a negative-valued error code. So if you were out here checking == -1, bestie, vibe check that code fr fr. πŸ’€ Also these three showed up:

  • gd_add_indir()
  • gd_add_sarray()
  • gd_add_sindir()

πŸ‘€ SEE ALSO πŸ‘€

like, go read these too, they're all connected iykyk:


Version 0.10.0 Β· 25 December 2016 Β· that's the whole gd_add_bit(3) page, bestie πŸ’– go forth and add those bits, you absolute legend πŸ‘‘βœ¨πŸ¦‹