Statistiques
| Révision :

root / src / valid.f90 @ 12

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

1 12 pfleura2
      function valid(string) result (isValid)
2 12 pfleura2
3 1 pfleura2
! This function returns true or false depending on the string you give as a parameter
4 1 pfleura2
! Its purpose is to centralize the debugging flags into only one external file
5 1 pfleura2
! so that debugging can be turned on or off easily at runtime.
6 1 pfleura2
! (basically as it was done in ADF...
7 1 pfleura2
! except that my version is much more basic (much much much more !) )
8 1 pfleura2
9 12 pfleura2
!----------------------------------------------------------------------
10 12 pfleura2
!  Copyright 2003-2014 Ecole Normale Supérieure de Lyon,
11 12 pfleura2
!  Centre National de la Recherche Scientifique,
12 12 pfleura2
!  Université Claude Bernard Lyon 1. All rights reserved.
13 12 pfleura2
!
14 12 pfleura2
!  This work is registered with the Agency for the Protection of Programs
15 12 pfleura2
!  as IDDN.FR.001.100009.000.S.P.2014.000.30625
16 12 pfleura2
!
17 12 pfleura2
!  Authors: P. Fleurat-Lessard, P. Dayal
18 12 pfleura2
!  Contact: optnpath@gmail.com
19 12 pfleura2
!
20 12 pfleura2
! This file is part of "Opt'n Path".
21 12 pfleura2
!
22 12 pfleura2
!  "Opt'n Path" is free software: you can redistribute it and/or modify
23 12 pfleura2
!  it under the terms of the GNU Affero General Public License as
24 12 pfleura2
!  published by the Free Software Foundation, either version 3 of the License,
25 12 pfleura2
!  or (at your option) any later version.
26 12 pfleura2
!
27 12 pfleura2
!  "Opt'n Path" is distributed in the hope that it will be useful,
28 12 pfleura2
!  but WITHOUT ANY WARRANTY; without even the implied warranty of
29 12 pfleura2
!
30 12 pfleura2
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 12 pfleura2
!  GNU Affero General Public License for more details.
32 12 pfleura2
!
33 12 pfleura2
!  You should have received a copy of the GNU Affero General Public License
34 12 pfleura2
!  along with "Opt'n Path". If not, see <http://www.gnu.org/licenses/>.
35 12 pfleura2
!
36 12 pfleura2
! Contact The Office of Technology Licensing, valorisation@ens-lyon.fr,
37 12 pfleura2
! for commercial licensing opportunities.
38 12 pfleura2
!----------------------------------------------------------------------
39 1 pfleura2
40 1 pfleura2
      use Io_module
41 1 pfleura2
42 1 pfleura2
      IMPLICIT NONE
43 1 pfleura2
44 1 pfleura2
      interface
45 1 pfleura2
         subroutine upcase(string)
46 1 pfleura2
           character(*), intent(inout) :: string
47 1 pfleura2
         end subroutine upcase
48 1 pfleura2
      end interface
49 1 pfleura2
50 1 pfleura2
      CHARACTER(*), intent(in) :: string
51 1 pfleura2
      logical                  :: isValid
52 1 pfleura2
      INTEGER(4), PARAMETER :: NMax=500
53 1 pfleura2
54 1 pfleura2
      CHARACTER(64),save :: List(NMax)
55 1 pfleura2
      LOGICAL,save       :: Value(NMax)
56 1 pfleura2
      LOGICAL,save       :: TInit=.False.
57 1 pfleura2
      CHARACTER(132) :: LINE, ValTMP, LString
58 1 pfleura2
      LOGICAL       :: ValueTMP, Found
59 1 pfleura2
      LOGICAL,SAVE       :: Tall=.False., FValidFile, ValAll
60 2 pfleura2
      INTEGER(4) :: ios, i, j
61 1 pfleura2
      INTEGER(4), SAVE ::  NEntries
62 5 pfleura2
      LOGICAL, SAVE :: Debug=.FALSE.
63 1 pfleura2
64 1 pfleura2
      IF (.not.TInit) THEN
65 1 pfleura2
         NEntries=0
66 1 pfleura2
         TInit=.TRUE.
67 1 pfleura2
         INQUIRE(FILE=DebugFile,EXIST=FValidFile)
68 1 pfleura2
         if (FValidFile) THEN
69 1 pfleura2
            OPEN(IOTMP,File=DebugFile,IOSTAT=ios)
70 1 pfleura2
71 1 pfleura2
! The file exists so we will read it !
72 1 pfleura2
            DO While (ios==0)
73 1 pfleura2
               READ(IOTMP,'(A)',ERR=999,END=999) LINE
74 2 pfleura2
               if (Debug) WRITE(*,*) 'LINE READ',trim(Line)
75 1 pfleura2
               if (ios==0) THEN
76 1 pfleura2
                  Line=AdjustL(Line)
77 2 pfleura2
                  if (debug) WRITE(*,*) 'LINE ADJ',trim(Line)
78 1 pfleura2
                  call Upcase(Line)
79 2 pfleura2
                  if (debug) WRITE(*,*) 'LINE UP',trim(Line)
80 1 pfleura2
                  if (Line(1:1)/='#') THEN
81 1 pfleura2
! This is not a comment, we go on
82 1 pfleura2
                     i=index(Line,' ')
83 1 pfleura2
! We take the first word, it will be our value
84 1 pfleura2
                     ValTMP=Line(1:i-1)
85 1 pfleura2
                     j=len_trim(line)
86 1 pfleura2
                     Line=adjustL((Line(i+1:j)))
87 2 pfleura2
                     if (debug) WRITE(*,*) 'VALID INIT ',NEntries,trim(ValTMP), &
88 2 pfleura2
        ' - ',trim(Line)
89 1 pfleura2
                     if (ValTMP(1:1)=='.') ValTmp=ValTMP(2:)
90 1 pfleura2
                     if (ValTMP(1:1)=='F') ValueTMP=.False.
91 1 pfleura2
                     if (ValTMP(1:1)=='T') ValueTMP=.True.
92 1 pfleura2
                     if (Line(1:1)=='*') THEN
93 1 pfleura2
                        ValAll=ValueTMP
94 1 pfleura2
                        TAll=.True.
95 1 pfleura2
                     ELSE
96 1 pfleura2
                        if (Tall) ValueTMP=ValAll
97 1 pfleura2
                        NEntries=NEntries+1
98 1 pfleura2
                        Value(NEntries)=ValueTMP
99 1 pfleura2
                        Line=AdjustL(Line)
100 1 pfleura2
                        List(NEntries)=Line(1:64)
101 1 pfleura2
                     END IF
102 1 pfleura2
                  END IF
103 1 pfleura2
               END IF
104 1 pfleura2
            END DO
105 1 pfleura2
 999     CONTINUE
106 1 pfleura2
         CLOSE(IOTMP)
107 2 pfleura2
         if (debug) THEN
108 2 pfleura2
            WRITE(*,*) "DBG Valid, " // Trim(DebugFile) // "read, with " &
109 2 pfleura2
                 ,NEntries
110 2 pfleura2
            DO I=1,NEntries
111 2 pfleura2
               WRITE(*,*) List(I),Value(I)
112 2 pfleura2
            END DO
113 2 pfleura2
         END IF
114 1 pfleura2
       END IF
115 1 pfleura2
      END IF
116 1 pfleura2
117 1 pfleura2
      IF (.NOT.FValidFile) THEN
118 1 pfleura2
         isValid=.FALSE.
119 1 pfleura2
         Return
120 1 pfleura2
      END IF
121 1 pfleura2
122 1 pfleura2
! The INIT file has been read !
123 1 pfleura2
      LString=trim(adjustL(String))
124 1 pfleura2
      Call UPcase(LString)
125 1 pfleura2
      Found=.false.
126 1 pfleura2
      Do I=1,NEntries
127 1 pfleura2
         if (trim(List(I)).eq.trim(LString)) THEN
128 1 pfleura2
            Found=.TRUE.
129 1 pfleura2
            isValid=Value(I)
130 1 pfleura2
!            WRITE(*,*) 'zoeurezoiru'
131 1 pfleura2
         END IF
132 1 pfleura2
!         WRITE(*,*) I,' : ',trim(list(I)),' - ',trim(LSTRING),' *'
133 1 pfleura2
      END DO
134 1 pfleura2
135 1 pfleura2
!      WRITE(*,*) 'Found:',Found,'isval',isvalid
136 1 pfleura2
!      WRITE(*,*) 'Debug is ',isvalid," for ",Trim(LString)
137 1 pfleura2
138 1 pfleura2
      if (.NOT.Found) THEN
139 1 pfleura2
         IF (Tall) THEN
140 8 pfleura2
            if (debug) THEN
141 8 pfleura2
               WRITE(*,*) 'The option ',String,' is not recognized.'
142 8 pfleura2
               WRITE(*,*) 'Assigning value ',ValAll
143 8 pfleura2
            END IF
144 1 pfleura2
            isValid=ValAll
145 1 pfleura2
         ELSE
146 1 pfleura2
            isValid=.FALSE.
147 1 pfleura2
         END IF
148 1 pfleura2
         NEntries=Nentries+1
149 2 pfleura2
         If (NEntries>NMax) THEN
150 2 pfleura2
            WRITE(*,*) 'Error: NEntries > NMax in Valid ! recompile'
151 2 pfleura2
            STOP
152 2 pfleura2
         END IF
153 1 pfleura2
         List(Nentries)=Trim(LString)
154 1 pfleura2
         Value(Nentries)=Valall
155 1 pfleura2
      END IF
156 1 pfleura2
157 1 pfleura2
      END function valid