xref: /phasta/phSolver/common/streamio.cc (revision ea868eb1c17e8b2a160bb27c128290bdf49f8ce8)
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->file = (int*) malloc(sizeof(int*));
26   sf->mode = 'r';
27   sf->grs = grs;
28   sf->rs = NULL;
29 }
30 
31 void streamio_setup_write(phio_fp* f, RStream* rs) {
32   *f = (phio_fp) malloc(sizeof(struct streamio_file));
33   stream_fp sf = (stream_fp) *f;
34   sf->ops = &stream_ops;
35   sf->file = (int*) malloc(sizeof(int*));
36   sf->mode = 'w';
37   sf->grs = NULL;
38   sf->rs = rs;
39 }
40 
41 void streamio_set_gr(grstream grs) {
42   geomRestartStream = grs;
43 }
44 
45 grstream streamio_get_gr() {
46   return geomRestartStream;
47 }
48 
49 void streamio_set_r(rstream rs) {
50   restartStream = rs;
51 }
52 
53 rstream streamio_get_r() {
54   return restartStream;
55 }
56