libgta  1.2.1
Read and Write Generic Tagged Array (GTA) files
Examples written in C: Using tags
/* This file is in the public domain. */
#include <gta/gta.h>
int main(void)
{
uintmax_t dimensions[] = { 170, 190 };
gta_header_t *header;
gta_taglist_t *taglist;
uintmax_t tags, t;
const char *name, *value;
/* Create an example GTA */
r = gta_create_header(&header);
if (r != GTA_OK) {
return 1;
}
r = gta_set_components(header, 3, components, NULL);
if (r != GTA_OK) {
return 1;
}
r = gta_set_dimensions(header, 2, dimensions);
if (r != GTA_OK) {
return 1;
}
/* The global taglist contains tags that affect the whole array */
taglist = gta_get_global_taglist(header);
/* Set a tag */
r = gta_set_tag(taglist, "PRODUCER", "FOO");
if (r != GTA_OK) {
return 1;
}
/* Get a tag */
value = gta_get_tag(taglist, "X-BAR");
if (!value) {
/* This tag is undefined */
}
else if (value[0] == '\0') {
/* This tag is defined but empty */
}
else {
/* This tag is defined and not empty */
}
/* Unset a tag, whether it is defined or not */
r = gta_unset_tag(taglist, "X-FOO");
if (r != GTA_OK) {
return 1;
}
/* Unset all tags (clear the taglist) */
/* Access all tags in the list */
tags = gta_get_tags(taglist);
for (t = 0; t < tags; t++) {
name = gta_get_tag_name(taglist, t);
value = gta_get_tag_value(taglist, t);
}
/* The dimension taglists contain tags that affect the array dimensions */
taglist = gta_get_dimension_taglist(header, 0);
r = gta_set_tag(taglist, "INTERPRETATION", "X");
if (r != GTA_OK) {
return 1;
}
/* ... */
taglist = gta_get_dimension_taglist(header, 1);
r = gta_set_tag(taglist, "INTERPRETATION", "Y");
if (r != GTA_OK) {
return 1;
}
/* ... */
/* The component taglists contain tags that affect the array element components */
taglist = gta_get_component_taglist(header, 0);
r = gta_set_tag(taglist, "INTERPRETATION", "X-FOO");
if (r != GTA_OK) {
return 1;
}
/* ... */
taglist = gta_get_component_taglist(header, 1);
r = gta_set_tag(taglist, "UNIT", "m");
if (r != GTA_OK) {
return 1;
}
/* ... */
taglist = gta_get_component_taglist(header, 2);
r = gta_set_tag(taglist, "X-FOO", "BAR");
if (r != GTA_OK) {
return 1;
}
/* ... */
return 0;
}
GTA_CFLOAT64
@ GTA_CFLOAT64
complex (re,im) based on two GTA_FLOAT64
Definition: gta.h:284
gta_get_dimension_taglist
gta_taglist_t * gta_get_dimension_taglist(gta_header_t *restrict header, uintmax_t i)
Get the tag list of a dimension (modifiable).
gta_get_tag
const char * gta_get_tag(const gta_taglist_t *restrict taglist, const char *restrict name)
Get a tag value by its name.
gta_get_tag_value
const char * gta_get_tag_value(const gta_taglist_t *restrict taglist, uintmax_t i)
Get the tag value with the given index.
gta_get_tag_name
const char * gta_get_tag_name(const gta_taglist_t *restrict taglist, uintmax_t i)
Get the tag name with the given index.
gta_set_dimensions
gta_result_t gta_set_dimensions(gta_header_t *restrict header, uintmax_t n, const uintmax_t *restrict sizes)
Set the dimensions.
gta_destroy_header
void gta_destroy_header(gta_header_t *restrict header)
Destroy a GTA header structure and free its resources.
gta_result_t
gta_result_t
GTA result type.
Definition: gta.h:212
gta_set_tag
gta_result_t gta_set_tag(gta_taglist_t *restrict taglist, const char *restrict name, const char *restrict value)
Set a tag.
GTA_OK
@ GTA_OK
Success / no error.
Definition: gta.h:214
gta.h
The libgta C interface.
gta_get_global_taglist
gta_taglist_t * gta_get_global_taglist(gta_header_t *restrict header)
Get the global tag list (modifiable).
GTA_FLOAT32
@ GTA_FLOAT32
IEEE 754 single precision floating point (on many platforms: float)
Definition: gta.h:280
gta_get_tags
uintmax_t gta_get_tags(const gta_taglist_t *restrict taglist)
Get the number of tags in a tag list.
gta_header_t
struct gta_internal_header_struct gta_header_t
The GTA header type.
Definition: gta.h:193
gta_taglist_t
struct gta_internal_taglist_struct gta_taglist_t
The GTA tag list type.
Definition: gta.h:204
gta_create_header
gta_result_t gta_create_header(gta_header_t *restrict *restrict header)
Create a new GTA header structure and initialize it.
GTA_UINT16
@ GTA_UINT16
uint16_t
Definition: gta.h:273
gta_unset_tag
gta_result_t gta_unset_tag(gta_taglist_t *restrict taglist, const char *restrict name)
Unset a tag.
gta_get_component_taglist
gta_taglist_t * gta_get_component_taglist(gta_header_t *restrict header, uintmax_t i)
Get the tag list of a component (modifiable).
gta_set_components
gta_result_t gta_set_components(gta_header_t *restrict header, uintmax_t n, const gta_type_t *restrict types, const uintmax_t *restrict sizes)
Set the components of an array element.
gta_unset_all_tags
void gta_unset_all_tags(gta_taglist_t *restrict taglist)
Unset all tags.
gta_type_t
gta_type_t
GTA data types.
Definition: gta.h:268