subroutine ESMF_IOWrite(io, fileName, keywordEnforcer, &
overwrite, status, &
timeslice, iofmt, schema, rc)
!
! !ARGUMENTS:
type(ESMF_IO), intent(in) :: io
character (len=*), intent(in) :: fileName
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
logical, intent(in), optional :: overwrite
type(ESMF_FileStatus_Flag), intent(in), optional :: status
integer, intent(in), optional :: timeslice
type(ESMF_IOFmt_Flag), intent(in), optional :: iofmt
character (len=*), intent(in), optional :: schema
integer, intent(out), optional :: rc
! !DESCRIPTION:
! Perform a write on an {\tt ESMF\_IO} object. Any properties specified
! will override, but not reset, those previously set on the io object.
!
! The arguments are:
! \begin{description}
! \item[io]
! The object instance to write.
! \item[fileName]
! The file name to be writtten to.
! \item[{[overwrite]}]
! \begin{sloppypar}
! A logical flag, the default is .false., i.e., existing field data may
! {\em not} be overwritten. If .true., the overwrite behavior depends
! on the value of {\tt iofmt} as shown below:
! \begin{description}
! \item[{\tt iofmt} = {\tt ESMF\_IOFMT\_BIN}:]\ All data in the file will
! be overwritten with each field's data.
! \item[{\tt iofmt} = {\tt ESMF\_IOFMT\_NETCDF}:]\ Only the
! data corresponding to each field's name will be
! be overwritten. If the {\tt timeslice} option is given, only data for
! the given timeslice may be overwritten.
! Note that it is always an error to attempt to overwrite a NetCDF
! variable with data which has a different shape.
! \end{description}
! \end{sloppypar}
! \item[{[status]}]
! \begin{sloppypar}
! The file status. Please see Section~\ref{const:filestatusflag} for
! the list of options. If not present, defaults to
! {\tt ESMF\_FILESTATUS\_UNKNOWN}.
! \end{sloppypar}
! \item[{[timeslice]}]
! \begin{sloppypar}
! Some I/O formats (e.g. NetCDF) support the output of data in form of
! time slices. The {\tt timeslice} argument provides access to this
! capability. {\tt timeslice} must be positive. The behavior of this
! option may depend on the setting of the {\tt overwrite} flag:
! \begin{description}
! \item[{\tt overwrite = .false.}:]\ If the timeslice value is
! less than the maximum time already in the file, the write will fail.
! \item[{\tt overwrite = .true.}:]\ Any positive timeslice value is valid.
! \end{description}
! By default, i.e. by omitting the {\tt timeslice} argument, no
! provisions for time slicing are made in the output file,
! however, if the file already contains a time axis for the variable,
! a timeslice one greater than the maximum will be written.
! \end{sloppypar}
! \item[{[iofmt]}]
! The file format to be used during the read. Default is
! ESMF_IOFMT_NETCDF
! \item[{[schema]}]
! Selects, for reading, the Attribute package of the ESMF
! objects included in <io> (e.g., with ESMF_IOAddArray)
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!EOPI
! !REQUIREMENTS:
!
integer :: localrc
integer :: len_fileName ! filename length or 0
type(ESMF_Logical) :: opt_overwriteflag ! helper variable
type(ESMF_FileStatus_Flag) :: opt_status ! helper variable
type(ESMF_IOFmt_Flag) :: opt_iofmt ! helper variable
integer :: len_schema ! schema string len or 0
! Assume failure until success
if (present(rc)) rc = ESMF_RC_NOT_IMPL
localrc = ESMF_RC_NOT_IMPL
! Set default flags
opt_overwriteflag = ESMF_FALSE
if (present(overwrite)) then
if (overwrite) opt_overwriteflag = ESMF_TRUE
end if
opt_status = ESMF_FILESTATUS_UNKNOWN
if (present(status)) opt_status = status
opt_iofmt = ESMF_IOFMT_NETCDF;
if ( present(iofmt)) opt_iofmt = iofmt
! Grab the filename length for the C++ level
len_fileName = len_trim(fileName)
! Grab the schema string length for the C++ level
if (present(schema)) then
len_schema = len_trim(schema)
else
len_schema = 0
endif
! invoke C to C++ entry point TODO
call c_ESMC_IOWrite(io, fileName, len_fileName, opt_iofmt, &
opt_overwriteflag, opt_status, timeslice, &
schema, len_schema, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_IOWrite