mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-23 04:43:57 +01:00
cppcheck fixes
This commit is contained in:
parent
98e303ffe2
commit
64081e46ad
@ -2625,46 +2625,76 @@ trexio_write_$group_dset$(trexio_t* const file,
|
||||
rc = trexio_read_$group_dset_sparse_dim$_64(file, &num);
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
|
||||
int32_t* index_sparse_p = (int32_t*) index_sparse;
|
||||
// shift indices to be zero-based if Fortran API is used
|
||||
if (file->one_based) {
|
||||
|
||||
uint64_t index_size = rank * buffer_size;
|
||||
index_sparse_p = CALLOC(index_size, int32_t);
|
||||
|
||||
int32_t* index_sparse_p = CALLOC(index_size, int32_t);
|
||||
if (index_sparse_p == NULL) return TREXIO_ALLOCATION_FAILED;
|
||||
|
||||
for (uint64_t i=0; i<index_size; ++i){
|
||||
index_sparse_p[i] = index_sparse[i] - 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_write_$group_dset$(file, offset_file, buffer_size, num, size_max, index_sparse_p, value_sparse);
|
||||
rc = trexio_text_write_$group_dset$(file, offset_file, buffer_size, num,
|
||||
size_max, index_sparse_p, value_sparse);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
#ifdef HAVE_HDF5
|
||||
rc = trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, num, index_sparse_p, value_sparse);
|
||||
rc = trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, num,
|
||||
index_sparse_p, value_sparse);
|
||||
break;
|
||||
#else
|
||||
rc = TREXIO_BACK_END_MISSING;
|
||||
break;
|
||||
#endif
|
||||
/*
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_write_$group_dset$(...);
|
||||
break;
|
||||
,*/
|
||||
,*/
|
||||
default:
|
||||
rc = TREXIO_FAILURE; /* Impossible case */
|
||||
break;
|
||||
}
|
||||
|
||||
// free the memory allocated to shift indices to be zero-based
|
||||
if (file->one_based) FREE(index_sparse_p);
|
||||
FREE(index_sparse_p);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_write_$group_dset$(file, offset_file, buffer_size, num,
|
||||
size_max, index_sparse, value_sparse);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
#ifdef HAVE_HDF5
|
||||
rc = trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, num,
|
||||
index_sparse, value_sparse);
|
||||
break;
|
||||
#else
|
||||
rc = TREXIO_BACK_END_MISSING;
|
||||
break;
|
||||
#endif
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_write_$group_dset$(...);
|
||||
break;
|
||||
,*/
|
||||
default:
|
||||
rc = TREXIO_FAILURE; /* Impossible case */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -1069,7 +1069,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
|
||||
This is error-prone due to the fact that for large files (>2 GB) in 32-bit systems ftell will fail.
|
||||
One can use ftello function which is adapted for large files.
|
||||
For now, we can use front-end-provided size_start, which has been checked for INT64_MAX overflow.
|
||||
*/
|
||||
,*/
|
||||
int64_t io_start_pos = size_start * line_length;
|
||||
|
||||
/* Write the data in the file and check the return code of fprintf to verify that > 0 bytes have been written */
|
||||
@ -1077,7 +1077,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
|
||||
for (uint64_t i=0UL; i < (uint64_t) size; ++i) {
|
||||
rc = fprintf(f, format_str,
|
||||
$group_dset_sparse_indices_printf$,
|
||||
*(value_sparse + i));
|
||||
,*(value_sparse + i));
|
||||
if(rc <= 0) {
|
||||
fclose(f);
|
||||
return TREXIO_FAILURE;
|
||||
@ -1168,7 +1168,7 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file,
|
||||
if(fgets(buffer, 1023, f) == NULL){
|
||||
|
||||
fclose(f);
|
||||
*eof_read_size = count;
|
||||
,*eof_read_size = count;
|
||||
return TREXIO_END;
|
||||
|
||||
} else {
|
||||
@ -1201,7 +1201,7 @@ trexio_exit_code trexio_text_read_$group_dset$_size(trexio_t* const file, int64_
|
||||
|
||||
/* Build the name of the file with sparse data.
|
||||
The $group_dset$.txt is limited to 256 symbols for the moment. What are the chances that it will exceed?
|
||||
*/
|
||||
,*/
|
||||
const char $group_dset$_file_name[256] = "/$group_dset$.txt.size";
|
||||
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
||||
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
||||
@ -1228,7 +1228,7 @@ trexio_exit_code trexio_text_read_$group_dset$_size(trexio_t* const file, int64_
|
||||
size_accum += size_item;
|
||||
} else {
|
||||
fclose(f);
|
||||
*size_max = -1L;
|
||||
,*size_max = -1L;
|
||||
return TREXIO_INT_SIZE_OVERFLOW;
|
||||
}
|
||||
}
|
||||
@ -1238,7 +1238,7 @@ trexio_exit_code trexio_text_read_$group_dset$_size(trexio_t* const file, int64_
|
||||
if(rc != 0) return TREXIO_FILE_ERROR;
|
||||
|
||||
/* Overwrite the value at the input address and return TREXIO_SUCCESS */
|
||||
*size_max = size_accum;
|
||||
,*size_max = size_accum;
|
||||
return TREXIO_SUCCESS;
|
||||
|
||||
}
|
||||
@ -1251,7 +1251,7 @@ trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file)
|
||||
|
||||
/* Build the name of the file with sparse data.
|
||||
The $group_dset$.txt is limited to 256 symbols for the moment. What are the chances that it will exceed?
|
||||
*/
|
||||
,*/
|
||||
const char $group_dset$_file_name[256] = "/$group_dset$.txt";
|
||||
/* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */
|
||||
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
|
||||
|
Loading…
Reference in New Issue
Block a user