Index: /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2631)
+++ /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2632)
@@ -497,5 +497,5 @@
 #endif
 
-      ierr = ierr + wrk_alloc()
+      ierr = ierr + wrk_alloc(numout, lwp)
 
       IF( lk_mpp    )   CALL mpp_sum( ierr )
Index: /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/wrk_nemo.F90
===================================================================
--- /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/wrk_nemo.F90	(revision 2631)
+++ /branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/wrk_nemo.F90	(revision 2632)
@@ -8,5 +8,4 @@
    !!----------------------------------------------------------------------
    USE par_oce        ! ocean parameters
-   USE in_out_manager ! I/O manager
 
    IMPLICIT NONE
@@ -87,4 +86,11 @@
    INTEGER, PARAMETER :: REAL_TYPE    = 2
 
+   INTEGER :: kumout  ! Local copy of numout unit number for error/warning
+                      ! messages
+   LOGICAL :: llwp    ! Local copy of lwp - whether we are master PE or not
+
+   CHARACTER(LEN=*), PARAMETER ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
+   CHARACTER(LEN=*), PARAMETER ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
+
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
@@ -94,5 +100,5 @@
 CONTAINS
 
-  FUNCTION wrk_alloc()
+  FUNCTION wrk_alloc(iunit, lwp_arg)
       !!----------------------------------------------------------------------
       !!                   ***  FUNCTION wrk_alloc  ***
@@ -101,10 +107,20 @@
       !!                work space arrays
       !!----------------------------------------------------------------------
-      INTEGER :: wrk_alloc     ! Return value
+      INTEGER, INTENT(in) :: iunit         ! Unit no. to use for error/warning
+                                           ! messages in this module
+      LOGICAL, INTENT(in) :: lwp_arg       ! Value of lwp
+      INTEGER             :: wrk_alloc     ! Return value
+      !
       INTEGER :: extent_1d     ! Extent to allocate for 1D arrays
       INTEGER :: ierror(8)     ! local integer
       !!----------------------------------------------------------------------
       !
-      ! Extent to use for 1D work arrays - find the maximum product of jpi*jpj, jpi*jpk and jpj*jpk and use that
+      ! Save the unit number to use for err/warning messages
+      kumout = iunit
+      ! Save whether we are master PE or not (for output messages)
+      llwp = lwp_arg
+      !
+      ! Extent to use for 1D work arrays - find the maximum product of 
+      ! jpi*jpj, jpi*jpk and jpj*jpk and use that
       IF    ( jpi < jpj .AND. jpi < jpk ) THEN   ;   extent_1d = jpj*jpk
       ELSEIF( jpj < jpi .AND. jpj < jpk ) THEN   ;   extent_1d = jpi*jpk
@@ -166,5 +182,8 @@
       ! Calling routine, nemo_alloc(), checks for errors and takes 
       ! appropriate action - we just print a warning message
-      IF( wrk_alloc /= 0 )   CALL ctl_warn('wrk_alloc: allocation of workspace arrays failed')
+      IF( wrk_alloc /= 0 ) THEN
+         WRITE(kumout,cform_war)
+         WRITE(kumout,*) 'wrk_alloc: allocation of workspace arrays failed'
+      END IF
       !
    END FUNCTION wrk_alloc
@@ -203,5 +222,5 @@
          IF( kdim == 1 ) THEN
             IF( iptr > num_1d_wrkspaces ) THEN
-               CALL ctl_stop('wrk_use - more 1D workspace arrays requested than defined in wrk_nemo module')
+               CALL wrk_stop('wrk_use - more 1D workspace arrays requested than defined in wrk_nemo module')
                wrk_use = .FALSE.
                EXIT
@@ -214,5 +233,5 @@
          ELSEIF( kdim == 2 ) THEN
             IF( iptr > num_2d_wrkspaces ) THEN
-               CALL ctl_stop('wrk_use - more 2D workspace arrays requested than defined in wrk_nemo module')
+               CALL wrk_stop('wrk_use - more 2D workspace arrays requested than defined in wrk_nemo module')
                wrk_use = .FALSE.
                EXIT
@@ -225,5 +244,5 @@
          ELSEIF( kdim == 3 ) THEN
             IF( iptr > num_3d_wrkspaces ) THEN
-               CALL ctl_stop( 'wrk_use - more 3D workspace arrays requested than defined in wrk_nemo module' )
+               CALL wrk_stop( 'wrk_use - more 3D workspace arrays requested than defined in wrk_nemo module' )
                wrk_use = .FALSE.
                EXIT
@@ -236,5 +255,5 @@
          ELSEIF( kdim == 4 ) THEN
             IF(iptr > num_4d_wrkspaces)THEN
-               CALL ctl_stop( 'wrk_use - more 4D workspace arrays requested than defined in wrk_nemo module' )
+               CALL wrk_stop( 'wrk_use - more 4D workspace arrays requested than defined in wrk_nemo module' )
                wrk_use = .FALSE.
                EXIT
@@ -247,6 +266,6 @@
             !
          ELSE 
-            IF(lwp) WRITE(numout,*) 'wrk_use: unsupported value of kdim = ',kdim
-            CALL ctl_stop( 'wrk_use: unrecognised value for number of dimensions' )
+            IF(llwp) WRITE(kumout,*) 'wrk_use: unsupported value of kdim = ',kdim
+            CALL wrk_stop( 'wrk_use: unrecognised value for number of dimensions' )
          END IF
 
@@ -261,5 +280,5 @@
             EXIT
          ELSEIF( iarg == -99 ) THEN
-            CALL ctl_stop( 'wrk_use - ERROR, caught unexpected argument count - BUG' )
+            CALL wrk_stop( 'wrk_use : caught unexpected argument count - BUG' )
             EXIT
          END IF
@@ -296,5 +315,5 @@
          IF( kdim == 2 ) THEN
             IF(iptr > num_2d_lwrkspaces)THEN
-               CALL ctl_stop('llwrk_use - more 2D workspace arrays requested than defined in wrk_nemo module')
+               CALL wrk_stop('llwrk_use - more 2D workspace arrays requested than defined in wrk_nemo module')
                llwrk_use = .FALSE.
                EXIT
@@ -308,5 +327,5 @@
             !
             IF(iptr > num_3d_lwrkspaces)THEN
-               CALL ctl_stop('llwrk_use - more 3D workspace arrays requested than defined in wrk_nemo module')
+               CALL wrk_stop('llwrk_use - more 3D workspace arrays requested than defined in wrk_nemo module')
                llwrk_use = .FALSE.
                EXIT
@@ -318,6 +337,6 @@
             in_use_3dll(iptr) = .TRUE.
          ELSE 
-            IF(lwp) WRITE(numout,*) 'llwrk_use: unsupported value of kdim = ',kdim
-            CALL ctl_stop('llwrk_use: unrecognised value for number of dimensions')
+            IF(llwp) WRITE(kumout,*) 'llwrk_use: unsupported value of kdim = ',kdim
+            CALL wrk_stop('llwrk_use: unrecognised value for number of dimensions')
          END IF
 
@@ -328,5 +347,5 @@
             EXIT
          ELSEIF( iarg == -99 ) THEN
-            CALL ctl_stop( 'llwrk_use - ERROR, caught unexpected argument count - BUG' )
+            CALL wrk_stop( 'llwrk_use - ERROR, caught unexpected argument count - BUG' )
             EXIT
          ENDIF
@@ -363,5 +382,5 @@
          IF( kdim == 2 ) THEN
             IF( iptr > num_2d_wrkspaces ) THEN
-               CALL ctl_stop( 'wrk_use - more 2D workspace arrays requested than defined in wrk_nemo module' )
+               CALL wrk_stop( 'wrk_use - more 2D workspace arrays requested than defined in wrk_nemo module' )
                iwrk_use = .FALSE.
             ELSEIF( in_use_2di(iptr) ) THEN
@@ -372,6 +391,6 @@
             !
          ELSE
-            IF(lwp) WRITE(numout,*) 'iwrk_use: unsupported value of kdim = ',kdim
-            CALL ctl_stop('iwrk_use: unsupported value for number of dimensions')
+            IF(llwp) WRITE(kumout,*) 'iwrk_use: unsupported value of kdim = ',kdim
+            CALL wrk_stop('iwrk_use: unsupported value for number of dimensions')
          END IF
 
@@ -405,5 +424,5 @@
             EXIT
          CASE DEFAULT
-            CALL ctl_stop( 'iwrk_use - ERROR, caught unexpected argument count - BUG' )
+            CALL wrk_stop( 'iwrk_use : caught unexpected argument count - BUG' )
             EXIT
          END SELECT
@@ -439,5 +458,5 @@
          !
          IF(iptr > num_xz_wrkspaces)THEN
-            CALL ctl_stop('wrk_use_xz - more 2D xz workspace arrays requested than defined in wrk_nemo module')
+            CALL wrk_stop('wrk_use_xz - more 2D xz workspace arrays requested than defined in wrk_nemo module')
             wrk_use_xz = .FALSE.
             EXIT
@@ -455,5 +474,5 @@
             EXIT
          ELSEIF( iarg == -99 ) THEN
-            CALL ctl_stop( 'wrk_use_xz - ERROR, caught unexpected argument count - BUG' )   ;   EXIT
+            CALL wrk_stop( 'wrk_use_xz : caught unexpected argument count - BUG' )   ;   EXIT
          END IF
          !
@@ -492,5 +511,5 @@
          IF( kdim == 1 ) THEN
             IF( iptr > num_1d_wrkspaces ) THEN
-               CALL ctl_stop( 'wrk_release - ERROR - attempt to release a non-existant 1D workspace array' )
+               CALL wrk_stop( 'wrk_release : attempt to release a non-existent 1D workspace array' )
                wrk_release = .FALSE.
             ELSE
@@ -500,5 +519,5 @@
          ELSE IF(kdim == 2)THEN
             IF( iptr > num_2d_wrkspaces ) THEN
-               CALL ctl_stop( 'wrk_release - ERROR - attempt to release a non-existant 2D workspace array' )
+               CALL wrk_stop( 'wrk_release : attempt to release a non-existent 2D workspace array' )
                wrk_release = .FALSE.
             ENDIF
@@ -507,5 +526,5 @@
          ELSEIF( kdim == 3 ) THEN
             IF( iptr > num_3d_wrkspaces ) THEN
-               CALL ctl_stop('wrk_release - ERROR - attempt to release a non-existant 3D workspace array')
+               CALL wrk_stop('wrk_release : attempt to release a non-existent 3D workspace array')
                wrk_release = .FALSE.
             END IF
@@ -514,5 +533,5 @@
           ELSEIF( kdim == 4 ) THEN
             IF(iptr > num_4d_wrkspaces)THEN
-               CALL ctl_stop('wrk_release - ERROR - attempt to release a non-existant 4D workspace array')
+               CALL wrk_stop('wrk_release - ERROR - attempt to release a non-existent 4D workspace array')
                wrk_release = .FALSE.
             END IF
@@ -520,6 +539,6 @@
             !
          ELSE 
-            IF(lwp) WRITE(numout,*) 'wrk_release: unsupported value of kdim = ',kdim
-            CALL ctl_stop('wrk_release: unrecognised value for number of dimensions')
+            IF(llwp) WRITE(kumout,*) 'wrk_release: unsupported value of kdim = ',kdim
+            CALL wrk_stop('wrk_release: unrecognised value for number of dimensions')
          ENDIF
          
@@ -536,5 +555,5 @@
             EXIT
          ELSEIF( iarg == -99 ) THEN
-             CALL ctl_stop('wrk_release - caught unexpected argument count - BUG')   ;   EXIT
+             CALL wrk_stop('wrk_release - caught unexpected argument count - BUG')   ;   EXIT
          END IF
          !
@@ -566,5 +585,5 @@
             !
             IF( iptr > num_2d_lwrkspaces ) THEN
-               CALL ctl_stop( 'llwrk_release - ERROR - attempt to release a non-existant 2D workspace array' )
+               CALL wrk_stop( 'llwrk_release : attempt to release a non-existent 2D workspace array' )
                llwrk_release = .FALSE.
                EXIT
@@ -574,5 +593,5 @@
          ELSEIF( kdim == 3 ) THEN
             IF( iptr > num_3d_lwrkspaces ) THEN
-               CALL ctl_stop('llwrk_release - ERROR - attempt to release a non-existant 3D workspace array')
+               CALL wrk_stop('llwrk_release : attempt to release a non-existent 3D workspace array')
                llwrk_release = .FALSE.
                EXIT
@@ -581,6 +600,6 @@
             !
          ELSE 
-            IF(lwp) WRITE(numout,*) 'llwrk_release: unsupported value of kdim = ', kdim
-            CALL ctl_stop( 'llwrk_release: unrecognised value for number of dimensions' )
+            IF(llwp) WRITE(kumout,*) 'llwrk_release: unsupported value of kdim = ', kdim
+            CALL wrk_stop( 'llwrk_release : unrecognised value for number of dimensions' )
          END IF
          !
@@ -592,5 +611,5 @@
              EXIT
          ELSEIF( iarg == -99 ) THEN
-            CALL ctl_stop( 'llwrk_release - ERROR, caught unexpected argument count - BUG' )   ;   EXIT
+            CALL wrk_stop( 'llwrk_release : caught unexpected argument count - BUG' )   ;   EXIT
          ENDIF
          !
@@ -624,11 +643,11 @@
          IF( kdim == 2 ) THEN
             IF( iptr > num_2d_iwrkspaces ) THEN
-               CALL ctl_stop('iwrk_release - ERROR - attempt to release a non-existant 2D workspace array')
+               CALL wrk_stop('iwrk_release : attempt to release a non-existant 2D workspace array')
                iwrk_release = .FALSE.
             ENDIF
             in_use_2di(iptr) = .FALSE.
          ELSE 
-            IF(lwp) WRITE(numout,*) 'iwrk_release: unsupported value of kdim = ',kdim
-            CALL ctl_stop('iwrk_release: unsupported value for number of dimensions')
+            IF(llwp) WRITE(kumout,*) 'iwrk_release: unsupported value of kdim = ',kdim
+            CALL wrk_stop('iwrk_release: unsupported value for number of dimensions')
          ENDIF
          !
@@ -662,5 +681,5 @@
             EXIT
          CASE DEFAULT
-            CALL ctl_stop( 'iwrk_release - ERROR, caught unexpected argument count - BUG' )
+            CALL wrk_stop( 'iwrk_release : caught unexpected argument count - BUG' )
             EXIT
          END SELECT
@@ -691,5 +710,5 @@
          !
          IF( iptr > num_xz_wrkspaces ) THEN
-            CALL ctl_stop('wrk_release_xz - ERROR - attempt to release a non-existant 2D xz workspace array')
+            CALL wrk_stop('wrk_release_xz : attempt to release a non-existant 2D xz workspace array')
             wrk_release_xz = .FALSE.
             EXIT
@@ -704,5 +723,5 @@
             EXIT
          ELSEIF( iarg == -99 ) THEN
-            CALL ctl_stop('wrk_release_xz - ERROR, caught unexpected argument count - BUG')
+            CALL wrk_stop('wrk_release_xz : caught unexpected argument count - BUG')
             EXIT
          END IF
@@ -728,5 +747,5 @@
       !!----------------------------------------------------------------------
 
-      IF(.NOT. lwp)   RETURN
+      IF(.NOT. llwp)   RETURN
 
       SELECT CASE ( kdim )
@@ -771,13 +790,13 @@
       END SELECT
 
-      WRITE(numout,*)
-      WRITE(numout,"('------------------------------------------')")
-      WRITE(numout,"('Table of ',I1,'D ',(A),' workspaces currently in use:')") kdim, TRIM(type_string)
-      WRITE(numout,"('Workspace   In use')")
+      WRITE(kumout,*)
+      WRITE(kumout,"('------------------------------------------')")
+      WRITE(kumout,"('Table of ',I1,'D ',(A),' workspaces currently in use:')") kdim, TRIM(type_string)
+      WRITE(kumout,"('Workspace   In use')")
       DO ji = 1, icount, 1
-         WRITE(numout,"(4x,I2,8x,L1)") ji, in_use_list(ji)
+         WRITE(kumout,"(4x,I2,8x,L1)") ji, in_use_list(ji)
       END DO
-      WRITE(numout,"('------------------------------------------')")
-      WRITE(numout,*)
+      WRITE(kumout,"('------------------------------------------')")
+      WRITE(kumout,*)
       !
    END SUBROUTINE print_in_use_list
@@ -913,4 +932,24 @@
    END SUBROUTINE get_next_arg
 
+
+   SUBROUTINE wrk_stop(cmsg)
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE wrk_stop  ***
+      !!    Purpose: to act as local alternative to ctl_stop. Avoids
+      !!             dependency on in_out_manager module.
+      !!----------------------------------------------------------------------
+      CHARACTER(LEN=*), INTENT(in) :: cmsg
+      !!----------------------------------------------------------------------
+
+      WRITE(kumout, cform_err)
+      WRITE(kumout,*) TRIM(cmsg)
+      ! ARPDBG - would like to call mppstop here to force a stop but that
+      ! introduces a dependency on lib_mpp. Could call mpi_abort() directly
+      ! but that's fairly brutal. Better to rely on calling routine to
+      ! deal with the error passed back from the wrk_X routine?
+      !CALL mppstop
+
+   END SUBROUTINE wrk_stop
+
    !!=====================================================================
 END MODULE wrk_nemo
