xref: /phasta/phSolver/common/streamio.cc (revision 06d45c3e23cf9519431c2d5c7bbad33ddf2fbe7a)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <cassert>
4 #include "streamio.h"
5 #include "phio_stream.h"
6 #include "phio_posix.h"
7 #include "phio_base.h"
8 
9 grstream geomRestartStream;
10 rstream restartStream;
11 
12 static struct phio_ops stream_ops = {
13   stream_openfile,
14   stream_closefile,
15   stream_readheader,
16   stream_writeheader,
17   stream_readdatablock,
18   stream_writedatablock,
19   stream_constructname
20 };
21 
22 void streamio_setup_r(phio_fp* f, RStream* rs, char mode) {
23   assert(rs);
24   *f = (phio_fp) malloc(sizeof(struct streamio_file));
25   stream_fp sf = (stream_fp) *f;
26   sf->ops = &stream_ops;
27   sf->mode = mode;
28   sf->grs = NULL;
29   sf->rs = rs;
30 }
31 
32 void streamio_setup_read(phio_fp* f, GRStream* grs) {
33   *f = (phio_fp) malloc(sizeof(struct streamio_file));
34   stream_fp sf = (stream_fp) *f;
35   sf->ops = &stream_ops;
36   sf->mode = 'r';
37   sf->grs = grs;
38   sf->rs = NULL;
39 }
40 
41 void streamio_setup_write(phio_fp* f, RStream* rs) {
42   *f = (phio_fp) malloc(sizeof(struct streamio_file));
43   stream_fp sf = (stream_fp) *f;
44   sf->ops = &stream_ops;
45   sf->mode = 'w';
46   sf->grs = NULL;
47   sf->rs = rs;
48 }
49 
50 void streamio_set_gr(grstream grs) {
51   geomRestartStream = grs;
52 }
53 
54 grstream streamio_get_gr() {
55   return geomRestartStream;
56 }
57 
58 void streamio_set_r(rstream rs) {
59   restartStream = rs;
60 }
61 
62 rstream streamio_get_r() {
63   return restartStream;
64 }
65