kim-api  2.1.2+v2.1.2.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
collections-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 end module error
44 
45 module utilities
46  implicit none
47 
48  public
49 
50 contains
51  subroutine dirs_for_collection(collection, col)
52  use, intrinsic :: iso_c_binding
56  implicit none
57  type(kim_collection_type), intent(in) :: collection
58  type(kim_collections_handle_type), intent(inout) :: col
59 
60  integer(c_int) ierr
61  integer(c_int) i
62  integer(c_int) extent
63  character(len=2048, kind=c_char) coll_str
64  character(len=2048, kind=c_char) item_type_str
65  character(len=2048, kind=c_char) dir_str
66 
67 
68  call kim_cache_list_of_directory_names(col, collection, &
70  call kim_to_string(collection, coll_str)
71  call kim_to_string(kim_collection_item_type_model_driver, item_type_str)
72  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
73 
74  do i=1,extent
75  call kim_get_directory_name(col, i, dir_str, ierr)
76  print '(A,A)', achar(9), trim(dir_str)
77  end do
78 
79  call kim_cache_list_of_directory_names(col, collection, &
81  call kim_to_string(collection, coll_str)
82  call kim_to_string(kim_collection_item_type_portable_model, item_type_str)
83  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
84 
85  do i=1,extent
86  call kim_get_directory_name(col, i, dir_str, ierr)
87  print '(A,A)', achar(9), trim(dir_str)
88  end do
89 
90  call kim_cache_list_of_directory_names(col, collection, &
92  call kim_to_string(collection, coll_str)
93  call kim_to_string(kim_collection_item_type_simulator_model, item_type_str)
94  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
95 
96  do i=1,extent
97  call kim_get_directory_name(col, i, dir_str, ierr)
98  print '(A,A)', achar(9), trim(dir_str)
99  end do
100  end subroutine dirs_for_collection
101 
102  subroutine names_for_collection(kc, col)
103  use, intrinsic :: iso_c_binding
107  implicit none
108  type(kim_collection_type), intent(in) :: kc
109  type(kim_collections_handle_type), intent(inout) :: col
110 
111  integer(c_int) ierr
112  integer(c_int) i
113  integer(c_int) extent
114  character(len=2048, kind=c_char) coll_str
115  character(len=2048, kind=c_char) item_type_str
116  character(len=2048, kind=c_char) name_str
117 
118  call kim_cache_list_of_item_names_by_collection_and_type(col, kc, &
120  call kim_to_string(kc, coll_str)
121  call kim_to_string(kim_collection_item_type_model_driver, item_type_str)
122  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
123 
124  do i=1,extent
125  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
126  print '(A,A)', achar(9), trim(name_str)
127  end do
128 
129  call kim_cache_list_of_item_names_by_collection_and_type(col, kc, &
131  call kim_to_string(kc, coll_str)
132  call kim_to_string(kim_collection_item_type_portable_model, item_type_str)
133  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
134 
135  do i=1,extent
136  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
137  print '(A,A)', achar(9), trim(name_str)
138  end do
139 
140  call kim_cache_list_of_item_names_by_collection_and_type(col, kc, &
142  call kim_to_string(kc, coll_str)
143  call kim_to_string(kim_collection_item_type_simulator_model, item_type_str)
144  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
145 
146  do i=1,extent
147  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
148  print '(A,A)', achar(9), trim(name_str)
149  end do
150  end subroutine names_for_collection
151 end module utilities
152 
153 !-------------------------------------------------------------------------------
154 !
155 ! Main program
156 !
157 !-------------------------------------------------------------------------------
159  use, intrinsic :: iso_c_binding
160  use error
161  use utilities
165  implicit none
166 
167  integer(c_int) :: ierr
168  integer(c_int) :: extent
169  integer(c_int) :: i
170  type(kim_collections_handle_type) :: col
171  type(kim_collection_type) col_t
172  type(kim_collection_item_type_type) it
173  character(len=2048, kind=c_char) project_name
174  character(len=2048, kind=c_char) sem_ver
175  character(len=2048, kind=c_char) name
176  character(len=2048, kind=c_char) value
177  character(len=2048, kind=c_char) file_name
178  integer(c_long) file_length
179  integer(c_int) available_as_string
180  integer(c_signed_char) file_raw_data(10000)
181  character(len=10000, kind=c_char) file_string
182  character(len=2048, kind=c_char) item_type_str
183 
184  call kim_collections_create(col, ierr)
185 
186  if (ierr /= 0) then
187  call my_error("Unable to create collections object.")
188  end if
189 
190  call kim_get_project_name_and_sem_ver(col, project_name, sem_ver)
191  print *, "Project : ", trim(project_name)
192  print *, "semVer : ", trim(sem_ver)
193  print *, ""
194 
195 
196 
198  call kim_get_environment_variable_name(col, it, name, ierr)
199  call kim_to_string(it, item_type_str)
200  print '(A," env name : ",A)', trim(item_type_str), trim(name)
201  print *, ""
202 
204  call kim_get_environment_variable_name(col, it, name, ierr)
205  call kim_to_string(it, item_type_str)
206  print '(A," env name : ",A)', trim(item_type_str), trim(name)
207  print *, ""
208 
210  call kim_get_environment_variable_name(col, it, name, ierr)
211  call kim_to_string(it, item_type_str)
212  print '(A," env name : ",A)', trim(item_type_str), trim(name)
213  print *, ""
214 
215  call kim_get_configuration_file_environment_variable(col, name, value)
216  print '("config file env name : ",A)', trim(name)
217  print '("config file env value : ",A)', trim(value)
218  print *, ""
219 
220  call kim_get_configuration_file_name(col, file_name)
221  print '("config file name : ",A)', trim(file_name)
222  print *, ""
223 
228  print *, ""
229 
234  print *, ""
235 
237  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
238  call kim_to_string(it, item_type_str)
239  print '(A," :")', trim(item_type_str)
240  do i=1,extent
241  call kim_get_item_name_by_type(col, i, name, ierr)
242  print '(A,A)', achar(9), trim(name)
243  end do
244 
246  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
247  call kim_to_string(it, item_type_str)
248  print '(A," :")', trim(item_type_str)
249  do i=1,extent
250  call kim_get_item_name_by_type(col, i, name, ierr)
251  print '(A,A)', achar(9), trim(name)
252  end do
253 
255  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
256  call kim_to_string(it, item_type_str)
257  print '(A," :")', trim(item_type_str)
258  do i=1,extent
259  call kim_get_item_name_by_type(col, i, name, ierr)
260  print '(A,A)', achar(9), trim(name)
261  end do
262 
263  call kim_get_item_library_file_name_and_collection(col, it, &
264  trim("Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"), name, col_t, ierr)
265  if (ierr /= 0) then
266  print '(A)', "Error from GetItemLibraryFileNameAndCollection"
267  else
268  call kim_to_string(col_t, value)
269  print '(A,A,A,A,A)', &
270  "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu has library name '", &
271  trim(name), "' and is part of the '", trim(value), "' collection."
272  end if
273 
274  call kim_cache_list_of_item_metadata_files(col, it, &
275  trim("Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"), extent, ierr)
276  if (ierr /= 0) then
277  print '(A)', "Error from CacheListOfItemMetadataFiles"
278  else
279  do i=1,extent
280  call kim_get_item_metadata_file_length(col, i, file_length, &
281  available_as_string, ierr)
282  call kim_get_item_metadata_file_values(col, i, file_name, &
283  file_raw_data, file_string, ierr)
284  print '(A,I2,A,A,A,I6)', "Metadata File ", i, ", ", trim(file_name), &
285  ", is of length", file_length
286  print '(A)', trim(file_string)
287  end do
288  end if
289 
290  call kim_collections_destroy(col)
291 
292 end program collections_example_fortran
type(kim_collection_item_type_type), save, public, protected kim_collection_item_type_model_driver
type(kim_collection_type), save, public, protected kim_collection_user
subroutine dirs_for_collection(collection, col)
An Extensible Enumeration for the CollectionItemType's supported by the KIM API.
recursive subroutine, public kim_collections_create(collections_handle, ierr)
Create a new KIM API Collections object.
Provides the interface to the KIM API Collections and is meant to be used by simulators.
type(kim_collection_item_type_type), save, public, protected kim_collection_item_type_portable_model
recursive subroutine my_error(message)
type(kim_collection_type), save, public, protected kim_collection_environment_variable
subroutine names_for_collection(kc, col)
type(kim_collection_item_type_type), save, public, protected kim_collection_item_type_simulator_model
type(kim_collection_type), save, public, protected kim_collection_system
program collections_example_fortran
type(kim_collection_type), save, public, protected kim_collection_current_working_directory
An Extensible Enumeration for the Collection's supported by the KIM API.
recursive subroutine, public kim_collections_destroy(collections_handle)
Destroy a previously Collections::Create'd object.