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 @ 12032

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

ENHANCE-02_ISF_nemo: improve isf debug with a basic checksum

File size: 5.7 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) WRITE(numout,*) TRIM(cdtxt),' (min, max, sum, tag) : ',zmin, zmax, zsum, itmps
90      !
91      CALL FLUSH(numout)
92      !
93   END SUBROUTINE debug2d
94
95   SUBROUTINE debug3d(cdtxt,pvar)
96      !!--------------------------------------------------------------------
97      !!                  ***  ROUTINE isf_debug3d  ***
98      !!
99      !! ** Purpose : add debug print for 3d variables
100      !!
101      !!-------------------------- IN  -------------------------------------
102      CHARACTER(LEN=256)              , INTENT(in   ) :: cdtxt
103      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) :: pvar
104      !!--------------------------------------------------------------------
105      REAL(wp) :: zmin, zmax, zsum
106      INTEGER(i8) :: imodd, ip
107      INTEGER     :: itmps,imods, ji, jj, jk
108      !!--------------------------------------------------------------------
109      !
110      ! global min/max/sum to check data range and NaN
111      zsum = glob_sum( 'debug', pvar(:,:,:) )
112      zmin = glob_min( 'debug', pvar(:,:,:) )
113      zmax = glob_max( 'debug', pvar(:,:,:) )
114      !
115      ! basic check sum to check reproducibility
116      ! TRANSFER function find out the integer corresponding to pvar(i,j) bit pattern
117      ! MOD allow us to keep only the latest digits during the sum
118      ! imod is not choosen to be very large as at the end there is a classic mpp_sum
119      imodd=65521 ! highest prime number < 2**16 with i8 type
120      imods=65521 ! highest prime number < 2**16 with default integer for mpp_sum subroutine
121      itmps=0
122      DO jk=1,jpk
123         DO jj=nldj,nlej
124            DO ji=nldi,nlei
125               itmps = MOD(itmps + MOD(TRANSFER(pvar(ji,jj,jk), ip),imodd), imods)
126            END DO
127         END DO
128      END DO
129      CALL mpp_sum('debug',itmps)
130      !
131      ! print out
132      IF (lwp) WRITE(numout,*) TRIM(cdtxt),' (min, max, sum, tag) : ',zmin, zmax, zsum, itmps
133      !
134      CALL FLUSH(numout)
135      !
136   END SUBROUTINE debug3d
137
138END MODULE isfutils
Note: See TracBrowser for help on using the repository browser.