Index: palm/trunk/SOURCE/init_pegrid.f90
===================================================================
--- palm/trunk/SOURCE/init_pegrid.f90	(revision 226)
+++ palm/trunk/SOURCE/init_pegrid.f90	(revision 254)
@@ -2,6 +2,7 @@
 
 !------------------------------------------------------------------------------!
-! Actual revisions:
+! Current revisions:
 ! -----------------
+! Output of messages replaced by message handling routine.
 ! ATTENTION: nnz_x undefined problem still has to be solved!!!!!!!!
 ! TEST OUTPUT (TO BE REMOVED) logging mpi2 ierr values
@@ -121,9 +122,8 @@
 !--    must be equal to the number of PEs available to the job
        IF ( ( npex * npey ) /= numprocs )  THEN
-          PRINT*, '+++ init_pegrid:'
-          PRINT*, '    number of PEs of the prescribed topology (', npex*npey, &
-                      ') does not match the number of PEs available to the ',  &
-                      'job (', numprocs, ')'
-          CALL local_stop
+          WRITE( message_string, * ) 'number of PEs of the prescribed topology (', &
+                                     npex*npey,') does not match & the number of ',  & 
+                                     'PEs available to the job (', numprocs, ')'
+          CALL message( 'init_pegrid', 'PA0221', 1, 2, 0, 6, 0 )
        ENDIF
        pdims(1) = npex
@@ -134,9 +134,8 @@
 !--    If the processor topology is prescribed by the user, the number of
 !--    PEs must be given in both directions
-       PRINT*, '+++ init_pegrid:'
-       PRINT*, '    if the processor topology is prescribed by the user, ',   &
-                    'both values of "npex" and "npey" must be given in the ', &
-                    'NAMELIST-parameter file'
-       CALL local_stop
+       message_string = 'if the processor topology is prescribed by the user, ' // &
+                    '& both values of "npex" and "npey" must be given in the ' //    &
+                    '&NAMELIST-parameter file'
+       CALL message( 'init_pegrid', 'PA0222', 1, 2, 0, 6, 0 )
 
     ENDIF
@@ -145,8 +144,7 @@
 !-- The hybrid solver can only be used in case of a 1d-decomposition along x
     IF ( pdims(2) /= 1  .AND.  psolver == 'poisfft_hybrid' )  THEN
-       IF ( myid == 0 )  THEN
-          PRINT*, '*** init_pegrid: psolver = "poisfft_hybrid" can only be'
-          PRINT*, '                 used in case of a 1d-decomposition along x'
-       ENDIF
+       message_string = 'psolver = "poisfft_hybrid" can only be' // &
+                        '& used in case of a 1d-decomposition along x'
+       CALL message( 'init_pegrid', 'PA0223', 1, 2, 0, 6, 0 )
     ENDIF
 
@@ -224,8 +222,6 @@
 
        IF ( .NOT. found )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ init_pegrid: no matching grid for transpositions found'
-          ENDIF
-          CALL local_stop
+          message_string = 'no matching grid for transpositions found'
+          CALL message( 'init_pegrid', 'PA0224', 1, 2, 0, 6, 0 )
        ENDIF
 
@@ -239,21 +235,17 @@
 
     IF ( MOD( nxa+1 , pdims(1) ) /= 0 )  THEN
-       IF ( myid == 0 )  THEN
-          PRINT*,'+++ x-direction:  gridpoint number (',nx+1,') is not an'
-          PRINT*,'                  integral divisor of the number of proces', &
-                                   &'sors (', pdims(1),')'
-       ENDIF
-       CALL local_stop
+       WRITE( message_string, * ) 'x-direction: gridpoint number (',nx+1,') is not an',&
+                                  '& integral divisor of the number of proces', &
+                                  'sors (', pdims(1),')'
+       CALL message( 'init_pegrid', 'PA0225', 1, 2, 0, 6, 0 )
     ELSE
        nnx  = ( nxa + 1 ) / pdims(1)
        IF ( nnx*pdims(1) - ( nx + 1) > nnx )  THEN
-          IF ( myid == 0 )  THEN
-	     PRINT*,'+++ x-direction: nx does not match the requirements ', &
-	                 'given by the number of PEs'
-             PRINT*,'                 used'
-             PRINT*,'    please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) &
-	                 - ( nx + 1 ) ) ), ' instead of nx =', nx
-          ENDIF
-	  CALL local_stop
+          WRITE( message_string, * ) 'x-direction: nx does not match the', & 
+                                     'requirements given by the number of PEs', &
+                                     '& used',&
+                                     '& please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) &
+	                               - ( nx + 1 ) ) ), ' instead of nx =', nx
+          CALL message( 'init_pegrid', 'PA0226', 1, 2, 0, 6, 0 )
        ENDIF
     ENDIF    
@@ -270,21 +262,17 @@
 !-- Calculate array bounds in y-direction for every PE.
     IF ( MOD( nya+1 , pdims(2) ) /= 0 )  THEN
-       IF ( myid == 0 )  THEN
-          PRINT*,'+++ y-direction:  gridpoint number (',ny+1,') is not an'
-          PRINT*,'                  integral divisor of the number of proces', &
-                                   &'sors (', pdims(2),')'
-       ENDIF
-       CALL local_stop
+       WRITE( message_string, * ) 'y-direction: gridpoint number (',ny+1,') is not an', &
+                                  '& integral divisor of the number of proces', &
+                                  'sors (', pdims(2),')'
+       CALL message( 'init_pegrid', 'PA0227', 1, 2, 0, 6, 0 )
     ELSE
        nny  = ( nya + 1 ) / pdims(2)
        IF ( nny*pdims(2) - ( ny + 1) > nny )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ x-direction: nx does not match the requirements ', &
-                         'given by the number of PEs'
-             PRINT*,'                 used'
-             PRINT*,'    please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) &
-                         - ( nx + 1 ) ) ), ' instead of nx =', nx
-          ENDIF
-          CALL local_stop
+          WRITE( message_string, * ) 'y-direction: ny does not match the',&
+                                     'requirements given by the number of PEs', &
+                                     '& used', &
+                                     '& please use ny = ', ny - ( pdims(2) - ( nnx*pdims(2) &
+                                     - ( ny + 1 ) ) ), ' instead of ny =', ny
+          CALL message( 'init_pegrid', 'PA0228', 1, 2, 0, 6, 0 )
        ENDIF
     ENDIF    
@@ -326,9 +314,8 @@
        IF ( pdims(2) == 1  .AND. ( momentum_advec == 'ups-scheme'  .OR. &
             scalar_advec == 'ups-scheme' ) )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ WARNING: init_pegrid: 1d-decomposition along x ', &
-                                &'chosen but nz restrictions may occur'
-             PRINT*,'             since ups-scheme is activated'
-          ENDIF
+          message_string = '1d-decomposition along x ' // &
+                           'chosen but nz restrictions may occur' // &
+                           '& since ups-scheme is activated'
+          CALL message( 'init_pegrid', 'PA0229', 0, 1, 0, 6, 0 )
        ENDIF
        nys_x  = nys
@@ -337,10 +324,8 @@
        nny_x  = nny
        IF ( MOD( nza , pdims(1) ) /= 0 )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ transposition z --> x:'
-             PRINT*,'    nz=',nz,' is not an integral divisior of pdims(1)=', &
-                    &pdims(1)
-          ENDIF
-          CALL local_stop
+          WRITE( message_string, * ) 'transposition z --> x:', &
+                                     '&nz=',nz,' is not an integral divisior of pdims(1)=', &
+                                     pdims(1)
+          CALL message( 'init_pegrid', 'PA0230', 1, 2, 0, 6, 0 )
        ENDIF
        nnz_x  = nza / pdims(1)
@@ -371,10 +356,8 @@
     nzt_y  = nzt_x
     IF ( MOD( nxa+1 , pdims(2) ) /= 0 )  THEN
-       IF ( myid == 0 )  THEN
-          PRINT*,'+++ transposition x --> y:'
-          PRINT*,'    nx+1=',nx+1,' is not an integral divisor of ',&
-                 &'pdims(2)=',pdims(2)
-       ENDIF
-       CALL local_stop
+       WRITE( message_string, * ) 'transposition x --> y:', &
+                                  '&nx+1=',nx+1,' is not an integral divisor of ',&
+                                  'pdims(2)=',pdims(2)
+       CALL message( 'init_pegrid', 'PA0231', 1, 2, 0, 6, 0 )
     ENDIF
     nnx_y = (nxa+1) / pdims(2)
@@ -399,10 +382,8 @@
        nxr_z  = nxr_y
        IF ( MOD( nya+1 , pdims(1) ) /= 0 )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ Transposition y --> z:'
-             PRINT*,'    ny+1=',ny+1,' is not an integral divisor of ',&
-                    &'pdims(1)=',pdims(1)
-          ENDIF
-          CALL local_stop
+          WRITE( message_string, * ) 'transposition y --> z:', &
+                                     '& ny+1=',ny+1,' is not an integral divisor of ',&
+                                     'pdims(1)=',pdims(1)
+          CALL message( 'init_pegrid', 'PA0232', 1, 2, 0, 6, 0 )
        ENDIF
        nny_z  = (nya+1) / pdims(1)
@@ -417,10 +398,8 @@
 !--    x --> y. This condition must be fulfilled for a 1D-decomposition along x
        IF ( MOD( nya+1 , pdims(1) ) /= 0 )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ Transposition x --> y:'
-             PRINT*,'    ny+1=',ny+1,' is not an integral divisor of ',&
-                    &'pdims(1)=',pdims(1)
-          ENDIF
-          CALL local_stop
+          WRITE( message_string, * ) 'transposition x --> y:', &
+                                     '& ny+1=',ny+1,' is not an integral divisor of ',&
+                                     'pdims(1)=',pdims(1)
+          CALL message( 'init_pegrid', 'PA0233', 1, 2, 0, 6, 0 )
        ENDIF
 
@@ -431,10 +410,8 @@
     IF ( dt_dosp /= 9999999.9 )  THEN
        IF ( MOD( nza, pdims(2) ) /= 0 )  THEN
-          IF ( myid == 0 )  THEN
-             PRINT*,'+++ Direct transposition z --> y (needed for spectra):'
-             PRINT*,'    nz=',nz,' is not an integral divisor of ',&
-                    &'pdims(2)=',pdims(2)
-          ENDIF
-          CALL local_stop
+          WRITE( message_string, * ) 'direct transposition z --> y (needed for spectra):', &
+                                     '& nz=',nz,' is not an integral divisor of ',&
+                                     'pdims(2)=',pdims(2)
+          CALL message( 'init_pegrid', 'PA0234', 1, 2, 0, 6, 0 )
        ELSE
           nxl_yd  = nxl
@@ -609,9 +586,9 @@
     IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
 
-       print*, '... before COMM_ACCEPT'
+       PRINT*, '... before COMM_ACCEPT'
        CALL MPI_COMM_ACCEPT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &
                              comm_inter, ierr )
-       print*, '--- ierr = ', ierr
-       print*, '--- comm_inter atmosphere = ', comm_inter
+       PRINT*, '--- ierr = ', ierr
+       PRINT*, '--- comm_inter atmosphere = ', comm_inter
 
        coupling_mode_remote = 'ocean_to_atmosphere'
@@ -620,9 +597,9 @@
 
        IF ( myid == 0 )  PRINT*, '*** read: ', port_name, '  ierr = ', ierr
-       print*, '... before COMM_CONNECT'
+       PRINT*, '... before COMM_CONNECT'
        CALL MPI_COMM_CONNECT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &
                               comm_inter, ierr )
-       print*, '--- ierr = ', ierr
-       print*, '--- comm_inter ocean      = ', comm_inter
+       PRINT*, '--- ierr = ', ierr
+       PRINT*, '--- comm_inter ocean      = ', comm_inter
 
        coupling_mode_remote = 'atmosphere_to_ocean'
@@ -776,8 +753,7 @@
              IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l  .OR.  &
                   mg_switch_to_pe0_level >= maximum_grid_level_l )  THEN
-                IF ( myid == 0 )  THEN
-                   PRINT*, '+++ WARNING init_pegrid: mg_switch_to_pe0_level ', &
-                               'out of range and reset to default (=0)'
-                ENDIF
+                message_string = 'mg_switch_to_pe0_level ' // &
+                                 'out of range and reset to default (=0)'
+                CALL message( 'init_pegrid', 'PA0235', 0, 1, 0, 6, 0 )
                 mg_switch_to_pe0_level = 0
              ELSE
@@ -836,14 +812,12 @@
 
              IF ( gathered_size > subdomain_size )  THEN
-                IF ( myid == 0 )  THEN
-                   PRINT*, '+++ init_pegrid: not enough memory for storing ', &
-                               'gathered multigrid data on PE0'
-                ENDIF
-                CALL local_stop
+                message_string = 'not enough memory for storing ' // &
+                                 'gathered multigrid data on PE0'
+                CALL message( 'init_pegrid', 'PA0236', 1, 2, 0, 6, 0 )
              ENDIF
 #else
-             PRINT*, '+++ init_pegrid: multigrid gather/scatter impossible ', &
+             message_string = 'multigrid gather/scatter impossible ' // &
                           'in non parallel mode'
-             CALL local_stop
+             CALL message( 'init_pegrid', 'PA0237', 1, 2, 0, 6, 0 )
 #endif
           ENDIF
@@ -1062,7 +1036,6 @@
 
               CASE DEFAULT
-                 IF ( myid == 0 )  PRINT*, '+++ init_pegrid: more than 10 ', &
-                                           ' multigrid levels'
-                 CALL local_stop
+                 message_string = 'more than 10 multigrid levels'
+                 CALL message( 'init_pegrid', 'PA0238', 1, 2, 0, 6, 0 )
 
           END SELECT
