libgta 1.2.1 Read and Write Generic Tagged Array (GTA) files

Examples written in C: Block-based input/output
/* This file is in the public domain. */
#include <stdio.h>
#include <stdlib.h>
#include <gta/gta.h>
/* This example opens a three-dimensional GTA and then reads a small block of
* array data.
* This is useful for arrays that do not fit into memory. However, the input
* file must be seekable (i.e. it must be a real file, no pipe or network
* stream), and the GTA must not be compressed. */
int main(void)
{
FILE *file;
gta_header_t *header;
gta_result_t r;
off_t data_offset;
uintmax_t block_indices_low[] = { 20, 30, 40 };
uintmax_t block_indices_high[] = { 50, 60, 70 };
void *block;
/* Read the header */
file = fopen("input.gta", "r");
if (!file) {
return 1;
}
r = gta_create_header(&header);
if (r != GTA_OK) {
return 1;
}
r = gta_read_header_from_stream(header, file);
if (r != GTA_OK) {
return 1;
}
/* We assume that the input GTA has three dimensions and one element
* component of type GTA_UINT16, and that it is large enough to contain
* the block defined above. */
data_offset = ftello(file);
if (data_offset == -1) {
return 1;
}
/* Read the data block */
block = malloc(31 * 31 * 31 * sizeof(uint16_t));
if (!block) {
return 1;
}
r = gta_read_block_from_stream(header, data_offset,
block_indices_low, block_indices_high, block, file);
if (r != GTA_OK) {
return 1;
}
/* do something with the data */
/* Cleanup */
free(block);
gta_destroy_header(header);
fclose(file);
return 0;
}
gta.h
The libgta C interface.
gta_result_t
gta_result_t
GTA result type.
Definition: gta.h:213
GTA_OK
@ GTA_OK
Success / no error.
Definition: gta.h:214
gta_destroy_header
void gta_destroy_header(gta_header_t *restrict header)
Destroy a GTA header structure and free its resources.
gta_read_block_from_stream
gta_result_t gta_read_block_from_stream(const gta_header_t *restrict header, intmax_t data_offset, const uintmax_t *restrict lower_coordinates, const uintmax_t *restrict higher_coordinates, void *restrict block, FILE *restrict f)
Read an array block from a stream.
gta_header_t
struct gta_internal_header_struct gta_header_t
The GTA header type.
Definition: gta.h:193
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_read_header_from_stream
gta_result_t gta_read_header_from_stream(gta_header_t *restrict header, FILE *restrict f)
Read a GTA header from a stream.