Index: palm/trunk/UTIL/interpret_config.f90
===================================================================
--- palm/trunk/UTIL/interpret_config.f90	(revision 69)
+++ palm/trunk/UTIL/interpret_config.f90	(revision 72)
@@ -1,42 +1,52 @@
  PROGRAM interpret_config
 
-!-------------------------------------------------------------------------------!
+!------------------------------------------------------------------------------!
+! Actual revisions:
+! -----------------
+! mrun environment variables are read from NAMELIST instead of using GETENV.
+! Variables are allways assigned a value, also if they already got one. These
+! values are re-assigned later in mrun.
+!
+! Former revisions:
+! -----------------
+! $Id$
+!
+! 28/02/07 - Siggi - empty lines in configuration file are accepted
+! 01/11/05 - Siggi - s2b-Feld erlaubt den Wert locopt
+! 29/06/05 - Siggi - Fehlermeldung ins englische uebertragen und ergaenzt
+! 29/04/05 - Siggi - extin wird auch fuer Input-Dateien ausgegeben
+! 18/11/97 - Siggi - Komma in 2010-FORMAT hinzugefuegt
 ! 21/07/97 - Siggi - Erste Fassung
-! 18/11/97 - Siggi - Komma in 2010-FORMAT hinzugefuegt
-! 29/04/05 - Siggi - extin wird auch fuer Input-Dateien ausgegeben
-! 29/06/05 - Siggi - Fehlermeldung ins englische uebertragen und ergaenzt
-! 01/11/05 - Siggi - s2b-Feld erlaubt den Wert locopt
-! 28/02/07 - Siggi - empty lines in configuration file are accepted
-!
-! Letzte Aenderungen:
-! -------------------
-!
-! Beschreibung:
+!
+! Description:
 ! -------------
-! Interpretation der MRUN-Konfigurationsdatei. Ausgegeben werden ksh-Kommandos,
-! die anschliessend von MRUN ausgefuehrt werden muessen.
-!-------------------------------------------------------------------------------!
+! This program reads the mrun-configuration file .mrun.config and outputs
+! its content in form of ksh-commands, which can then be executed by mrun.
+! mrun is also able to directly read from the configuration file by using
+! the option "-S" (but with much slower speed).
+!------------------------------------------------------------------------------!
 
     IMPLICIT NONE
 
-    CHARACTER (LEN=1)   ::  bs = ACHAR( 92 )   ! backslash (auf vpp sonst n. druckbar)
+    CHARACTER (LEN=1)   ::  bs = ACHAR( 92 )   ! backslash (auf vpp sonst n.
+                                               ! druckbar)
     CHARACTER (LEN=20)  ::  do_remote, do_trace, host, localhost
     CHARACTER (LEN=100) ::  config_file, icf
-    CHARACTER (LEN=300) ::  cond1, cond2, empty = REPEAT( ' ', 240 ), &
-                            for_cond1, for_cond2, for_host, input_list, &
+    CHARACTER (LEN=300) ::  cond1, cond2, empty = REPEAT( ' ', 240 ),       &
+                            for_cond1, for_cond2, for_host, input_list,     &
                             iolist, output_list, s1, s2, s2a, s2b, s2c, s3, &
-                            s3cond, s4, s5, s6, value, value_mrun,&
-                            var, zeile
-
-    INTEGER ::  dummy, i, icomment = 0, icond1, icond2, idatver = 0, iec = 0, &
-                ienvvar = 0, ifor_cond1, ifor_cond2, ifor_host, ihost, &
+                            s3cond, s4, s5, s6, value, value_mrun, var, zeile
+
+    INTEGER ::  dummy, i, icomment = 0, icond1, icond2, idatver = 0, iec = 0,  &
+                ienvvar = 0, ifor_cond1, ifor_cond2, ifor_host, ihost,         &
                 iic = 0, iicf, iin = 0, iinput_list, il, ilocalhost,  ioc = 0, &
-                ios, iout = 0, ioutput_list, is1, is2, is2a, is2b, is2c, &
-                is3, is3cond, is4, is5, is6, ivalue, ivalue_mrun, ivar, izeile
+                ios, iout = 0, ioutput_list, is1, is2, is2a, is2b, is2c,       &
+                is3, is3cond, is4, is5, is6, ivalue, ivar, izeile
 
     LOGICAL ::  found
 
-    NAMELIST /mrun_environment/  cond1, cond2, config_file, do_remote, do_trace, &
-                                 host, input_list, icf, localhost, output_list
+    NAMELIST /mrun_environment/  cond1, cond2, config_file, do_remote,       &
+                                 do_trace, host, input_list, icf, localhost, &
+                                 output_list
 
 
@@ -53,14 +63,4 @@
     ioutput_list = LEN_TRIM( output_list )
 
-!    CALL local_getenv( 'cond1', 5, cond1, icond1 )
-!    CALL local_getenv( 'cond2', 5, cond2, icond2 )
-!    CALL local_getenv( 'config_file', 11, config_file, il )
-!    CALL local_getenv( 'do_remote', 9, do_remote, dummy )
-!    CALL local_getenv( 'do_trace', 8, do_trace, dummy )
-!    CALL local_getenv( 'host', 4, host, ihost )
-!    CALL local_getenv( 'input_list', 10, input_list, iinput_list )
-!    CALL local_getenv( 'interpreted_config_file', 23, icf, iicf )
-!    CALL local_getenv( 'localhost', 9, localhost, ilocalhost )
-!    CALL local_getenv( 'output_list', 11, output_list, ioutput_list )
     iolist = input_list(1:iinput_list) // output_list(1:ioutput_list)
 
@@ -89,8 +89,13 @@
 
        IF ( LEN_TRIM( zeile ) == 0 )  THEN
+
           CONTINUE
+
        ELSEIF ( zeile(1:1) == '#' )  THEN
+
           icomment = icomment + 1
+
        ELSEIF ( zeile(1:1) == '%' )  THEN
+
           ienvvar = ienvvar + 1
           i = INDEX( zeile, ' ' )
@@ -98,30 +103,25 @@
           ivar = i - 2
 
-!
-!--       Achtung: Auf hpmuk und vpp sind nur die Variablen bekannt, die
-!--       von MRUN exportiert wurden!
-!          CALL local_getenv( var, ivar, value_mrun, ivalue_mrun )
-          value_mrun = ''
-          ivalue_mrun = 1
-
-!
-!--       Variable bekommt nur dann neuen Wert, wenn ihr per Shellscript-
-!--       Option noch keiner zugewiesen wurde
-          IF ( value_mrun(1:ivalue_mrun) == ''  .OR. &
-               value_mrun(1:ivalue_mrun) == '0' )  THEN
+          zeile(1:i) = empty(1:i)
+          zeile = ADJUSTL( zeile )
+          i = INDEX( zeile, ' ' )
+          value = zeile(1:i-1)
+          ivalue = i - 1
+
+          zeile(1:i) = empty(1:i)
+          zeile = ADJUSTL( zeile )
+          i = INDEX( zeile, ' ' )
+
+          IF ( i /= 1 )  THEN
+             for_host = zeile(1:i-1)
+             ifor_host = i - 1
 
              zeile(1:i) = empty(1:i)
              zeile = ADJUSTL( zeile )
              i = INDEX( zeile, ' ' )
-             value = zeile(1:i-1)
-             ivalue = i - 1
-
-             zeile(1:i) = empty(1:i)
-             zeile = ADJUSTL( zeile )
-             i = INDEX( zeile, ' ' )
 
              IF ( i /= 1 )  THEN
-                for_host = zeile(1:i-1)
-                ifor_host = i - 1
+                for_cond1 = zeile(1:i-1)
+                ifor_cond1 = i - 1
 
                 zeile(1:i) = empty(1:i)
@@ -130,27 +130,11 @@
 
                 IF ( i /= 1 )  THEN
-                   for_cond1 = zeile(1:i-1)
-                   ifor_cond1 = i - 1
-
-                   zeile(1:i) = empty(1:i)
-                   zeile = ADJUSTL( zeile )
-                   i = INDEX( zeile, ' ' )
-
-                   IF ( i /= 1 )  THEN
-                      for_cond2 = zeile(1:i-1)
-                      ifor_cond2 = i - 1
-                   ELSE
-                      for_cond2 = ''
-                      ifor_cond2 = 0
-                   ENDIF
+                   for_cond2 = zeile(1:i-1)
+                   ifor_cond2 = i - 1
                 ELSE
-                   for_cond1 = ''
-                   ifor_cond1 = 0
                    for_cond2 = ''
                    ifor_cond2 = 0
                 ENDIF
              ELSE
-                for_host = ' '
-                ifor_host = 1
                 for_cond1 = ''
                 ifor_cond1 = 0
@@ -158,80 +142,86 @@
                 ifor_cond2 = 0
              ENDIF
+          ELSE
+             for_host = ' '
+             ifor_host = 1
+             for_cond1 = ''
+             ifor_cond1 = 0
+             for_cond2 = ''
+             ifor_cond2 = 0
+          ENDIF
+          IF ( do_trace(1:4) == 'true' )  THEN
+             PRINT*,'var="',var(1:ivar),'"'
+             PRINT*,'value="',value(1:ivalue),'"'
+             PRINT*,'for_host="',for_host(1:ifor_host),'"'
+             PRINT*,'for_cond1="',for_cond1(1:ifor_cond1),'"'
+             PRINT*,'for_cond2="',for_cond2(1:ifor_cond2),'"'
+          ENDIF
+!
+!--       Geltungsbereich pruefen und evtl. Variable ausgeben
+          IF ( for_host == ' '  .OR.  ( &
+               for_host(1:ifor_host) == host(1:ihost)  .AND. &
+               for_cond1(1:ifor_cond1) == cond1(1:icond1)  .AND. &
+               for_cond2(1:ifor_cond2) == cond2(1:icond2) &
+                                      )  .OR. ( &
+               INDEX( iolist, for_host(1:ifor_host) ) /= 0 &
+                                              ) )  THEN
+
+!
+!--          Zuerst Doppelpunkte durch Blanks ersetzen (aber doppelt
+!--          auftretende Doppelpunkte durch einen Doppelpunkt)
+             i = 0
+             DO
+                i = i + 1
+                IF ( i > ivalue )  EXIT
+                IF ( value(i:i) == ':' )  THEN
+                   IF ( value(i+1:i+1) == ':' )  THEN
+                      value = value(1:i) // value(i+2:ivalue)
+                      ivalue = ivalue - 1
+                   ELSE
+                      value(i:i) = ' '
+                   ENDIF
+                ENDIF
+             ENDDO
+
+!
+!--          Variable ausgeben
+             WRITE (2,2200)  var(1:ivar), bs, value(1:ivalue), bs, &
+                             var(1:ivar)
+ 2200        FORMAT ('eval ',A,'=',A,'"',A,A,'"'/'export ',A)
+
              IF ( do_trace(1:4) == 'true' )  THEN
-                PRINT*,'var="',var(1:ivar),'"'
-                PRINT*,'value="',value(1:ivalue),'"'
-                PRINT*,'for_host="',for_host(1:ifor_host),'"'
-                PRINT*,'for_cond1="',for_cond1(1:ifor_cond1),'"'
-                PRINT*,'for_cond2="',for_cond2(1:ifor_cond2),'"'
-             ENDIF
-!
-!--          Geltungsbereich pruefen und evtl. Variable ausgeben
-             IF ( for_host == ' '  .OR.  ( &
-                  for_host(1:ifor_host) == host(1:ihost)  .AND. &
-                  for_cond1(1:ifor_cond1) == cond1(1:icond1)  .AND. &
-                  for_cond2(1:ifor_cond2) == cond2(1:icond2) &
-                                         )  .OR. ( &
-                  INDEX( iolist, for_host(1:ifor_host) ) /= 0 &
-                                                 ) )  THEN
-
-!
-!--             Zuerst Doppelpunkte durch Blanks ersetzen (aber doppelt
-!--             auftretende Doppelpunkte durch einen Doppelpunkt)
-                i = 0
-                DO
-                   i = i + 1
-                   IF ( i > ivalue )  EXIT
-                   IF ( value(i:i) == ':' )  THEN
-                      IF ( value(i+1:i+1) == ':' )  THEN
-                         value = value(1:i) // value(i+2:ivalue)
-                         ivalue = ivalue - 1
-                      ELSE
-                         value(i:i) = ' '
-                      ENDIF
-                   ENDIF
-                ENDDO
-
-!
-!--             Variable ausgeben
-                WRITE (2,2200)  var(1:ivar), bs, value(1:ivalue), bs, &
-                                var(1:ivar)
- 2200           FORMAT ('eval ',A,'=',A,'"',A,A,'"'/'export ',A)
-
-                IF ( do_trace(1:4) == 'true' )  THEN
-                   WRITE (2,2201)  bs, var(1:ivar), value(1:ivalue)
- 2201              FORMAT ('printf "',A,'n*** ENVIRONMENT-VARIABLE ',A,' = ',A)
-                ENDIF
-
-             ENDIF
-
-!
-!--          Variable "host" muss gleich ausgewertet werden, da mit ihr ein
-!--          neuer Geltungsbereich festgelegt wird
-             IF ( var(1:ivar) == 'host' )  THEN
-
-                host  = value(1:ivalue)
-                ihost = ivalue
-
-!                IF ( host(1:ihost) /= localhost(1:ilocalhost) )  THEN
-!
-!                   SELECT CASE ( value(1:ivalue) )
-!
-!                      CASE ( 'cray','hpcs','t3d','t3eb','t3eh','unics','vpp' )
-!
-!                         dummy = 1
-!
-!                      CASE DEFAULT
-!
-!                         WRITE (2,2202)  bs, bs, value(1:ivalue), bs, bs
-! 2202                    FORMAT ('printf "',A,'n +++ Auf Zielrechner ',A,'"',A,A,'" ist kein NQS-System vorhanden"'/ &
-!                                 'printf "',A,'n     Programmlauf kann deshalb nicht gestartet werden"'/ &
-!                                 'locat=nqs; exit')
-!                         STOP
-!
-!                   END SELECT
-!
-!                ENDIF
-
-             ENDIF
+                WRITE (2,2201)  bs, var(1:ivar), value(1:ivalue)
+ 2201           FORMAT ('printf "',A,'n*** ENVIRONMENT-VARIABLE ',A,' = ',A)
+             ENDIF
+
+          ENDIF
+
+!
+!--       Variable "host" muss gleich ausgewertet werden, da mit ihr ein
+!--       neuer Geltungsbereich festgelegt wird
+          IF ( var(1:ivar) == 'host' )  THEN
+
+             host  = value(1:ivalue)
+             ihost = ivalue
+
+!             IF ( host(1:ihost) /= localhost(1:ilocalhost) )  THEN
+!
+!                SELECT CASE ( value(1:ivalue) )
+!
+!                   CASE ( 'cray','hpcs','t3d','t3eb','t3eh','unics','vpp' )
+!
+!                      dummy = 1
+!
+!                   CASE DEFAULT
+!
+!                      WRITE (2,2202)  bs, bs, value(1:ivalue), bs, bs
+! 2202                 FORMAT ('printf "',A,'n +++ Auf Zielrechner ',A,'"',A,A,'" ist kein NQS-System vorhanden"'/ &
+!                              'printf "',A,'n     Programmlauf kann deshalb nicht gestartet werden"'/ &
+!                              'locat=nqs; exit')
+!                      STOP
+!
+!                END SELECT
+!
+!             ENDIF
 
           ENDIF
