Index: /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2627)
+++ /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2628)
@@ -477,35 +477,5 @@
 #endif
 
-     ! TOP-related alloc routines...
-#if defined key_top
-      USE trcadv,       ONLY: trc_adv_alloc
-      USE trc,          ONLY: trc_alloc
-      USE trcnxt,       ONLY: trc_nxt_alloc
-      USE trczdf,       ONLY: trc_zdf_alloc
-      USE trdmod_trc_oce,ONLY: trd_mod_trc_oce_alloc
-#endif
-#if defined key_top && ! defined key_iomput
-      USE trcdia,       ONLY: trc_dia_alloc
-#endif
-#if  defined key_top && defined key_trcdmp 
-      USE trcdmp,       ONLY: trc_dmp_alloc
-#endif
-#if  defined key_top  &&  defined key_dtatrc
-      USE trcdta,       ONLY: trc_dta_alloc
-#endif
-#if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
-      USE trdmld_trc,   ONLY: trd_mld_trc_alloc
-#endif
-#if defined key_cfc
-     USE trcsms_cfc,   ONLY: trc_sms_cfc_alloc
-#endif
-      ! ...end of TOP-related alloc routines
-
-      ! LOBSTER-related alloc routines...
-#if defined key_lobster
-      USE sms_lobster,  ONLY: sms_lobster_alloc
-#endif
-      ! ...end of LOBSTER-related alloc routines
-
+     ! TRD-related alloc routines...
 #if   defined key_trdmld   ||   defined key_esopa
       USE trdmld,       ONLY: trd_mld_alloc
@@ -539,32 +509,4 @@
       ierr = ierr + obc_oce_alloc()
 #endif
-
-      ! Start of TOP-related alloc routines...
-#if defined key_top
-      ierr = ierr + trc_adv_alloc()
-      ierr = ierr + trc_alloc()
-      ierr = ierr + trc_nxt_alloc()
-      ierr = ierr + trc_zdf_alloc()
-      ierr = ierr + trd_mod_trc_oce_alloc()
-#endif
-#if defined key_top && ! defined key_iomput
-      ierr = ierr + trc_dia_alloc()
-#endif
-#if  defined key_top && defined key_trcdmp 
-      ierr = ierr + trc_dmp_alloc()
-#endif
-#if  defined key_top  &&  defined key_dtatrc
-      ierr = ierr + trc_dta_alloc()
-#endif
-#if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
-      ierr = ierr + trd_mld_trc_alloc()
-#endif
-      ! ...end of TOP-related alloc routines
-
-      ! Start of LOBSTER-related alloc routines
-#if defined key_lobster
-      ierr = ierr + sms_lobster_alloc()
-#endif
-      ! ...end of LOBSTER-related alloc routines
 
 #if   defined key_trdmld   ||   defined key_esopa
Index: /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 2627)
+++ /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 2628)
@@ -4,8 +4,8 @@
    !! TOP :   Manage the passive tracer initialization
    !!======================================================================
-   !! History :    -   !  1991-03  ()  original code
-   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
-   !!              -   !  2005-10 (C. Ethe) print control
-   !!             2.0  !  2005-10 (C. Ethe, G. Madec) revised architecture
+   !! History :   -   ! 1991-03 (O. Marti)  original code
+   !!            1.0  ! 2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!            2.0  ! 2005-10 (C. Ethe, G. Madec) revised architecture
+   !!            4.0  ! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -13,6 +13,6 @@
    !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   trc_init :   Initialization for passive tracer
+   !!   trc_init  :   Initialization for passive tracer
+   !!   top_alloc :   allocate the TOP arrays
    !!----------------------------------------------------------------------
    USE oce_trc
@@ -40,5 +40,9 @@
     !! * Substitutions
 #  include "domzgr_substitute.h90"
-  
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 4.0 , NEMO Consortium (2011)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
    
@@ -57,5 +61,4 @@
       INTEGER ::   jk, jn    ! dummy loop indices
       CHARACTER (len=25) :: charout
-
       !!---------------------------------------------------------------------
 
@@ -64,10 +67,13 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~'
 
-      !                 ! masked grid volume
+      CALL top_alloc()              ! allocate TOP arrays
+
+
+      !                             ! masked grid volume
       DO jk = 1, jpk
          cvol(:,:,jk) = e1t(:,:) * e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) 
       END DO
 
-      ! total volume of the ocean
+      !                             ! total volume of the ocean
 #if ! defined key_degrad
       areatot = glob_sum( cvol(:,:,:) )
@@ -76,7 +82,7 @@
 #endif
 
-                                  CALL trc_nam      ! read passive tracers namelists
-
-      ! restart for passive tracer (input)
+      CALL trc_nam                  ! read passive tracers namelists
+
+      !                             ! restart for passive tracer (input)
       IF( ln_rsttr ) THEN
          IF(lwp) WRITE(numout,*) '       read a restart file for passive tracer : ', cn_trcrst_in
@@ -136,12 +142,12 @@
       ENDIF
  
-      tra(:,:,:,:) = 0.
+      tra(:,:,:,:) = 0._wp
       
       IF( ln_zps .AND. .NOT. lk_c1d )   &              ! Partial steps: before horizontal gradient of passive
-      &                     CALL zps_hde( nit000, jptra, trn, gtru, gtrv )       ! tracers at the bottom ocean level
-
-
-      !                 ! Computation content of all tracers
-      trai = 0.e0
+         CALL zps_hde( nit000, jptra, trn, gtru, gtrv )       ! tracers at the bottom ocean level
+
+
+      !           
+      trai = 0._wp         ! Computation content of all tracers
       DO jn = 1, jptra
 #if ! defined key_degrad
@@ -152,22 +158,83 @@
       END DO      
 
-      !                 ! control print
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
-      IF(lwp) WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
-      IF(lwp) WRITE(numout,*) '          *** Total inital content of all tracers  = ', trai
-      IF(lwp) WRITE(numout,*)
-
-      IF( ln_ctl )   CALL prt_ctl_trc_init      ! control print
-      !
-
-      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+      IF(lwp) THEN               ! control print
+         WRITE(numout,*)
+         WRITE(numout,*)
+         WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
+         WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
+         WRITE(numout,*) '          *** Total inital content of all tracers  = ', trai
+         WRITE(numout,*)
+      ENDIF
+
+      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
+         CALL prt_ctl_trc_init
          WRITE(charout, FMT="('ini ')")
          CALL prt_ctl_trc_info( charout )
          CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
       ENDIF
-
+      !
    END SUBROUTINE trc_init
+
+
+   SUBROUTINE top_alloc
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE top_alloc  ***
+      !!
+      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
+      !!----------------------------------------------------------------------
+      !
+      USE trcadv        , ONLY:   trc_adv_alloc          ! TOP-related alloc routines...
+      USE trc           , ONLY:   trc_alloc
+      USE trcnxt        , ONLY:   trc_nxt_alloc
+      USE trczdf        , ONLY:   trc_zdf_alloc
+      USE trdmod_trc_oce, ONLY:   trd_mod_trc_oce_alloc
+#if ! defined key_iomput
+      USE trcdia        , ONLY:   trc_dia_alloc
+#endif
+#if defined key_trcdmp 
+      USE trcdmp        , ONLY:   trc_dmp_alloc
+#endif
+#if defined key_dtatrc
+      USE trcdta        , ONLY:   trc_dta_alloc
+#endif
+#if defined key_trdmld_trc   ||   defined key_esopa
+      USE trdmld_trc    , ONLY:   trd_mld_trc_alloc
+#endif
+#if defined key_cfc
+     USE trcsms_cfc     , ONLY:   trc_sms_cfc_alloc
+#endif
+#if defined key_lobster
+      USE sms_lobster   , ONLY:   sms_lobster_alloc      ! LOBSTER-related alloc routines...
+#endif
+      !
+      INTEGER :: ierr
+      !!----------------------------------------------------------------------
+      !
+      ierr =        trc_adv_alloc()          ! Start of TOP-related alloc routines...
+      ierr = ierr + trc_alloc()
+      ierr = ierr + trc_nxt_alloc()
+      ierr = ierr + trc_zdf_alloc()
+      ierr = ierr + trd_mod_trc_oce_alloc()
+#if ! defined key_iomput
+      ierr = ierr + trc_dia_alloc()
+#endif
+#if defined key_trcdmp 
+      ierr = ierr + trc_dmp_alloc()
+#endif
+#if defined key_dtatrc
+      ierr = ierr + trc_dta_alloc()
+#endif
+#if defined key_trdmld_trc   ||   defined key_esopa
+      ierr = ierr + trd_mld_trc_alloc()
+#endif
+      !
+#if defined key_lobster
+      ierr = ierr + sms_lobster_alloc()      ! Start of LOBSTER-related alloc routines
+#endif
+      !
+      IF( lk_mpp    )   CALL mpp_sum( ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_alloc : unable to allocate standard ocean arrays' )
+      !
+   END SUBROUTINE top_alloc
 
 #else
@@ -180,8 +247,4 @@
 #endif
 
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
 END MODULE trcini
