Calling Lammps code from Fortran

Hello,

I am using reverse monte carlo code written in Fortran for a simulation and would like to use lammps to calculate energy. I would like to do this by calling lammps inside my fortran code. To test I wrote a very small fortran code that is supposed to start lammps. Unfortunately, whenever I try to compile it i get errors. Any assistance would be appreciated.

The code I am trying to compile is:

Program adder
IMPLICIT NONE

!void lammps_open_no_mpi(int argc, char **argv, void **ptr)
!int sally[2][3] = {{2,3,4},{5,6,7}};
!char start_ups[][] = [[’-l’], [‘log’ ]] ;
!character(1) , dimension (2) :: argv
INTERFACE
SUBROUTINE lammps_open_no_mpi(argc, argv, ptr) BIND©
USE, INTRINSIC :: ISO_C_BINDING, only : C_char, C_ptr, C_int
INTEGER (C_INT) :: argc
CHARACTER (C_CHAR ) :: argv
POINTER (C_ptr) :: ptr
END SUBROUTINE lammps_open_no_mpi
END INTERFACE
integer a,b

a = 1
b = 2
call lammps_open_no_mpi(1 ,‘lmp -log log.simple’ , &void)

PRINT *, ‘Hello World’
end Program

The error message I am getting is

adder.f90(13): error #5082: Syntax error, found ‘)’ when expecting one of: ,
POINTER (C_ptr) :: ptr
------------------------------^
adder.f90(20): error #5082: Syntax error, found IDENTIFIER ‘VOID’ when expecting one of: <POUND_VAL> <INTEGER_KIND_CON> <POUND_BASE> <INTEGER_CONSTANT>
call lammps_open_no_mpi(1 ,‘lmp -log log.simple’ , &void)

I am using mpif90 adder.f90 to compile it.

Hello,

I am using reverse monte carlo code written in Fortran for a simulation
and would like to use lammps to calculate energy. I would like to do this
by calling lammps inside my fortran code. To test I wrote a very small
fortran code that is supposed to start lammps. Unfortunately, whenever I
try to compile it i get errors. Any assistance would be appreciated.

it is not at all surprising that your compiler refused to compile this,
since ​your code is not valid fortran 2003 syntax in several ways and also
not correctly doing the interfacing in places, where the syntax is correct.​

​ ​you need significant help from a fortran expert knowledgeable in using
the ISO_C_BINDINGS module.


please note, that ​there are ​two examples of fortran wrappers in the
"example/COUPLE/" folder. however, those have not been updated in many
years while there have been some changes to the library interface, so they
are not likely to function completely.

​axel.​

The examples/COUPLE/fortran2 one is the newer of the examples.

We’ll be adding a fortran3 one soon, which was recently contributed.

Steve