Skip to content

Commit

Permalink
Merge branch 'framework/smiol_file_format' into develop (PR #1219)
Browse files Browse the repository at this point in the history
This merge updates the SMIOL code in src/external/SMIOL from the MPAS-Dev/SMIOL
repository to include modifications that allow the file format to be specified
in calls to SMIOLf_open_file. By default, new output files are still created in
CDF-5 format as before, but it is now possible to specify either
SMIOL_FORMAT_CDF5 or SMIOL_FORMAT_CDF2 for the optional fformat argument to
SMIOLf_open_file.

The changes introduced here come from commit 5df48736 in the MPAS-Dev/SMIOL
repository; but since the SMIOL code in this repository has diverged from that
in the MPAS-Dev/SMIOL repository, the smiol.c file isn't identical between the
two repositories.

* framework/smiol_file_format:
  Update SMIOL code to support specified format for file creation
  • Loading branch information
mgduda committed Jul 29, 2024
2 parents eb62cd1 + 70720bd commit c9e6446
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
25 changes: 23 additions & 2 deletions src/external/SMIOL/smiol.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,17 @@ int SMIOL_inquire(void)
* blocking write interface, while a nonzero value enables the use of the
* non-blocking, buffered interface for writing.
*
* When a file is opened with a mode of SMIOL_FILE_CREATE, the fformat argument
* is used to set the file format. Otherwise fformat is ignored.
*
* Upon successful completion, SMIOL_SUCCESS is returned, and the file handle
* argument will point to a valid file handle and the current frame for the
* file will be set to zero. Otherwise, the file handle is NULL and an error
* code other than SMIOL_SUCCESS is returned.
*
********************************************************************************/
int SMIOL_open_file(struct SMIOL_context *context, const char *filename,
int mode, struct SMIOL_file **file, size_t bufsize)
int mode, struct SMIOL_file **file, size_t bufsize, int fformat)
{
int io_group;
MPI_Comm io_file_comm;
Expand Down Expand Up @@ -318,8 +321,24 @@ int SMIOL_open_file(struct SMIOL_context *context, const char *filename,
if (mode & SMIOL_FILE_CREATE) {
#ifdef SMIOL_PNETCDF
if ((*file)->io_task) {
/*
* Convert fformat to a PNetCDF file creation mode
*/
int filecmode;
if (fformat == SMIOL_FORMAT_CDF2) {
filecmode = NC_64BIT_OFFSET;
} else if (fformat == SMIOL_FORMAT_CDF5) {
filecmode = NC_64BIT_DATA;
} else {
free((*file));
(*file) = NULL;
MPI_Comm_free(&io_file_comm);
MPI_Comm_free(&io_group_comm);
return SMIOL_INVALID_FORMAT;
}

ierr = ncmpi_create(io_file_comm, filename,
(NC_64BIT_DATA | NC_CLOBBER),
(filecmode | NC_CLOBBER),
MPI_INFO_NULL,
&((*file)->ncidp));
}
Expand Down Expand Up @@ -1983,6 +2002,8 @@ const char *SMIOL_error_string(int errno)
return "argument is of the wrong type";
case SMIOL_INSUFFICIENT_ARG:
return "argument is of insufficient size";
case SMIOL_INVALID_FORMAT:
return "invalid format for file creation";
default:
return "Unknown error";
}
Expand Down
2 changes: 1 addition & 1 deletion src/external/SMIOL/smiol.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int SMIOL_inquire(void);
* File methods
*/
int SMIOL_open_file(struct SMIOL_context *context, const char *filename,
int mode, struct SMIOL_file **file, size_t bufsize);
int mode, struct SMIOL_file **file, size_t bufsize, int fformat);
int SMIOL_close_file(struct SMIOL_file **file);

/*
Expand Down
4 changes: 4 additions & 0 deletions src/external/SMIOL/smiol_codes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define SMIOL_LIBRARY_ERROR (-5)
#define SMIOL_WRONG_ARG_TYPE (-6)
#define SMIOL_INSUFFICIENT_ARG (-7)
#define SMIOL_INVALID_FORMAT (-8)

#define SMIOL_FILE_CREATE (1)
#define SMIOL_FILE_READ (2)
Expand All @@ -19,3 +20,6 @@
#define SMIOL_INT32 (2002)
#define SMIOL_CHAR (2003)
#define SMIOL_UNKNOWN_VAR_TYPE (2004)

#define SMIOL_FORMAT_CDF2 (3000)
#define SMIOL_FORMAT_CDF5 (3001)
21 changes: 17 additions & 4 deletions src/external/SMIOL/smiolf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,16 @@ end function SMIOLf_inquire
!> the use of the non-blocking, buffered interface for writing. If the bufsize
!> argument is not present, a default buffer size of 128 MiB is used.
!>
!> When a file is opened with a mode of SMIOL_FILE_CREATE, the fformat optional
!> argument is used to set the file format. Otherwise, fformat is ignored. If
!> not present, the default file format is SMIOL_FORMAT_CDF5.
!>
!> Upon successful completion, SMIOL_SUCCESS is returned, and the file handle argument
!> will point to a valid file handle. Otherwise, the file handle is not associated
!> and an error code other than SMIOL_SUCCESS is returned.
!
!-----------------------------------------------------------------------
integer function SMIOLf_open_file(context, filename, mode, file, bufsize) result(ierr)
integer function SMIOLf_open_file(context, filename, mode, file, bufsize, fformat) result(ierr)

use iso_c_binding, only : c_loc, c_ptr, c_null_ptr, c_char, c_size_t, c_associated, c_f_pointer

Expand All @@ -382,6 +386,7 @@ integer function SMIOLf_open_file(context, filename, mode, file, bufsize) result
integer, intent(in) :: mode
type (SMIOLf_file), pointer :: file
integer(kind=c_size_t), intent(in), optional :: bufsize
integer, intent(in), optional :: fformat

! Default buffer size to use if optional bufsize argument is not provided
integer (kind=c_size_t), parameter :: default_bufsize = int(128*1024*1024, kind=c_size_t)
Expand All @@ -390,16 +395,18 @@ integer function SMIOLf_open_file(context, filename, mode, file, bufsize) result
type (c_ptr) :: c_file = c_null_ptr
integer(kind=c_int) :: c_mode
character(kind=c_char), dimension(:), pointer :: c_filename
integer(kind=c_int) :: c_fformat

! C interface definitions
interface
function SMIOL_open_file(context, filename, mode, file, bufsize) result(ierr) bind(C, name='SMIOL_open_file')
function SMIOL_open_file(context, filename, mode, file, bufsize, fformat) result(ierr) bind(C, name='SMIOL_open_file')
use iso_c_binding, only : c_char, c_ptr, c_int, c_size_t
type (c_ptr), value :: context
character(kind=c_char), dimension(*) :: filename
integer(kind=c_int), value :: mode
type (c_ptr) :: file
integer(kind=c_size_t), value :: bufsize
integer(kind=c_int), value :: fformat
integer(kind=c_int) :: ierr
end function
end interface
Expand All @@ -416,12 +423,18 @@ function SMIOL_open_file(context, filename, mode, file, bufsize) result(ierr) bi

c_mode = mode

if (present(fformat)) then
c_fformat = fformat
else
c_fformat = SMIOL_FORMAT_CDF5
end if

if (present(bufsize)) then
ierr = SMIOL_open_file(c_context, c_filename, c_mode, c_file, &
bufsize)
bufsize, c_fformat)
else
ierr = SMIOL_open_file(c_context, c_filename, c_mode, c_file, &
default_bufsize)
default_bufsize, c_fformat)
end if

deallocate(c_filename)
Expand Down

0 comments on commit c9e6446

Please sign in to comment.