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.
dtatsd.F90 in NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DOM – NEMO

source: NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DOM/dtatsd.F90 @ 13700

Last change on this file since 13700 was 12340, checked in by acc, 4 years ago

Branch 2019/dev_r11943_MERGE_2019. This commit introduces basic do loop macro
substitution to the 2019 option 1, merge branch. These changes have been SETTE
tested. The only addition is the do_loop_substitute.h90 file in the OCE directory but
the macros defined therein are used throughout the code to replace identifiable, 2D-
and 3D- nested loop opening and closing statements with single-line alternatives. Code
indents are also adjusted accordingly.

The following explanation is taken from comments in the new header file:

This header file contains preprocessor definitions and macros used in the do-loop
substitutions introduced between version 4.0 and 4.2. The primary aim of these macros
is to assist in future applications of tiling to improve performance. This is expected
to be achieved by alternative versions of these macros in selected locations. The
initial introduction of these macros simply replaces all identifiable nested 2D- and
3D-loops with single line statements (and adjusts indenting accordingly). Do loops
are identifiable if they comform to either:

DO jk = ....

DO jj = .... DO jj = ...

DO ji = .... DO ji = ...
. OR .
. .

END DO END DO

END DO END DO

END DO

and white-space variants thereof.

Additionally, only loops with recognised jj and ji loops limits are treated; these are:
Lower limits of 1, 2 or fs_2
Upper limits of jpi, jpim1 or fs_jpim1 (for ji) or jpj, jpjm1 or fs_jpjm1 (for jj)

The macro naming convention takes the form: DO_2D_BT_LR where:

B is the Bottom offset from the PE's inner domain;
T is the Top offset from the PE's inner domain;
L is the Left offset from the PE's inner domain;
R is the Right offset from the PE's inner domain

So, given an inner domain of 2,jpim1 and 2,jpjm1, a typical example would replace:

DO jj = 2, jpj

DO ji = 1, jpim1
.
.

END DO

END DO

with:

DO_2D_01_10
.
.
END_2D

similar conventions apply to the 3D loops macros. jk loop limits are retained
through macro arguments and are not restricted. This includes the possibility of
strides for which an extra set of DO_3DS macros are defined.

In the example definition below the inner PE domain is defined by start indices of
(kIs, kJs) and end indices of (kIe, KJe)

#define DO_2D_00_00 DO jj = kJs, kJe ; DO ji = kIs, kIe
#define END_2D END DO ; END DO

TO DO:


Only conventional nested loops have been identified and replaced by this step. There are constructs such as:

DO jk = 2, jpkm1

z2d(:,:) = z2d(:,:) + e3w(:,:,jk,Kmm) * z3d(:,:,jk) * wmask(:,:,jk)

END DO

which may need to be considered.

  • Property svn:keywords set to Id
File size: 13.0 KB
Line 
1MODULE dtatsd
2   !!======================================================================
3   !!                     ***  MODULE  dtatsd  ***
4   !! Ocean data  :  read ocean Temperature & Salinity Data from gridded data
5   !!======================================================================
6   !! History :  OPA  ! 1991-03  ()  Original code
7   !!             -   ! 1992-07  (M. Imbard)
8   !!            8.0  ! 1999-10  (M.A. Foujols, M. Imbard)  NetCDF FORMAT
9   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
10   !!            3.3  ! 2010-10  (C. Bricaud, S. Masson)  use of fldread
11   !!            3.4  ! 2010-11  (G. Madec, C. Ethe) Merge of dtatem and dtasal + remove CPP keys
12   !!----------------------------------------------------------------------
13
14   !!----------------------------------------------------------------------
15   !!   dta_tsd      : read and time interpolated ocean Temperature & Salinity Data
16   !!----------------------------------------------------------------------
17   USE oce             ! ocean dynamics and tracers
18   USE phycst          ! physical constants
19   USE dom_oce         ! ocean space and time domain
20   USE fldread         ! read input fields
21   !
22   USE in_out_manager  ! I/O manager
23   USE lib_mpp         ! MPP library
24
25   IMPLICIT NONE
26   PRIVATE
27
28   PUBLIC   dta_tsd_init   ! called by opa.F90
29   PUBLIC   dta_tsd        ! called by istate.F90 and tradmp.90
30
31   !                                  !!* namtsd  namelist : Temperature & Salinity Data *
32   LOGICAL , PUBLIC ::   ln_tsd_init   !: T & S data flag
33   LOGICAL , PUBLIC ::   ln_tsd_dmp    !: internal damping toward input data flag
34
35   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_tsd   ! structure of input SST (file informations, fields read)
36
37   !! * Substitutions
38#  include "do_loop_substitute.h90"
39   !!----------------------------------------------------------------------
40   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
41   !! $Id$
42   !! Software governed by the CeCILL license (see ./LICENSE)
43   !!----------------------------------------------------------------------
44CONTAINS
45
46   SUBROUTINE dta_tsd_init( ld_tradmp )
47      !!----------------------------------------------------------------------
48      !!                   ***  ROUTINE dta_tsd_init  ***
49      !!                   
50      !! ** Purpose :   initialisation of T & S input data
51      !!
52      !! ** Method  : - Read namtsd namelist
53      !!              - allocates T & S data structure
54      !!----------------------------------------------------------------------
55      LOGICAL, INTENT(in), OPTIONAL ::   ld_tradmp   ! force the initialization when tradp is used
56      !
57      INTEGER ::   ios, ierr0, ierr1, ierr2, ierr3   ! local integers
58      !!
59      CHARACTER(len=100)            ::   cn_dir          ! Root directory for location of ssr files
60      TYPE(FLD_N), DIMENSION( jpts) ::   slf_i           ! array of namelist informations on the fields to read
61      TYPE(FLD_N)                   ::   sn_tem, sn_sal
62      !!
63      NAMELIST/namtsd/   ln_tsd_init, ln_tsd_dmp, cn_dir, sn_tem, sn_sal
64      !!----------------------------------------------------------------------
65      !
66      !  Initialisation
67      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0
68      !
69      READ  ( numnam_ref, namtsd, IOSTAT = ios, ERR = 901)
70901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtsd in reference namelist' )
71      READ  ( numnam_cfg, namtsd, IOSTAT = ios, ERR = 902 )
72902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtsd in configuration namelist' )
73      IF(lwm) WRITE ( numond, namtsd )
74
75      IF( PRESENT( ld_tradmp ) )   ln_tsd_dmp = .TRUE.     ! forces the initialization when tradmp is used
76     
77      IF(lwp) THEN                  ! control print
78         WRITE(numout,*)
79         WRITE(numout,*) 'dta_tsd_init : Temperature & Salinity data '
80         WRITE(numout,*) '~~~~~~~~~~~~ '
81         WRITE(numout,*) '   Namelist namtsd'
82         WRITE(numout,*) '      Initialisation of ocean T & S with T &S input data   ln_tsd_init = ', ln_tsd_init
83         WRITE(numout,*) '      damping of ocean T & S toward T &S input data        ln_tsd_dmp  = ', ln_tsd_dmp
84         WRITE(numout,*)
85         IF( .NOT.ln_tsd_init .AND. .NOT.ln_tsd_dmp ) THEN
86            WRITE(numout,*)
87            WRITE(numout,*) '   ===>>   T & S data not used'
88         ENDIF
89      ENDIF
90      !
91      IF( ln_rstart .AND. ln_tsd_init ) THEN
92         CALL ctl_warn( 'dta_tsd_init: ocean restart and T & S data intialisation, ',   &
93            &           'we keep the restart T & S values and set ln_tsd_init to FALSE' )
94         ln_tsd_init = .FALSE.
95      ENDIF
96      !
97      !                             ! allocate the arrays (if necessary)
98      IF( ln_tsd_init .OR. ln_tsd_dmp ) THEN
99         !
100         ALLOCATE( sf_tsd(jpts), STAT=ierr0 )
101         IF( ierr0 > 0 ) THEN
102            CALL ctl_stop( 'dta_tsd_init: unable to allocate sf_tsd structure' )   ;   RETURN
103         ENDIF
104         !
105                                ALLOCATE( sf_tsd(jp_tem)%fnow(jpi,jpj,jpk)   , STAT=ierr0 )
106         IF( sn_tem%ln_tint )   ALLOCATE( sf_tsd(jp_tem)%fdta(jpi,jpj,jpk,2) , STAT=ierr1 )
107                                ALLOCATE( sf_tsd(jp_sal)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
108         IF( sn_sal%ln_tint )   ALLOCATE( sf_tsd(jp_sal)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
109         !
110         IF( ierr0 + ierr1 + ierr2 + ierr3 > 0 ) THEN
111            CALL ctl_stop( 'dta_tsd : unable to allocate T & S data arrays' )   ;   RETURN
112         ENDIF
113         !                         ! fill sf_tsd with sn_tem & sn_sal and control print
114         slf_i(jp_tem) = sn_tem   ;   slf_i(jp_sal) = sn_sal
115         CALL fld_fill( sf_tsd, slf_i, cn_dir, 'dta_tsd', 'Temperature & Salinity data', 'namtsd', no_print )
116         !
117      ENDIF
118      !
119   END SUBROUTINE dta_tsd_init
120
121
122   SUBROUTINE dta_tsd( kt, ptsd )
123      !!----------------------------------------------------------------------
124      !!                   ***  ROUTINE dta_tsd  ***
125      !!                   
126      !! ** Purpose :   provides T and S data at kt
127      !!
128      !! ** Method  : - call fldread routine
129      !!              - ORCA_R2: add some hand made alteration to read data 
130      !!              - 'key_orca_lev10' interpolates on 10 times more levels
131      !!              - s- or mixed z-s coordinate: vertical interpolation on model mesh
132      !!              - ln_tsd_dmp=F: deallocates the T-S data structure
133      !!                as T-S data are no are used
134      !!
135      !! ** Action  :   ptsd   T-S data on medl mesh and interpolated at time-step kt
136      !!----------------------------------------------------------------------
137      INTEGER                              , INTENT(in   ) ::   kt     ! ocean time-step
138      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(  out) ::   ptsd   ! T & S data
139      !
140      INTEGER ::   ji, jj, jk, jl, jkk   ! dummy loop indicies
141      INTEGER ::   ik, il0, il1, ii0, ii1, ij0, ij1   ! local integers
142      REAL(wp)::   zl, zi                             ! local scalars
143      REAL(wp), DIMENSION(jpk) ::  ztp, zsp   ! 1D workspace
144      !!----------------------------------------------------------------------
145      !
146      CALL fld_read( kt, 1, sf_tsd )      !==   read T & S data at kt time step   ==!
147      !
148      !
149!!gm  This should be removed from the code   ===>>>>  T & S files has to be changed
150      !
151      !                                   !==   ORCA_R2 configuration and T & S damping   ==!
152      IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
153         IF( nn_cfg == 2 .AND. ln_tsd_dmp ) THEN    ! some hand made alterations
154            !
155            ij0 = 101   ;   ij1 = 109                       ! Reduced T & S in the Alboran Sea
156            ii0 = 141   ;   ii1 = 155
157            DO jj = mj0(ij0), mj1(ij1)
158               DO ji = mi0(ii0), mi1(ii1)
159                  sf_tsd(jp_tem)%fnow(ji,jj,13:13) = sf_tsd(jp_tem)%fnow(ji,jj,13:13) - 0.20_wp
160                  sf_tsd(jp_tem)%fnow(ji,jj,14:15) = sf_tsd(jp_tem)%fnow(ji,jj,14:15) - 0.35_wp
161                  sf_tsd(jp_tem)%fnow(ji,jj,16:25) = sf_tsd(jp_tem)%fnow(ji,jj,16:25) - 0.40_wp
162                  !
163                  sf_tsd(jp_sal)%fnow(ji,jj,13:13) = sf_tsd(jp_sal)%fnow(ji,jj,13:13) - 0.15_wp
164                  sf_tsd(jp_sal)%fnow(ji,jj,14:15) = sf_tsd(jp_sal)%fnow(ji,jj,14:15) - 0.25_wp
165                  sf_tsd(jp_sal)%fnow(ji,jj,16:17) = sf_tsd(jp_sal)%fnow(ji,jj,16:17) - 0.30_wp
166                  sf_tsd(jp_sal)%fnow(ji,jj,18:25) = sf_tsd(jp_sal)%fnow(ji,jj,18:25) - 0.35_wp
167               END DO
168            END DO
169            ij0 =  87   ;   ij1 =  96                          ! Reduced temperature in Red Sea
170            ii0 = 148   ;   ii1 = 160
171            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 ) = 7.0_wp
172            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 ) = 6.5_wp
173            sf_tsd(jp_tem)%fnow( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 ) = 6.0_wp
174         ENDIF
175      ENDIF
176!!gm end
177      !
178      ptsd(:,:,:,jp_tem) = sf_tsd(jp_tem)%fnow(:,:,:)    ! NO mask
179      ptsd(:,:,:,jp_sal) = sf_tsd(jp_sal)%fnow(:,:,:) 
180      !
181      IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
182         !
183         IF( kt == nit000 .AND. lwp )THEN
184            WRITE(numout,*)
185            WRITE(numout,*) 'dta_tsd: interpolates T & S data onto the s- or mixed s-z-coordinate mesh'
186         ENDIF
187         !
188         DO_2D_11_11
189            DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
190               zl = gdept_0(ji,jj,jk)
191               IF(     zl < gdept_1d(1  ) ) THEN          ! above the first level of data
192                  ztp(jk) =  ptsd(ji,jj,1    ,jp_tem)
193                  zsp(jk) =  ptsd(ji,jj,1    ,jp_sal)
194               ELSEIF( zl > gdept_1d(jpk) ) THEN          ! below the last level of data
195                  ztp(jk) =  ptsd(ji,jj,jpkm1,jp_tem)
196                  zsp(jk) =  ptsd(ji,jj,jpkm1,jp_sal)
197               ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
198                  DO jkk = 1, jpkm1                                  ! when  gdept(jkk) < zl < gdept(jkk+1)
199                     IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
200                        zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
201                        ztp(jk) = ptsd(ji,jj,jkk,jp_tem) + ( ptsd(ji,jj,jkk+1,jp_tem) - ptsd(ji,jj,jkk,jp_tem) ) * zi 
202                        zsp(jk) = ptsd(ji,jj,jkk,jp_sal) + ( ptsd(ji,jj,jkk+1,jp_sal) - ptsd(ji,jj,jkk,jp_sal) ) * zi
203                     ENDIF
204                  END DO
205               ENDIF
206            END DO
207            DO jk = 1, jpkm1
208               ptsd(ji,jj,jk,jp_tem) = ztp(jk) * tmask(ji,jj,jk)     ! mask required for mixed zps-s-coord
209               ptsd(ji,jj,jk,jp_sal) = zsp(jk) * tmask(ji,jj,jk)
210            END DO
211            ptsd(ji,jj,jpk,jp_tem) = 0._wp
212            ptsd(ji,jj,jpk,jp_sal) = 0._wp
213         END_2D
214         !
215      ELSE                                !==   z- or zps- coordinate   ==!
216         !                             
217         ptsd(:,:,:,jp_tem) = ptsd(:,:,:,jp_tem) * tmask(:,:,:)    ! Mask
218         ptsd(:,:,:,jp_sal) = ptsd(:,:,:,jp_sal) * tmask(:,:,:)
219         !
220         IF( ln_zps ) THEN                      ! zps-coordinate (partial steps) interpolation at the last ocean level
221            DO_2D_11_11
222               ik = mbkt(ji,jj) 
223               IF( ik > 1 ) THEN
224                  zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
225                  ptsd(ji,jj,ik,jp_tem) = (1.-zl) * ptsd(ji,jj,ik,jp_tem) + zl * ptsd(ji,jj,ik-1,jp_tem)
226                  ptsd(ji,jj,ik,jp_sal) = (1.-zl) * ptsd(ji,jj,ik,jp_sal) + zl * ptsd(ji,jj,ik-1,jp_sal)
227               ENDIF
228               ik = mikt(ji,jj)
229               IF( ik > 1 ) THEN
230                  zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) ) 
231                  ptsd(ji,jj,ik,jp_tem) = (1.-zl) * ptsd(ji,jj,ik,jp_tem) + zl * ptsd(ji,jj,ik+1,jp_tem)
232                  ptsd(ji,jj,ik,jp_sal) = (1.-zl) * ptsd(ji,jj,ik,jp_sal) + zl * ptsd(ji,jj,ik+1,jp_sal)
233               END IF
234            END_2D
235         ENDIF
236         !
237      ENDIF
238      !
239      IF( .NOT.ln_tsd_dmp ) THEN                   !==   deallocate T & S structure   ==!
240         !                                              (data used only for initialisation)
241         IF(lwp) WRITE(numout,*) 'dta_tsd: deallocte T & S arrays as they are only use to initialize the run'
242                                        DEALLOCATE( sf_tsd(jp_tem)%fnow )     ! T arrays in the structure
243         IF( sf_tsd(jp_tem)%ln_tint )   DEALLOCATE( sf_tsd(jp_tem)%fdta )
244                                        DEALLOCATE( sf_tsd(jp_sal)%fnow )     ! S arrays in the structure
245         IF( sf_tsd(jp_sal)%ln_tint )   DEALLOCATE( sf_tsd(jp_sal)%fdta )
246                                        DEALLOCATE( sf_tsd              )     ! the structure itself
247      ENDIF
248      !
249   END SUBROUTINE dta_tsd
250
251   !!======================================================================
252END MODULE dtatsd
Note: See TracBrowser for help on using the repository browser.