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