|
| sdfio_status | sdfio_writer_create (const sdfio_allocator *allocator, sdfio_writer **writer) |
| | Creates a writer.
|
| sdfio_status | sdfio_writer_add_binary (sdfio_writer *writer) |
| | Adds the binary format to the formats that the writer writes.
|
| sdfio_status | sdfio_writer_add_ascii (sdfio_writer *writer) |
| | Adds the ASCII format to the formats that the writer writes.
|
| sdfio_status | sdfio_writer_set_buffer (sdfio_writer *writer, size_t size) |
| | Sets the size in bytes of the buffer between the writer and its stream.
|
| sdfio_status | sdfio_writer_set_chunk (sdfio_writer *writer, size_t count) |
| | Sets the number of values that the writer converts at a time.
|
| sdfio_status | sdfio_writer_set_time_zone (sdfio_writer *writer, const sdfio_time_zone *time_zone) |
| | Sets the conversion of the dates of ISO-1.0 files.
|
| sdfio_status | sdfio_writer_reset (sdfio_writer *writer) |
| | Returns a writer to the state new, so that it can create another file on a path or a stream.
|
| void | sdfio_writer_free (sdfio_writer *writer) |
| | Releases a writer.
|
| sdfio_status | sdfio_writer_estimate_size (const sdfio_writer *writer, const sdfio_header *header, size_t *size) |
| | Estimates the number of bytes that the writer writes for a header, without the trailer.
|
| sdfio_status | sdfio_create_stream (sdfio_writer *writer, const sdfio_stream *stream, const sdfio_header *header) |
| | Starts a file that the header describes, including the numbers of columns and rows.
|
| sdfio_status | sdfio_write_data (sdfio_writer *writer, const sdfio_layout *layout, const void *src, size_t rows) |
| | Writes the next rows of the data area.
|
| sdfio_status | sdfio_write_heights (sdfio_writer *writer, const sdfio_layout *layout, const void *src) |
| | Writes the whole data area from a matrix of heights in metres that lies in memory as the layout describes.
|
| sdfio_status | sdfio_write_trailer_field (sdfio_writer *writer, const char *name, const char *value) |
| | Writes a line field = value of the trailer, which ISO-2.0 expects.
|
| sdfio_status | sdfio_write_trailer_text (sdfio_writer *writer, const char *text, size_t size) |
| | Writes text to the trailer.
|
| sdfio_status | sdfio_copy_trailer (sdfio_reader *reader, sdfio_writer *writer) |
| | Copies the trailer of the file that a reader has opened to the file of a writer.
|
| sdfio_status | sdfio_end_file (sdfio_writer *writer) |
| | Ends the file: closes the trailer, the last record, flushes the stream and, for a file that sdfio_create_file() created, closes the file.
|
| const char * | sdfio_writer_error_message (const sdfio_writer *writer) |
| | Returns a description of the most recent failure of the writer, or an empty string if none occurred.
|
Writer of a file or a stream.
- Process
- A writer writes one file at a time, from the start to the end:
- sdfio_writer_create() creates the writer.
- sdfio_writer_add_binary() and sdfio_writer_add_ascii() add the formats that it writes, at least one. sdfio_writer_set_buffer(), sdfio_writer_set_chunk() and sdfio_writer_set_time_zone() set the options.
- sdfio_create_file() or sdfio_create_stream() starts the file from a header. sdfio_writer_estimate_size() estimates the bytes to write.
- sdfio_write_heights() writes the whole data area, or sdfio_write_data() writes it in parts of one row or more, in the order of the file, until all rows of the header are written.
- sdfio_write_trailer_field(), sdfio_write_trailer_text() and sdfio_copy_trailer() write the trailer, which is optional.
- sdfio_end_file() ends the file, also if it has no trailer.
- sdfio_writer_free() releases the writer. sdfio_writer_reset() instead returns it to the state new, so that it can create another file.
- States
- A writer is in one of five states. It is new until a file is created, then created. When all rows are written, the first call that writes the trailer moves it to trailer. sdfio_end_file() moves it to ended, from created if all rows are written, or from trailer. An error that loses the position in the stream moves it to failed: an error of the stream, of writing the header or of closing the file, and a height in sdfio_write_heights() that cannot be written.
- Formats and options can be set in the state new only. The first creation that passes the checks of the header fixes them, also after sdfio_writer_reset().
- The header is checked and copied when the file is created, so later changes of it have no effect. It is written with the first rows, because sdfio_write_heights() can still determine the z-scale.
- A call that the state does not allow returns SDFIO_ERR_STATE, and an invalid argument returns SDFIO_ERR_ARGUMENT. Neither changes the state or the position in the file.
- A creation that fails leaves the writer new, so it can create the file again.
- A writer that is released before sdfio_end_file() leaves an incomplete file.
Copies the trailer of the file that a reader has opened to the file of a writer.
The rows of the data area that the reader has not read are read and discarded, and the writer must have written all of its rows. A program that saves a changed file as a new one reads the rows, writes the changed rows and then copies the trailer.
The function does not end the trailer, so fields of sdfio_write_trailer_field(), for instance a line that records the change, can follow the copy. sdfio_end_file() ends the file. The copy has the text that sdfio_read_trailer() returns, with the line ends that sdfio_write_trailer_text() writes. A file without a trailer copies nothing.
If a call fails, sdfio_writer_error_message() describes the failure, also when the reader failed.
- Parameters
-
| [in,out] | reader | The reader that has opened a file. |
| [in,out] | writer | The writer that has created a file. |
- Return values
-
| SDFIO_ERR_ARGUMENT | A pointer is null. |
| SDFIO_ERR_STATE | The reader has no file or failed, or the writer has no file, has not written all rows, or ended the file. |
| SDFIO_ERR_IO | A stream failed. |
| SDFIO_ERR_FORMAT | The file of the reader is damaged or truncated. |
Writes the next rows of the data area.
src contains rows times header.columns coded values of header.data_type in the byte order of the machine, in the order of the file. The bad value is written unchanged.
The buffer lies in memory as the layout describes, whose type has to be the data type of the file, as for sdfio_read_data(). sdfio_layout_packed() describes coded values that follow each other.
The first row written is the first row stored in the file, the row with y = 0.
- Parameters
-
| [in,out] | writer | The writer. |
| [in] | layout | The layout of the buffer. |
| [in] | src | The coded values to write. |
| rows | The number of rows to write. |
- Return values
-
| SDFIO_ERR_ARGUMENT | A pointer is null, rows exceeds the rows remaining, the type of the layout is not the data type of the file, the strides are invalid, or the data type is an integer type and the z-scale is not set. |
| SDFIO_ERR_STATE | No file is created, or an earlier error ended the writing. |
| SDFIO_ERR_IO | The stream failed. |
- Examples
- write_coded.c.
Writes a line field = value of the trailer, which ISO-2.0 expects.
The line goes to the stream as it is given, so nothing is assembled in memory. All rows of the data area must have been written. The fields and the text of sdfio_write_trailer_text() can follow each other in any order. sdfio_end_file() ends the trailer.
The value is text. The caller formats numbers, for instance with snprintf() in the C locale, because a locale with a decimal comma would produce 20,5.
- Parameters
-
| [in,out] | writer | The writer. |
| [in] | name | The field name: letters, digits and _. |
| [in] | value | The value: one line. The encoding is not checked; the standard asks for 7-bit ASCII. |
- Return values
-
| SDFIO_ERR_ARGUMENT | A pointer is null, the field name is empty or contains another character, or the value contains a CR or an LF. |
| SDFIO_ERR_STATE | No file is created, rows are missing, the file is ended, or an earlier error ended the writing. |
| SDFIO_ERR_IO | The stream failed. |
- Examples
- write_heights.c.
Writes text to the trailer.
ISO-2.0 requires the trailer to consist of lines in the form of sdfio_write_trailer_field(); the form of the text is neither checked nor enforced. All rows must have been written. The text and the fields can follow each other in any order.
A call can write any part of the text: an open line continues with the next call. A field line ends the open line, and so does sdfio_end_file() in an ASCII file, before its closing line *. A binary file ends with the text as it is. Line ends, LF or CRLF, are written as CRLF in both formats. In an ASCII file a line that consists only of * ends the record, so the text must not contain one.
- Parameters
-
| [in,out] | writer | The writer. |
| [in] | text | The text. |
| size | The length of the text in bytes. |
- Return values
-
| SDFIO_ERR_ARGUMENT | text is null and size is not 0. |
| SDFIO_ERR_STATE | No file is created, rows are missing, the file is ended, or an earlier error ended the writing. |
| SDFIO_ERR_IO | The stream failed. |