---
name: "gd_add_multiply"
section: "3"
platform: "linux"
package: "libgetdata-doc"
version: "0.11.0-15"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/gd_add_bit"
---

# gd\_add\_multiply(3)

add a field to a Dirfile

Part of [gd\_add\_bit(3)](/gd_add_bit/3.md).

## NAME

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 — add a field to a Dirfile

## SYNOPSIS

**#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

These functions provide alternatives to using the [**gd\_add**(3)](/gd_add/3.md) or [**gd\_add\_spec**(3)](/gd_add_spec/3.md) functions to add a new field of the indicated type to the dirfile specified by *dirfile*.

In all of these calls, *field\_name* indicates 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)](/gd_fragmentname/3.md).) The meaning and allowed types of other arguments may be obtained from the [**gd\_entry**(3)](/gd_entry/3.md) and [dirfile-format(5)](/dirfile-format/5.md) manual pages.

The **gd\_add\_clincom**() and **gd\_add\_cpolynom**() functions are identical to **gd\_add\_lincom**() and **gd\_add\_polynom**(), except they take complex scalar parameters, instead of purely real values.

The **gd\_add\_lincom**() and **gd\_add\_clincom**() functions takes 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*).

The **gd\_add\_carray**(), **gd\_add\_const**(), **gd\_add\_sarray**(), and **gd\_add\_string**() functions 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)](/gd_entry/3.md) for details.

A metafield may be added to the dirfile either by calling these functions with *field\_name* containing the fully formed "*\<parent-field\>*/*\<meta-field\>*" field code, or else by using the corresponding **gd\_madd\_**...() function (see [**gd\_madd\_bit**(3)](/gd_madd_bit/3.md), &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)](/gd_add/3.md) or [**gd\_add\_spec**(3)](/gd_add_spec/3.md).

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:\
  .TP 8 **GD\_E\_ACCMODE** The specified dirfile was opened read-only.\
  .TP 8 **GD\_E\_ALLOC** The library was unable to allocate memory.\
  .TP 8 **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.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_BAD\_ENTRY** One or more of the field parameters specified was invalid.\
  .TP 8 **GD\_E\_BAD\_INDEX** The *fragment\_index* argument was out of range.\
  .TP 8 **GD\_E\_BAD\_TYPE** The *data\_type* or *const\_type* argument provided to **gd\_add\_raw**() or **gd\_add\_const**() was invalid.\
  .TP 8 **GD\_E\_DUPLICATE** The *field\_name* provided duplicated that of an already existing field.\
  .TP 8 **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.\
  .TP 8 **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.\
  .TP 8 **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.\
  .TP 8 **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.\
  .TP 8 **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)](/gd_error/3.md). A descriptive error string for the last error encountered can be obtained from a call to [**gd\_error\_string**(3)](/gd_error_string/3.md).

## 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

The functions **dirfile\_add\_bit**(), **dirfile\_add\_const**(), **dirfile\_add\_lincom**(), **dirfile\_add\_linterp**(), **dirfile\_add\_multiply**(), **dirfile\_add\_phase**(), **dirfile\_add\_raw**(), and **dirfile\_add\_string**() appeared in GetData-0.4.0.

The functions **dirfile\_add\_clincom**(), **dirfile\_add\_cpolynom**(), **dirfile\_add\_polynom**(), and **dirfile\_add\_sbit**() appeared in GetData-0.6.0.

In GetData-0.7.0, the functions were renamed to **gd\_add\_bit**(), **gd\_add\_clincom**(), **gd\_add\_const**(), **gd\_add\_cpolynom**(), **gd\_add\_lincom**(), **gd\_add\_linterp**(), **gd\_add\_multiply**(), **gd\_add\_phase**(), **gd\_add\_polynom**(), **gd\_add\_raw**(), **gd\_add\_sbit**(), and **gd\_add\_string**(). The functions **gd\_add\_carray**(), **gd\_add\_crecip**(), **gd\_add\_divide**(), and **gd\_add\_recip**() also appeared in this version.

In GetData-0.8.0, these functions first allowed adding metafields by providing the full (slashed) field name.  The functions **gd\_add\_mplex**() and **gd\_add\_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\_add\_indir**(), **gd\_add\_sarray**(), and **gd\_add\_sindir**() also appeared in this version.

## SEE ALSO

[**gd\_add**(3)](/gd_add/3.md), [**gd\_add\_spec**(3)](/gd_add_spec/3.md), [**gd\_entry**(3)](/gd_entry/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), the corresponding **gd\_madd\_**\<entry-type\> functions (e.g. [**gd\_madd\_bit**(3)](/gd_madd_bit/3.md)), [**gd\_metaflush**(3)](/gd_metaflush/3.md), [**gd\_open**(3)](/gd_open/3.md), [dirfile-format(5)](/dirfile-format/5.md)
