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/OPA_SRC/DIA/diawri.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/OPA_SRC/DIA/diawri.F90

    r2561 r2715  
    4848   USE dtatem 
    4949   USE dtasal 
     50   USE lib_mpp         ! MPP library 
    5051 
    5152   IMPLICIT NONE 
     
    5455   PUBLIC   dia_wri                 ! routines called by step.F90 
    5556   PUBLIC   dia_wri_state 
     57   PUBLIC   dia_wri_alloc           ! Called by nemogcm module 
    5658 
    5759   INTEGER ::   nid_T, nz_T, nh_T, ndim_T, ndim_hT   ! grid_T file 
     
    6062   INTEGER ::   nid_W, nz_W, nh_W                    ! grid_W file 
    6163   INTEGER ::   ndex(1)                              ! ??? 
    62    INTEGER, DIMENSION(jpi*jpj)     ::  ndex_hT, ndex_hU, ndex_hV 
    63    INTEGER, DIMENSION(jpi*jpj*jpk) ::  ndex_T, ndex_U, ndex_V 
     64   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hT, ndex_hU, ndex_hV 
     65   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_T, ndex_U, ndex_V 
    6466 
    6567   !! * Substitutions 
     
    7476CONTAINS 
    7577 
     78   INTEGER FUNCTION dia_wri_alloc() 
     79      !!---------------------------------------------------------------------- 
     80      INTEGER, DIMENSION(2) :: ierr 
     81      !!---------------------------------------------------------------------- 
     82      ! 
     83      ierr = 0 
     84      ! 
     85      ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     & 
     86         &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     & 
     87         &      ndex_hV(jpi*jpj) , ndex_V(jpi*jpj*jpk) , STAT=ierr(1) ) 
     88         ! 
     89      dia_wri_alloc = MAXVAL(ierr) 
     90      IF( lk_mpp )   CALL mpp_sum( dia_wri_alloc ) 
     91      ! 
     92  END FUNCTION dia_wri_alloc 
     93 
    7694#if defined key_dimgout 
    7795   !!---------------------------------------------------------------------- 
     
    88106   !!   'key_iomput'                                        use IOM library 
    89107   !!---------------------------------------------------------------------- 
     108 
    90109   SUBROUTINE dia_wri( kt ) 
    91110      !!--------------------------------------------------------------------- 
     
    98117      !!---------------------------------------------------------------------- 
    99118      USE oce, ONLY :   z3d => ta   ! use ta as 3D workspace 
     119      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released 
     120      USE wrk_nemo, ONLY: z2d => wrk_2d_1 
    100121      !! 
    101122      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index 
     
    103124      INTEGER                      ::   ji, jj, jk              ! dummy loop indices 
    104125      REAL(wp)                     ::   zztmp, zztmpx, zztmpy   !  
    105       REAL(wp), DIMENSION(jpi,jpj) ::   z2d                     !  
    106126      !!---------------------------------------------------------------------- 
    107127      !  
     128      IF( wrk_in_use(2, 1))THEN 
     129         CALL ctl_stop('dia_wri: ERROR - requested 2D workspace unavailable.') 
     130         RETURN 
     131      END IF 
     132      ! 
    108133      ! Output the initial state and forcings 
    109134      IF( ninist == 1 ) THEN                        
     
    175200      ENDIF 
    176201      ! 
     202      IF( wrk_not_released(2, 1))THEN 
     203         CALL ctl_stop('dia_wri: ERROR - failed to release 2D workspace.') 
     204         RETURN 
     205      END IF 
     206      ! 
    177207   END SUBROUTINE dia_wri 
    178208 
     
    194224      !!      Each nwrite time step, output the instantaneous or mean fields 
    195225      !!---------------------------------------------------------------------- 
     226      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released 
     227      USE wrk_nemo, ONLY: zw2d => wrk_2d_1 
     228      !! 
    196229      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index 
    197230      !! 
     
    201234      INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers 
    202235      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt           ! local scalars 
    203       REAL(wp), DIMENSION(jpi,jpj) ::   zw2d                 ! 2D workspace 
    204236      !!---------------------------------------------------------------------- 
     237      ! 
     238      IF( wrk_in_use(2, 1))THEN 
     239         CALL ctl_stop('dia_wri: ERROR - requested 2D workspace unavailable.') 
     240         RETURN 
     241      END IF 
    205242      ! 
    206243      ! Output the initial state and forcings 
     
    502539      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping 
    503540      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping 
    504       zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1) 
     541      IF( ln_ssr ) zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1) 
    505542      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping 
    506543#endif 
     
    508545      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping 
    509546      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping 
    510          zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1) 
     547         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1) 
    511548      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping 
    512549#endif 
     
    570607         CALL histclo( nid_W ) 
    571608      ENDIF 
     609      ! 
     610      IF( wrk_not_released(2, 1))THEN 
     611         CALL ctl_stop('dia_wri: ERROR - failed to release 2D workspace.') 
     612         RETURN 
     613      END IF 
    572614      ! 
    573615   END SUBROUTINE dia_wri 
Note: See TracChangeset for help on using the changeset viewer.