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

# gd\_putdata(3)

write data to a Dirfile database

## NAME

gd\_putdata — write data to a Dirfile database

## SYNOPSIS

**#include \<getdata.h\>**

**size\_t gd\_putdata(DIRFILE \****dirfile***, const char \****field\_code***, off\_t** *first\_frame***, off\_t** *first\_sample***, size\_t** *num\_frames***, size\_t** *num\_samples***, gd\_type\_t** *data\_type***, const void \****data\_in***);**

## DESCRIPTION

The **gd\_putdata**() function writes data to a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* for the field *field\_code*, which may not contain a representation suffix.  It writes *num\_frames* frames plus *num\_samples* samples to this field, starting  *first\_sample* samples past frame *first\_frame*. The data is read from the user-supplied buffer *data\_in,* which is has a data type specified by *data\_type*. This interface cannot write to field representations.

The  *dirfile* argument must point to a valid DIRFILE object previously created by a call to [**gd\_open**(3)](/gd_open/3.md).

Unless using **GD\_HERE** (see below), the first sample written will be

*first\_frame* \* *samples\_per\_frame* + *first\_sample*

as measured from the start of the dirfile, where *samples\_per\_frame* is the number of samples per frame as returned by [**gd\_spf**(3)](/gd_spf/3.md). The number of samples which **gd\_putdata**() attempts to write is, similarly,

*num\_frames* \* *samples\_per\_frame* + *num\_samples*.

Although calling **gd\_putdata**() using both samples and frames is possible, the function is typically called with either *num\_samples* and *first\_sample*, or *num\_frames* and *first\_frames*, equal to zero.

Instead of explicitly specifying the origin of the write, the caller may pass the special symbol **GD\_HERE** as *first\_frame*. This will result in the write occurring at the current position of the I/O pointer for the field (see [**gd\_getdata**(3)](/gd_getdata/3.md) for a discussion of I/O pointers).  In this case, the value of *first\_sample* is ignored.

The  *data\_type* argument should be one of the following symbols, which indicates the type of the input data:

- **GD\_UINT8**

  unsigned 8-bit integer\
    .TP 8 **GD\_INT8** signed (two's complement) 8-bit integer\
    .TP 8 **GD\_UINT16** unsigned 16-bit integer\
    .TP 8 **GD\_INT16** signed (two's complement) 16-bit integer\
    .TP 8 **GD\_UINT32** unsigned 32-bit integer\
    .TP 8 **GD\_INT32** signed (two's complement) 32-bit integer\
    .TP 8 **GD\_UINT64** unsigned 64-bit integer\
    .TP 8 **GD\_INT64** signed (two's complement) 64-bit integer\
    .TP 8 **GD\_FLOAT32** IEEE-754 standard 32-bit single precision floating point number\
    .TP 8 **GD\_FLOAT64** IEEE-754 standard 64-bit double precision floating point number\
    .TP 8 **GD\_COMPLEX64** C99-conformant 64-bit single precision complex number\
    .TP 8 **GD\_COMPLEX128** C99-conformant 128-bit double precision complex number

The type of the input data need not be the same as the type of the data stored in the database.  Type conversion will be performed as necessary to write the appropriate type.  The argument *data\_in* must point to a valid memory location of containing all the data to be written.

Upon successful completion, the I/O pointer of the field will be on the sample immediately following the last sample written, if possible.  On error, the position of the I/O pointer is not specified.

## RETURN VALUE

In all cases, **gd\_putdata**() returns the number of samples (not bytes) successfully written to the database, which may be zero if an error has occurred.

On error, this function returns zero and stores a negative-valued error code in the **DIRFILE** object which may be retrieved by a subsequent call to [**gd\_error**(3)](/gd_error/3.md). Possible error codes 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 specified by *field\_code*, or one of the fields it uses for input, was not found in the database.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** An invalid *dirfile* was supplied.\
  .TP 8 **GD\_E\_BAD\_FIELD\_TYPE** Either the field specified by *field\_code*, or one of the fields it uses for input, was of **MULTIPLY**, **DIVIDE**, **WINDOW**, **INDIR**, or **SINDIR** type, or a **LINCOM** with more than one input field, or a **POLYNOM** with quadratic or higer terms.  Alternately, the caller may have attempted to write to the implicit INDEX field, which is not possible.\
  .TP 8 **GD\_E\_BAD\_TYPE** An invalid *data\_type* was specified.\
  .TP 8 **GD\_E\_DIMENSION** The field specified by *field\_code* was not a vector field.  The caller should use [**gd\_put\_carray**(3)](/gd_put_carray/3.md), [**gd\_put\_constant**(3)](/gd_put_constant/3.md), or [**gd\_put\_string**(3)](/gd_put_string/3.md) instead.  Or, a scalar field was found where a vector field was expected in the definition of *field\_code*.\
  .TP 8 **GD\_E\_DOMAIN** An attempt was made to write to a **LINTERP** field with a look-up table which was not monotonic or not purely real.\
  .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 maintainer.\
  .TP 8 **GD\_E\_IO** An error occurred while trying to open, read from, or write to a file on disk containing a raw field or a **LINTERP** table.\
  .TP 8 **GD\_E\_LUT** A **LINTERP** table was malformed.\
  .TP 8 **GD\_E\_PROTECTED** The data of the **RAW** field backing *field\_code* was protected from change by a /PROTECT directive.\
  .TP 8 **GD\_E\_RANGE** An attempt was made to write data either before the beginning-of-frame marker for *field\_code*, or the raw field it depends on, or else outside the addressable Dirfile range (more than 2\*\*63 samples beyond the start of the Dirfile).\
  .TP 8 **GD\_E\_RECURSE\_LEVEL** Too many levels of recursion were encountered while trying to resolve *field\_code*. This usually indicates a circular dependency in field specification in the dirfile.\
  .TP 8 **GD\_E\_UNSUPPORTED** Reading from dirfiles with the encoding scheme of the specified dirfile is not supported by the library.  See [dirfile-encoding(5)](/dirfile-encoding/5.md) for details on dirfile encoding schemes.

A descriptive error string for the error may be obtained by calling [**gd\_error\_string**(3)](/gd_error_string/3.md).

## NOTES

When operating on a platform whose **size\_t** is *N*-bytes wide, a single call of **gd\_putdata**() will never write more than (2\*\*(*N*-*M*) - 1) samples, where *M* is the size, in bytes, of the largest data type used to calculate the stored field. If a larger request is specified, less data than requested will be written, without raising an error.  This limit is imposed even when  *data\_type* is **GD\_NULL** (i.e., even when no actual I/O or calculation occurs).  In all cases, the actual amount of data is returned.

## HISTORY

The **putdata**() function appeared in GetData-0.3.0.

In GetData-0.7.0, this function was renamed to **gd\_getdata**().

The **GD\_HERE** symbol used for sequential writes appeared in GetData-0.8.0.

## SEE ALSO

[**GD\_SIZE**(3)](/GD_SIZE/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_getdata**(3)](/gd_getdata/3.md), [**gd\_open**(3)](/gd_open/3.md), [**gd\_put\_carray**(3)](/gd_put_carray/3.md), [**gd\_put\_constant**(3)](/gd_put_constant/3.md), [**gd\_put\_sarray**(3)](/gd_put_sarray/3.md), [**gd\_put\_string**(3)](/gd_put_string/3.md), [**gd\_seek**(3)](/gd_seek/3.md), [**gd\_spf**(3)](/gd_spf/3.md), [dirfile(5)](/dirfile/5.md), [dirfile-encoding(5)](/dirfile-encoding/5.md)
