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, 13*a93de25bSCameron Smith sync_writedatablock, 14*a93de25bSCameron Smith sync_constructname 15ab645d52SCameron Smith }; 16ab645d52SCameron Smith 17ab645d52SCameron Smith static struct phio_ops sync_ops_read = { 18ab645d52SCameron Smith sync_openfile_read, 19ab645d52SCameron Smith sync_closefile, 20ab645d52SCameron Smith sync_readheader, 21ab645d52SCameron Smith sync_writeheader, 22ab645d52SCameron Smith sync_readdatablock, 23*a93de25bSCameron Smith sync_writedatablock, 24*a93de25bSCameron Smith sync_constructname 25ab645d52SCameron Smith }; 26ab645d52SCameron Smith 27ab645d52SCameron Smith void init(sync_fp f, char mode) { 28ab645d52SCameron Smith if(mode == 'w') 299a3ccc9bSCameron Smith f->ops = &sync_ops_write; 30ab645d52SCameron Smith else if(mode == 'r') 319a3ccc9bSCameron Smith f->ops = &sync_ops_read; 32ab645d52SCameron Smith else { 33ab645d52SCameron Smith fprintf(stderr, "ERROR unsupported file mode in %s on line %d" 34ab645d52SCameron Smith "... exiting", __FILE__, __LINE__); 35ab645d52SCameron Smith exit(EXIT_FAILURE); 36ab645d52SCameron Smith } 379a3ccc9bSCameron Smith f->file = (int*) malloc(sizeof(int*)); 389a3ccc9bSCameron Smith f->mode = mode; 39ab645d52SCameron Smith } 40ab645d52SCameron Smith 41ab645d52SCameron Smith void syncio_setup_read(int nfiles, phio_fp* f) { 42ab645d52SCameron Smith *f = (phio_fp) malloc(sizeof(struct syncio_file)); 43ab645d52SCameron Smith sync_fp sf = (sync_fp) *f; 44ab645d52SCameron Smith init(sf, 'r'); 45ab645d52SCameron Smith sf->nfiles = nfiles; 46ab645d52SCameron Smith sf->nfields = 0; 47ab645d52SCameron Smith sf->nppf = 0; 48ab645d52SCameron Smith } 49ab645d52SCameron Smith 50ab645d52SCameron Smith void syncio_setup_write(int nfiles, int nfields, int nppf, phio_fp* f) { 51ab645d52SCameron Smith *f = (phio_fp) malloc(sizeof(struct syncio_file)); 52ab645d52SCameron Smith sync_fp sf = (sync_fp) *f; 53ab645d52SCameron Smith init(sf, 'w'); 54ab645d52SCameron Smith sf->nfiles = nfiles; 55ab645d52SCameron Smith sf->nfields = nfields; 56ab645d52SCameron Smith sf->nppf = nppf; 57ab645d52SCameron Smith } 58