forked from gemini3d/gemini3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsys.f90
More file actions
71 lines (49 loc) · 1.73 KB
/
Copy pathsys.f90
File metadata and controls
71 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module gemini3d_sysinfo
!! procedure to get information from the system
use, intrinsic :: iso_fortran_env, only : stderr=>error_unit, compiler_version
use filesystem, only : expanduser
implicit none (type, external)
private
public :: get_compiler_vendor, expand_envvar
contains
character(5) function get_compiler_vendor() result(vendor)
character(80) :: cvers
integer :: i, j
character(*), parameter :: vendors(2) = [character(5) :: "Intel", "GCC"]
cvers = compiler_version()
do j = 1,size(vendors)
vendor = vendors(j)
i = index(cvers, vendor)
if (i > 0) exit
end do
if(vendor=="GCC") then
vendor = "GNU"
elseif(i == 0) then
vendor = ""
write(stderr,'(A,/,A)') "could not determine compiler vendor from",cvers
end if
end function get_compiler_vendor
function expand_envvar(path) result(expanded)
!! replace @...@ string like metabuild system e.g. CMake, based on environment variable.
!!
!! NOTE: only expands the first @envvar@ substring. Nest calls if mutliple @envvar@ substrings
character(*), intent(in) :: path
character(:), allocatable :: expanded, envvar
integer :: i0, i1
integer :: L, istat
character(1000) :: buf
expanded = expanduser(path)
i0 = index(path, "@")
if (i0 < 1) return
i0 = i0
i1 = index(path(i0+1:), "@")
if (i1 < 1) return !< a single @ without a matching @
i1 = i0 + i1
envvar = path(i0+1:i1-1)
if(len_trim(envvar) == 0) return !< only blanks in envvar
call get_environment_variable(envvar, buf, length=L, status=istat)
if(istat /= 0) error stop "config:expand_envvar: environment variable not defined: " // envvar
if(L < 1) error stop "config:expand_envvar: environment variable empty: " // envvar
expanded = path(:i0-1) // trim(adjustl(buf)) // path(i1+1:)
end function expand_envvar
end module gemini3d_sysinfo