kim-api  2.2.1+v2.2.1.GNU.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--2020, 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  call kim_cache_list_of_directory_names( &
68  col, collection, kim_collection_item_type_model_driver, extent, ierr)
69  call kim_to_string(collection, coll_str)
70  call kim_to_string(kim_collection_item_type_model_driver, item_type_str)
71  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
72 
73  do i = 1, extent
74  call kim_get_directory_name(col, i, dir_str, ierr)
75  print '(A,A)', achar(9), trim(dir_str)
76  end do
77 
78  call kim_cache_list_of_directory_names( &
79  col, collection, kim_collection_item_type_portable_model, extent, ierr)
80  call kim_to_string(collection, coll_str)
81  call kim_to_string(kim_collection_item_type_portable_model, item_type_str)
82  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
83 
84  do i = 1, extent
85  call kim_get_directory_name(col, i, dir_str, ierr)
86  print '(A,A)', achar(9), trim(dir_str)
87  end do
88 
89  call kim_cache_list_of_directory_names( &
90  col, collection, kim_collection_item_type_simulator_model, extent, ierr)
91  call kim_to_string(collection, coll_str)
92  call kim_to_string(kim_collection_item_type_simulator_model, item_type_str)
93  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
94 
95  do i = 1, extent
96  call kim_get_directory_name(col, i, dir_str, ierr)
97  print '(A,A)', achar(9), trim(dir_str)
98  end do
99  end subroutine dirs_for_collection
100 
101  subroutine names_for_collection(kc, col)
102  use, intrinsic :: iso_c_binding
106  implicit none
107  type(kim_collection_type), intent(in) :: kc
108  type(kim_collections_handle_type), intent(inout) :: col
109 
110  integer(c_int) ierr
111  integer(c_int) i
112  integer(c_int) extent
113  character(len=2048, kind=c_char) coll_str
114  character(len=2048, kind=c_char) item_type_str
115  character(len=2048, kind=c_char) name_str
116 
117  call kim_cache_list_of_item_names_by_collection_and_type( &
118  col, kc, kim_collection_item_type_model_driver, extent, ierr)
119  call kim_to_string(kc, coll_str)
120  call kim_to_string(kim_collection_item_type_model_driver, item_type_str)
121  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
122 
123  do i = 1, extent
124  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
125  print '(A,A)', achar(9), trim(name_str)
126  end do
127 
128  call kim_cache_list_of_item_names_by_collection_and_type( &
129  col, kc, kim_collection_item_type_portable_model, extent, ierr)
130  call kim_to_string(kc, coll_str)
131  call kim_to_string(kim_collection_item_type_portable_model, item_type_str)
132  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
133 
134  do i = 1, extent
135  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
136  print '(A,A)', achar(9), trim(name_str)
137  end do
138 
139  call kim_cache_list_of_item_names_by_collection_and_type( &
140  col, kc, kim_collection_item_type_simulator_model, extent, ierr)
141  call kim_to_string(kc, coll_str)
142  call kim_to_string(kim_collection_item_type_simulator_model, item_type_str)
143  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
144 
145  do i = 1, extent
146  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
147  print '(A,A)', achar(9), trim(name_str)
148  end do
149  end subroutine names_for_collection
150 end module utilities
151 
152 !-------------------------------------------------------------------------------
153 !
154 ! Main program
155 !
156 !-------------------------------------------------------------------------------
158  use, intrinsic :: iso_c_binding
159  use error
160  use utilities
164  implicit none
165 
166  integer(c_int) :: ierr
167  integer(c_int) :: extent
168  integer(c_int) :: i
169  type(kim_collections_handle_type) :: col
170  type(kim_collection_type) col_t
171  type(kim_collection_item_type_type) it
172  character(len=2048, kind=c_char) project_name
173  character(len=2048, kind=c_char) sem_ver
174  character(len=2048, kind=c_char) name
175  character(len=2048, kind=c_char) value
176  character(len=2048, kind=c_char) file_name
177  integer(c_long) file_length
178  integer(c_int) available_as_string
179  integer(c_signed_char) file_raw_data(10000)
180  character(len=10000, kind=c_char) file_string
181  character(len=2048, kind=c_char) item_type_str
182 
183  call kim_collections_create(col, ierr)
184 
185  if (ierr /= 0) then
186  call my_error("Unable to create collections object.")
187  end if
188 
189  call kim_get_project_name_and_sem_ver(col, project_name, sem_ver)
190  print *, "Project : ", trim(project_name)
191  print *, "semVer : ", trim(sem_ver)
192  print *, ""
193 
195  call kim_get_environment_variable_name(col, it, name, ierr)
196  call kim_to_string(it, item_type_str)
197  print '(A," env name : ",A)', trim(item_type_str), trim(name)
198  print *, ""
199 
201  call kim_get_environment_variable_name(col, it, name, ierr)
202  call kim_to_string(it, item_type_str)
203  print '(A," env name : ",A)', trim(item_type_str), trim(name)
204  print *, ""
205 
207  call kim_get_environment_variable_name(col, it, name, ierr)
208  call kim_to_string(it, item_type_str)
209  print '(A," env name : ",A)', trim(item_type_str), trim(name)
210  print *, ""
211 
212  call kim_get_configuration_file_environment_variable(col, name, value)
213  print '("config file env name : ",A)', trim(name)
214  print '("config file env value : ",A)', trim(value)
215  print *, ""
216 
217  call kim_get_configuration_file_name(col, file_name)
218  print '("config file name : ",A)', trim(file_name)
219  print *, ""
220 
225  print *, ""
226 
231  print *, ""
232 
234  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
235  call kim_to_string(it, item_type_str)
236  print '(A," :")', trim(item_type_str)
237  do i = 1, extent
238  call kim_get_item_name_by_type(col, i, name, ierr)
239  print '(A,A)', achar(9), trim(name)
240  end do
241 
243  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
244  call kim_to_string(it, item_type_str)
245  print '(A," :")', trim(item_type_str)
246  do i = 1, extent
247  call kim_get_item_name_by_type(col, i, name, ierr)
248  print '(A,A)', achar(9), trim(name)
249  end do
250 
252  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
253  call kim_to_string(it, item_type_str)
254  print '(A," :")', trim(item_type_str)
255  do i = 1, extent
256  call kim_get_item_name_by_type(col, i, name, ierr)
257  print '(A,A)', achar(9), trim(name)
258  end do
259 
260  call kim_get_item_library_file_name_and_collection( &
261  col, it, trim("Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"), name, &
262  col_t, ierr)
263  if (ierr /= 0) then
264  print '(A)', "Error from GetItemLibraryFileNameAndCollection"
265  else
266  call kim_to_string(col_t, value)
267  print '(A,A,A,A,A,A)', &
268  "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu ", &
269  "has library name '", trim(name), "' and is part of the '", &
270  trim(value), "' collection."
271  end if
272 
273  call kim_cache_list_of_item_metadata_files( &
274  col, it, trim("Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"), extent, ierr)
275  if (ierr /= 0) then
276  print '(A)', "Error from CacheListOfItemMetadataFiles"
277  else
278  do i = 1, extent
279  call kim_get_item_metadata_file_length(col, i, file_length, &
280  available_as_string, ierr)
281  call kim_get_item_metadata_file_values(col, i, file_name, &
282  file_raw_data, file_string, ierr)
283  print '(A,I2,A,A,A,I6)', "Metadata File ", i, ", ", trim(file_name), &
284  ", is of length", file_length
285  print '(A)', trim(file_string)
286  end do
287  end if
288 
289  call kim_collections_destroy(col)
290 
291 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.