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.
isfutils.F90 in NEMO/branches/2019/ENHANCE-02_ISF_nemo/src/OCE/ISF – NEMO

source: NEMO/branches/2019/ENHANCE-02_ISF_nemo/src/OCE/ISF/isfutils.F90 @ 12062

Last change on this file since 12062 was 12062, checked in by mathiot, 4 years ago

changes required by N.J. review

File size: 5.8 KB
Line 
1MODULE isfutils
2   !!======================================================================
3   !!                       ***  MODULE  isfutils  ***
4   !! istutils module : miscelenious useful routines
5   !!======================================================================
6   !! History :  4.1  !  2019-09  (P. Mathiot) original code
7   !!----------------------------------------------------------------------
8
9   !!----------------------------------------------------------------------
10   !!   isfutils       : - read_2dcstdta to read a constant input file with iom_get
11   !!                    - debug to print array sum, min, max in ocean.output
12   !!----------------------------------------------------------------------
13
14   USE iom           , ONLY: iom_open, iom_get, iom_close, jpdom_data ! read input file
15   USE lib_fortran   , ONLY: glob_sum, glob_min, glob_max             ! compute global value
16   USE par_oce       , ONLY: jpi,jpj,jpk                              ! domain size
17   USE dom_oce       , ONLY: nldi, nlei, nldj, nlej                   ! local domain
18   USE in_out_manager, ONLY: i8, wp, lwp, numout                          ! miscelenious
19   USE lib_mpp
20
21   IMPLICIT NONE
22
23   PRIVATE
24
25   INTERFACE debug
26      MODULE PROCEDURE debug2d, debug3d
27   END INTERFACE debug
28
29   PUBLIC read_2dcstdta, debug
30
31CONTAINS
32
33   SUBROUTINE read_2dcstdta(cdfile, cdvar, pvar)
34      !!--------------------------------------------------------------------
35      !!                  ***  ROUTINE read_2dcstdta  ***
36      !!
37      !! ** Purpose : read input file
38      !!
39      !!-------------------------- OUT -------------------------------------
40      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) :: pvar          ! output variable
41      !!-------------------------- IN  -------------------------------------
42      CHARACTER(len=256)          , INTENT(in   ) :: cdfile   ! input file name
43      CHARACTER(len=34)           , INTENT(in   ) :: cdvar    ! variable name
44      !!--------------------------------------------------------------------
45      INTEGER :: inum
46      !!--------------------------------------------------------------------
47
48      CALL iom_open( TRIM(cdfile), inum )
49      CALL iom_get( inum, jpdom_data, TRIM(cdvar), pvar)
50      CALL iom_close(inum)
51
52   END SUBROUTINE read_2dcstdta
53
54   SUBROUTINE debug2d(cdtxt,pvar)
55      !!--------------------------------------------------------------------
56      !!                  ***  ROUTINE isf_debug2d  ***
57      !!
58      !! ** Purpose : add debug print for 2d variables
59      !!
60      !!-------------------------- IN  -------------------------------------
61      CHARACTER(LEN=256)          , INTENT(in   ) :: cdtxt
62      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) :: pvar
63      !!--------------------------------------------------------------------
64      REAL(wp)    :: zmin, zmax, zsum
65      INTEGER(i8) :: imodd, ip
66      INTEGER     :: itmps,imods, ji, jj, jk
67      !!--------------------------------------------------------------------
68      !
69      ! global min/max/sum to check data range and NaN
70      zsum = glob_sum( 'debug', pvar(:,:) )
71      zmin = glob_min( 'debug', pvar(:,:) )
72      zmax = glob_max( 'debug', pvar(:,:) )
73      !
74      ! basic check sum to check reproducibility
75      ! TRANSFER function find out the integer corresponding to pvar(i,j) bit pattern
76      ! MOD allow us to keep only the latest digits during the sum
77      ! imod is not choosen to be very large as at the end there is a classic mpp_sum
78      imodd=65521 ! highest prime number < 2**16 with i8 type
79      imods=65521 ! highest prime number < 2**16 with default integer for mpp_sum subroutine
80      itmps=0
81      DO jj=nldj,nlej
82         DO ji=nldi,nlei
83            itmps = MOD(itmps + MOD(TRANSFER(pvar(ji,jj), ip),imodd), imods)
84         END DO
85      END DO
86      CALL mpp_sum('debug',itmps)
87      !
88      ! print out
89      IF (lwp) THEN
90         WRITE(numout,*) TRIM(cdtxt),' (min, max, sum, tag) : ',zmin, zmax, zsum, itmps
91         CALL FLUSH(numout)
92      END IF
93      !
94   END SUBROUTINE debug2d
95
96   SUBROUTINE debug3d(cdtxt,pvar)
97      !!--------------------------------------------------------------------
98      !!                  ***  ROUTINE isf_debug3d  ***
99      !!
100      !! ** Purpose : add debug print for 3d variables
101      !!
102      !!-------------------------- IN  -------------------------------------
103      CHARACTER(LEN=256)              , INTENT(in   ) :: cdtxt
104      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) :: pvar
105      !!--------------------------------------------------------------------
106      REAL(wp) :: zmin, zmax, zsum
107      INTEGER(i8) :: imodd, ip
108      INTEGER     :: itmps,imods, ji, jj, jk
109      !!--------------------------------------------------------------------
110      !
111      ! global min/max/sum to check data range and NaN
112      zsum = glob_sum( 'debug', pvar(:,:,:) )
113      zmin = glob_min( 'debug', pvar(:,:,:) )
114      zmax = glob_max( 'debug', pvar(:,:,:) )
115      !
116      ! basic check sum to check reproducibility
117      ! TRANSFER function find out the integer corresponding to pvar(i,j) bit pattern
118      ! MOD allow us to keep only the latest digits during the sum
119      ! imod is not choosen to be very large as at the end there is a classic mpp_sum
120      imodd=65521 ! highest prime number < 2**16 with i8 type
121      imods=65521 ! highest prime number < 2**16 with default integer for mpp_sum subroutine
122      itmps=0
123      DO jk=1,jpk
124         DO jj=nldj,nlej
125            DO ji=nldi,nlei
126               itmps = MOD(itmps + MOD(TRANSFER(pvar(ji,jj,jk), ip),imodd), imods)
127            END DO
128         END DO
129      END DO
130      CALL mpp_sum('debug',itmps)
131      !
132      ! print out
133      IF (lwp) THEN
134         WRITE(numout,*) TRIM(cdtxt),' (min, max, sum, tag) : ',zmin, zmax, zsum, itmps
135         CALL FLUSH(numout)
136      END IF
137      !
138   END SUBROUTINE debug3d
139
140END MODULE isfutils
Note: See TracBrowser for help on using the repository browser.