kim-api  2.1.1+v2.1.1.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_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  character(len=2048, kind=c_char) item_type_str
178 
179  call kim_collections_create(col, ierr)
180 
181  if (ierr /= 0) then
182  call my_error("Unable to create collections object.")
183  end if
184 
185  call kim_get_project_name_and_sem_ver(col, project_name, sem_ver)
186  print *, "Project : ", trim(project_name)
187  print *, "semVer : ", trim(sem_ver)
188  print *, ""
189 
190 
191 
193  call kim_get_environment_variable_name(col, it, name, ierr)
194  call kim_to_string(it, item_type_str)
195  print '(A," env name : ",A)', trim(item_type_str), trim(name)
196  print *, ""
197 
199  call kim_get_environment_variable_name(col, it, name, ierr)
200  call kim_to_string(it, item_type_str)
201  print '(A," env name : ",A)', trim(item_type_str), trim(name)
202  print *, ""
203 
205  call kim_get_environment_variable_name(col, it, name, ierr)
206  call kim_to_string(it, item_type_str)
207  print '(A," env name : ",A)', trim(item_type_str), trim(name)
208  print *, ""
209 
210  call kim_get_configuration_file_environment_variable(col, name, value)
211  print '("config file env name : ",A)', trim(name)
212  print '("config file env value : ",A)', trim(value)
213  print *, ""
214 
215  call kim_get_configuration_file_name(col, file_name)
216  print '("config file name : ",A)', trim(file_name)
217  print *, ""
218 
223  print *, ""
224 
229  print *, ""
230 
232  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
233  call kim_to_string(it, item_type_str)
234  print '(A," :")', trim(item_type_str)
235  do i=1,extent
236  call kim_get_item_name_by_type(col, i, name, ierr)
237  print '(A,A)', achar(9), trim(name)
238  end do
239 
241  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
242  call kim_to_string(it, item_type_str)
243  print '(A," :")', trim(item_type_str)
244  do i=1,extent
245  call kim_get_item_name_by_type(col, i, name, ierr)
246  print '(A,A)', achar(9), trim(name)
247  end do
248 
250  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
251  call kim_to_string(it, item_type_str)
252  print '(A," :")', trim(item_type_str)
253  do i=1,extent
254  call kim_get_item_name_by_type(col, i, name, ierr)
255  print '(A,A)', achar(9), trim(name)
256  end do
257 
258  call kim_collections_destroy(col)
259 
260 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.