Index: palm/trunk/SOURCE/pmc_interface.f90
===================================================================
--- palm/trunk/SOURCE/pmc_interface.f90	(revision 1767)
+++ palm/trunk/SOURCE/pmc_interface.f90	(revision 1779)
@@ -20,5 +20,7 @@
 ! Current revisions:
 ! ------------------
-!
+! only the total number of PEs is given for the domains, npe_x and npe_y
+! replaced by npe_total,
+! array management changed from linked list to sequential loop
 !
 ! Former revisions:
@@ -59,7 +61,8 @@
 
     USE control_parameters,                                                    &
-        ONLY:  dt_3d, dz, humidity, message_string, nest_bound_l,              &
-               nest_bound_r, nest_bound_s, nest_bound_n, passive_scalar,       &
-               simulated_time, topography, volume_flow
+        ONLY:  coupling_char, dt_3d, dz, humidity, message_string,             &
+               nest_bound_l, nest_bound_r, nest_bound_s, nest_bound_n,         &
+               nest_domain, passive_scalar, simulated_time, topography,        &
+               volume_flow
 
     USE cpulog,                                                                &
@@ -88,6 +91,7 @@
 
     USE pmc_client,                                                            &
-        ONLY:  pmc_clientinit, pmc_c_getnextarray, pmc_c_get_2d_index_list,    &
-               pmc_c_getbuffer, pmc_c_putbuffer, pmc_c_setind_and_allocmem,    &
+        ONLY:  pmc_clientinit, pmc_c_clear_next_array_list,                    &
+               pmc_c_getnextarray, pmc_c_get_2d_index_list, pmc_c_getbuffer,   &
+               pmc_c_putbuffer, pmc_c_setind_and_allocmem,                     &
                pmc_c_set_dataarray, pmc_set_dataarray_name
 
@@ -104,8 +108,8 @@
 
     USE pmc_server,                                                            &
-        ONLY:  pmc_serverinit, pmc_s_fillbuffer, pmc_s_getdata_from_buffer,    &
-               pmc_s_getnextarray, pmc_s_setind_and_allocmem,                  &
-               pmc_s_set_active_data_array, pmc_s_set_dataarray,               &
-               pmc_s_set_2d_index_list
+        ONLY:  pmc_serverinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,  &
+               pmc_s_getdata_from_buffer, pmc_s_getnextarray,                  &
+               pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,         &
+               pmc_s_set_dataarray, pmc_s_set_2d_index_list
 
 #endif
@@ -116,6 +120,6 @@
 !--        limit. Try to reduce as much as possible
 
-!-- TO_DO: shouldn't we use public as default here? Only a minority of the
-!-- variables is private.
+!-- TO_DO: are all of these variables following now really PUBLIC?
+!--        Klaus and I guess they are not
     PRIVATE    !:  Note that the default publicity is here set to private.
 
@@ -129,6 +133,5 @@
     INTEGER(iwp), PUBLIC, SAVE      ::  cpl_id  = 1            !:
     CHARACTER(LEN=32), PUBLIC, SAVE ::  cpl_name               !:
-    INTEGER(iwp), PUBLIC, SAVE      ::  cpl_npex               !:
-    INTEGER(iwp), PUBLIC, SAVE      ::  cpl_npey               !:
+    INTEGER(iwp), PUBLIC, SAVE      ::  cpl_npe_total          !:
     INTEGER(iwp), PUBLIC, SAVE      ::  cpl_parent_id          !:
 
@@ -266,5 +269,5 @@
 !-- Module private variables.
     INTEGER(iwp), DIMENSION(3)          ::  define_coarse_grid_int    !:
-    REAL(wp), DIMENSION(9)              ::  define_coarse_grid_real   !:
+    REAL(wp), DIMENSION(7)              ::  define_coarse_grid_real   !:
 
     TYPE coarsegrid_def
@@ -364,26 +367,33 @@
 !
 !--    This is not a nested run
-!
-!--    TO_DO: this wouldn't be required any more?
        world_comm = MPI_COMM_WORLD
        cpl_id     = 1
        cpl_name   = ""
-       cpl_npex   = 2
-       cpl_npey   = 2
-       lower_left_coord_x = 0.0_wp
-       lower_left_coord_y = 0.0_wp
+
        RETURN
-    ELSE
-!
-!--    Set the general steering switch which tells PALM that its a nested run
-       nested_run = .TRUE.
+
     ENDIF
 
+!
+!-- Set the general steering switch which tells PALM that its a nested run
+    nested_run = .TRUE.
+
+!
+!-- Get some variables required by the pmc-interface (and in some cases in the
+!-- PALM code out of the pmci) out of the pmc-core
     CALL pmc_get_local_model_info( my_cpl_id = cpl_id,                         &
                                    my_cpl_parent_id = cpl_parent_id,           &
                                    cpl_name = cpl_name,                        &
-                                   npe_x = cpl_npex, npe_y = cpl_npey,         &
+                                   npe_total = cpl_npe_total,                  &
                                    lower_left_x = lower_left_coord_x,          &
                                    lower_left_y = lower_left_coord_y )
+!
+!-- Set the steering switch which tells the models that they are nested (of
+!-- course the root domain (cpl_id = 1 ) is not nested)
+    IF ( cpl_id >= 2 )  THEN
+       nest_domain = .TRUE.
+       WRITE( coupling_char, '(A1,I2.2)') '_', cpl_id
+    ENDIF
+
 !
 !-- Message that communicators for nesting are initialized.
@@ -493,12 +503,9 @@
           define_coarse_grid_real(1) = lower_left_coord_x
           define_coarse_grid_real(2) = lower_left_coord_y
-!--       TO_DO: remove this?
-          define_coarse_grid_real(3) = 0             !  KK currently not used.
-          define_coarse_grid_real(4) = 0
-          define_coarse_grid_real(5) = dx
-          define_coarse_grid_real(6) = dy
-          define_coarse_grid_real(7) = lower_left_coord_x + ( nx + 1 ) * dx
-          define_coarse_grid_real(8) = lower_left_coord_y + ( ny + 1 ) * dy
-          define_coarse_grid_real(9) = dz
+          define_coarse_grid_real(3) = dx
+          define_coarse_grid_real(4) = dy
+          define_coarse_grid_real(5) = lower_left_coord_x + ( nx + 1 ) * dx
+          define_coarse_grid_real(6) = lower_left_coord_y + ( ny + 1 ) * dy
+          define_coarse_grid_real(7) = dz
 
           define_coarse_grid_int(1)  = nx
@@ -512,7 +519,7 @@
           yez = ( nbgp + 1 ) * dy 
           IF ( cl_coord_x(0) < define_coarse_grid_real(1) + xez )          nomatch = 1 
-          IF ( cl_coord_x(nx_cl + 1) > define_coarse_grid_real(7) - xez )  nomatch = 1 
+          IF ( cl_coord_x(nx_cl + 1) > define_coarse_grid_real(5) - xez )  nomatch = 1
           IF ( cl_coord_y(0) < define_coarse_grid_real(2) + yez )          nomatch = 1 
-          IF ( cl_coord_y(ny_cl + 1) > define_coarse_grid_real(8) - yez )  nomatch = 1
+          IF ( cl_coord_y(ny_cl + 1) > define_coarse_grid_real(6) - yez )  nomatch = 1
 
           DEALLOCATE( cl_coord_x )
@@ -521,5 +528,6 @@
 !
 !--       Send coarse grid information to client
-          CALL pmc_send_to_client( client_id, Define_coarse_grid_real, 9, 0,   &
+          CALL pmc_send_to_client( client_id, Define_coarse_grid_real,         &
+                                   SIZE(define_coarse_grid_real), 0,           &
                                    21, ierr )
           CALL pmc_send_to_client( client_id, Define_coarse_grid_int,  3, 0,   &
@@ -553,4 +561,5 @@
 !
 !--    Include couple arrays into server content
+       CALL pmc_s_clear_next_array_list
        DO  WHILE ( pmc_s_getnextarray( client_id, myname ) )
           CALL pmci_set_array_pointer( myname, client_id = client_id,          &
@@ -676,5 +685,11 @@
     IF ( .NOT. pmc_is_rootmodel() )  THEN
        CALL pmc_clientinit
-       
+!
+!--    Here and only here the arrays are defined, which actualy will be
+!--    exchanged between client and server.
+!--    Please check, if the arrays are in the list of possible exchange arrays
+!--    in subroutines:
+!--    pmci_set_array_pointer (for server arrays)
+!--    pmci_create_client_arrays (for client arrays)
        CALL pmc_set_dataarray_name( 'coarse', 'u'  ,'fine', 'u',  ierr )
        CALL pmc_set_dataarray_name( 'coarse', 'v'  ,'fine', 'v',  ierr )
@@ -709,5 +724,6 @@
 !
 !--       Receive Coarse grid information.
-          CALL pmc_recv_from_server( define_coarse_grid_real, 9, 0, 21, ierr )
+          CALL pmc_recv_from_server( define_coarse_grid_real,                  &
+                                     SIZE(define_coarse_grid_real), 0, 21, ierr )
           CALL pmc_recv_from_server( define_coarse_grid_int,  3, 0, 22, ierr )
 
@@ -719,9 +735,9 @@
           WRITE(0,*) 'startx_tot    = ',define_coarse_grid_real(1)
           WRITE(0,*) 'starty_tot    = ',define_coarse_grid_real(2)
-          WRITE(0,*) 'endx_tot      = ',define_coarse_grid_real(7)
-          WRITE(0,*) 'endy_tot      = ',define_coarse_grid_real(8)
-          WRITE(0,*) 'dx            = ',define_coarse_grid_real(5)
-          WRITE(0,*) 'dy            = ',define_coarse_grid_real(6)
-          WRITE(0,*) 'dz            = ',define_coarse_grid_real(9)
+          WRITE(0,*) 'endx_tot      = ',define_coarse_grid_real(5)
+          WRITE(0,*) 'endy_tot      = ',define_coarse_grid_real(6)
+          WRITE(0,*) 'dx            = ',define_coarse_grid_real(3)
+          WRITE(0,*) 'dy            = ',define_coarse_grid_real(4)
+          WRITE(0,*) 'dz            = ',define_coarse_grid_real(7)
           WRITE(0,*) 'nx_coarse     = ',define_coarse_grid_int(1)
           WRITE(0,*) 'ny_coarse     = ',define_coarse_grid_int(2)
@@ -729,10 +745,11 @@
        ENDIF
 
-       CALL MPI_BCAST( define_coarse_grid_real, 9, MPI_REAL, 0, comm2d, ierr )
+       CALL MPI_BCAST( define_coarse_grid_real, SIZE(define_coarse_grid_real), &
+                       MPI_REAL, 0, comm2d, ierr )
        CALL MPI_BCAST( define_coarse_grid_int, 3, MPI_INTEGER, 0, comm2d, ierr )
 
-       cg%dx = define_coarse_grid_real(5)
-       cg%dy = define_coarse_grid_real(6)
-       cg%dz = define_coarse_grid_real(9)
+       cg%dx = define_coarse_grid_real(3)
+       cg%dy = define_coarse_grid_real(4)
+       cg%dz = define_coarse_grid_real(7)
        cg%nx = define_coarse_grid_int(1)
        cg%ny = define_coarse_grid_int(2)
@@ -778,4 +795,5 @@
 !
 !--    Include couple arrays into client content.
+       CALL  pmc_c_clear_next_array_list
        DO  WHILE ( pmc_c_getnextarray( myname ) )
 !--       TO_DO: Klaus, why the c-arrays are still up to cg%nz??
@@ -880,6 +898,4 @@
            ENDIF
         ENDDO
-
-        WRITE( 0, * )  'Coarse area ', myid, icl, icr, jcs, jcn
 
         coarse_bound(1) = icl
@@ -3397,4 +3413,5 @@
 !
 !-- List of array names, which can be coupled
+!-- In case of 3D please change also the second array for the pointer version
     IF ( TRIM(name) == "u" )     p_3d => u
     IF ( TRIM(name) == "v" )     p_3d => v
@@ -3403,5 +3420,8 @@
     IF ( TRIM(name) == "pt" )    p_3d => pt
     IF ( TRIM(name) == "q" )     p_3d => q
-    !IF ( TRIM(name) == "z0" )    p_2d => z0
+!
+!-- This is just an example for a 2D array, not active for coupling
+!-- Please note, that z0 has to be declared as TARGET array in modules.f90
+!    IF ( TRIM(name) == "z0" )    p_2d => z0
 
 #if defined( __nopointer )
@@ -3431,5 +3451,5 @@
     IF ( TRIM(name) == "e" )     p_3d_sec => e_2
     IF ( TRIM(name) == "pt" )    p_3d_sec => pt_2
-    !IF ( TRIM(name) == "z0" )    p_2d_sec => z0_2
+    IF ( TRIM(name) == "q" )     p_3d_sec => q_2
 
     IF ( ASSOCIATED( p_3d ) )  THEN
@@ -3437,5 +3457,5 @@
                                  array_2 = p_3d_sec )
     ELSEIF ( ASSOCIATED( p_2d ) )  THEN
-       CALL pmc_s_set_dataarray( client_id, p_2d, array_2 = p_2d_sec )
+       CALL pmc_s_set_dataarray( client_id, p_2d )
     ELSE
 !
