From 0c105658c3ddc428f9e66b883721eba01f8a8603 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 5 May 2016 15:11:28 +0200 Subject: [PATCH] simplifying --- code/C_routines.c | 2 +- code/spectral_interface.f90 | 28 ++++++++-------------------- code/system_routines.f90 | 2 +- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/code/C_routines.c b/code/C_routines.c index a212680bb..242d5344c 100644 --- a/code/C_routines.c +++ b/code/C_routines.c @@ -14,7 +14,7 @@ void getcurrentworkdir_c(char cwd[], int *stat ){ if(getcwd(cwd_tmp, sizeof(cwd_tmp)) == cwd_tmp){ *stat = 0; strcpy(cwd, cwd_tmp); - } + } else{ *stat = 1; } diff --git a/code/spectral_interface.f90 b/code/spectral_interface.f90 index f02b3f412..11339ccb3 100644 --- a/code/spectral_interface.f90 +++ b/code/spectral_interface.f90 @@ -185,7 +185,7 @@ subroutine DAMASK_interface_init(loadCaseParameterIn,geometryParameterIn) call quit(1_pInt) endif - workingDirectory = storeWorkingDirectory(trim(workingDirArg),trim(geometryArg)) + workingDirectory = trim(storeWorkingDirectory(trim(workingDirArg),trim(geometryArg))) geometryFile = getGeometryFile(geometryArg) loadCaseFile = getLoadCaseFile(loadCaseArg) @@ -230,16 +230,14 @@ character(len=1024) function storeWorkingDirectory(workingDirectoryArg,geometryA logical :: error external :: quit - - pathSep = getPathSep() wdGiven: if (len(workingDirectoryArg)>0) then - if (workingDirectoryArg(1:1) == pathSep) then ! absolute path given as command line argument + absolutePath: if (workingDirectoryArg(1:1) == pathSep) then storeWorkingDirectory = workingDirectoryArg - else - error = getCWD(cwd) ! relative path given as command line argument + else absolutePath + error = getCWD(cwd) storeWorkingDirectory = trim(cwd)//pathSep//workingDirectoryArg - endif + endif absolutePath if (storeWorkingDirectory(len(trim(storeWorkingDirectory)):len(trim(storeWorkingDirectory)))/= pathSep) & storeWorkingDirectory = trim(storeWorkingDirectory)//pathSep ! if path seperator is not given, append it if(.not. isDirectory(trim(storeWorkingDirectory))) then ! check if the directory exists @@ -255,7 +253,7 @@ character(len=1024) function storeWorkingDirectory(workingDirectoryArg,geometryA geometryArg(1:scan(geometryArg,pathSep,back=.true.)) endif endif wdGiven - storeWorkingDirectory = rectifyPath(storeWorkingDirectory) + storeWorkingDirectory = trim(rectifyPath(storeWorkingDirectory)) end function storeWorkingDirectory @@ -302,14 +300,10 @@ end function getSolverJobName !> @brief basename of geometry file with extension from command line arguments !-------------------------------------------------------------------------------------------------- character(len=1024) function getGeometryFile(geometryParameter) - use system_routines, only: & - getCWD implicit none character(len=1024), intent(in) :: & geometryParameter - character(len=1024) :: & - cwd integer :: posExt, posSep character :: pathSep logical :: error @@ -321,8 +315,7 @@ character(len=1024) function getGeometryFile(geometryParameter) if (posExt <= posSep) getGeometryFile = trim(getGeometryFile)//('.geom') ! no extension present if (scan(getGeometryFile,pathSep) /= 1) then ! relative path given as command line argument - error = getCWD(cwd) - getGeometryFile = rectifyPath(trim(cwd)//pathSep//getGeometryFile) + getGeometryFile = rectifyPath(trim(workingDirectory)//pathSep//getGeometryFile) else getGeometryFile = rectifyPath(getGeometryFile) endif @@ -336,14 +329,10 @@ end function getGeometryFile !> @brief relative path of loadcase from command line arguments !-------------------------------------------------------------------------------------------------- character(len=1024) function getLoadCaseFile(loadCaseParameter) - use system_routines, only: & - getCWD implicit none character(len=1024), intent(in) :: & loadCaseParameter - character(len=1024) :: & - cwd integer :: posExt, posSep logical :: error character :: pathSep @@ -355,8 +344,7 @@ character(len=1024) function getLoadCaseFile(loadCaseParameter) if (posExt <= posSep) getLoadCaseFile = trim(getLoadCaseFile)//('.load') ! no extension present if (scan(getLoadCaseFile,pathSep) /= 1) then ! relative path given as command line argument - error = getCWD(cwd) - getLoadCaseFile = rectifyPath(trim(cwd)//pathSep//getLoadCaseFile) + getLoadCaseFile = rectifyPath(trim(workingDirectory)//pathSep//getLoadCaseFile) else getLoadCaseFile = rectifyPath(getLoadCaseFile) endif diff --git a/code/system_routines.f90 b/code/system_routines.f90 index ebcd8e50b..98c7be098 100644 --- a/code/system_routines.f90 +++ b/code/system_routines.f90 @@ -64,7 +64,7 @@ logical function getCWD(str) character(len=1024) :: strFixedLength integer(C_INT) :: stat - str = repeat(C_NULL_CHAR,1024) + str = repeat(C_NULL_CHAR,len(str)) call getCurrentWorkDir_C(strFixedLength,stat) str = strFixedLength(1:scan(strFixedLength,C_NULL_CHAR,.True.)-1) getCWD=merge(.True.,.False.,stat /= 0_C_INT)