src/gray_params.f90: improve handling of absolute paths

This commit is contained in:
Lorenzo Figini 2021-12-22 19:10:20 +01:00 committed by Michele Guerini Rocco
parent d3a87e1044
commit efd4fc51e5
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
2 changed files with 20 additions and 7 deletions

View File

@ -344,13 +344,16 @@ contains
close(u)
! Convert all filenames to absolute paths
! Note: `filenm` is assumed to be a path relative to the
! gray_params.data file.
block
use utils, only : dirname
params%antenna%filenm = dirname(filename) // params%antenna%filenm
params%equilibrium%filenm = dirname(filename) // params%equilibrium%filenm
params%profiles%filenm = dirname(filename) // params%profiles%filenm
use utils, only : dirname, isrelative
if (isrelative(params%antenna%filenm)) &
params%antenna%filenm = dirname(filename) // params%antenna%filenm
if (isrelative(params%equilibrium%filenm)) &
params%equilibrium%filenm = dirname(filename) // params%equilibrium%filenm
if (isrelative(params%profiles%filenm)) &
params%profiles%filenm = dirname(filename) // params%profiles%filenm
end block
end subroutine read_parameters

View File

@ -293,10 +293,20 @@ contains
directory = filepath(1:last_sep)
! append the cwd to relative paths
if (filepath(1:1) /= '/') then
if (isrelative(filepath)) then
call getcwd(cwd)
directory = trim(cwd) // '/' // directory
end if
end function dirname
function isrelative(filepath)
! Check if `filepath` is a relative or an absolute path
! function arguments
character(*), intent(in) :: filepath
logical :: isrelative
isrelative = (filepath(1:1) /= '/')
end function isrelative
end module utils