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 12372 for NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/SBC/fldread.F90 – NEMO

Ignore:
Timestamp:
2020-02-12T13:37:21+01:00 (4 years ago)
Author:
acc
Message:

Branch 2019/dev_r11943_MERGE_2019. A few changes to align the option 1 branch with the trunk@12371. These include a fix for #2317 (changes for LFRA freshwater correction) which was done at changeset 12279 on the trunk. These affect dynatf.F90, traatf.F90 and isfdynatf.F90 and pass SETTE but change results in all tests that use freshwater input (expected). All other changes on the trunk are present (where applicable) up to and including changeset 12367 (Solve #2380)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/SBC/fldread.F90

    r12350 r12372  
    571571 
    572572      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdta_read       ! data read in bdy file 
    573       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdta_read_z     ! depth of the data read in bdy file 
    574       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdta_read_dz    ! thickness of the levels in bdy file 
     573      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdta_read_z     ! depth of the data read in bdy file 
     574      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdta_read_dz    ! thickness of the levels in bdy file 
    575575      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdta            ! output field on model grid (2 dimensional) 
    576576      REAL(wp)                  , INTENT(in   ) ::   pfv             ! fillvalue of the data read in bdy file 
     
    580580      INTEGER, OPTIONAL         , INTENT(in   ) ::   Kmm             ! ocean time level index 
    581581      !! 
    582       INTEGER                                   ::   ipi             ! length of boundary data on local process 
    583       INTEGER                                   ::   ipkb            ! number of vertical levels in boundary data file 
    584       INTEGER                                   ::   jb, ji, jj, jk, jkb   ! loop counters 
    585       REAL(wp)                                  ::   zcoef 
    586       REAL(wp)                                  ::   zl, zi, zh      ! tmp variable for current depth and interpolation factor 
    587       REAL(wp)                                  ::   zfv_alt, ztrans, ztrans_new ! fillvalue and alternative -ABS(pfv) 
    588       REAL(wp), DIMENSION(jpk)                  ::   zdepth, zdhalf  ! level and half-level depth 
     582      INTEGER                  ::   ipi                 ! length of boundary data on local process 
     583      INTEGER                  ::   ipkb                ! number of vertical levels in boundary data file 
     584      INTEGER                  ::   ipkmax              ! number of vertical levels in boundary data file where no mask 
     585      INTEGER                  ::   jb, ji, jj, jk, jkb ! loop counters 
     586      REAL(wp)                 ::   zcoef, zi           !  
     587      REAL(wp)                 ::   ztrans, ztrans_new  ! transports 
     588      REAL(wp), DIMENSION(jpk) ::   zdepth, zdhalf      ! level and half-level depth 
    589589      !!--------------------------------------------------------------------- 
    590590      
     
    592592      ipkb = SIZE( pdta_read, 3 ) 
    593593       
    594       zfv_alt = -ABS(pfv)  ! set _FillValue < 0 as we make use of MAXVAL and MAXLOC later 
    595       ! 
    596       WHERE( pdta_read == pfv ) 
    597          pdta_read_z  = zfv_alt ! safety: put fillvalue into external depth field so consistent with data 
    598          pdta_read_dz = 0._wp   ! safety: put 0._wp into external thickness factors to ensure transport is correct 
    599       ENDWHERE 
    600        
    601594      DO jb = 1, ipi 
    602595         ji = idx_bdy(kbdy)%nbi(jb,kgrd) 
    603596         jj = idx_bdy(kbdy)%nbj(jb,kgrd) 
    604          zh  = SUM(pdta_read_dz(jb,1,:) ) 
    605          ! 
     597         ! 
     598         ! --- max jk where input data /= FillValue --- ! 
     599         ipkmax = 1 
     600         DO jkb = 2, ipkb 
     601            IF( pdta_read(jb,1,jkb) /= pfv )   ipkmax = MAX( ipkmax, jkb ) 
     602         END DO 
     603         ! 
     604         ! --- calculate depth at t,u,v points --- ! 
    606605         SELECT CASE( kgrd )                          
    607          CASE(1) 
    608             ! depth of T points: 
     606         CASE(1)            ! depth of T points: 
    609607            zdepth(:) = gdept(ji,jj,:,Kmm) 
    610          CASE(2) 
    611             ! depth of U points: we must not use gdept_n as we don't want to do a communication 
    612             !   --> copy what is done for gdept_n in domvvl... 
     608         CASE(2)            ! depth of U points: we must not use gdept_n as we don't want to do a communication 
     609            !                 --> copy what is done for gdept_n in domvvl... 
    613610            zdhalf(1) = 0.0_wp 
    614611            zdepth(1) = 0.5_wp * e3uw(ji,jj,1,Kmm) 
     
    620617               zcoef = ( umask(ji,jj,jk) - wumask(ji,jj,jk) ) 
    621618               zdhalf(jk) = zdhalf(jk-1) + e3u(ji,jj,jk-1,Kmm) 
    622                zdepth(jk) =      zcoef  * ( zdhalf(jk  ) + 0.5 * e3uw(ji,jj,jk,Kmm))  & 
    623                   &         + (1-zcoef) * ( zdepth(jk-1) + e3uw(ji,jj,jk,Kmm)) 
     619               zdepth(jk) =          zcoef  * ( zdhalf(jk  ) + 0.5_wp * e3uw(ji,jj,jk,Kmm))  & 
     620                  &         + (1._wp-zcoef) * ( zdepth(jk-1) +          e3uw(ji,jj,jk,Kmm)) 
    624621            END DO 
    625          CASE(3) 
    626             ! depth of V points: we must not use gdept_n as we don't want to do a communication 
    627             !   --> copy what is done for gdept_n in domvvl... 
     622         CASE(3)            ! depth of V points: we must not use gdept_n as we don't want to do a communication 
     623            !                 --> copy what is done for gdept_n in domvvl... 
    628624            zdhalf(1) = 0.0_wp 
    629625            zdepth(1) = 0.5_wp * e3vw(ji,jj,1,Kmm) 
     
    635631               zcoef = ( vmask(ji,jj,jk) - wvmask(ji,jj,jk) ) 
    636632               zdhalf(jk) = zdhalf(jk-1) + e3v(ji,jj,jk-1,Kmm) 
    637                zdepth(jk) =      zcoef  * ( zdhalf(jk  ) + 0.5 * e3vw(ji,jj,jk,Kmm))  & 
    638                   &         + (1-zcoef) * ( zdepth(jk-1) + e3vw(ji,jj,jk,Kmm)) 
     633               zdepth(jk) =          zcoef  * ( zdhalf(jk  ) + 0.5_wp * e3vw(ji,jj,jk,Kmm))  & 
     634                  &         + (1._wp-zcoef) * ( zdepth(jk-1) +          e3vw(ji,jj,jk,Kmm)) 
    639635            END DO 
    640636         END SELECT 
    641          ! 
    642          DO jk = 1, jpk                       
    643             IF(     zdepth(jk) < pdta_read_z(jb,1,          1) ) THEN                ! above the first level of external data 
    644                pdta(jb,1,jk) =  pdta_read(jb,1,1) 
    645             ELSEIF( zdepth(jk) > pdta_read_z(jb,1,ipkb) ) THEN                       ! below the last level of external data  
    646                pdta(jb,1,jk) =  pdta_read(jb,1,MAXLOC(pdta_read_z(jb,1,:),1)) 
    647             ELSE                                                             ! inbetween: vertical interpolation between jkb & jkb+1 
    648                DO jkb = 1, ipkb-1                                            ! when  gdept_n(jkb) < zdepth(jk) < gdept_n(jkb+1) 
    649                   IF( ( ( zdepth(jk) - pdta_read_z(jb,1,jkb) ) * ( zdepth(jk) - pdta_read_z(jb,1,jkb+1) ) <= 0._wp ) & 
    650                      &    .AND. ( pdta_read_z(jb,1,jkb+1) /= zfv_alt) ) THEN  ! linear interpolation between 2 levels 
     637         !          
     638         ! --- interpolate bdy data on the model grid --- ! 
     639         DO jk = 1, jpk 
     640            IF(     zdepth(jk) <= pdta_read_z(jb,1,1)      ) THEN   ! above the first level of external data 
     641               pdta(jb,1,jk) = pdta_read(jb,1,1) 
     642            ELSEIF( zdepth(jk) >  pdta_read_z(jb,1,ipkmax) ) THEN   ! below the last level of external data /= FillValue 
     643               pdta(jb,1,jk) = pdta_read(jb,1,ipkmax) 
     644            ELSE                                                    ! inbetween: vertical interpolation between jkb & jkb+1 
     645               DO jkb = 1, ipkmax-1 
     646                  IF( ( ( zdepth(jk) - pdta_read_z(jb,1,jkb) ) * ( zdepth(jk) - pdta_read_z(jb,1,jkb+1) ) ) <= 0._wp ) THEN ! linear interpolation between 2 levels 
    651647                     zi = ( zdepth(jk) - pdta_read_z(jb,1,jkb) ) / ( pdta_read_z(jb,1,jkb+1) - pdta_read_z(jb,1,jkb) ) 
    652                      pdta(jb,1,jk) = pdta_read(jb,1,jkb) + ( pdta_read  (jb,1,jkb+1) - pdta_read  (jb,1,jkb) ) * zi 
     648                     pdta(jb,1,jk) = pdta_read(jb,1,jkb) + zi * ( pdta_read(jb,1,jkb+1) - pdta_read(jb,1,jkb) ) 
    653649                  ENDIF 
    654650               END DO 
     
    657653         ! 
    658654      END DO   ! ipi 
    659        
    660       IF(kgrd == 2) THEN                                  ! do we need to adjust the transport term? 
     655 
     656      ! --- mask data and adjust transport --- ! 
     657      SELECT CASE( kgrd )                          
     658 
     659      CASE(1)                                 ! mask data (probably unecessary) 
    661660         DO jb = 1, ipi 
    662661            ji = idx_bdy(kbdy)%nbi(jb,kgrd) 
    663662            jj = idx_bdy(kbdy)%nbj(jb,kgrd) 
    664             zh  = SUM(pdta_read_dz(jb,1,:) ) 
     663            DO jk = 1, jpk                       
     664               pdta(jb,1,jk) = pdta(jb,1,jk) * tmask(ji,jj,jk) 
     665            END DO 
     666         END DO 
     667          
     668      CASE(2)                                 ! adjust the U-transport term 
     669         DO jb = 1, ipi 
     670            ji = idx_bdy(kbdy)%nbi(jb,kgrd) 
     671            jj = idx_bdy(kbdy)%nbj(jb,kgrd) 
    665672            ztrans = 0._wp 
     673            DO jkb = 1, ipkb                              ! calculate transport on input grid 
     674               IF( pdta_read(jb,1,jkb) /= pfv )   ztrans = ztrans + pdta_read(jb,1,jkb) * pdta_read_dz(jb,1,jkb) 
     675            ENDDO 
    666676            ztrans_new = 0._wp 
    667             DO jkb = 1, ipkb                              ! calculate transport on input grid 
    668                ztrans     = ztrans     + pdta_read(jb,1,jkb) * pdta_read_dz(jb, 1,jkb) 
    669             ENDDO 
    670677            DO jk = 1, jpk                                ! calculate transport on model grid 
    671678               ztrans_new = ztrans_new +      pdta(jb,1,jk ) * e3u(ji,jj,jk,Kmm ) * umask(ji,jj,jk) 
     
    674681               IF(ldtotvel) THEN ! bdy data are total velocity so adjust bt transport term to match input data 
    675682                  pdta(jb,1,jk) = ( pdta(jb,1,jk) + ( ztrans - ztrans_new ) * r1_hu(ji,jj,Kmm) ) * umask(ji,jj,jk) 
    676                ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero 
     683               ELSE              ! we're just dealing with bc velocity so bt transport term should sum to zero 
    677684                  pdta(jb,1,jk) =   pdta(jb,1,jk) + (  0._wp - ztrans_new ) * r1_hu(ji,jj,Kmm)   * umask(ji,jj,jk) 
    678685               ENDIF 
    679686            ENDDO 
    680687         ENDDO 
    681       ENDIF 
    682        
    683       IF(kgrd == 3) THEN                                  ! do we need to adjust the transport term? 
     688 
     689      CASE(3)                                 ! adjust the V-transport term 
    684690         DO jb = 1, ipi 
    685691            ji = idx_bdy(kbdy)%nbi(jb,kgrd) 
    686692            jj = idx_bdy(kbdy)%nbj(jb,kgrd) 
    687             zh  = SUM(pdta_read_dz(jb,1,:) ) 
    688693            ztrans = 0._wp 
     694            DO jkb = 1, ipkb                              ! calculate transport on input grid 
     695               IF( pdta_read(jb,1,jkb) /= pfv )   ztrans = ztrans + pdta_read(jb,1,jkb) * pdta_read_dz(jb,1,jkb) 
     696            ENDDO 
    689697            ztrans_new = 0._wp 
    690             DO jkb = 1, ipkb                              ! calculate transport on input grid 
    691                ztrans     = ztrans     + pdta_read(jb,1,jkb) * pdta_read_dz(jb, 1,jkb) 
    692             ENDDO 
    693698            DO jk = 1, jpk                                ! calculate transport on model grid 
    694                ztrans_new = ztrans_new +      pdta(jb,1,jk ) *        e3v(ji,jj,jk,Kmm ) * vmask(ji,jj,jk) 
     699               ztrans_new = ztrans_new +      pdta(jb,1,jk ) * e3v(ji,jj,jk,Kmm ) * vmask(ji,jj,jk) 
    695700            ENDDO 
    696701            DO jk = 1, jpk                                ! make transport correction 
    697702               IF(ldtotvel) THEN ! bdy data are total velocity so adjust bt transport term to match input data 
    698703                  pdta(jb,1,jk) = ( pdta(jb,1,jk) + ( ztrans - ztrans_new ) * r1_hv(ji,jj,Kmm) ) * vmask(ji,jj,jk) 
    699                ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero 
     704               ELSE              ! we're just dealing with bc velocity so bt transport term should sum to zero 
    700705                  pdta(jb,1,jk) =   pdta(jb,1,jk) + (  0._wp - ztrans_new ) * r1_hv(ji,jj,Kmm)   * vmask(ji,jj,jk) 
    701706               ENDIF 
    702707            ENDDO 
    703708         ENDDO 
    704       ENDIF 
     709      END SELECT 
    705710       
    706711   END SUBROUTINE fld_bdy_interp 
Note: See TracChangeset for help on using the changeset viewer.