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/dev_r12072_MERGE_OPTION2_2019/src/OCE/ISF – NEMO

source: NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/OCE/ISF/isfutils.F90 @ 12172

Last change on this file since 12172 was 12169, checked in by cetlod, 4 years ago

Bugfixes

File size: 5.8 KB
RevLine 
[11395]1MODULE isfutils
[11403]2   !!======================================================================
3   !!                       ***  MODULE  isfutils  ***
4   !! istutils module : miscelenious useful routines
5   !!======================================================================
6   !! History :  4.1  !  2019-09  (P. Mathiot) original code
7   !!----------------------------------------------------------------------
[11395]8
[11403]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   !!----------------------------------------------------------------------
[11395]13
[11852]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
[11931]16   USE par_oce       , ONLY: jpi,jpj,jpk                              ! domain size
[12032]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
[11395]20
[11403]21   IMPLICIT NONE
[11395]22
[11403]23   PRIVATE
[11395]24
[11403]25   INTERFACE debug
26      MODULE PROCEDURE debug2d, debug3d
27   END INTERFACE debug
[11395]28
[11403]29   PUBLIC read_2dcstdta, debug
30
[11395]31CONTAINS
32
33   SUBROUTINE read_2dcstdta(cdfile, cdvar, pvar)
[11403]34      !!--------------------------------------------------------------------
[11395]35      !!                  ***  ROUTINE read_2dcstdta  ***
36      !!
37      !! ** Purpose : read input file
38      !!
39      !!-------------------------- OUT -------------------------------------
[11403]40      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) :: pvar          ! output variable
[11395]41      !!-------------------------- IN  -------------------------------------
[12169]42      CHARACTER(len=*)          , INTENT(in   ) :: cdfile   ! input file name
43      CHARACTER(len=*)           , INTENT(in   ) :: cdvar    ! variable name
[11395]44      !!--------------------------------------------------------------------
45      INTEGER :: inum
[11403]46      !!--------------------------------------------------------------------
[11395]47
[11494]48      CALL iom_open( TRIM(cdfile), inum )
49      CALL iom_get( inum, jpdom_data, TRIM(cdvar), pvar)
[11395]50      CALL iom_close(inum)
51
52   END SUBROUTINE read_2dcstdta
53
[11403]54   SUBROUTINE debug2d(cdtxt,pvar)
55      !!--------------------------------------------------------------------
56      !!                  ***  ROUTINE isf_debug2d  ***
57      !!
[11987]58      !! ** Purpose : add debug print for 2d variables
[11403]59      !!
60      !!-------------------------- IN  -------------------------------------
[12169]61      CHARACTER(LEN=*)          , INTENT(in   ) :: cdtxt
[11395]62      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) :: pvar
[11403]63      !!--------------------------------------------------------------------
[12032]64      REAL(wp)    :: zmin, zmax, zsum
65      INTEGER(i8) :: imodd, ip
66      INTEGER     :: itmps,imods, ji, jj, jk
[11403]67      !!--------------------------------------------------------------------
68      !
[12032]69      ! global min/max/sum to check data range and NaN
[11844]70      zsum = glob_sum( 'debug', pvar(:,:) )
71      zmin = glob_min( 'debug', pvar(:,:) )
72      zmax = glob_max( 'debug', pvar(:,:) )
[11403]73      !
[12032]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)
[11403]87      !
[12032]88      ! print out
[12062]89      IF (lwp) THEN
90         WRITE(numout,*) TRIM(cdtxt),' (min, max, sum, tag) : ',zmin, zmax, zsum, itmps
91         CALL FLUSH(numout)
92      END IF
[12032]93      !
[11403]94   END SUBROUTINE debug2d
[11395]95
[11403]96   SUBROUTINE debug3d(cdtxt,pvar)
97      !!--------------------------------------------------------------------
98      !!                  ***  ROUTINE isf_debug3d  ***
99      !!
[11987]100      !! ** Purpose : add debug print for 3d variables
[11403]101      !!
102      !!-------------------------- IN  -------------------------------------
[12169]103      CHARACTER(LEN=*)              , INTENT(in   ) :: cdtxt
[11395]104      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) :: pvar
[11403]105      !!--------------------------------------------------------------------
[11395]106      REAL(wp) :: zmin, zmax, zsum
[12032]107      INTEGER(i8) :: imodd, ip
108      INTEGER     :: itmps,imods, ji, jj, jk
[11403]109      !!--------------------------------------------------------------------
110      !
[12032]111      ! global min/max/sum to check data range and NaN
[11844]112      zsum = glob_sum( 'debug', pvar(:,:,:) )
113      zmin = glob_min( 'debug', pvar(:,:,:) )
114      zmax = glob_max( 'debug', pvar(:,:,:) )
[11403]115      !
[12032]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)
[11403]131      !
[12032]132      ! print out
[12062]133      IF (lwp) THEN
134         WRITE(numout,*) TRIM(cdtxt),' (min, max, sum, tag) : ',zmin, zmax, zsum, itmps
135         CALL FLUSH(numout)
136      END IF
[12032]137      !
[11403]138   END SUBROUTINE debug3d
[11395]139
140END MODULE isfutils
Note: See TracBrowser for help on using the repository browser.