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