args.F90 2.27 KB
Newer Older
1 2 3 4 5 6 7
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
MODULE m_juDFT_args
!This subroutine allows to query for command line arguments
8 9 10
  PRIVATE
  CHARACTER(len=5):: ENV_NAME="juDFT" !name of environment variable
  PUBLIC judft_was_argument,juDFT_string_for_argument
11 12
CONTAINS
  FUNCTION juDFT_was_argument(arg) RESULT(OK)
13
    USE m_check_arguments
14 15 16 17 18 19
    IMPLICIT NONE
    CHARACTER(len=*),INTENT(IN)::arg
    LOGICAL ok

    INTEGER:: i
    CHARACTER(LEN=30)::str
20 21 22 23 24 25 26

    !check if argument is allowed
    IF (argument_type(arg)<0) THEN
       PRINT *,"Argument query invalid:",arg
       PRINT *,"Add specification for fleur_arguments"
       STOP "BUG in FLEUR, invalid argument query"
    END IF
27 28 29 30 31 32 33 34
    ok=.FALSE.
    DO i=1,COMMAND_ARGUMENT_COUNT()
       CALL GET_COMMAND_ARGUMENT(i,str)
       IF(ADJUSTL(str)==ADJUSTL(arg)) ok=.TRUE.
    ENDDO
    IF (ok) RETURN
    !Test for environment variable as well
    CALL GET_ENVIRONMENT_VARIABLE("juDFT",str,status=i)
35
    IF (i==0) ok=INDEX(str//' ',TRIM(ADJUSTL(arg))//' ')>0
36 37

  END FUNCTION juDFT_was_argument
38

39
  FUNCTION juDFT_string_for_argument(arg) RESULT(argstring)
40 41
    IMPLICIT NONE
    CHARACTER(len=*),INTENT(IN)::arg
42
    CHARACTER(len=1000)::argstring
43 44

    INTEGER:: i
45 46
    CHARACTER(LEN=30)  ::str
    CHARACTER(LEN=1000)::env
47
    argstring=""
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    IF (judft_was_argument(arg)) THEN
       DO i=1,COMMAND_ARGUMENT_COUNT()
          CALL GET_COMMAND_ARGUMENT(i,str)
          IF(ADJUSTL(str)==ADJUSTL(arg)) THEN
             IF (i<=COMMAND_ARGUMENT_COUNT()) CALL GET_COMMAND_ARGUMENT(i+1,argstring)
             RETURN !Argument found
          ENDIF
       ENDDO
       !Not found so must be in environment variable
       CALL GET_ENVIRONMENT_VARIABLE("juDFT",env,status=i)
       !cut of argument string
       env=ADJUSTL(env(INDEX(env//' ',TRIM(ADJUSTL(arg)))+1:))//' '
       i=INDEX(env,' ') !find first blank
       argstring=TRIM(env(:i))
    END IF
    
64
  END FUNCTION juDFT_string_for_argument
65
END MODULE m_juDFT_args