args.F90 2.37 KB
Newer Older
1
!--------------------------------------------------------------------------------
2
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
3 4 5 6 7
! 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
    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
59
       env=ADJUSTL(env(INDEX(env//' ',TRIM(ADJUSTL(arg)))+LEN(TRIM(ADJUSTL(arg))):))//' '
60
       i=INDEX(env,' ') !find first blank
61 62 63 64 65
       IF (i<1) THEN 
          argstring=trim(env)
       ELSE
          argstring=TRIM(env(:i))
       ENDIF
66 67
    END IF
    
68
  END FUNCTION juDFT_string_for_argument
69
END MODULE m_juDFT_args