Fortran constants/variables as LAMMPS variables

Hello Sir,

I try to search a basic question about how to input or use Fortran constants/variables as input variables for LAMMPS in Fortran that uses LAMMPS as a library. But i can not find it. Now i am just doing liike saving Fortran variables in a file and reading these variables in LAMMPS. But i believe that there may be some direct way of doing this.

Only i can search about accessing system properties or how to use LAMMPS variables as a Fortran constant/variables. BUT can not find the reverse like how to input Fortran variables as LAMMPS input variables.

Thank you

That kind of feature is currently only available from C++ and not (yet) exposed to the C library interface and by extension thus also not available through any of the other library interfaces, i.e. the fortran module or the python module or the swig based wrappers.

Your currently best option is to delete and recreate the variable from LAMMPS commands. Here is a simple example:

PROGRAM testvar
  USE liblammps
  TYPE(lammps) :: lmp
  CHARACTER(LEN=40) :: cmd
  REAL(kind=8) :: val

  lmp = lammps()
  CALL lmp%command('variable testme index 1.1')
  CALL lmp%command('print "LAMMPS before: testme = ${testme}"')

  CALL lmp%command('variable testme delete')
  val = 2.45
  WRITE(cmd, '(A,F10.6)') 'variable testme index', val
  CALL lmp%command(cmd)

  CALL lmp%command('print "LAMMPS after: testme = ${testme}"')
  CALL lmp%close(.TRUE.)