DAMASK with grid solvers  Revision: v2.0.3-2204-gdb1f2151
The Düsseldorf Advanced Material Simulation Kit with Grid Solvers
system_routines.f90
Go to the documentation of this file.
1 # 1 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/system_routines.f90"
2 # 1 "<built-in>"
3 # 1 "<command-line>"
4 # 1 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/system_routines.f90"
5 !--------------------------------------------------------------------------------------------------
8 !--------------------------------------------------------------------------------------------------
10  use, intrinsic :: iso_c_binding
11 
12  use prec
13 
14  implicit none
15 
16  public :: &
17  signalterm_c, &
18  signalusr1_c, &
19  signalusr2_c, &
20  isdirectory, &
21  getcwd, &
22  gethostname, &
23  setcwd
24 
25  interface
26 
27  function isdirectory_c(path) bind(C)
28  use, intrinsic :: iso_c_binding, only: &
29  c_int, &
30  c_char
31 
32  use prec
33 
34  integer(C_INT) :: isdirectory_c
35  character(kind=C_CHAR), dimension(pPathLen), intent(in) :: path ! C string is an array
36  end function isdirectory_c
37 
38  subroutine getcurrentworkdir_c(path, stat) bind(C)
39  use, intrinsic :: iso_c_binding, only: &
40  c_int, &
41  c_char
42 
43  use prec
44 
45  character(kind=C_CHAR), dimension(pPathLen), intent(out) :: path ! C string is an array
46  integer(C_INT), intent(out) :: stat
47  end subroutine getcurrentworkdir_c
48 
49  subroutine gethostname_c(str, stat) bind(C)
50  use, intrinsic :: iso_c_binding, only: &
51  c_int, &
52  c_char
53 
54  use prec
55 
56  character(kind=C_CHAR), dimension(pStringLen), intent(out) :: str ! C string is an array
57  integer(C_INT), intent(out) :: stat
58  end subroutine gethostname_c
59 
60  function chdir_c(path) bind(C)
61  use, intrinsic :: iso_c_binding, only: &
62  c_int, &
63  c_char
64 
65  use prec
66 
67  integer(C_INT) :: chdir_c
68  character(kind=C_CHAR), dimension(pPathLen), intent(in) :: path ! C string is an array
69  end function chdir_c
70 
71  subroutine signalterm_c(handler) bind(C)
72  use, intrinsic :: iso_c_binding, only: &
73  c_funptr
74 
75  type(c_funptr), intent(in), value :: handler
76  end subroutine signalterm_c
77 
78  subroutine signalusr1_c(handler) bind(C)
79  use, intrinsic :: iso_c_binding, only: &
80  c_funptr
81 
82  type(c_funptr), intent(in), value :: handler
83  end subroutine signalusr1_c
84 
85  subroutine signalusr2_c(handler) bind(C)
86  use, intrinsic :: iso_c_binding, only: &
87  c_funptr
88 
89  type(c_funptr), intent(in), value :: handler
90  end subroutine signalusr2_c
91 
92  end interface
93 
94 contains
95 
96 !--------------------------------------------------------------------------------------------------
98 !--------------------------------------------------------------------------------------------------
99 logical function isdirectory(path)
100 
101  character(len=*), intent(in) :: path
102  character(kind=C_CHAR), dimension(pPathLen) :: strfixedlength ! C string as array
103  integer :: i
104 
105  strfixedlength = repeat(c_null_char,len(strfixedlength))
106  do i=1,len(path) ! copy array components
107  strfixedlength(i)=path(i:i)
108  enddo
109  isdirectory=merge(.true.,.false.,isdirectory_c(strfixedlength) /= 0_c_int)
110 
111 end function isdirectory
112 
113 
114 !--------------------------------------------------------------------------------------------------
116 !--------------------------------------------------------------------------------------------------
117 function getcwd()
118 
119  character(kind=C_CHAR), dimension(pPathLen) :: chararray ! C string is an array
120  character(len=:), allocatable :: getcwd
121  integer(C_INT) :: stat
122  integer :: i
123 
124  call getcurrentworkdir_c(chararray,stat)
125 
126  if (stat /= 0_c_int) then
127  getcwd = 'Error occured when getting currend working directory'
128  else
129  allocate(character(len=pPathLen)::getcwd)
130  arraytostring: do i=1,len(getcwd)
131  if (chararray(i) /= c_null_char) then
132  getcwd(i:i)=chararray(i)
133  else
134  getcwd = getcwd(:i-1)
135  exit
136  endif
137  enddo arraytostring
138  endif
139 
140 end function getcwd
141 
142 
143 !--------------------------------------------------------------------------------------------------
145 !--------------------------------------------------------------------------------------------------
146 function gethostname()
147 
148  character(kind=C_CHAR), dimension(pPathLen) :: chararray ! C string is an array
149  character(len=:), allocatable :: gethostname
150  integer(C_INT) :: stat
151  integer :: i
152 
153  call gethostname_c(chararray,stat)
154 
155  if (stat /= 0_c_int) then
156  gethostname = 'Error occured when getting host name'
157  else
158  allocate(character(len=pPathLen)::gethostname)
159  arraytostring: do i=1,len(gethostname)
160  if (chararray(i) /= c_null_char) then
161  gethostname(i:i)=chararray(i)
162  else
163  gethostname = gethostname(:i-1)
164  exit
165  endif
166  enddo arraytostring
167  endif
168 
169 end function gethostname
170 
171 
172 !--------------------------------------------------------------------------------------------------
174 !--------------------------------------------------------------------------------------------------
175 logical function setcwd(path)
176 
177  character(len=*), intent(in) :: path
178  character(kind=C_CHAR), dimension(pPathLen) :: strfixedlength ! C string is an array
179  integer :: i
180 
181  strfixedlength = repeat(c_null_char,len(strfixedlength))
182  do i=1,len(path) ! copy array components
183  strfixedlength(i)=path(i:i)
184  enddo
185  setcwd=merge(.true.,.false.,chdir_c(strfixedlength) /= 0_c_int)
186 
187 end function setcwd
188 
189 end module system_routines
190 
system_routines::setcwd
logical function, public setcwd(path)
changes the current working directory
Definition: system_routines.f90:176
system_routines::getcwd
character(len=:) function, allocatable, public getcwd()
gets the current working directory
Definition: system_routines.f90:118
prec
setting precision for real and int type
Definition: prec.f90:13
system_routines::isdirectory
logical function, public isdirectory(path)
figures out if a given path is a directory (and not an ordinary file)
Definition: system_routines.f90:100
system_routines
provides wrappers to C routines
Definition: system_routines.f90:9
system_routines::gethostname
character(len=:) function, allocatable, public gethostname()
gets the current host name
Definition: system_routines.f90:147