#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32)
#include <fcntl.h>
#include <io.h>
#endif
int main(void)
{
#if defined(_WIN32)
_setmode(_fileno(stdin), _O_BINARY);
#endif
{
return EXIT_FAILURE;
}
size_t coded_size = 0;
size_t heights_size = 0;
? malloc(coded_size)
: NULL;
double *heights =
? malloc(heights_size)
: NULL;
if (coded == NULL || heights == NULL)
{
fprintf(stderr, "a row does not fit in memory\n");
free(coded);
free(heights);
return EXIT_FAILURE;
}
double lowest = INFINITY;
double highest = -INFINITY;
for (size_t row = 0; row < rows; ++row)
{
{
break;
}
for (size_t column = 0; column < columns; ++column)
{
if (!isnan(heights[column]))
{
lowest = fmin(lowest, heights[column]);
highest = fmax(highest, heights[column]);
}
}
}
{
}
else
{
printf("from %g m to %g m\n", lowest, highest);
}
free(coded);
free(heights);
return status ==
SDFIO_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}
Files by path, and the stream over a C file.
void sdfio_stdio_stream(sdfio_stream *stream, FILE *file)
Creates a stream over a C file.
sdfio_status sdfio_decode_heights(const sdfio_header *header, const sdfio_layout *layout, const void *data, size_t count, void *heights)
Converts values of the data area into heights in metres.
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_read_data(sdfio_reader *reader, const sdfio_layout *layout, void *dst, size_t rows)
Reads the next rows of the data area as the file codes them.
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.
sdfio_status sdfio_open_stream(sdfio_reader *reader, const sdfio_stream *stream)
Opens a stream as the source and reads the header.
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.
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_row_size(const sdfio_header *header, sdfio_data_type type, size_t *bytes)
Returns the size in bytes of a buffer for one row of heights in a type, for sdfio_decode_heights() an...
sdfio_status sdfio_data_row_size(const sdfio_header *header, size_t *bytes)
Returns the size in bytes of a buffer for one row of the data area, to read or write the data row by ...
Description of a buffer of the caller for heights or for the values of the data area: the type of its...
Definition layout.h:45
Callbacks that provide or accept the bytes of a file.
Definition types.h:213
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_DOUBLE
double: IEEE 754 binary64.
Definition types.h:122