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