grib_api: Accessing header and data values

- Main Page
- Modules
- Files
- Related Pages
- Examples

# Accessing header and data values

## Functions
int | grib_get_offset (grib_handle *h, const char *key, size_t *offset)
| Get the number offset of a key, in a message if several keys of the same name are present, the offset of the last one is returned.
int | grib_get_size (grib_handle *h, const char *key, size_t *size)
| Get the number of coded value from a key, if several keys of the same name are present, the total sum is returned.
int | grib_get_long (grib_handle *h, const char *key, long *value)
| Get a long value from a key, if several keys of the same name are present, the last one is returned.
int | grib_get_double (grib_handle *h, const char *key, double *value)
| Get a double value from a key, if several keys of the same name are present, the last one is returned.
int | grib_get_double_element (grib_handle *h, const char *key, int i, double *value)
| Get as double the i-th element of the "key" array.
int | grib_get_double_elements (grib_handle *h, const char *key, int *i, long size, double *value)
| Get as double array the elements of the "key" array whose indexes are listed in the input array i.
int | grib_get_string (grib_handle *h, const char *key, char *mesg, size_t *length)
| Get a string value from a key, if several keys of the same name are present, the last one is returned.
int | grib_get_bytes (grib_handle *h, const char *key, unsigned char *bytes, size_t *length)
| Get raw bytes values from a key.
int | grib_get_double_array (grib_handle *h, const char *key, double *vals, size_t *length)
| Get double array values from a key.
int | grib_get_long_array (grib_handle *h, const char *key, long *vals, size_t *length)
| Get long array values from a key.
int | grib_copy_namespace (grib_handle *dest, const char *name, grib_handle *src)
| Copy the keys belonging to a given namespace from a source handle to a destination handle.
int | grib_set_long (grib_handle *h, const char *key, long val)
| Set a long value from a key.
int | grib_set_double (grib_handle *h, const char *key, double val)
| Set a double value from a key.
int | grib_set_string (grib_handle *h, const char *key, const char *mesg, size_t *length)
| Set a string value from a key.
int | grib_set_bytes (grib_handle *h, const char *key, const unsigned char *bytes, size_t *length)
| Set a bytes array from a key.
int | grib_set_double_array (grib_handle *h, const char *key, const double *vals, size_t length)
| Set a double array from a key.
int | grib_set_long_array (grib_handle *h, const char *key, const long *vals, size_t length)
| Set a long array from a key.

## Detailed Description

## Function Documentation

int grib_copy_namespace | ( | grib_handle * | dest,
|  | const char * | name,
|  | grib_handle * | src |
| ) |  |  |

Copy the keys belonging to a given namespace from a source handle to a destination handle.

Parameters:

  | dest | : destination handle
  | name | : namespace
  | src | : source handle

Returns:
  0 if OK, integer value on error

int grib_get_bytes | ( | grib_handle * | h,
|  | const char * | key,
|  | unsigned char * | bytes,
|  | size_t * | length |
| ) |  |  |

Get raw bytes values from a key.

If several keys of the same name are present, the last one is returned

See also:
  grib_set_bytes

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | bytes | : the address of a byte array where the data will be retreived
  | length | : the address of a size_t that contains allocated length of the byte array on input, and that contains the actual length of the byte array on output

Returns:
  0 if OK, integer value on error

int grib_get_double | ( | grib_handle * | h,
|  | const char * | key,
|  | double * | value |
| ) |  |  |

Get a double value from a key, if several keys of the same name are present, the last one is returned.

See also:
  grib_set_double

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | value | : the address of a double where the data will be retreived

Returns:
  0 if OK, integer value on error

Examples:
  get.c, iterator.c, and print_data.c.

int grib_get_double_array | ( | grib_handle * | h,
|  | const char * | key,
|  | double * | vals,
|  | size_t * | length |
| ) |  |  |

Get double array values from a key.

If several keys of the same name are present, the last one is returned

See also:
  grib_set_double_array

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | vals | : the address of a double array where the data will be retreived
  | length | : the address of a size_t that contains allocated length of the double array on input, and that contains the actual length of the double array on output

Returns:
  0 if OK, integer value on error

Examples:
  get.c, precision.c, and print_data.c.

int grib_get_double_element | ( | grib_handle * | h,
|  | const char * | key,
|  | int | i,
|  | double * | value |
| ) |  |  |

Get as double the i-th element of the "key" array.

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | i | : zero based index
  | value | : the address of a double where the data will be retreived

Returns:
  0 if OK, integer value on error

int grib_get_double_elements | ( | grib_handle * | h,
|  | const char * | key,
|  | int * | i,
|  | long | size,
|  | double * | value |
| ) |  |  |

Get as double array the elements of the "key" array whose indexes are listed in the input array i.

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | i | : zero based array of indexes
  | size | : size of the i and value arrays
  | value | : the address of a double where the data will be retreived

Returns:
  0 if OK, integer value on error

int grib_get_long | ( | grib_handle * | h,
|  | const char * | key,
|  | long * | value |
| ) |  |  |

Get a long value from a key, if several keys of the same name are present, the last one is returned.

See also:
  grib_set_long

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | value | : the address of a long where the data will be retreived

Returns:
  0 if OK, integer value on error

Examples:
  get.c, multi.c, nearest.c, precision.c, and set.c.

int grib_get_long_array | ( | grib_handle * | h,
|  | const char * | key,
|  | long * | vals,
|  | size_t * | length |
| ) |  |  |

Get long array values from a key.

If several keys of the same name are present, the last one is returned

See also:
  grib_set_long_array

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | vals | : the address of a long array where the data will be retreived
  | length | : the address of a size_t that contains allocated length of the long array on input, and that contains the actual length of the long array on output

Returns:
  0 if OK, integer value on error

int grib_get_offset | ( | grib_handle * | h,
|  | const char * | key,
|  | size_t * | offset |
| ) |  |  |

Get the number offset of a key, in a message if several keys of the same name are present, the offset of the last one is returned.

Parameters:

  | h | : the handle to get the offset from
  | key | : the key to be searched
  | offset | : the address of a size_t where the offset will be set

Returns:
  0 if OK, integer value on error

int grib_get_size | ( | grib_handle * | h,
|  | const char * | key,
|  | size_t * | size |
| ) |  |  |

Get the number of coded value from a key, if several keys of the same name are present, the total sum is returned.

Parameters:

  | h | : the handle to get the offset from
  | key | : the key to be searched
  | size | : the address of a size_t where the size will be set

Returns:
  0 if OK, integer value on error

Examples:
  count_messages.f90, get.c, get.f90, get_fortran.F, get_pl.f90, get_pv.f90, precision.c, precision.f90, precision_fortran.F, print_data.c, print_data.f90, print_data_fortran.F, samples.f90, and set_bitmap.f90.

int grib_get_string | ( | grib_handle * | h,
|  | const char * | key,
|  | char * | mesg,
|  | size_t * | length |
| ) |  |  |

Get a string value from a key, if several keys of the same name are present, the last one is returned.

See also:
  grib_set_string

Parameters:

  | h | : the handle to get the data from
  | key | : the key to be searched
  | mesg | : the address of a string where the data will be retreived
  | length | : the address of a size_t that contains allocated length of the string on input, and that contains the actual length of the string on output

Returns:
  0 if OK, integer value on error

Examples:
  keys_iterator.c, keys_iterator_fortran.F, nearest.c, set.c, and set_fortran.F.

int grib_set_bytes | ( | grib_handle * | h,
|  | const char * | key,
|  | const unsigned char * | bytes,
|  | size_t * | length |
| ) |  |  |

Set a bytes array from a key.

If several keys of the same name are present, the last one is set

See also:
  grib_get_bytes

Parameters:

  | h | : the handle to set the data to
  | key | : the key to be searched
  | bytes | : the address of a byte array where the data will be read
  | length | : the address of a size_t that contains the length of the byte array on input, and that contains the actual packed length of the byte array on output

Returns:
  0 if OK, integer value on error

int grib_set_double | ( | grib_handle * | h,
|  | const char * | key,
|  | double | val |
| ) |  |  |

Set a double value from a key.

If several keys of the same name are present, the last one is set

See also:
  grib_get_double

Parameters:

  | h | : the handle to set the data to
  | key | : the key to be searched
  | val | : a double where the data will be read

Returns:
  0 if OK, integer value on error

int grib_set_double_array | ( | grib_handle * | h,
|  | const char * | key,
|  | const double * | vals,
|  | size_t | length |
| ) |  |  |

Set a double array from a key.

If several keys of the same name are present, the last one is set

See also:
  grib_get_double_array

Parameters:

  | h | : the handle to set the data to
  | key | : the key to be searched
  | vals | : the address of a double array where the data will be read
  | length | : a size_t that contains the length of the byte array on input

Returns:
  0 if OK, integer value on error

int grib_set_long | ( | grib_handle * | h,
|  | const char * | key,
|  | long | val |
| ) |  |  |

Set a long value from a key.

If several keys of the same name are present, the last one is set

See also:
  grib_get_long

Parameters:

  | h | : the handle to set the data to
  | key | : the key to be searched
  | val | : a long where the data will be read

Returns:
  0 if OK, integer value on error

Examples:
  multi_write.c, precision.c, and set.c.

int grib_set_long_array | ( | grib_handle * | h,
|  | const char * | key,
|  | const long * | vals,
|  | size_t | length |
| ) |  |  |

Set a long array from a key.

If several keys of the same name are present, the last one is set

See also:
  grib_get_long_array

Parameters:

  | h | : the handle to set the data to
  | key | : the key to be searched
  | vals | : the address of a long array where the data will be read
  | length | : a size_t that contains the length of the long array on input

Returns:
  0 if OK, integer value on error

int grib_set_string | ( | grib_handle * | h,
|  | const char * | key,
|  | const char * | mesg,
|  | size_t * | length |
| ) |  |  |

Set a string value from a key.

If several keys of the same name are present, the last one is set

See also:
  grib_get_string

Parameters:

  | h | : the handle to set the data to
  | key | : the key to be searched
  | mesg | : the address of a string where the data will be read
  | length | : the address of a size_t that contains the length of the string on input, and that contains the actual packed length of the string on output

Returns:
  0 if OK, integer value on error