now getting path separator by counting slashes and backslashes in $PATH environment variable
This commit is contained in:
parent
79663a7f76
commit
9dc730dea4
|
@ -21,7 +21,6 @@
|
|||
!********************************************************************
|
||||
|
||||
MODULE DAMASK_interface
|
||||
use prec, only: pInt, pReal
|
||||
implicit none
|
||||
|
||||
character(len=64), parameter :: FEsolver = 'Spectral'
|
||||
|
@ -36,6 +35,7 @@ CONTAINS
|
|||
!********************************************************************
|
||||
subroutine DAMASK_interface_init()
|
||||
use, intrinsic :: iso_fortran_env ! to get compiler_version and compiler_options (at least for gfortran 4.6 at the moment)
|
||||
use prec, only: pInt
|
||||
implicit none
|
||||
|
||||
character(len=1024) commandLine, hostName, userName
|
||||
|
@ -44,7 +44,8 @@ subroutine DAMASK_interface_init()
|
|||
call get_command(commandLine)
|
||||
call DATE_AND_TIME(VALUES=date_and_time_values)
|
||||
do i=1,len(commandLine) ! remove capitals
|
||||
if(64<iachar(commandLine(i:i)) .and. iachar(commandLine(i:i))<91) commandLine(i:i) =achar(iachar(commandLine(i:i))+32)
|
||||
if(64<iachar(commandLine(i:i)) .and. iachar(commandLine(i:i))<91) commandLine(i:i) = &
|
||||
achar(iachar(commandLine(i:i))+32)
|
||||
enddo
|
||||
|
||||
if(index(commandLine,' -h ',.true.)>0 .or. index(commandLine,' --help ',.true.)>0) then ! search for ' -h ' or '--help'
|
||||
|
@ -83,7 +84,7 @@ subroutine DAMASK_interface_init()
|
|||
print '(a)', ' --help'
|
||||
print '(a)', ' Prints this message and exits'
|
||||
print '(a)', ' '
|
||||
stop
|
||||
call quit(0_pInt)
|
||||
endif
|
||||
if (.not.(command_argument_count()==4 .or. command_argument_count()==6)) & ! check for correct number of given arguments (no --help)
|
||||
stop 'Wrong Nr. of Arguments. Run DAMASK_spectral.exe --help' ! Could not find valid keyword (position 0 +3). Functions from IO.f90 are not available
|
||||
|
@ -94,7 +95,10 @@ subroutine DAMASK_interface_init()
|
|||
if (index(commandLine,'--geometry',.true.)>0) then ! again, now searching for --geometry'
|
||||
start = index(commandLine,'--geometry',.true.) + 11
|
||||
endif
|
||||
if(start==3_pInt) stop 'No Geometry specified, terminating DAMASK'! Could not find valid keyword (position 0 +3). Functions from IO.f90 are not available
|
||||
if(start==3_pInt) then ! Could not find valid keyword (position 0 +3). Functions from IO.f90 are not available
|
||||
print '(a)', 'No Geometry specified'
|
||||
call quit(9999)
|
||||
endif
|
||||
length = index(commandLine(start:len(commandLine)),' ',.false.)
|
||||
|
||||
call get_command(commandLine) ! may contain capitals
|
||||
|
@ -102,7 +106,8 @@ subroutine DAMASK_interface_init()
|
|||
geometryParameter(1:length)=commandLine(start:start+length)
|
||||
|
||||
do i=1,len(commandLine) ! remove capitals
|
||||
if(64<iachar(commandLine(i:i)) .and. iachar(commandLine(i:i))<91) commandLine(i:i) =achar(iachar(commandLine(i:i))+32)
|
||||
if(64<iachar(commandLine(i:i)) .and. iachar(commandLine(i:i))<91) commandLine(i:i)&
|
||||
= achar(iachar(commandLine(i:i))+32)
|
||||
enddo
|
||||
|
||||
start = index(commandLine,'-l',.true.) + 3 ! search for '-l' and jump forward iby 3 to given name
|
||||
|
@ -112,15 +117,20 @@ subroutine DAMASK_interface_init()
|
|||
if (index(commandLine,'--loadcase',.true.)>0) then ! again, now searching for --loadcase'
|
||||
start = index(commandLine,'--loadcase',.true.) + 11
|
||||
endif
|
||||
if(start==3_pInt) stop 'No Loadcase specified, terminating DAMASK'! Could not find valid keyword (position 0 +3). Functions from IO.f90 are not available
|
||||
if(start==3_pInt) then ! Could not find valid keyword (position 0 +3). Functions from IO.f90 are not available
|
||||
print '(a)', 'No Loadcase specified'
|
||||
call quit(9999)
|
||||
endif
|
||||
length = index(commandLine(start:len(commandLine)),' ',.false.)
|
||||
|
||||
call get_command(commandLine) ! may contain capitals
|
||||
loadcaseParameter = '' ! should be empty
|
||||
loadcaseParameter(1:length)=commandLine(start:start+length)
|
||||
|
||||
print*, loadcaseParameter
|
||||
do i=1,len(commandLine) ! remove capitals
|
||||
if(64<iachar(commandLine(i:i)) .and. iachar(commandLine(i:i))<91) commandLine(i:i) =achar(iachar(commandLine(i:i))+32)
|
||||
if(64<iachar(commandLine(i:i)) .and. iachar(commandLine(i:i))<91) commandLine(i:i)&
|
||||
= achar(iachar(commandLine(i:i))+32)
|
||||
enddo
|
||||
|
||||
start = index(commandLine,'-r',.true.) + 3 ! search for '-r' and jump forward iby 3 to given name
|
||||
|
@ -145,6 +155,7 @@ subroutine DAMASK_interface_init()
|
|||
date_and_time_values(7)
|
||||
write(6,*) 'Host Name: ', trim(hostName)
|
||||
write(6,*) 'User Name: ', trim(userName)
|
||||
write(6,*) 'Path Separator: ', getPathSep()
|
||||
write(6,*) 'Command line call: ', trim(commandLine)
|
||||
write(6,*) 'Geometry Parameter: ', trim(geometryParameter)
|
||||
write(6,*) 'Loadcase Parameter: ', trim(loadcaseParameter)
|
||||
|
@ -158,17 +169,18 @@ endsubroutine DAMASK_interface_init
|
|||
!********************************************************************
|
||||
function getSolverWorkingDirectoryName()
|
||||
|
||||
use prec, only: pInt
|
||||
implicit none
|
||||
|
||||
character(len=1024) cwd,getSolverWorkingDirectoryName
|
||||
character(len=*), parameter :: pathSep = achar(47) //achar(92) !forwardslash, backwardslash
|
||||
character :: pathSep
|
||||
|
||||
if (scan(geometryParameter,pathSep) == 1) then ! absolute path given as command line argument
|
||||
pathSep = getPathSep()
|
||||
|
||||
if (geometryParameter(1:1) == pathSep) then ! absolute path given as command line argument
|
||||
getSolverWorkingDirectoryName = geometryParameter(1:scan(geometryParameter,pathSep,back=.true.))
|
||||
else
|
||||
call getcwd(cwd)
|
||||
getSolverWorkingDirectoryName = trim(cwd)//'/'//geometryParameter(1:scan(geometryParameter,pathSep,back=.true.))
|
||||
getSolverWorkingDirectoryName = trim(cwd)//pathSep//geometryParameter(1:scan(geometryParameter,pathSep,back=.true.))
|
||||
endif
|
||||
|
||||
getSolverWorkingDirectoryName = rectifyPath(getSolverWorkingDirectoryName)
|
||||
|
@ -200,9 +212,10 @@ function getModelName()
|
|||
implicit none
|
||||
|
||||
character(1024) getModelName, cwd
|
||||
character(len=*), parameter :: pathSep = achar(47)//achar(92) ! forwardslash, backwardslash
|
||||
integer :: posExt,posSep
|
||||
character :: pathSep
|
||||
|
||||
pathSep = getPathSep()
|
||||
posExt = scan(geometryParameter,'.',back=.true.)
|
||||
posSep = scan(geometryParameter,pathSep,back=.true.)
|
||||
|
||||
|
@ -230,9 +243,10 @@ function getLoadCase()
|
|||
implicit none
|
||||
|
||||
character(1024) :: getLoadCase
|
||||
character(len=*), parameter :: pathSep = achar(47)//achar(92) ! forwardslash, backwardslash
|
||||
integer :: posExt,posSep
|
||||
character :: pathSep
|
||||
|
||||
pathSep = getPathSep()
|
||||
posExt = scan(loadcaseParameter,'.',back=.true.)
|
||||
posSep = scan(loadcaseParameter,pathSep,back=.true.)
|
||||
|
||||
|
@ -248,13 +262,13 @@ endfunction getLoadCase
|
|||
!********************************************************************
|
||||
function getLoadcaseName()
|
||||
|
||||
use prec, only: pInt
|
||||
|
||||
implicit none
|
||||
|
||||
character(len=1024) :: getLoadcaseName,cwd
|
||||
character(len=*), parameter :: pathSep = achar(47)//achar(92) ! forwardslash, backwardslash
|
||||
integer :: posExt = 0, posSep
|
||||
character :: pathSep
|
||||
|
||||
pathSep = getPathSep()
|
||||
getLoadcaseName = loadcaseParameter
|
||||
posExt = scan(getLoadcaseName,'.',back=.true.)
|
||||
posSep = scan(getLoadcaseName,pathSep,back=.true.)
|
||||
|
@ -262,7 +276,7 @@ function getLoadcaseName()
|
|||
if (posExt <= posSep) getLoadcaseName = trim(getLoadcaseName)//('.load') ! no extension present
|
||||
if (scan(getLoadcaseName,pathSep) /= 1) then ! relative path given as command line argument
|
||||
call getcwd(cwd)
|
||||
getLoadcaseName = rectifyPath(trim(cwd)//'/'//getLoadcaseName)
|
||||
getLoadcaseName = rectifyPath(trim(cwd)//pathSep//getLoadcaseName)
|
||||
else
|
||||
getLoadcaseName = rectifyPath(getLoadcaseName)
|
||||
endif
|
||||
|
@ -278,67 +292,96 @@ endfunction getLoadcaseName
|
|||
!********************************************************************
|
||||
function rectifyPath(path)
|
||||
|
||||
use prec, only: pInt
|
||||
|
||||
implicit none
|
||||
|
||||
character(len=*) :: path
|
||||
character(len=len_trim(path)) :: rectifyPath
|
||||
character :: pathSep
|
||||
integer :: i,j,k,l !no pInt
|
||||
|
||||
pathSep = getPathSep()
|
||||
|
||||
!remove ./ from path
|
||||
l = len_trim(path)
|
||||
rectifyPath = path
|
||||
do i = l,3,-1
|
||||
if ( rectifyPath(i-1:i) == './' .and. rectifyPath(i-2:i-2) /= '.' ) &
|
||||
if ( rectifyPath(i-1:i) == '.'//pathSep .and. rectifyPath(i-2:i-2) /= '.' ) &
|
||||
rectifyPath(i-1:l) = rectifyPath(i+1:l)//' '
|
||||
enddo
|
||||
|
||||
!remove ../ and corresponding directory from rectifyPath
|
||||
l = len_trim(rectifyPath)
|
||||
i = index(rectifyPath(i:l),'../')
|
||||
i = index(rectifyPath(i:l),'..'//pathSep)
|
||||
j = 0
|
||||
do while (i > j)
|
||||
j = scan(rectifyPath(1:i-2),'/',back=.true.)
|
||||
j = scan(rectifyPath(1:i-2),pathSep,back=.true.)
|
||||
rectifyPath(j+1:l) = rectifyPath(i+3:l)//repeat(' ',2+i-j)
|
||||
if (rectifyPath(j+1:j+1) == '/') then !search for '//' that appear in case of XXX/../../XXX
|
||||
if (rectifyPath(j+1:j+1) == pathSep) then !search for '//' that appear in case of XXX/../../XXX
|
||||
k = len_trim(rectifyPath)
|
||||
rectifyPath(j+1:k-1) = rectifyPath(j+2:k)
|
||||
rectifyPath(k:k) = ' '
|
||||
endif
|
||||
i = j+index(rectifyPath(j+1:l),'../')
|
||||
i = j+index(rectifyPath(j+1:l),'..'//pathSep)
|
||||
enddo
|
||||
if(len_trim(rectifyPath) == 0) rectifyPath = '/'
|
||||
if(len_trim(rectifyPath) == 0) rectifyPath = pathSep
|
||||
|
||||
end function rectifyPath
|
||||
|
||||
|
||||
|
||||
!********************************************************************
|
||||
! relative path from absolute a to absolute b
|
||||
!
|
||||
!********************************************************************
|
||||
function makeRelativePath(a,b)
|
||||
|
||||
use prec, only: pInt
|
||||
|
||||
implicit none
|
||||
|
||||
character (len=*) :: a,b
|
||||
character (len=1024) :: makeRelativePath
|
||||
character :: pathSep
|
||||
integer :: i,posLastCommonSlash,remainingSlashes !no pInt
|
||||
|
||||
pathSep = getPathSep()
|
||||
posLastCommonSlash = 0
|
||||
remainingSlashes = 0
|
||||
|
||||
do i = 1, min(1024,len_trim(a),len_trim(b))
|
||||
if (a(i:i) /= b(i:i)) exit
|
||||
if (a(i:i) == '/') posLastCommonSlash = i
|
||||
if (a(i:i) == pathSep) posLastCommonSlash = i
|
||||
enddo
|
||||
do i = posLastCommonSlash+1,len_trim(a)
|
||||
if (a(i:i) == '/') remainingSlashes = remainingSlashes + 1
|
||||
if (a(i:i) == pathSep) remainingSlashes = remainingSlashes + 1
|
||||
enddo
|
||||
makeRelativePath = repeat('../',remainingSlashes)//b(posLastCommonSlash+1:len_trim(b))
|
||||
makeRelativePath = repeat('..'//pathSep,remainingSlashes)//b(posLastCommonSlash+1:len_trim(b))
|
||||
|
||||
endfunction makeRelativePath
|
||||
|
||||
|
||||
!********************************************************************
|
||||
! counting / and \ in $PATH System variable
|
||||
! the character occuring more often is assumed to be the path separator
|
||||
!********************************************************************
|
||||
function getPathSep()
|
||||
|
||||
use prec, only: pInt
|
||||
implicit none
|
||||
character :: getPathSep
|
||||
character(len=2048) path
|
||||
integer(pInt) :: backslash = 0_pInt, slash = 0_pInt
|
||||
integer :: i
|
||||
|
||||
call get_environment_variable('PATH',path)
|
||||
do i=1, len(trim(path))
|
||||
if (path(i:i)=='/') slash = slash + 1_pInt
|
||||
if (path(i:i)=='\') backslash = backslash + 1_pInt
|
||||
enddo
|
||||
|
||||
if (backslash>slash) then
|
||||
getPathSep = '\'
|
||||
else
|
||||
getPathSep = '/'
|
||||
endif
|
||||
|
||||
end function
|
||||
|
||||
END MODULE
|
||||
|
|
Loading…
Reference in New Issue