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 4977 for branches/2014/dev_MERGE_2014 – NEMO

Ignore:
Timestamp:
2014-12-06T09:40:23+01:00 (9 years ago)
Author:
gm
Message:

add missing dealloc in diahsb + style improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90

    r4967 r4977  
    99 
    1010   !!---------------------------------------------------------------------- 
     11   !!   dia_hsb       : Diagnose the conservation of ocean heat and salt contents, and volume 
     12   !!   dia_hsb_rst   : Read or write DIA file in restart file 
     13   !!   dia_hsb_init  : Initialization of the conservation diagnostic 
     14   !!---------------------------------------------------------------------- 
    1115   USE oce             ! ocean dynamics and tracers 
    1216   USE dom_oce         ! ocean space and time domain 
    1317   USE phycst          ! physical constants 
    1418   USE sbc_oce         ! surface thermohaline fluxes 
    15    USE in_out_manager  ! I/O manager 
     19   USE sbcrnf          ! river runoff 
     20   USE sbcisf          ! ice shelves 
    1621   USE domvvl          ! vertical scale factors 
    1722   USE traqsr          ! penetrative solar radiation 
    1823   USE trabbc          ! bottom boundary condition  
    19    USE lib_mpp         ! distributed memory computing library 
    2024   USE trabbc          ! bottom boundary condition 
    2125   USE bdy_par         ! (for lk_bdy) 
     26   USE restart         ! ocean restart 
     27   ! 
     28   USE iom             ! I/O manager 
     29   USE in_out_manager  ! I/O manager 
     30   USE lib_fortran     ! glob_sum 
     31   USE lib_mpp         ! distributed memory computing library 
    2232   USE timing          ! preformance summary 
    23    USE iom             ! I/O manager 
    24    USE lib_fortran     ! glob_sum 
    25    USE restart         ! ocean restart 
    2633   USE wrk_nemo        ! work arrays 
    27    USE sbcrnf          ! river runoff 
    28    USE sbcisf          ! ice shelves 
    2934 
    3035   IMPLICIT NONE 
     
    3742   LOGICAL, PUBLIC ::   ln_diahsb   !: check the heat and salt budgets 
    3843 
    39    real(wp)                                ::   surf_tot                ! 
    40    real(wp)                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends 
    41    real(wp)                                ::   frc_wn_t      , frc_wn_s ! global forcing trends 
    42    real(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf      , ssh_ini              ! 
    43    real(wp), DIMENSION(:,:,:), ALLOCATABLE ::   hc_loc_ini, sc_loc_ini, e3t_ini  ! 
    44    real(wp), DIMENSION(:,:)  , ALLOCATABLE ::   ssh_hc_loc_ini, ssh_sc_loc_ini 
     44   REAL(wp) ::   surf_tot              ! ocean surface 
     45   REAL(wp) ::   frc_t, frc_s, frc_v   ! global forcing trends 
     46   REAL(wp) ::   frc_wn_t, frc_wn_s    ! global forcing trends 
     47   ! 
     48   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf          , ssh_ini          ! 
     49   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   ssh_hc_loc_ini, ssh_sc_loc_ini   ! 
     50   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   hc_loc_ini, sc_loc_ini, e3t_ini  ! 
    4551 
    4652   !! * Substitutions 
    4753#  include "domzgr_substitute.h90" 
    4854#  include "vectopt_loop_substitute.h90" 
    49  
    5055   !!---------------------------------------------------------------------- 
    5156   !! NEMO/OPA 3.3 , NEMO Consortium (2010) 
     
    5358   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt) 
    5459   !!---------------------------------------------------------------------- 
    55  
    5660CONTAINS 
    5761 
     
    6872      !!--------------------------------------------------------------------------- 
    6973      INTEGER, INTENT(in) ::   kt   ! ocean time-step index 
    70       !! 
    71       INTEGER    ::   jk, ji, jj                          ! dummy loop indice 
    72       real(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations 
    73       real(wp)   ::   zdiff_hc1   , zdiff_sc1     ! -   -   -   -   -   -   -   -  
    74       real(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation 
    75       real(wp)   ::   zerr_hc1    , zerr_sc1       ! heat and salt content misfit 
    76       real(wp)   ::   zvol_tot                    ! volume 
    77       real(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     - 
    78       real(wp)   ::   z_frc_trd_v                 !    -     - 
    79       real(wp)   ::   z_wn_trd_t , z_wn_trd_s   !    -     - 
    80       real(wp)   ::   z_ssh_hc , z_ssh_sc   !    -     - 
    81       real(wp), DIMENSION(:,:), POINTER      ::   z2d0, z2d1 
     74      ! 
     75      INTEGER    ::   ji, jj, jk                  ! dummy loop indice 
     76      REAL(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations 
     77      REAL(wp)   ::   zdiff_hc1   , zdiff_sc1     !  -         -     -        -  
     78      REAL(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation 
     79      REAL(wp)   ::   zerr_hc1    , zerr_sc1      ! heat and salt content misfit 
     80      REAL(wp)   ::   zvol_tot                    ! volume 
     81      REAL(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     - 
     82      REAL(wp)   ::   z_frc_trd_v                 !    -     - 
     83      REAL(wp)   ::   z_wn_trd_t , z_wn_trd_s     !    -     - 
     84      REAL(wp)   ::   z_ssh_hc , z_ssh_sc         !    -     - 
     85      REAL(wp), DIMENSION(:,:), POINTER ::   z2d0, z2d1 
    8286      !!--------------------------------------------------------------------------- 
    8387      IF( nn_timing == 1 )   CALL timing_start('dia_hsb')       
    84       CALL wrk_alloc( jpi,jpj, z2d0, z2d1 ) 
     88      CALL wrk_alloc( jpi,jpj,   z2d0, z2d1 ) 
     89      ! 
    8590      tsn(:,:,:,1) = tsn(:,:,:,1) * tmask(:,:,:) ; tsb(:,:,:,1) = tsb(:,:,:,1) * tmask(:,:,:) ; 
    8691      tsn(:,:,:,2) = tsn(:,:,:,2) * tmask(:,:,:) ; tsb(:,:,:,2) = tsb(:,:,:,2) * tmask(:,:,:) ; 
     
    130135      ! 2 -  Content variations ! 
    131136      ! ------------------------ ! 
    132       zdiff_v2 = 0.d0 
    133       zdiff_hc = 0.d0 
    134       zdiff_sc = 0.d0 
     137      zdiff_v2 = 0._wp 
     138      zdiff_hc = 0._wp 
     139      zdiff_sc = 0._wp 
    135140 
    136141      ! volume variation (calculated with ssh) 
     
    139144      ! heat & salt content variation (associated with ssh) 
    140145      IF( .NOT. lk_vvl ) THEN 
    141          z2d0=0.0_wp ; z2d1=0.0_wp 
    142          DO ji=1,jpi 
    143             DO jj=1,jpj 
     146         z2d0 = 0._wp   ;   z2d1 = 0._wp 
     147         DO ji = 1, jpi 
     148            DO jj = 1, jpj 
    144149              z2d0(ji,jj) = surf(ji,jj) * ( tsn(ji,jj,mikt(ji,jj),jp_tem) * sshn(ji,jj) - ssh_hc_loc_ini(ji,jj) )  
    145150              z2d1(ji,jj) = surf(ji,jj) * ( tsn(ji,jj,mikt(ji,jj),jp_sal) * sshn(ji,jj) - ssh_sc_loc_ini(ji,jj) )  
    146             ENDDO 
    147          ENDDO 
     151            END DO 
     152         END DO 
    148153         z_ssh_hc = glob_sum( z2d0 )  
    149154         z_ssh_sc = glob_sum( z2d1 )  
     
    177182      ! 3 - Diagnostics writing ! 
    178183      ! ----------------------- ! 
    179       zvol_tot   = 0.d0                                                   ! total ocean volume 
     184      zvol_tot = 0._wp                    ! total ocean volume (calculated with scale factors) 
    180185      DO jk = 1, jpkm1 
    181186         zvol_tot  = zvol_tot + glob_sum( surf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) ) 
    182187      END DO 
     188 
     189!!gm to be added ? 
     190!      IF( .NOT. lk_vvl ) THEN            ! fixed volume, add the ssh contribution 
     191!        zvol_tot = zvol_tot + glob_sum( surf(:,:) * sshn(:,:) ) 
     192!      ENDIF 
     193!!gm end 
     194 
    183195 
    184196      IF( lk_vvl ) THEN 
     
    207219      IF( lrst_oce )   CALL dia_hsb_rst( kt, 'WRITE' ) 
    208220 
     221      CALL wrk_dealloc( jpi,jpj,   z2d0, z2d1 ) 
     222 
    209223      IF( nn_timing == 1 )   CALL timing_stop('dia_hsb') 
    210 ! 
     224      ! 
    211225   END SUBROUTINE dia_hsb 
    212226 
    213  
    214    SUBROUTINE dia_hsb_init 
    215       !!--------------------------------------------------------------------------- 
    216       !!                  ***  ROUTINE dia_hsb  *** 
    217       !!      
    218       !! ** Purpose: Initialization for the heat salt volume budgets 
    219       !!  
    220       !! ** Method : Compute initial heat content, salt content and volume 
    221       !! 
    222       !! ** Action : - Compute initial heat content, salt content and volume 
    223       !!             - Initialize forcing trends 
    224       !!             - Compute coefficients for conversion 
    225       !!--------------------------------------------------------------------------- 
    226       INTEGER            ::   jk       ! dummy loop indice 
    227       INTEGER            ::   ierror   ! local integer 
    228       !! 
    229       NAMELIST/namhsb/ ln_diahsb 
    230       ! 
    231       INTEGER  ::   ios 
    232       !!---------------------------------------------------------------------- 
    233  
    234       IF(lwp) THEN 
    235          WRITE(numout,*) 
    236          WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets' 
    237          WRITE(numout,*) '~~~~~~~~ ' 
    238       ENDIF 
    239  
    240       REWIND( numnam_ref )              ! Namelist namhsb in reference namelist 
    241       READ  ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901) 
    242 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in reference namelist', lwp ) 
    243  
    244       REWIND( numnam_cfg )              ! Namelist namhsb in configuration namelist 
    245       READ  ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 ) 
    246 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in configuration namelist', lwp ) 
    247       IF(lwm) WRITE ( numond, namhsb ) 
    248  
    249       ! 
    250       IF(lwp) THEN                   ! Control print 
    251          WRITE(numout,*) 
    252          WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets' 
    253          WRITE(numout,*) '~~~~~~~~~~~~' 
    254          WRITE(numout,*) '   Namelist namhsb : set hsb parameters' 
    255          WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb 
    256          WRITE(numout,*) 
    257       ENDIF 
    258  
    259       IF( .NOT. ln_diahsb )   RETURN 
    260 !      IF( .NOT. lk_mpp_rep ) & 
    261 !        CALL ctl_stop (' Your global mpp_sum if performed in single precision - 64 bits -', & 
    262 !             &         ' whereas the global sum to be precise must be done in double precision ',& 
    263 !             &         ' please add key_mpp_rep') 
    264  
    265       ! ------------------- ! 
    266       ! 1 - Allocate memory ! 
    267       ! ------------------- ! 
    268       ALLOCATE( hc_loc_ini(jpi,jpj,jpk), sc_loc_ini(jpi,jpj,jpk), & 
    269          &      e3t_ini(jpi,jpj,jpk), surf(jpi,jpj),  ssh_ini(jpi,jpj), STAT=ierror ) 
    270       IF( ierror > 0 ) THEN 
    271          CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN 
    272       ENDIF 
    273  
    274       IF(.NOT. lk_vvl ) ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror ) 
    275       IF( ierror > 0 ) THEN 
    276          CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN 
    277       ENDIF 
    278  
    279       ! ----------------------------------------------- ! 
    280       ! 2 - Time independant variables and file opening ! 
    281       ! ----------------------------------------------- ! 
    282       IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated" 
    283       IF(lwp) WRITE(numout,*) '~~~~~~~' 
    284       surf(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)      ! masked surface grid cell area 
    285       surf_tot  = glob_sum( surf(:,:) )                                       ! total ocean surface area 
    286  
    287       IF( lk_bdy ) CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )          
    288       ! 
    289       ! ---------------------------------- ! 
    290       ! 4 - initial conservation variables ! 
    291       ! ---------------------------------- ! 
    292       CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files 
    293       ! 
    294    END SUBROUTINE dia_hsb_init 
    295227 
    296228   SUBROUTINE dia_hsb_rst( kt, cdrw ) 
     
    305237     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag 
    306238     ! 
    307      INTEGER ::   jk,ji,jj   !  
    308      INTEGER ::   id1   ! local integers 
     239     INTEGER ::   ji, jj, jk   ! dummy loop indices 
     240     INTEGER ::   id1          ! local integers 
    309241     !!---------------------------------------------------------------------- 
    310242     ! 
     
    341273             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content 
    342274          END DO 
    343           frc_v = 0.d0                                           ! volume       trend due to forcing 
    344           frc_t = 0.d0                                           ! heat content   -    -   -    -    
    345           frc_s = 0.d0                                           ! salt content   -    -   -    -         
     275          frc_v = 0._wp                                           ! volume       trend due to forcing 
     276          frc_t = 0._wp                                           ! heat content   -    -   -    -    
     277          frc_s = 0._wp                                           ! salt content   -    -   -    -         
    346278          IF( .NOT. lk_vvl ) THEN 
    347279             DO ji=1,jpi 
     
    351283                ENDDO 
    352284             ENDDO 
    353              frc_wn_t = 0.d0                                       ! initial heat content misfit due to free surface 
    354              frc_wn_s = 0.d0                                       ! initial salt content misfit due to free surface 
     285             frc_wn_t = 0._wp                                       ! initial heat content misfit due to free surface 
     286             frc_wn_s = 0._wp                                       ! initial salt content misfit due to free surface 
    355287          ENDIF 
    356288       ENDIF 
     
    382314   END SUBROUTINE dia_hsb_rst 
    383315 
     316 
     317   SUBROUTINE dia_hsb_init 
     318      !!--------------------------------------------------------------------------- 
     319      !!                  ***  ROUTINE dia_hsb  *** 
     320      !!      
     321      !! ** Purpose: Initialization for the heat salt volume budgets 
     322      !!  
     323      !! ** Method : Compute initial heat content, salt content and volume 
     324      !! 
     325      !! ** Action : - Compute initial heat content, salt content and volume 
     326      !!             - Initialize forcing trends 
     327      !!             - Compute coefficients for conversion 
     328      !!--------------------------------------------------------------------------- 
     329      INTEGER ::   jk       ! dummy loop indice 
     330      INTEGER ::   ierror   ! local integer 
     331      INTEGER ::   ios 
     332      ! 
     333      NAMELIST/namhsb/ ln_diahsb 
     334      !!---------------------------------------------------------------------- 
     335 
     336      IF(lwp) THEN 
     337         WRITE(numout,*) 
     338         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets' 
     339         WRITE(numout,*) '~~~~~~~~ ' 
     340      ENDIF 
     341 
     342      REWIND( numnam_ref )              ! Namelist namhsb in reference namelist 
     343      READ  ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901) 
     344901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in reference namelist', lwp ) 
     345 
     346      REWIND( numnam_cfg )              ! Namelist namhsb in configuration namelist 
     347      READ  ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 ) 
     348902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in configuration namelist', lwp ) 
     349      IF(lwm) WRITE ( numond, namhsb ) 
     350 
     351      ! 
     352      IF(lwp) THEN                   ! Control print 
     353         WRITE(numout,*) 
     354         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets' 
     355         WRITE(numout,*) '~~~~~~~~~~~~' 
     356         WRITE(numout,*) '   Namelist namhsb : set hsb parameters' 
     357         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb 
     358         WRITE(numout,*) 
     359      ENDIF 
     360 
     361      IF( .NOT. ln_diahsb )   RETURN 
     362         !      IF( .NOT. lk_mpp_rep ) & 
     363         !        CALL ctl_stop (' Your global mpp_sum if performed in single precision - 64 bits -', & 
     364         !             &         ' whereas the global sum to be precise must be done in double precision ',& 
     365         !             &         ' please add key_mpp_rep') 
     366 
     367      ! ------------------- ! 
     368      ! 1 - Allocate memory ! 
     369      ! ------------------- ! 
     370      ALLOCATE( hc_loc_ini(jpi,jpj,jpk), sc_loc_ini(jpi,jpj,jpk), & 
     371         &      e3t_ini(jpi,jpj,jpk), surf(jpi,jpj),  ssh_ini(jpi,jpj), STAT=ierror ) 
     372      IF( ierror > 0 ) THEN 
     373         CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN 
     374      ENDIF 
     375 
     376      IF(.NOT. lk_vvl ) ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror ) 
     377      IF( ierror > 0 ) THEN 
     378         CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN 
     379      ENDIF 
     380 
     381      ! ----------------------------------------------- ! 
     382      ! 2 - Time independant variables and file opening ! 
     383      ! ----------------------------------------------- ! 
     384      IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated" 
     385      IF(lwp) WRITE(numout,*) '~~~~~~~' 
     386      surf(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)      ! masked surface grid cell area 
     387      surf_tot  = glob_sum( surf(:,:) )                                       ! total ocean surface area 
     388 
     389      IF( lk_bdy ) CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )          
     390      ! 
     391      ! ---------------------------------- ! 
     392      ! 4 - initial conservation variables ! 
     393      ! ---------------------------------- ! 
     394      CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files 
     395      ! 
     396   END SUBROUTINE dia_hsb_init 
     397 
    384398   !!====================================================================== 
    385399END MODULE diahsb 
Note: See TracChangeset for help on using the changeset viewer.