kim-api  2.1.0+v2.1.0.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
simulator-model-example-fortran.f90
Go to the documentation of this file.
1 !
2 ! CDDL HEADER START
3 !
4 ! The contents of this file are subject to the terms of the Common Development
5 ! and Distribution License Version 1.0 (the "License").
6 !
7 ! You can obtain a copy of the license at
8 ! http://www.opensource.org/licenses/CDDL-1.0. See the License for the
9 ! specific language governing permissions and limitations under the License.
10 !
11 ! When distributing Covered Code, include this CDDL HEADER in each file and
12 ! include the License file in a prominent location with the name LICENSE.CDDL.
13 ! If applicable, add the following below this CDDL HEADER, with the fields
14 ! enclosed by brackets "[]" replaced with your own identifying information:
15 !
16 ! Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
17 !
18 ! CDDL HEADER END
19 !
20 
21 !
22 ! Copyright (c) 2013--2019, Regents of the University of Minnesota.
23 ! All rights reserved.
24 !
25 ! Contributors:
26 ! Ryan S. Elliott
27 !
28 
29 module error
30  use, intrinsic :: iso_c_binding
31  implicit none
32 
33  public
34 
35 contains
36  recursive subroutine my_error(message)
37  implicit none
38  character(len=*, kind=c_char), intent(in) :: message
39 
40  print *,"* Error : ", trim(message)
41  stop 1
42  end subroutine my_error
43 
44  recursive subroutine my_warning(message)
45  implicit none
46  character(len=*, kind=c_char), intent(in) :: message
47 
48  print *,"* Warning : ", trim(message)
49  end subroutine my_warning
50 end module error
51 
52 !-------------------------------------------------------------------------------
53 !
54 ! Main program
55 !
56 !-------------------------------------------------------------------------------
58  use, intrinsic :: iso_c_binding
59  use error
61  implicit none
62 
63  integer(c_int) :: ierr
64  integer(c_int) :: extent
65  integer(c_int) :: no_fields
66  integer(c_int) :: i
67  integer(c_int) :: j
68  type(kim_simulator_model_handle_type) :: sm
69 
70  character(len=2048, kind=c_char) s_name
71  character(len=2048, kind=c_char) s_ver
72  character(len=2048, kind=c_char) species
73  character(len=2048, kind=c_char) field_name
74  character(len=2048, kind=c_char) line
75  character(len=2048, kind=c_char) dir_name
76  character(len=2048, kind=c_char) spec_name
77  character(len=2048, kind=c_char) param_name
78 
79 
80  call kim_simulator_model_create( &
81  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu", sm, ierr)
82 
83  if (ierr /= 0) then
84  call my_error("Can't create SM.")
85  end if
86 
87  call kim_get_simulator_name_and_version(sm, s_name, s_ver)
88  print *, "Simulator name : ", trim(s_name)
89  print *, "Simulator version : ", trim(s_ver)
90  print *, ""
91 
92  call kim_get_number_of_supported_species(sm, extent)
93  print *, "SM supports", extent, " species:"
94  do i=1,extent
95  call kim_get_supported_species(sm, i, species, ierr)
96  if (ierr /= 0) then
97  call my_error("Unable to get species.")
98  else
99  print '(" ",I2," ",A)', i, trim(species)
100  end if
101  end do
102  print *, ""
103 
104  call kim_add_template_map(sm, "atom-type-sym-list", "Pb Pb Au Pb", ierr)
105  if (ierr /= 0) then
106  call my_error("Unable to add template map.")
107  end if
108  call kim_close_template_map(sm)
109  call kim_get_number_of_simulator_fields(sm, no_fields)
110  print '("SM has ",I2," fields :")', no_fields
111  do i=1,no_fields
112  call kim_get_simulator_field_metadata(sm, i, extent, field_name, ierr)
113  print '(" Field",I2," is ",A," and has ",I2," lines:")', &
114  i, trim(field_name), extent
115 
116  do j=1,extent
117  call kim_get_simulator_field_line(sm, i, j, line, ierr)
118  if (ierr /= 0) then
119  call my_error("Unable to get field line.")
120  else
121  print '(" ",A)', trim(line)
122  end if
123  end do
124  end do
125  print *,""
126 
127  call kim_get_parameter_file_directory_name(sm, dir_name)
128  print '("SM param dir name is ",A)', trim(dir_name)
129 
130  call kim_get_specification_file_name(sm, spec_name)
131  print '("SM spec file name is ",A)', trim(spec_name)
132  ierr = system("cat "//trim(dir_name)//"/"//trim(spec_name))
133 
134  call kim_get_number_of_parameter_files(sm, extent)
135  print '("SM has ",I1," parameter files:")', extent
136  do i=1,extent
137  call kim_get_parameter_file_name(sm, i, param_name, ierr)
138  if (ierr /= 0) then
139  call my_error("Unable to get parameter file name.")
140  else
141  print '("Parameter file ",I2," has name ",A)', i, trim(param_name)
142  ierr = system("cat "//trim(dir_name)//"/"//trim(param_name))
143  print *,""
144  end if
145  end do
146 
147  call kim_simulator_model_destroy(sm)
148 
149 end program collections_example_fortran
recursive subroutine my_warning(message)
recursive subroutine my_error(message)
program collections_example_fortran