gd_madd_bit(3)

πŸ’– NAME πŸ’–

okay so bestie, welcome to the GETDATA manual, and today's main character is gd_madd_bit(3) β€” plus the whole entire girl squad: gd_madd_carray, gd_madd_clincom, gd_madd_const, gd_madd_cpolynom, gd_madd_crecip, gd_madd_divide, gd_madd_indir, gd_madd_lincom, gd_madd_linterp, gd_madd_multiply, gd_madd_phase, gd_madd_polynom, gd_madd_recip, gd_madd_sarray, gd_madd_sbit, gd_madd_sindir, gd_madd_string β€” and what do they all do? add a field to a Dirfile. periodt. πŸ’…


✨ SYNOPSIS ✨

first things first, you gotta let the compiler know what's up:

#include <getdata.h>

and then, the whole roster, exactly as they live in the header:

int gd_madd_bit(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, int bitnum, int numbits);

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

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

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

int gd_madd_cpolynom(DIRFILE *dirfile, const char *parent, const char *field_name, int poly_ord, const char *in_field, const double complex *ca);

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

int gd_madd_divide(DIRFILE *dirfile, const char *parent, const char *field_name,  const char *in_field1, const char *in_field2);

int gd_madd_indir(DIRFILE *dirfile, const char *parent, const char *field_name,  const char *index_field, const char *carray_field);

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

int gd_madd_linterp(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, const char *table);

int gd_madd_mplex(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, const char *count_field, int count_val, int period);

int gd_madd_multiply(DIRFILE *dirfile, const char *parent, const char *field_name,  const char *in_field1, const char *in_field2);

int gd_madd_polynom(DIRFILE *dirfile, const char *parent, const char *field_name, int poly_ord, const char *in_field, const double *a);

int gd_madd_phase(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, gd_int64_t shift);

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

int gd_madd_sarray(DIRFILE *dirfile, const char *parent, const char *field_name, size_t array_len ,constchar**"value);

int gd_madd_sbit(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, int bitnum, int numbits);

int gd_madd_sindir(DIRFILE *dirfile, const char *parent, const char *field_name,  const char *index_field, const char *sarray_field);

int gd_madd_string(DIRFILE *dirfile, const char *parent, const char *field_name, const char *value);

int gd_madd_window(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, const char *check_field, gd_windop_t windop, gd_triplet_t threshold);
not me copying that gd_madd_sarray line exactly as it is in the source, typos and all πŸ™ˆ β€” bestie, I do not make the rules, I just transcribe them.

🌸 DESCRIPTION 🌸

so here's the tea πŸ“: these functions add a brand new metafield of whatever type you picked, under the parent field you pass as parent, into the dirfile you pass as dirfile.

In all of these calls, field_name is the name of the field you're adding. Heads up tho β€” it should not be the full <parent-field>/<meta-field> field code. And if you wanna know what the other arguments actually mean and which types are valid for them, that lore lives in the gd_entry(3) and dirfile-format(5) manual pages. πŸ’œ

The gd_madd_clincom() and gd_madd_cpolynom() functions are literally identical to gd_madd_lincom() and gd_madd_polynom(), except they take complex scalar parameters instead of purely real values. imaginary numbers said "let me in" and honestly? iconic. ✨

The gd_madd_lincom() and gd_madd_clincom() functions take pointers to three arrays of length n_fields, holding:

  • the input field names (in_fields)
  • the gain factors (m or cm)
  • the offset terms (b or cb)

Similarly, gd_madd_polynom() and gd_madd_cpolynom() take an array of length poly_ord + 1 containing the polynomial co-efficients (a or ca). math girlies rise 🧚

The gd_madd_carray(), gd_madd_const(), gd_madd_sarray(), and gd_madd_string() functions do two things: they add the field and set the value of the field to value. For gd_madd_const() and gd_madd_carray(), the const_type argument says what the storage type for the const is, while data_type says the data type of the value that value points at. And for gd_madd_sarray(), value should contain 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 you should set depends on the operator you picked for the WINDOW field. gd_entry(3) has the details, go peek. πŸ‘‘

big important vibe check: all fields added with this interface must contain numerical parameters. Fields whose parameters are scalar fields cannot be added with these functions β€” those ones have to go through gd_madd(3) or gd_madd_spec(3). And see gd_add_bit(3), &c. for an alternate way of adding metafields with explicit parameters.

Also, scroll down to NOTES if you're out here using gd_madd_clincom(), gd_madd_cpolynom(), and gd_madd_crecip() in the C89 GetData API. you've been warned bestie 😭


πŸ’« RETURN VALUE πŸ’«

On success, any of these functions returns zero. On error, a negative-valued error code comes back at you. Possible error codes are:

  • GD_E_ACCMODE β€” the specified dirfile was opened read-only. rude.
  • GD_E_ALLOC β€” the library could not allocate memory. it's giving low memory energy πŸ’€
  • GD_E_BAD_CODE β€” the field_name argument contained invalid characters. Alternatively, the parent field code was not found, or was already a metafield.
  • GD_E_BAD_DIRFILE β€” the supplied dirfile was invalid.
  • GD_E_BAD_ENTRY β€” one or more of the field parameters you specified was invalid.
  • GD_E_BAD_TYPE β€” the data_type or const_type argument provided to gd_madd_const() or gd_madd_carray() was invalid.
  • GD_E_DUPLICATE β€” the field_name you gave duplicated that of an already existing field. we don't do repeats here πŸ™ˆ
  • GD_E_PROTECTED β€” the metadata of the fragment was protected from change. hands off βœ‹

The dirfile error may also be retrieved by calling gd_error(3). And if you want a descriptive error string for the last error encountered, that's a gd_error_string(3) call. 🫢


πŸ¦‹ NOTES πŸ¦‹

The C89 GetData API provides different prototypes for gd_madd_clincom(), and gd_madd_crecip():

#define GD_C89_API
#include <getdata.h>

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

int gd_madd_cpolynom(DIRFILE *dirfile, const char *parent, const char *field_name, int poly_ord, const char *in_field, const double *ca);

int gd_madd_crecip(DIRFILE *dirfile, const char *parent, const char *field_name, const char *in_field, 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. So like, 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 and so forth. Similarly, the cdividend parameter becomes a double precision array of length two. alternating real/imag is such a pattern, honestly obsessed 🌈

For gd_madd_clincom() and gd_madd_cpolynom(), these are simply different (but equivalent) declarations of the C99 function entry point. For gd_madd_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_madd_crecip() is always available, and may be accessed as gd_madd_crecip89(), with the C89 prototype, in both the C99 and C89 APIs. portability queen πŸ’…


πŸ“œ HISTORY πŸ“œ

The functions dirfile_madd_bit(), dirfile_madd_const(), dirfile_madd_lincom(), dirfile_madd_linterp(), dirfile_madd_multiply(), dirfile_madd_phase(), and dirfile_madd_string() appeared in GetData-0.4.0. the OGs fr fr

The functions dirfile_madd_clincom(), dirfile_madd_cpolynom(), dirfile_madd_polynom(), and dirfile_madd_sbit() appeared in GetData-0.6.0.

In GetData-0.7.0, the functions were renamed to gd_madd_bit(), gd_madd_clincom(), gd_madd_const(), gd_madd_cpolynom(), gd_madd_lincom(), gd_madd_linterp(), gd_madd_multiply(), gd_madd_phase(), gd_madd_polynom(), gd_madd_sbit(), and gd_madd_string(). The functions gd_madd_carray(), gd_madd_crecip(), gd_madd_divide(), and gd_madd_recip() also appeared in this version. glow-up era ✨

In GetData-0.8.0, these functions first allowed adding metafields by providing the full (slashed) field name. The functions gd_madd_mplex() and gd_madd_window() also appeared in this version.

In GetData-0.10.0, the error return from these functions changed from -1 to a negative-valued error code. The functions gd_madd_indir(), gd_madd_sarray(), and gd_madd_sindir() also appeared in this version. character development πŸ”₯


πŸ‘€ SEE ALSO πŸ‘€


okay that's the whole page bestie, go forth and add fields πŸŒΈπŸ¦‹

Version 0.10.0 Β· 25 December 2016 Β· mwah, happy madd-ing πŸ’–βœ¨πŸŽ€