New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 2715 for trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90 – NEMO

Ignore:
Timestamp:
2011-03-30T17:58:35+02:00 (13 years ago)
Author:
rblod
Message:

First attempt to put dynamic allocation on the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90

    r2528 r2715  
    2323   USE zdfddm  , ONLY : avs  !: salinity vertical diffusivity coeff. at w-point 
    2424# endif 
    25    USE trcnam_trp      ! passive tracers transport namelist variables 
     25   USE trcnam_trp        ! passive tracers transport namelist variables 
    2626   USE trdmod_trc_oce    ! definition of main arrays used for trends computations 
    2727   USE in_out_manager    ! I/O manager 
     
    3030   USE ioipsl            ! NetCDF library 
    3131   USE lbclnk            ! ocean lateral boundary conditions (or mpp link) 
     32   USE lib_mpp           ! MPP library 
    3233   USE trdmld_trc_rst    ! restart for diagnosing the ML trends 
    3334   USE prtctl            ! print control 
     
    3940 
    4041   PUBLIC trd_mld_trc 
     42   PUBLIC trd_mld_trc_alloc 
    4143   PUBLIC trd_mld_bio 
    4244   PUBLIC trd_mld_trc_init 
     
    4648   CHARACTER (LEN=40) ::  clhstnam                                ! name of the trends NetCDF file 
    4749   INTEGER ::   nmoymltrd 
    48    INTEGER ::   ndextrd1(jpi*jpj) 
     50   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) ::   ndextrd1 
    4951   INTEGER, DIMENSION(jptra) ::   nidtrd, nh_t 
    5052   INTEGER ::   ndimtrd1                         
     
    5860   LOGICAL :: lldebug = .TRUE. 
    5961 
     62   ! Workspace array for trd_mld_trc() routine. Declared here as is 4D and 
     63   ! cannot use workspaces in wrk_nemo module. 
     64   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztmltrd2   ! 
     65#if defined key_lobster 
     66   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ztmltrdbio2  ! only needed for mean diagnostics in trd_mld_bio() 
     67#endif 
     68 
    6069   !! * Substitutions 
    6170#  include "top_substitute.h90" 
     
    6372   !! NEMO/TOP 3.3 , NEMO Consortium (2010) 
    6473   !! $Header:  $  
    65    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) 
     74   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt) 
    6675   !!---------------------------------------------------------------------- 
    67  
    6876CONTAINS 
     77 
     78   INTEGER FUNCTION trd_mld_trc_alloc() 
     79      !!---------------------------------------------------------------------- 
     80      !!                  ***  ROUTINE trd_mld_trc_alloc  *** 
     81      !!---------------------------------------------------------------------- 
     82      ALLOCATE( ztmltrd2(jpi,jpj,jpltrd_trc,jptra) ,      & 
     83#if defined key_lobster 
     84         &      ztmltrdbio2(jpi,jpj,jpdiabio)      ,      & 
     85#endif 
     86         &      ndextrd1(jpi*jpj)                  ,  STAT=trd_mld_trc_alloc) 
     87         ! 
     88      IF( lk_mpp                )   CALL mpp_sum ( trd_mld_trc_alloc ) 
     89      IF( trd_mld_trc_alloc /=0 )   CALL ctl_warn('trd_mld_trc_alloc: failed to allocate arrays') 
     90      ! 
     91   END FUNCTION trd_mld_trc_alloc 
     92 
    6993 
    7094   SUBROUTINE trd_mld_trc_zint( ptrc_trdmld, ktrd, ctype, kjn ) 
     
    88112      !!            surface and the control surface is called "mixed-layer" 
    89113      !!---------------------------------------------------------------------- 
     114      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released 
     115      USE wrk_nemo, ONLY:   zvlmsk => wrk_2d_1 
     116      !! 
    90117      INTEGER, INTENT( in ) ::   ktrd, kjn                        ! ocean trend index and passive tracer rank 
    91118      CHARACTER(len=2), INTENT( in ) ::  ctype                    ! surface/bottom (2D) or interior (3D) physics 
    92119      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  ptrc_trdmld ! passive tracer trend 
    93120      INTEGER ::   ji, jj, jk, isum 
    94       REAL(wp), DIMENSION(jpi,jpj) ::  zvlmsk 
    95       !!---------------------------------------------------------------------- 
     121      !!---------------------------------------------------------------------- 
     122 
     123      IF( wrk_in_use(2, 1) ) THEN 
     124         CALL ctl_stop('trd_mld_trc_zint: requested workspace array unavailable')   ;   RETURN 
     125      ENDIF 
    96126 
    97127      ! I. Definition of control surface and integration weights 
     
    177207            tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmld(:,:,1) * wkx_trc(:,:,1)  ! non penetrative 
    178208      END SELECT 
    179  
    180     END SUBROUTINE trd_mld_trc_zint 
    181      
    182     SUBROUTINE trd_mld_bio_zint( ptrc_trdmld, ktrd ) 
     209      ! 
     210      IF( wrk_not_released(2, 1) )   CALL ctl_stop('trd_mld_trc_zint: failed to release workspace array') 
     211      ! 
     212   END SUBROUTINE trd_mld_trc_zint 
     213 
     214 
     215   SUBROUTINE trd_mld_bio_zint( ptrc_trdmld, ktrd ) 
    183216      !!---------------------------------------------------------------------- 
    184217      !!                  ***  ROUTINE trd_mld_bio_zint  *** 
     
    198231      !!            surface and the control surface is called "mixed-layer" 
    199232      !!---------------------------------------------------------------------- 
    200       INTEGER, INTENT( in ) ::   ktrd          ! bio trend index 
    201       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  ptrc_trdmld ! passive trc trend 
     233      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released 
     234      USE wrk_nemo, ONLY:   zvlmsk => wrk_2d_1 
     235      !! 
     236      INTEGER                         , INTENT(in) ::   ktrd          ! bio trend index 
     237      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) ::   ptrc_trdmld   ! passive trc trend 
    202238#if defined key_lobster 
    203       !! local variables 
     239      ! 
    204240      INTEGER ::   ji, jj, jk, isum 
    205       REAL(wp), DIMENSION(jpi,jpj) ::  zvlmsk 
    206       !!---------------------------------------------------------------------- 
     241      !!---------------------------------------------------------------------- 
     242 
     243      IF( wrk_in_use(2, 1) ) THEN 
     244         CALL ctl_stop('trd_mld_bio_zint: requested workspace array unavailable')   ;   RETURN 
     245      ENDIF 
    207246 
    208247      ! I. Definition of control surface and integration weights 
     
    286325      END DO 
    287326 
    288 #endif 
    289  
    290     END SUBROUTINE trd_mld_bio_zint 
    291  
    292  
    293     SUBROUTINE trd_mld_trc( kt ) 
     327      IF( wrk_not_released(2, 1) )   CALL ctl_stop('trd_mld_bio_zint: failed to release workspace array') 
     328#endif 
     329      ! 
     330   END SUBROUTINE trd_mld_bio_zint 
     331 
     332 
     333   SUBROUTINE trd_mld_trc( kt ) 
    294334      !!---------------------------------------------------------------------- 
    295335      !!                  ***  ROUTINE trd_mld_trc  *** 
     
    338378      !!       - See NEMO documentation (in preparation) 
    339379      !!---------------------------------------------------------------------- 
    340       INTEGER, INTENT( in ) ::   kt                               ! ocean time-step index 
     380      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released 
     381      USE wrk_nemo, ONLY:   wrk_3d_1, wrk_3d_2, wrk_3d_3, wrk_3d_4 
     382      USE wrk_nemo, ONLY:   wrk_3d_5, wrk_3d_6, wrk_3d_7, wrk_3d_8, wrk_3d_9 
     383      ! 
     384      INTEGER, INTENT(in) ::   kt   ! ocean time-step index 
     385      ! 
    341386      INTEGER ::   ji, jj, jk, jl, ik, it, itmod, jn 
    342387      REAL(wp) ::   zavt, zfn, zfn2 
    343       !! 
    344       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmltot             ! d(trc)/dt over the anlysis window (incl. Asselin) 
    345       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmlres             ! residual = dh/dt entrainment term 
    346       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmlatf             ! for storage only 
    347       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmlrad             ! for storage only (for trb<0 corr in trcrad) 
    348       !! 
    349       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmltot2            ! -+ 
    350       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmlres2            !  | working arrays to diagnose the trends 
    351       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmltrdm2           !  | associated with the time meaned ML 
    352       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmlatf2            !  | passive tracers 
    353       REAL(wp), DIMENSION(jpi,jpj,jptra) ::   ztmlrad2            !  | (-> for trb<0 corr in trcrad) 
    354       REAL(wp), DIMENSION(jpi,jpj,jpltrd_trc,jptra) ::  ztmltrd2  ! -+ 
    355       !! 
     388      ! 
     389      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot             ! d(trc)/dt over the anlysis window (incl. Asselin) 
     390      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres             ! residual = dh/dt entrainment term 
     391      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf             ! for storage only 
     392      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad             ! for storage only (for trb<0 corr in trcrad) 
     393      ! 
     394      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot2            ! -+ 
     395      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres2            !  | working arrays to diagnose the trends 
     396      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltrdm2           !  | associated with the time meaned ML 
     397      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf2            !  | passive tracers 
     398      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad2            !  | (-> for trb<0 corr in trcrad) 
     399      !REAL(wp), DIMENSION(jpi,jpj,jpltrd_trc,jptra) ::  ztmltrd2  ! -+ 
     400      ! 
    356401      CHARACTER (LEN= 5) ::   clvar 
    357402#if defined key_dimgout 
     
    361406      !!---------------------------------------------------------------------- 
    362407 
    363       IF( nn_dttrc  /= 1  ) CALL ctl_stop( " Be careful, trends diags never validated " ) 
     408      IF( wrk_in_use(3, 1,2,3,4,5,6,7,8,9) ) THEN 
     409         CALL ctl_stop('trd_mld_trc : requested workspace arrays unavailable')   ;   RETURN 
     410      ENDIF 
     411      ! Set-up pointers into sub-arrays of workspaces 
     412      ztmltot   => wrk_3d_1(:,:,1:jptra) 
     413      ztmlres   => wrk_3d_2(:,:,1:jptra) 
     414      ztmlatf   => wrk_3d_3(:,:,1:jptra) 
     415      ztmlrad   => wrk_3d_4(:,:,1:jptra) 
     416      ztmltot2  => wrk_3d_5(:,:,1:jptra) 
     417      ztmlres2  => wrk_3d_6(:,:,1:jptra) 
     418      ztmltrdm2 => wrk_3d_7(:,:,1:jptra) 
     419      ztmlatf2  => wrk_3d_8(:,:,1:jptra) 
     420      ztmlrad2  => wrk_3d_9(:,:,1:jptra) 
     421 
     422 
     423      IF( nn_dttrc  /= 1  )   CALL ctl_stop( " Be careful, trends diags never validated " ) 
    364424 
    365425      ! ====================================================================== 
     
    386446 
    387447         DO jn = 1, jptra 
    388          ! ... Remove this K_z trend from the iso-neutral diffusion term (if any) 
     448            ! ... Remove this K_z trend from the iso-neutral diffusion term (if any) 
    389449            IF( ln_trdtrc(jn) ) & 
    390450                 tmltrd_trc(:,:,jpmld_trc_ldf,jn) = tmltrd_trc(:,:,jpmld_trc_ldf,jn) - tmltrd_trc(:,:,jpmld_trc_zdf,jn) 
     
    847907      IF( lrst_trc )   CALL trd_mld_trc_rst_write( kt )  ! this must be after the array swap above (III.3) 
    848908 
     909      IF( wrk_not_released(3, 1,2,3,4,5,6,7,8,9) )   CALL ctl_stop('trd_mld_trc: failed to release workspace arrays') 
     910      ! 
    849911   END SUBROUTINE trd_mld_trc 
    850912 
    851     SUBROUTINE trd_mld_bio( kt ) 
     913 
     914   SUBROUTINE trd_mld_bio( kt ) 
    852915      !!---------------------------------------------------------------------- 
    853916      !!                  ***  ROUTINE trd_mld  *** 
     
    900963      INTEGER  ::  jl, it, itmod 
    901964      LOGICAL  :: llwarn  = .TRUE., lldebug = .TRUE. 
    902       REAL(wp), DIMENSION(jpi,jpj,jpdiabio) ::  ztmltrdbio2  ! only needed for mean diagnostics 
    903965      REAL(wp) :: zfn, zfn2 
    904966#if defined key_dimgout 
     
    10851147   END SUBROUTINE trd_mld_bio 
    10861148 
     1149 
    10871150   REAL FUNCTION sum2d( ztab ) 
    10881151      !!---------------------------------------------------------------------- 
     
    10911154      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::  ztab       
    10921155      !!---------------------------------------------------------------------- 
    1093       sum2d = SUM(ztab(2:jpi-1,2:jpj-1)) 
     1156      sum2d = SUM( ztab(2:jpi-1,2:jpj-1) ) 
    10941157   END FUNCTION sum2d 
     1158 
    10951159 
    10961160   SUBROUTINE trd_mld_trc_init 
     
    13781442   !!   Default option :                                       Empty module 
    13791443   !!---------------------------------------------------------------------- 
    1380  
    13811444CONTAINS 
    1382  
    13831445   SUBROUTINE trd_mld_trc( kt )                                   ! Empty routine 
    13841446      INTEGER, INTENT( in) ::   kt 
    13851447      WRITE(*,*) 'trd_mld_trc: You should not have seen this print! error?', kt 
    13861448   END SUBROUTINE trd_mld_trc 
    1387  
    13881449   SUBROUTINE trd_mld_bio( kt ) 
    13891450      INTEGER, INTENT( in) ::   kt 
    13901451      WRITE(*,*) 'trd_mld_bio: You should not have seen this print! error?', kt 
    13911452   END SUBROUTINE trd_mld_bio 
    1392  
    13931453   SUBROUTINE trd_mld_trc_zint( ptrc_trdmld, ktrd, ctype, kjn ) 
    13941454      INTEGER               , INTENT( in ) ::  ktrd, kjn              ! ocean trend index and passive tracer rank 
     
    14001460      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn 
    14011461   END SUBROUTINE trd_mld_trc_zint 
    1402  
    14031462   SUBROUTINE trd_mld_trc_init                                    ! Empty routine 
    14041463      WRITE(*,*) 'trd_mld_trc_init: You should not have seen this print! error?' 
Note: See TracChangeset for help on using the changeset viewer.