#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc < 2)
{
fprintf(stderr, "usage: %s input.sdf\n", argv[0]);
return EXIT_FAILURE;
}
{
return EXIT_FAILURE;
}
size_t heights_size = 0;
float *heights =
? malloc(heights_size)
: NULL;
if (heights == NULL)
{
fprintf(stderr, "the heights do not fit in memory\n");
return EXIT_FAILURE;
}
char trailer[1024];
size_t trailer_size = 0;
heights);
{
&trailer_size);
}
{
free(heights);
return EXIT_FAILURE;
}
double sum = 0.0;
size_t measured = 0;
const size_t count =
for (size_t i = 0; i < count; ++i)
{
if (!isnan(heights[i]))
{
sum += heights[i];
++measured;
}
}
printf("%s %lu x %lu, mean %g m\ntrailer:\n%.*s",
: "ISO-2.0",
measured > 0 ? sum / (double)measured : 0.0, (int)trailer_size,
trailer);
size_t position = 0;
size_t name_at = 0;
size_t value_at = 0;
size_t name_size = 0;
size_t value_size = 0;
&name_size, &value_at, &value_size))
{
printf("field %.*s: %.*s\n", (int)name_size, trailer + name_at,
(int)value_size, trailer + value_at);
}
&value_at, &value_size))
{
printf("operator: %.*s\n", (int)value_size, trailer + value_at);
}
free(heights);
return EXIT_SUCCESS;
}
Files by path, and the stream over a C file.
sdfio_status sdfio_open_file(sdfio_reader *reader, const char *path)
Opens the file at a path as the source and reads its header, as sdfio_open_stream() does for a stream...
const sdfio_layout * sdfio_layout_packed(sdfio_data_type type)
Returns the layout of a plain array: the elements follow each other and the rows follow each other.
sdfio_status sdfio_reader_add_binary(sdfio_reader *reader)
Adds the binary format to the formats that the reader reads, the version numbers bISO-1....
const sdfio_header * sdfio_reader_header(const sdfio_reader *reader)
Returns the header of the opened file, or null if no file is open.
struct sdfio_reader sdfio_reader
Opaque handle of a reader.
Definition reader.h:58
sdfio_status sdfio_reader_add_ascii(sdfio_reader *reader)
Adds the ASCII format to the formats that the reader reads, the version numbers aISO-1....
sdfio_status sdfio_reader_create(const sdfio_allocator *allocator, sdfio_reader **reader)
Creates a reader.
sdfio_status sdfio_read_trailer(sdfio_reader *reader, char *buffer, size_t capacity, size_t *size)
Reads the next part of the trailer, the free text after the data area, into a buffer of the caller.
sdfio_status sdfio_read_heights(sdfio_reader *reader, const sdfio_layout *layout, void *dst)
Reads the remaining rows as heights in metres into a buffer that lies in memory as the layout describ...
const char * sdfio_reader_error_message(const sdfio_reader *reader)
Returns a description of the most recent failure of the reader, or an empty string if none occurred.
void sdfio_reader_free(sdfio_reader *reader)
Releases a reader and closes the file that sdfio_open_file() opened, if any.
Reading and writing of ISO 25178-71 SDF surface data files.
sdfio_status sdfio_heights_size(const sdfio_header *header, sdfio_data_type type, size_t *bytes)
Returns the size in bytes of a buffer for the whole matrix of heights in a type, for sdfio_read_heigh...
bool sdfio_trailer_find_field(const char *text, size_t size, const char *name, size_t *value_at, size_t *value_size)
Finds the value of the field of a name in a trailer text.
bool sdfio_trailer_next_field(const char *text, size_t size, size_t *position, size_t *name_at, size_t *name_size, size_t *value_at, size_t *value_size)
Finds the next field of a trailer text, a line of the form Name = Value, which ISO-2....
@ SDFIO_ISO_1_0
Revision ISO-1.0.
Definition types.h:74
const char * sdfio_status_string(sdfio_status status)
Returns a constant description of a status.
sdfio_status
Result of a function call.
Definition types.h:31
@ SDFIO_OK
The call succeeded.
Definition types.h:33
const sdfio_allocator * sdfio_default_allocator(void)
Returns the allocator that uses malloc() and free().
@ SDFIO_TYPE_FLOAT
float: IEEE 754 binary32.
Definition types.h:114