xref: /phasta/phSolver/common/syncio.cc (revision ab645d527a403248f92b1511f47c35aaadb4947d)
1*ab645d52SCameron Smith #include <stdio.h>
2*ab645d52SCameron Smith #include <stdlib.h>
3*ab645d52SCameron Smith #include "syncio.h"
4*ab645d52SCameron Smith #include "phio_sync.h"
5*ab645d52SCameron Smith #include "phio_base.h"
6*ab645d52SCameron Smith 
7*ab645d52SCameron Smith static struct phio_ops sync_ops_write = {
8*ab645d52SCameron Smith   sync_openfile_write,
9*ab645d52SCameron Smith   sync_closefile,
10*ab645d52SCameron Smith   sync_readheader,
11*ab645d52SCameron Smith   sync_writeheader,
12*ab645d52SCameron Smith   sync_readdatablock,
13*ab645d52SCameron Smith   sync_writedatablock
14*ab645d52SCameron Smith };
15*ab645d52SCameron Smith 
16*ab645d52SCameron Smith static struct phio_ops sync_ops_read = {
17*ab645d52SCameron Smith   sync_openfile_read,
18*ab645d52SCameron Smith   sync_closefile,
19*ab645d52SCameron Smith   sync_readheader,
20*ab645d52SCameron Smith   sync_writeheader,
21*ab645d52SCameron Smith   sync_readdatablock,
22*ab645d52SCameron Smith   sync_writedatablock
23*ab645d52SCameron Smith };
24*ab645d52SCameron Smith 
25*ab645d52SCameron Smith void init(sync_fp f, char mode) {
26*ab645d52SCameron Smith   if(mode == 'w')
27*ab645d52SCameron Smith     f->base->ops = &sync_ops_write;
28*ab645d52SCameron Smith   else if(mode == 'r')
29*ab645d52SCameron Smith     f->base->ops = &sync_ops_read;
30*ab645d52SCameron Smith   else {
31*ab645d52SCameron Smith     fprintf(stderr, "ERROR unsupported file mode in %s on line %d"
32*ab645d52SCameron Smith         "... exiting", __FILE__, __LINE__);
33*ab645d52SCameron Smith     exit(EXIT_FAILURE);
34*ab645d52SCameron Smith   }
35*ab645d52SCameron Smith   f->base->file = (int*) malloc(sizeof(int*));
36*ab645d52SCameron Smith   f->base->mode = mode;
37*ab645d52SCameron Smith }
38*ab645d52SCameron Smith 
39*ab645d52SCameron Smith void syncio_setup_read(int nfiles, phio_fp* f) {
40*ab645d52SCameron Smith   *f = (phio_fp) malloc(sizeof(struct syncio_file));
41*ab645d52SCameron Smith   sync_fp sf = (sync_fp) *f;
42*ab645d52SCameron Smith   init(sf, 'r');
43*ab645d52SCameron Smith   sf->nfiles = nfiles;
44*ab645d52SCameron Smith   sf->nfields = 0;
45*ab645d52SCameron Smith   sf->nppf = 0;
46*ab645d52SCameron Smith }
47*ab645d52SCameron Smith 
48*ab645d52SCameron Smith void syncio_setup_write(int nfiles, int nfields, int nppf, phio_fp* f) {
49*ab645d52SCameron Smith   *f = (phio_fp) malloc(sizeof(struct syncio_file));
50*ab645d52SCameron Smith   sync_fp sf = (sync_fp) *f;
51*ab645d52SCameron Smith   init(sf, 'w');
52*ab645d52SCameron Smith   sf->nfiles = nfiles;
53*ab645d52SCameron Smith   sf->nfields = nfields;
54*ab645d52SCameron Smith   sf->nppf = nppf;
55*ab645d52SCameron Smith }
56