Implemented plugin_name and plugin_count and their docs

This commit is contained in:
Karl Hammond
2022-10-26 00:02:54 -05:00
parent 19f93009c1
commit b8781aca15
2 changed files with 89 additions and 6 deletions

View File

@ -350,6 +350,10 @@ of the contents of the :f:mod:`LIBLAMMPS` Fortran interface to LAMMPS.
:ftype id_count: function
:f id_name: :f:subr:`id_name`
:ftype id_name: subroutine
:f plugin_count: :f:func:`plugin_count`
:ftype plugin_count: function
:f plugin_name: :f:subr:`plugin_name`
:ftype plugin_count: subroutine
:f encode_image_flags: :f:func:`encode_image_flags`
:ftype encode_image_flags: function
:f decode_image_flags: :f:subr:`decode_image_flags`
@ -1985,6 +1989,48 @@ Procedures Bound to the :f:type:`lammps` Derived Type
If *idx* is out of range, *buffer* is set to an empty string and a warning
is issued.
:p character(len=\*) category: category of IDs
:p integer(c_int) idx: index of the ID in the list of *category*
styles (:math:`0 \leq idx < count`)
:p character(len=\*) buffer: string into which to copy the name of the
style
:to: :cpp:func:`lammps_id_name`
--------
.. f:function:: plugin_count()
This function counts the number of loaded plugins.
.. versionadded:: TBD
:to: :cpp:func:`lammps_plugin_count`
:r n: number of loaded plugins
:rtype n: integer(c_int)
--------
.. f:subroutine:: plugin_name(idx, stylebuf, namebuf)
Look up the style and name of a plugin by its index in the list of plugins.
.. versionadded:: TBD
This function copies the name of the *style* plugin with the index *idx*
into the provided C-style string buffer. The length of the buffer must be
provided as *buf_size* argument. If the name of the style exceeds the
length of the buffer, it will be truncated accordingly. If the index is out
of range, both strings are set to the empty string and a warning is
printed.
:p integer(c_int) idx: index of the plugin in the list all or
*style* plugins
:p character(len=\*) stylebuf: string into which to copy the style of the
plugin
:p character(len=\*) namebuf: string into which to copy the style of the
plugin
:to: :cpp:func:`lammps_plugin_name`
--------
.. f:function:: encode_image_flags(ix, iy, iz)

View File

@ -163,7 +163,8 @@ MODULE LIBLAMMPS
PROCEDURE :: has_id => lmp_has_id
PROCEDURE :: id_count => lmp_id_count
PROCEDURE :: id_name => lmp_id_name
!
PROCEDURE, NOPASS :: plugin_count => lammps_plugin_count
PROCEDURE :: plugin_name => lmp_plugin_name
PROCEDURE :: encode_image_flags => lmp_encode_image_flags
PROCEDURE, PRIVATE :: lmp_decode_image_flags
PROCEDURE, PRIVATE :: lmp_decode_image_flags_bigbig
@ -684,8 +685,19 @@ MODULE LIBLAMMPS
INTEGER(c_int) :: lammps_id_name
END FUNCTION lammps_id_name
!INTEGER(c_int) FUNCTION lammps_plugin_count
!SUBROUTINE lammps_plugin_name
FUNCTION lammps_plugin_count() BIND(C)
IMPORT :: c_int
IMPLICIT NONE
INTEGER(c_int) :: lammps_plugin_count
END FUNCTION lammps_plugin_count
FUNCTION lammps_plugin_name(idx, stylebuf, namebuf, buf_size) BIND(C)
IMPORT :: c_int, c_ptr
IMPLICIT NONE
INTEGER(c_int), VALUE :: idx, buf_size
TYPE(c_ptr), VALUE :: stylebuf, namebuf
INTEGER(c_int) :: lammps_plugin_name
END FUNCTION lammps_plugin_name
! We don't call lammps_encode_image_flags because its interface is
! ambiguous: we don't know sizeof(imageint) prior to compile time.
@ -2177,6 +2189,31 @@ CONTAINS
CALL lammps_free(Cbuffer)
END SUBROUTINE lmp_id_name
! equivalent function to lammps_plugin_name
SUBROUTINE lmp_plugin_name(self, idx, stylebuf, namebuf)
CLASS(lammps), INTENT(IN) :: self
INTEGER(c_int), INTENT(IN) :: idx
CHARACTER(LEN=*), INTENT(OUT) :: stylebuf, namebuf
INTEGER(c_int) :: buf_size, success
TYPE(c_ptr) :: Cstylebuf, Cnamebuf
buf_size = MIN(LEN(stylebuf, KIND=c_int), LEN(namebuf, KIND=c_int))
Cstylebuf = lammps_malloc(INT(buf_size, KIND=c_size_t))
Cnamebuf = lammps_malloc(INT(buf_size, KIND=c_size_t))
success = lammps_plugin_name(idx, Cstylebuf, Cnamebuf, buf_size)
IF (success /= 0_c_int) THEN
stylebuf = c2f_string(Cstylebuf)
namebuf = c2f_string(Cnamebuf)
ELSE
stylebuf = ''
namebuf = ''
CALL lmp_error(self, LMP_ERROR_WARNING + LMP_ERROR_WORLD, &
'call to lammps_plugin_name failed [Fortran/plugin_name]')
END IF
CALL lammps_free(Cstylebuf)
CALL lammps_free(Cnamebuf)
END SUBROUTINE lmp_plugin_name
! equivalent function to lammps_encode_image_flags
FUNCTION lmp_encode_image_flags(self, ix, iy, iz) RESULT (image)
CLASS(lammps), INTENT(IN), TARGET :: self