mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
format: properly handle header of villas-human format
This commit is contained in:
parent
6922e273bb
commit
8ee79185ff
1 changed files with 39 additions and 9 deletions
|
@ -20,6 +20,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
@ -31,6 +32,10 @@
|
|||
#include "sample.h"
|
||||
#include "io/villas_human.h"
|
||||
|
||||
struct villas_human {
|
||||
bool header_written;
|
||||
};
|
||||
|
||||
size_t villas_sprint_single(char *buf, size_t len, struct sample *s, int flags)
|
||||
{
|
||||
size_t off = 0;
|
||||
|
@ -228,6 +233,26 @@ int villas_fprint(FILE *f, struct sample *smps[], unsigned cnt, int flags)
|
|||
return i;
|
||||
}
|
||||
|
||||
int villas_print(struct io *io, struct sample *smps[], unsigned cnt)
|
||||
{
|
||||
struct villas_human *h = io->_vd;
|
||||
|
||||
FILE *f = io->mode == IO_MODE_ADVIO
|
||||
? io->advio.output->file
|
||||
: io->stdio.output;
|
||||
|
||||
if (!h->header_written) {
|
||||
fprintf(f, "# %-20s\t\t%s\n", "sec.nsec+offset", "data[]");
|
||||
|
||||
if (io->flags & IO_FLUSH)
|
||||
io_flush(io);
|
||||
|
||||
h->header_written = true;
|
||||
}
|
||||
|
||||
return villas_fprint(f, smps, cnt, io->flags);
|
||||
}
|
||||
|
||||
int villas_fscan(FILE *f, struct sample *smps[], unsigned cnt, int flags)
|
||||
{
|
||||
int ret, i;
|
||||
|
@ -243,35 +268,40 @@ int villas_fscan(FILE *f, struct sample *smps[], unsigned cnt, int flags)
|
|||
|
||||
int villas_open(struct io *io, const char *uri)
|
||||
{
|
||||
struct villas_human *h = io->_vd;
|
||||
int ret;
|
||||
|
||||
ret = io_stream_open(io, uri);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
FILE *f = io->mode == IO_MODE_ADVIO
|
||||
? io->advio.output->file
|
||||
: io->stdio.output;
|
||||
|
||||
fprintf(f, "# %-20s\t\t%s\n", "sec.nsec+offset", "data[]");
|
||||
|
||||
if (io->flags & IO_FLUSH)
|
||||
io_flush(io);
|
||||
h->header_written = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void villas_rewind(struct io *io)
|
||||
{
|
||||
struct villas_human *h = io->_vd;
|
||||
|
||||
h->header_written = false;
|
||||
|
||||
io_stream_rewind(io);
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "villas-human",
|
||||
.description = "VILLAS human readable format",
|
||||
.type = PLUGIN_TYPE_IO,
|
||||
.io = {
|
||||
.open = villas_open,
|
||||
.rewind = villas_rewind,
|
||||
.print = villas_print,
|
||||
.fprint = villas_fprint,
|
||||
.fscan = villas_fscan,
|
||||
.sprint = villas_sprint,
|
||||
.sscan = villas_sscan,
|
||||
.size = 0
|
||||
.size = sizeof(struct villas_human)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue