28 #include "sion_debug.h" 30 #include "sion_filedesc.h" 33 #define DFUNCTION "fsion_open_c" 58 sion_int64 *chunksizes,
59 sion_int32 *fsblksize,
68 char *fname_tmp, *fmode_tmp;
71 fname_tmp = (
char *) malloc((
size_t) ((fname_len + 1) *
sizeof(
char)));
72 if(fname_tmp == NULL) {
73 fprintf(stderr,
"could not allocate memory for internal filename buffer, returning ...\n");
78 fmode_tmp = (
char *) malloc((
size_t) ((file_mode_len + 1) *
sizeof(
char)));
79 if(fmode_tmp == NULL) {
80 fprintf(stderr,
"could not allocate memory for internal filemode buffer, returning ...\n");
91 strncpy(fname_tmp, fname, fname_len);
92 strncpy(fmode_tmp, file_mode, file_mode_len);
94 fname_tmp[fname_len] =
'\0';
95 fmode_tmp[file_mode_len] =
'\0';
99 DPRINTFP((2, DFUNCTION, -1,
"params: %s %s %d %ld \n", fname_tmp, fmode_tmp, (
int) *ntasks, (
long) *fsblksize));
101 if (!strcmp(fmode_tmp,
"bw") || !strcmp(fmode_tmp,
"wb")) {
103 (*sid) =
sion_open(fname_tmp, fmode_tmp, ntasks, nfiles, &chunksizes, fsblksize, &globalranks, &fileptr);
105 (*sid) =
sion_open(fname_tmp, fmode_tmp, ntasks, nfiles, NULL, fsblksize, NULL, &fileptr);
107 DPRINTFP((2, DFUNCTION, -1,
"sid: %d\n", *sid));
110 free(fname_tmp); fname_tmp=NULL;
111 free(fmode_tmp); fmode_tmp=NULL;
144 sion_int64 *chunksize,
145 sion_int32 *fsblksize,
154 char *fname_tmp, *fmode_tmp;
156 fname_tmp = (
char *) malloc((
size_t) ((fname_len + 1) *
sizeof(
char)));
157 fmode_tmp = (
char *) malloc((
size_t) ((file_mode_len + 1) *
sizeof(
char)));
159 strncpy(fname_tmp, fname, fname_len);
160 strncpy(fmode_tmp, file_mode, file_mode_len);
161 fname_tmp[fname_len] =
'\0';
162 fmode_tmp[file_mode_len] =
'\0';
164 (*sid) =
sion_open_rank(fname_tmp, fmode_tmp, chunksize, fsblksize, rank, &fileptr);
213 #define DFUNCTION "fsion_seek_c" 233 sion_int64 *posinblk,
237 DPRINTFP((2, DFUNCTION, -1,
"params: %d %d %d %lld\n", *sid, *rank, *currentblocknr, *posinblk));
239 (*ierr) =
sion_seek(*sid, *rank, *currentblocknr, *posinblk);
327 sion_int64 *globalskip,
328 sion_int64 *start_of_varheader,
329 sion_int64 **sion_localsizes,
330 sion_int64 **sion_globalranks,
331 sion_int64 **sion_chunkcount,
332 sion_int64 **sion_chunksizes,
336 (*ierr) =
sion_get_locations(*sid, ntasks, maxblocks, globalskip, start_of_varheader, sion_localsizes,
337 sion_globalranks, sion_chunkcount, sion_chunksizes);
356 void fsion_get_current_locations_c(
int *sid,
358 sion_int64 **sion_currentpos,
359 sion_int64 **sion_currentblocknr,
367 void fsion_get_chunksizes_c(
int *sid,
368 sion_int64 *chunksizes,
375 if ((_sion_vcdtype(*sid) != SION_FILEDESCRIPTOR)
376 || !(sion_filedesc = _sion_vcdtovcon(*sid))) {
377 fprintf(stderr,
"invalid sion_filedesc, aborting %d ...\n", *sid);
382 for(i=0;i<sion_filedesc->
ntasks;i++) {
389 void fsion_get_globalranks_c(
int *sid,
397 if ((_sion_vcdtype(*sid) != SION_FILEDESCRIPTOR)
398 || !(sion_filedesc = _sion_vcdtovcon(*sid))) {
399 fprintf(stderr,
"invalid sion_filedesc, aborting %d ...\n", *sid);
404 for(i=0;i<sion_filedesc->
ntasks;i++) {
411 void fsion_get_mapping_spec_c(
int *sid,
418 if ((_sion_vcdtype(*sid) != SION_FILEDESCRIPTOR)
419 || !(sion_filedesc = _sion_vcdtovcon(*sid))) {
420 fprintf(stderr,
"invalid sion_filedesc, aborting %d ...\n", *sid);
425 *numfiles = sion_filedesc->
nfiles;
429 #define DFUNCTION "fsion_get_mapping_c" 430 void fsion_get_mapping_c(
int *sid,
437 if ((_sion_vcdtype(*sid) != SION_FILEDESCRIPTOR)
438 || !(sion_filedesc = _sion_vcdtovcon(*sid))) {
439 fprintf(stderr,
"invalid sion_filedesc, aborting %d ...\n", *sid);
443 if(sion_filedesc->
nfiles>1) {
444 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
445 DPRINTFP((32, DFUNCTION, 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
446 mapping[rank*2+0]=sion_filedesc->
mapping[rank*2+0];
447 mapping[rank*2+1]=sion_filedesc->
mapping[rank*2+1];
467 if ((_sion_vcdtype(*sid) != SION_FILEDESCRIPTOR)
468 || !(sion_filedesc = _sion_vcdtovcon(*sid))) {
469 fprintf(stderr,
"invalid sion_filedesc, aborting %d ...\n", *sid);
473 *filenumber = _sion_file_get_fd(sion_filedesc->
fileptr);
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
sion_int64 sion_bytes_avail_in_block(int sid)
Return the number of bytes available in the current chunk.
Sion File Descriptor Structure.
void fsion_get_locations_c(int *sid, int *ntasks, int *maxblocks, sion_int64 *globalskip, sion_int64 *start_of_varheader, sion_int64 **sion_localsizes, sion_int64 **sion_globalranks, sion_int64 **sion_chunkcount, sion_int64 **sion_chunksizes, int *ierr)
Fortran procedure that returns pointers to internal fields.
int sion_get_endianness(void)
Return endianness.
int sion_ensure_free_space(int sid, sion_int64 bytes)
Funtion to ensure that enough space is available for writing.
sion_int64 sion_get_position(int sid)
Function that returns the current file position.
void fsion_close_c(int *sid, int *ierr)
Fortran procedure to close a sion file.
void fsion_flush_c(int *sid, int *ierr)
Fortran procedure to flush a sion file.
int sion_get_file_endianness(int sid)
Returns edianness of data in file sid.
sion_int64 * all_globalranks
int sion_close(int sid)
Close a sion file.
void fsion_get_endianness_c(int *endianness)
Fortran function that returns current endianness (1-> big endian, 0 ->little endian)
void fsion_seek_c(int *sid, int *rank, int *currentblocknr, sion_int64 *posinblk, int *ierr)
Fortran procedure to set the file pointer to a new position.
int sion_get_current_locations(int sid, int *ntasks, sion_int64 **sion_currentpos, sion_int64 **sion_currentblocknr)
Returns current position in file and pointer fiels containing chunk sizes.
int sion_get_locations(int sid, int *ntasks, int *maxchunks, sion_int64 *globalskip, sion_int64 *start_of_varheader, sion_int64 **sion_chunksizes, sion_int64 **sion_globalranks, sion_int64 **sion_blockcount, sion_int64 **sion_blocksizes)
Returns pointers to internal fields.
void fsion_open_c(char *fname, char *file_mode, int *ntasks, int *nfiles, sion_int64 *chunksizes, sion_int32 *fsblksize, int *globalranks, int *sid, int fname_len, int file_mode_len)
Fortran procedure to open a sion file in serial mode.
int sion_endianness_swap_needed(int sid)
Returns whether or not byte swapping is needed for sid.
void fsion_swap_c(void *target, void *source, int *size, int *n, int *aflag, int *rc)
Fortran procedure to swap endianness of data.
void fsion_ensure_free_space_c(int *sid, sion_int64 *bytes, int *ierr)
Fortran procedure to ensure that enough space is available.
int sion_open_rank(char *fname, const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize, int *rank, FILE **fileptr)
Open a sion file for a specific rank.
int sion_seek(int sid, int rank, int currentblocknr, sion_int64 posinblk)
Function to set the file pointer to a new position.
void fsion_open_rank_c(char *fname, char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize, int *rank, int *sid, int fname_len, int file_mode_len)
Fortran procedure to open a sion file for a specific rank.
sion_int64 fsion_bytes_avail_in_block_c(int *sid)
Fortran function that returns the number of bytes available in the current chunk.
sion_int64 * all_chunksizes
void fsion_endianness_swap_needed_c(int *sid, int *needed)
Fortran function that returns whether or not byte swapping is needed (1 -> needed,...
int sion_open(char *fname, const char *file_mode, int *ntasks, int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize, int **globalranks, FILE **fileptr)
Open a sion file in serial mode.
sion_int64 fsion_get_position_c(int *sid)
Fortran function that returns the current file position.
void sion_swap(void *target, void *source, int size, int n, int aflag)
void fsion_get_file_endianness_c(int *sid, int *endianness)
Fortran function that returns endianness of a sion file (1-> big endian, 0 ->little endian)
void fsion_feof_c(int *sid, int *eof)
Fortran function that indicates the end of file for this task.
void fsion_get_fileno_c(int *sid, int *filenumber)
Fortran function that returns the current file number.
int sion_flush(int sid)
Flushed sion file.