Statistiques
| Révision :

root / src / valid.f90 @ 3

Historique | Voir | Annoter | Télécharger (4,06 ko)

1 1 pfleura2
! This function returns true or false depending on the string you give as a parameter
2 1 pfleura2
! Its purpose is to centralize the debugging flags into only one external file
3 1 pfleura2
! so that debugging can be turned on or off easily at runtime.
4 1 pfleura2
! (basically as it was done in ADF...
5 1 pfleura2
! except that my version is much more basic (much much much more !) )
6 1 pfleura2
7 1 pfleura2
      function valid(string) result (isValid)
8 1 pfleura2
9 1 pfleura2
      use Io_module
10 1 pfleura2
11 1 pfleura2
      IMPLICIT NONE
12 1 pfleura2
13 1 pfleura2
      interface
14 1 pfleura2
         subroutine upcase(string)
15 1 pfleura2
           character(*), intent(inout) :: string
16 1 pfleura2
         end subroutine upcase
17 1 pfleura2
      end interface
18 1 pfleura2
19 1 pfleura2
      CHARACTER(*), intent(in) :: string
20 1 pfleura2
      logical                  :: isValid
21 1 pfleura2
      INTEGER(4), PARAMETER :: NMax=500
22 1 pfleura2
23 1 pfleura2
      CHARACTER(64),save :: List(NMax)
24 1 pfleura2
      LOGICAL,save       :: Value(NMax)
25 1 pfleura2
      LOGICAL,save       :: TInit=.False.
26 1 pfleura2
      CHARACTER(132) :: LINE, ValTMP, LString
27 1 pfleura2
      LOGICAL       :: ValueTMP, Found
28 1 pfleura2
      LOGICAL,SAVE       :: Tall=.False., FValidFile, ValAll
29 2 pfleura2
      INTEGER(4) :: ios, i, j
30 1 pfleura2
      INTEGER(4), SAVE ::  NEntries
31 2 pfleura2
      LOGICAL, SAVE :: Debug=.TRUE.
32 1 pfleura2
33 1 pfleura2
      IF (.not.TInit) THEN
34 1 pfleura2
         NEntries=0
35 1 pfleura2
         TInit=.TRUE.
36 1 pfleura2
         INQUIRE(FILE=DebugFile,EXIST=FValidFile)
37 1 pfleura2
         if (FValidFile) THEN
38 1 pfleura2
            OPEN(IOTMP,File=DebugFile,IOSTAT=ios)
39 1 pfleura2
40 1 pfleura2
! The file exists so we will read it !
41 1 pfleura2
            DO While (ios==0)
42 1 pfleura2
               READ(IOTMP,'(A)',ERR=999,END=999) LINE
43 2 pfleura2
               if (Debug) WRITE(*,*) 'LINE READ',trim(Line)
44 1 pfleura2
               if (ios==0) THEN
45 1 pfleura2
                  Line=AdjustL(Line)
46 2 pfleura2
                  if (debug) WRITE(*,*) 'LINE ADJ',trim(Line)
47 1 pfleura2
                  call Upcase(Line)
48 2 pfleura2
                  if (debug) WRITE(*,*) 'LINE UP',trim(Line)
49 1 pfleura2
                  if (Line(1:1)/='#') THEN
50 1 pfleura2
! This is not a comment, we go on
51 1 pfleura2
                     i=index(Line,' ')
52 1 pfleura2
! We take the first word, it will be our value
53 1 pfleura2
                     ValTMP=Line(1:i-1)
54 1 pfleura2
                     j=len_trim(line)
55 1 pfleura2
                     Line=adjustL((Line(i+1:j)))
56 2 pfleura2
                     if (debug) WRITE(*,*) 'VALID INIT ',NEntries,trim(ValTMP), &
57 2 pfleura2
        ' - ',trim(Line)
58 1 pfleura2
                     if (ValTMP(1:1)=='.') ValTmp=ValTMP(2:)
59 1 pfleura2
                     if (ValTMP(1:1)=='F') ValueTMP=.False.
60 1 pfleura2
                     if (ValTMP(1:1)=='T') ValueTMP=.True.
61 1 pfleura2
                     if (Line(1:1)=='*') THEN
62 1 pfleura2
                        ValAll=ValueTMP
63 1 pfleura2
                        TAll=.True.
64 1 pfleura2
                     ELSE
65 1 pfleura2
                        if (Tall) ValueTMP=ValAll
66 1 pfleura2
                        NEntries=NEntries+1
67 1 pfleura2
                        Value(NEntries)=ValueTMP
68 1 pfleura2
                        Line=AdjustL(Line)
69 1 pfleura2
                        List(NEntries)=Line(1:64)
70 1 pfleura2
                     END IF
71 1 pfleura2
                  END IF
72 1 pfleura2
               END IF
73 1 pfleura2
            END DO
74 1 pfleura2
 999     CONTINUE
75 1 pfleura2
         CLOSE(IOTMP)
76 2 pfleura2
         if (debug) THEN
77 2 pfleura2
            WRITE(*,*) "DBG Valid, " // Trim(DebugFile) // "read, with " &
78 2 pfleura2
                 ,NEntries
79 2 pfleura2
            DO I=1,NEntries
80 2 pfleura2
               WRITE(*,*) List(I),Value(I)
81 2 pfleura2
            END DO
82 2 pfleura2
         END IF
83 1 pfleura2
       END IF
84 1 pfleura2
      END IF
85 1 pfleura2
86 1 pfleura2
      IF (.NOT.FValidFile) THEN
87 1 pfleura2
         isValid=.FALSE.
88 1 pfleura2
         Return
89 1 pfleura2
      END IF
90 1 pfleura2
91 1 pfleura2
! The INIT file has been read !
92 1 pfleura2
      LString=trim(adjustL(String))
93 1 pfleura2
      Call UPcase(LString)
94 1 pfleura2
      Found=.false.
95 1 pfleura2
      Do I=1,NEntries
96 1 pfleura2
         if (trim(List(I)).eq.trim(LString)) THEN
97 1 pfleura2
            Found=.TRUE.
98 1 pfleura2
            isValid=Value(I)
99 1 pfleura2
!            WRITE(*,*) 'zoeurezoiru'
100 1 pfleura2
         END IF
101 1 pfleura2
!         WRITE(*,*) I,' : ',trim(list(I)),' - ',trim(LSTRING),' *'
102 1 pfleura2
      END DO
103 1 pfleura2
104 1 pfleura2
!      WRITE(*,*) 'Found:',Found,'isval',isvalid
105 1 pfleura2
!      WRITE(*,*) 'Debug is ',isvalid," for ",Trim(LString)
106 1 pfleura2
107 1 pfleura2
      if (.NOT.Found) THEN
108 1 pfleura2
         IF (Tall) THEN
109 1 pfleura2
            WRITE(*,*) 'The option ',String, &
110 1 pfleura2
                 ' is not recognized'
111 1 pfleura2
            WRITE(*,*) 'Assigning value ',ValAll
112 1 pfleura2
            isValid=ValAll
113 1 pfleura2
         ELSE
114 1 pfleura2
            isValid=.FALSE.
115 1 pfleura2
         END IF
116 1 pfleura2
         NEntries=Nentries+1
117 2 pfleura2
         If (NEntries>NMax) THEN
118 2 pfleura2
            WRITE(*,*) 'Error: NEntries > NMax in Valid ! recompile'
119 2 pfleura2
            STOP
120 2 pfleura2
         END IF
121 1 pfleura2
         List(Nentries)=Trim(LString)
122 1 pfleura2
         Value(Nentries)=Valall
123 1 pfleura2
      END IF
124 1 pfleura2
125 1 pfleura2
      END function valid