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.
cpl_rnf_1d.F90 in branches/UKMO/dev_r5518_GO6_fix_zemp_ice_10681/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/dev_r5518_GO6_fix_zemp_ice_10681/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_rnf_1d.F90 @ 13298

Last change on this file since 13298 was 13298, checked in by dancopsey, 2 years ago

Improve error message when there is a zero river area for one of the rivers.

File size: 8.8 KB
Line 
1MODULE cpl_rnf_1d
2   !!======================================================================
3   !!                       ***  MODULE  cpl_rnf_1d  ***
4   !! Ocean forcing:  River runoff passed from the atmosphere using
5   !!                 1D array. One value per river.
6   !!=====================================================================
7   !! History : ?.?  ! 2018-01 (D. Copsey) Initial setup
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   cpl_rnf_1d_init : runoffs initialisation
12   !!----------------------------------------------------------------------
13
14#if defined key_oasis3
15   USE mod_oasis                    ! OASIS3-MCT module
16#endif
17   USE timing          ! Timing
18   USE in_out_manager  ! I/O units
19   USE lib_mpp         ! MPP library
20   USE iom
21   USE wrk_nemo        ! Memory allocation
22   USE dom_oce         ! Domain sizes (for grid box area e1e2t)
23   USE sbc_oce         ! Surface boundary condition: ocean fields
24   USE lib_fortran,    ONLY: DDPDD
25   
26   IMPLICIT NONE
27   PRIVATE
28   
29   PUBLIC   cpl_rnf_1d_init     ! routine called in nemo_init
30   PUBLIC   cpl_rnf_1d_to_2d      ! routine called in sbccpl.F90
31   
32   TYPE, PUBLIC ::   RIVERS_DATA     !: Storage for river outflow data
33      INTEGER, POINTER, DIMENSION(:,:)    ::   river_number       !: River outflow number
34      REAL(wp), POINTER, DIMENSION(:)     ::   river_area         ! 1D array listing areas of each river outflow (m2)
35      COMPLEX(wp), POINTER, DIMENSION(:)  ::   river_area_c       ! Comlex version of river_area for use in bit reproducible sums (m2)
36   END TYPE RIVERS_DATA
37   
38   TYPE(RIVERS_DATA), PUBLIC, TARGET :: rivers  !: River data
39   
40   INTEGER, PUBLIC            :: nn_cpl_river   ! Maximum number of rivers being passed through the coupler
41   INTEGER, PUBLIC            :: runoff_id      ! OASIS coupling id used in oasis_get command
42   LOGICAL                    :: ln_print_river_info  ! Diagnostic prints of river coupling information
43   
44CONTAINS
45
46   SUBROUTINE cpl_rnf_1d_init
47      !!----------------------------------------------------------------------
48      !!                    ***  SUBROUTINE cpl_rnf_1d_init  ***
49      !!                     
50      !! ** Purpose : - Read in file for river outflow numbers.
51      !!                Calculate 2D area of river outflow points.
52      !!                Called from nemo_init (nemogcm.F90).
53      !!
54      !!----------------------------------------------------------------------
55      !! namelist variables
56      !!-------------------
57      CHARACTER(len=80)                         ::   file_riv_number             !: Filename for river numbers
58      INTEGER                                   ::   ios                 ! Local integer output status for namelist read
59      INTEGER                                   ::   inum
60      INTEGER                                   ::   ii, jj, rr          !: Loop indices
61      INTEGER                                   ::   max_river
62      REAL(wp), POINTER, DIMENSION(:,:)         ::   river_number        ! 2D array containing the river outflow numbers
63      REAL(wp)                                  ::   min_river_area      ! Mininum river area used for debugging
64      INTEGER                                   ::   min_river_number    ! Number of minimum river area used for debugging
65     
66      NAMELIST/nam_cpl_rnf_1d/file_riv_number, nn_cpl_river, ln_print_river_info
67      !!----------------------------------------------------------------------
68
69      IF( nn_timing == 1 ) CALL timing_start('cpl_rnf_1d_init')
70     
71      IF(lwp) WRITE(numout,*)
72      IF(lwp) WRITE(numout,*) 'cpl_rnf_1d_init : initialization of river runoff coupling'
73      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
74     
75      REWIND(numnam_cfg)
76     
77      ! Read the namelist
78      READ  ( numnam_ref, nam_cpl_rnf_1d, IOSTAT = ios, ERR = 901)
79901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_cpl_rnf_1d in reference namelist', lwp )
80      READ  ( numnam_cfg, nam_cpl_rnf_1d, IOSTAT = ios, ERR = 902 )
81902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_cpl_rnf_1d in configuration namelist', lwp )
82      IF(lwm) WRITE ( numond, nam_cpl_rnf_1d )
83
84      !                                               ! Parameter control and print
85      IF(lwp) WRITE(numout,*) '  '
86      IF(lwp) WRITE(numout,*) '          Namelist nam_cpl_rnf_1d : Coupled runoff using 1D array'
87      IF(lwp) WRITE(numout,*) '             Input file that contains river numbers = ',file_riv_number
88      IF(lwp) WRITE(numout,*) '             Maximum number of rivers to couple = ',nn_cpl_river
89      IF(lwp) WRITE(numout,*) '             Print river information = ',ln_print_river_info
90      IF(lwp) WRITE(numout,*) ' '
91     
92      ! Assign space for river numbers
93      ALLOCATE( rivers%river_number( jpi, jpj ) )
94      CALL wrk_alloc( jpi, jpj, river_number )
95     
96      ! Read the river numbers from netcdf file
97      CALL iom_open (file_riv_number , inum )
98      CALL iom_get  ( inum, jpdom_data, 'river_number', river_number )
99      CALL iom_close( inum )
100     
101      ! Convert from a real array to an integer array
102      max_river=0
103      DO ii = 1, jpi
104        DO jj = 1, jpj
105          rivers%river_number(ii,jj) = INT(river_number(ii,jj))
106          IF ( rivers%river_number(ii,jj) > max_river ) THEN
107            max_river = rivers%river_number(ii,jj)
108          END IF
109        END DO
110      END DO
111     
112      ! Print out the largest river number
113      IF ( ln_print_river_info ) THEN
114         WRITE(numout,*) 'Maximum river number in input file = ',max_river
115      END IF
116     
117      ! Get the area of each river outflow
118      ALLOCATE( rivers%river_area( nn_cpl_river ) )
119      ALLOCATE( rivers%river_area_c( nn_cpl_river ) )
120      rivers%river_area_c(:) = CMPLX( 0.e0, 0.e0, wp )
121      DO ii = 1, jpi     
122        DO jj = 1, jpj
123          IF ( tmask_i(ii,jj) > 0.5 ) THEN  ! This makes sure we are not at a duplicated point (at north fold or east-west cyclic point)
124            IF ( rivers%river_number(ii,jj) > 0 .AND. rivers%river_number(ii,jj) <= nn_cpl_river ) THEN
125              ! Add the area of each grid box (e1e2t) into river_area_c using DDPDD which should maintain bit reproducibility (needs to be checked)
126              CALL DDPDD( CMPLX( e1e2t(ii,jj), 0.e0, wp ), rivers%river_area_c(rivers%river_number(ii,jj) ) )
127            END IF
128          END IF
129        END DO
130      END DO
131     
132      ! Use mpp_sum to add together river areas on other processors
133      CALL mpp_sum( rivers%river_area_c, nn_cpl_river )
134     
135      ! Convert from complex number to real
136      ! DO rr = 1, nn_cpl_river
137      !    rivers%river_area(rr) = rivers%river_area_c(rr)
138      ! END DO
139      rivers%river_area(:) = REAL(rivers%river_area_c(:),wp)
140     
141      IF ( ln_print_river_info ) THEN
142        WRITE(numout,*) 'Area of rivers 1 to 10 are ',rivers%river_area(1:10)
143      END IF
144
145      IF ( MINVAL(rivers%river_area(1:nn_cpl_river)) <= 0 ) THEN
146         min_river_area=9E15
147         min_river_number=0
148         DO rr = 1, nn_cpl_river
149            IF ( rivers%river_area(rr) < min_river_area ) THEN
150               min_river_area = rivers%river_area(rr)
151               min_river_number = rr
152            END IF
153         END DO
154         WRITE(numout,*) 'Minimum river area = ',min_river_area
155         WRITE(numout,*) 'First river number with minimum area = ',min_river_number
156         CALL ctl_stop( 'There is at least one river with a river outflow area of zero. Please check your file_riv_number file that all the allocated river numbers are at ocean points as defined by the bathymetry file.')
157      END IF
158     
159   END SUBROUTINE cpl_rnf_1d_init
160   
161   SUBROUTINE cpl_rnf_1d_to_2d( runoff_1d )
162   
163      !!----------------------------------------------------------------------
164      !!                    ***  SUBROUTINE cpl_rnf_1d_to_2d  ***
165      !!                     
166      !! ** Purpose : - Convert river outflow from 1D array (passed from the
167      !!                atmosphere) to the 2D NEMO runoff field.
168      !!                Called from sbc_cpl_ice_flx (sbccpl.F90).
169      !!
170      !!----------------------------------------------------------------------
171     
172      REAL                   , INTENT(in   ) ::   runoff_1d(nn_cpl_river)    ! River runoff. One value per river.
173     
174      INTEGER  ::   ii, jj                 ! Loop indices
175           
176      ! Convert the 1D total runoff per river to 2D runoff flux by
177      ! dividing by the area of each runoff zone.
178      DO ii = 1, jpi
179        DO jj = 1, jpj
180          IF ( rivers%river_number(ii,jj) > 0 .AND. rivers%river_number(ii,jj) <= nn_cpl_river ) THEN
181            rnf(ii,jj) = runoff_1d(rivers%river_number(ii,jj)) / rivers%river_area(rivers%river_number(ii,jj))
182          ELSE
183            rnf(ii,jj) = 0.0
184          END IF
185           
186        END DO
187      END DO
188
189   END SUBROUTINE cpl_rnf_1d_to_2d
190
191END MODULE cpl_rnf_1d
Note: See TracBrowser for help on using the repository browser.