xref: /phasta/phSolver/common/streamio.cc (revision ecf8d2a957efd836543027ab6bc915054d1d1142)
147926302SCameron Smith #include <stdio.h>
247926302SCameron Smith #include <stdlib.h>
3d7abaf6cSCameron Smith #include "streamio.h"
447926302SCameron Smith #include "phio_stream.h"
547926302SCameron Smith #include "phio_posix.h"
647926302SCameron Smith #include "phio_base.h"
7d7abaf6cSCameron Smith 
847926302SCameron Smith static struct phio_ops stream_ops = {
9*ecf8d2a9SCameron Smith   stream_openfile,
1047926302SCameron Smith   stream_closefile,
1147926302SCameron Smith   posix_readheader,
1247926302SCameron Smith   posix_writeheader,
1347926302SCameron Smith   posix_readdatablock,
1447926302SCameron Smith   posix_writedatablock,
1547926302SCameron Smith   stream_constructname
1647926302SCameron Smith };
1747926302SCameron Smith 
18*ecf8d2a9SCameron Smith void streamio_setup_read(phio_fp* f, GRStream* grs) {
1947926302SCameron Smith   *f = (phio_fp) malloc(sizeof(struct streamio_file));
2047926302SCameron Smith   stream_fp sf = (stream_fp) *f;
21*ecf8d2a9SCameron Smith   sf->ops = &stream_ops;
22*ecf8d2a9SCameron Smith   sf->file = (int*) malloc(sizeof(int*));
23*ecf8d2a9SCameron Smith   sf->mode = 'r';
2447926302SCameron Smith   sf->grs = grs;
25*ecf8d2a9SCameron Smith   sf->rs = NULL;
26d7abaf6cSCameron Smith }
2747926302SCameron Smith 
28*ecf8d2a9SCameron Smith void streamio_setup_write(phio_fp* f, RStream* rs) {
2947926302SCameron Smith   *f = (phio_fp) malloc(sizeof(struct streamio_file));
3047926302SCameron Smith   stream_fp sf = (stream_fp) *f;
31*ecf8d2a9SCameron Smith   sf->ops = &stream_ops;
32*ecf8d2a9SCameron Smith   sf->file = (int*) malloc(sizeof(int*));
33*ecf8d2a9SCameron Smith   sf->mode = 'w';
34*ecf8d2a9SCameron Smith   sf->grs = NULL;
3547926302SCameron Smith   sf->rs = rs;
36d7abaf6cSCameron Smith }
37