diff --git a/src/gray_params.f90 b/src/gray_params.f90 index 140b85f..f1b78f0 100644 --- a/src/gray_params.f90 +++ b/src/gray_params.f90 @@ -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 diff --git a/src/utils.f90 b/src/utils.f90 index 7a93f93..a2cc142 100644 --- a/src/utils.f90 +++ b/src/utils.f90 @@ -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