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

# gd\_nfields(3)

count field entries in a Dirfile

Part of [gd\_nentries(3)](/gd_nentries/3.md).

## NAME

gd\_nentries, gd\_nfields, gd\_nfields\_by\_type gd\_nmfields, gd\_nmfields\_by\_type, gd\_nmvectors, gd\_nvectors — count field entries in a Dirfile

## SYNOPSIS

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

**unsigned int gd\_nentries(DIRFILE \****dirfile***,** **const char \****parent***, unsigned int** *type***, unsigned int** *flags***);**

**unsigned int gd\_nfields(DIRFILE \****dirfile***);**

**unsigned int gd\_nfields\_by\_type(DIRFILE \****dirfile***, gd\_entype\_t** *type***);**

**unsigned int gd\_nmfields(DIRFILE \****dirfile***, const char \****parent***);**

**unsigned int gd\_nmfields\_by\_type(DIRFILE \****dirfile***,** **const char \****parent***, gd\_entype\_t** *type***);**

**unsigned int gd\_nmvectors(DIRFILE \****dirfile***, const char \****parent***);**

**unsigned int gd\_nvectors(DIRFILE \****dirfile***);**

## DESCRIPTION

The **gd\_nentries**() function queries a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* and counts the number of metadata entries satisfying the provided criteria.  If *parent* is non-NULL, metafields under the field specified by *parent* are considered; otherwise, top-level fields are considered, and metafields ignored.

The *type* argument should be one of the following symbols indicating an explicit entry type to count:

-

  **GD\_BIT\_ENTRY**, **GD\_CARRAY\_ENTRY**, **GD\_CONST\_ENTRY**, **GD\_DIVIDE\_ENTRY**, **GD\_INDEX\_ENTRY**, **GD\_INDIR\_ENTRY**, **GD\_LINCOM\_ENTRY**, **GD\_LINTERP\_ENTRY**, **GD\_MPLEX\_ENTRY**, **GD\_MULTIPLY\_ENTRY**, **GD\_PHASE\_ENTRY**, **GD\_POLYNOM\_ENTRY**, **GD\_RAW\_ENTRY**, **GD\_RECIP\_ENTRY**, **GD\_SARRAY\_ENTRY**, **GD\_SBIT\_ENTRY**, **GD\_SINDIR\_ENTRY**, **GD\_STRING\_ENTRY**, **GD\_WINDOW\_ENTRY**.

(**GD\_INDEX\_ENTRY** is a special field type for the implicit *INDEX* field) or else one of the following special symbols:\
  .TP 8 **GD\_ALL\_ENTRIES (=0)** Count entries of all types.\
  .TP 8 **GD\_ALIAS\_ENTRIES** Count only aliases.  This is the only way to get a count including aliases which do not point to valid field codes.\
  .TP 8 **GD\_SCALAR\_ENTRIES** Count only scalar field types (**CONST**, **CARRAY**, **SARRAY**, **STRING**).\
  .TP 8 **GD\_VECTOR\_ENTRIES** Count only numeric-valued vector field types (all field types except **SINDIR** and the scalar field types listed above).

The *flags* argument should be zero or more of the following flags, bitwise or'd together:\
  .TP 8 **GD\_ENTRIES\_HIDDEN** Include hidden entries (see [**gd\_hidden**(3)](/gd_hidden/3.md)) in the count: normally hidden entries are skipped;\
  .TP 8 **GD\_ENTRIES\_NOALIAS** Exclude aliases from the count: normally aliases are considered the same as their target (that is: a field with *n* aliases, plus its canonical name, will be counted *n*+1 times).

This function has a subset of the functionality of the [**gd\_match\_entries**(3)](/gd_match_entries/3.md) function (q.v.).

### Special Cases

The call

**gd\_nfields(***dirfile***);**

is equivalent to

**gd\_nentries(***dirfile***, NULL, GD\_ALL\_ENTRIES, 0);**

The call

**gd\_nfields\_by\_type(***dirfile***,** *type***);**

is equivalent to

**gd\_nentries(***dirfile***, NULL,** *type***, 0);**

The call

**gd\_nmfields(***dirfile***,** *parent***);**

is equivalent to

**gd\_nentries(***dirfile***,** *parent***, GD\_ALL\_ENTRIES, 0);**

The call

**gd\_nmfields\_by\_type(***dirfile***,** *parent***,** *type***);**

is equivalent to

**gd\_nentries(***dirfile***,** *parent***,** *type***, 0);**

The call

**gd\_nmvectors(***dirfile***,** *parent***);**

is equivalent to

**gd\_nentries(***dirfile***,** *parent***, GD\_VECTOR\_ENTRIES, 0);**

The call

**gd\_nvectors(***dirfile***);**

is equivalent to

**gd\_nentries(***dirfile***, NULL, GD\_VECTOR\_ENTRIES, 0);**

## RETURN VALUE

Upon successful completion, these functions return an unsigned in indicating the number of entries in the database satisfying the supplied criteria.

On error, these functions return zero and store 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\_BAD\_CODE** The supplied parent field code was not found, or referred to a metafield itself.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_BAD\_ENTRY** The *type* parameter supplied was not one of the symbols listed above.

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

## HISTORY

The **get\_nfields**() function appeared in GetData-0.3.0.

The **get\_nfields\_by\_type**(), **get\_nmfields**(), **get\_nmfields\_by\_type**(), **get\_nmvectors**(), and **get\_nvectors**() functions appeared in GetData-0.4.0.

In GetData-0.7.0, these functions were renamed to **gd\_nfields**(), **gd\_nfields\_by\_type**(), **gd\_nmfields**(), **gd\_nmfields\_by\_type**(), **gd\_nmvectors**(), and **gd\_nvectors**().

The **gd\_nentries**() function appeared in GetData-0.8.0.

## SEE ALSO

[dirfile(5)](/dirfile/5.md), [**gd\_open**(3)](/gd_open/3.md), [**gd\_entry\_list**(3)](/gd_entry_list/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_hidden**(3)](/gd_hidden/3.md), [**gd\_match\_entries**(3)](/gd_match_entries/3.md)
