Skip to content

Commit 5d00745

Browse files
committed
init [skip ci]
func [ci skip] doc, refine [skip ci] compat backslash [skip ci]' minreq
1 parent 0c269a6 commit 5d00745

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed

expanduser.f90

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module ioutils
2+
implicit none
3+
contains
4+
5+
subroutine expanduser(expandhome, indir)
6+
7+
character(*), intent(in), optional :: indir
8+
character(:), allocatable, intent(out) :: expandhome
9+
10+
character :: filesep
11+
character(256) :: buf
12+
! -- resolve home directory as Fortran does not understand tilde
13+
! works for Linux, Mac, Windows and more
14+
15+
if (present(indir)) then
16+
if (indir(1:1) /= '~') then
17+
expandhome = indir
18+
return
19+
endif
20+
endif
21+
22+
! assume MacOS/Linux/BSD/Cygwin/WSL
23+
filesep = '/'
24+
call get_environment_variable("HOME", buf)
25+
26+
if (len_trim(buf) == 0) then ! Windows
27+
call get_environment_variable("USERPROFILE", buf)
28+
filesep = char(92)
29+
endif
30+
31+
expandhome = trim(buf) // filesep // indir(3:)
32+
33+
34+
end subroutine expanduser
35+
36+
end module ioutils
37+
38+
!------ demo
39+
40+
program home
41+
42+
use ioutils
43+
implicit none
44+
! explores what '~' means for paths in Fortran
45+
! Note: when testing, enclose argument in '~/test.txt' quotes or
46+
! shell will expand '~' before it gets to Fortran!
47+
48+
integer :: fid, ios
49+
character(:), allocatable :: expanded
50+
character(256) :: buf
51+
52+
call get_command_argument(1, buf, status=ios)
53+
54+
if (ios==0) then
55+
call expanduser(expanded, trim(buf))
56+
else
57+
call expanduser(expanded)
58+
endif
59+
60+
print '(A)', trim(buf)
61+
print '(A)', expanded
62+
63+
end program

hdf5/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION 3.2.2) # 3.2.2 required for HDF5
1+
cmake_minimum_required (VERSION 3.10) # 3.10 required for HDF5 1.10
22
project(fortran2018demo Fortran)
33
enable_testing()
44
# INTEL COMPILER: https://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-hdf5-with-intel-compilers

special_characters.f90

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ program special_char
22
! This program shows a few special ASCII characters in Fortran.
33
! https://en.wikipedia.org/wiki/ASCII#Character_groups
44

5-
use, intrinsic:: iso_fortran_env, only: stdout=>error_unit
65
character, parameter :: &
76
nul = char(0), &
87
etx = char(3), &
9-
tab = char(9)
8+
tab = char(9), &
9+
backslash = char(92) ! necessary for strict compilers like PGI and Flang in strings
1010

1111
print *, 'null'
12-
write(stdout,'(A1)') nul
12+
print '(A1)', nul
1313

1414
print *, 'etx'
15-
write(stdout,'(A1)') etx
15+
print '(A1)', etx
1616

1717
print *, 'tab'
18-
write(stdout,'(A1)') tab
18+
print '(A1)', tab
19+
20+
print *, 'backslash'
21+
print '(A1)', backslash
1922

2023
end program

0 commit comments

Comments
 (0)