midas_calcStats sourceΒΆ

  1program midas_calcStats
  2  !
  3  !:Purpose: Swiss-knife type program originally used only for computing background-error covariances
  4  !          (**B**) based on homogeneous and isotropic (HI) correlations that was extended with time
  5  !          to compute various statistics and diagnostics from an ensemble of background-error estimates
  6  !
  7  !          ---
  8  !
  9  !:Algorithm: The ``calcStats`` program performs various types of statistics and diagnostics based on
 10  !            two modes defined through namelist options.
 11  !
 12  !              - **BHI**: Compute HI **B**. The approach for  limited-area applications is based on a bi-Fourier
 13  !                         spectral representation and the CVT described in <https://doi.org/10.1175/2010WAF2222401.1>.
 14  !                         For global applications, two formulations based on sperical-harmonics spectral representation
 15  !                         are available and controlled controlled by ``NAMCOMPUTEBHI``: 1) the legacy CVT formulation
 16  !                         described in <https://doi.org/10.1175/MWR-D-11-00097.1> and refereces therein,
 17  !                         and 2) an experimental-only formulation that mimics the CVT model used in the limited-area mode.
 18  !              - **TOOLBOX**: The swiss-knife component of this program controlled by ``NAMTOOLBOX`` from the
 19  !                global and LAM calcstats-related modules. Compute various statistics and diagnostics from
 20  !                an ensemble of background-error estimates in model-variable and/or control-variable space,
 21  !                such as:
 22  !                - HI vertical correlations
 23  !                - HI horizontal correlation functions
 24  !                - Variances
 25  !                - Local correlations
 26  !                - Optimal covariance localization radii
 27  !                - Power spectra
 28  !                Note that the above options are not all available in both global and limited-area
 29  !                applications.
 30  !            ---
 31  !
 32  !============================================= ==============================================================
 33  ! Input and Output Files                        Description of file
 34  !============================================= ==============================================================
 35  ! ``flnml``                                     In - Main namelist file with parameters user may modify
 36  ! ``ensemble/$YYYYMMDDHH_$HHH_$NNNN``           In - Background-error estimates
 37  ! ``various``                                   Out - Too many to be listed here
 38  !============================================= ==============================================================
 39  !
 40  !            --
 41  !
 42  !:Synopsis: Below is a summary of the ``calcStats`` program calling sequence:
 43  !
 44  !             - **Initial setups:**
 45  !
 46  !               - Read the NAMCONF and NAMENS namelist
 47  !
 48  !               - Setup horizontal and vertical grid objects using the first ensemble member
 49  !
 50  !               - Various modules are setup: ``gridStateVector_mod``, ``timeCoord_mod`` and ``bmatrix_mod``
 51  !
 52  !             - **Statistics and Diagnostics:**
 53  !
 54  !               - Intialize the module for global or limited-area applications
 55  !
 56  !               - Select the appropriate master routine based on the chosen mode
 57  !
 58  !               - The I/O and number crunching is performed within the global and limited-area modules
 59  !
 60  !
 61  !======================== ============ ==============================================================
 62  ! Module                   Namelist     Description of what is controlled
 63  !======================== ============ ==============================================================
 64  ! ``timeCoord_mod``        ``NAMTIME``  date of validity of the ensemble of background-error estimates
 65  !                                       the background state and increment
 66  ! ``calcstatslglb_mod``    ``mode-dependent``  Too many to be listed here
 67  ! ``calcstatslam_mod``     ``mode-dependent``  Too many to be listed here
 68  !======================== ============ ==============================================================
 69  !
 70 
 71  use version_mod
 72  use midasMpi_mod
 73  use fileNames_mod
 74  use horizontalCoord_mod
 75  use verticalCoord_mod
 76  use calcStatsGlb_mod
 77  use calcStatsLam_mod
 78  use utilities_mod
 79  use ramDisk_mod
 80  use gridStateVector_mod
 81  use timeCoord_mod
 82  implicit none
 83
 84  type(struct_vco), pointer :: vco_ens => null()
 85  type(struct_hco), pointer :: hco_ens => null()
 86
 87  character(len=256), parameter :: enspathname = 'ensemble'
 88
 89  integer           :: fstopc
 90  integer           :: nulnam, ierr, fnom, fclos
 91  character(len=256) :: ensFileName
 92  character(len=4), pointer :: anlVar(:)
 93
 94  ! namelist variables
 95  character(len=60) :: mode   ! can be 'BHI', 'TOOLBOX', 'STDDEV or 'POWERSPEC'
 96  integer           :: nens   ! Ensemble size
 97  integer           :: ip2    ! Ensemble lead time (hour) selected within the file
 98
 99  NAMELIST /NAMCONF/mode
100  NAMELIST /NAMENS/nens,ip2
101
102  call ver_printNameAndVersion('calcStats','Compute the homogeneous-isotropic stats')
103
104  !
105  !- 1.  Initilization
106  !
107  ierr = fstopc('MSGLVL','ERRORS',0)
108
109  !- 1.1 MPI and TMG
110  call mmpi_initialize
111  call tmg_init(mmpi_myid, 'TMG_INFO')
112
113  call utl_tmg_start(0,'Main')
114
115  ! Setup the ramdisk directory (if supplied)
116  call ram_setup
117
118  ! Setup time
119  call tim_setup
120
121  !- 1.2 Read NAMENS namelist
122  nens              = 96                ! default value
123  ip2               = -1                ! default value
124
125  nulnam = 0
126  ierr   = fnom(nulnam,'./flnml','FTN+SEQ+R/O',0)
127  read (nulnam,nml=namens)
128  write(*     ,nml=namens)
129  ierr=fclos(nulnam)
130
131  !- 2.3 Initialize variables of the model states
132  call gsv_setup
133
134  call fln_ensfileName(ensFileName, ensPathName, memberIndex_opt=1)
135
136  !- 1.3 Initialize the horizontal grid
137  nullify(anlVar)
138  call gsv_varNamesList(anlVar)
139  call hco_SetupFromFile(hco_ens, ensFileName, ' ', 'Ensemble', varName_opt=anlVar(1)) ! IN
140
141  !- 1.4 Initialize the vertical grid
142  call vco_SetupFromFile( vco_ens,        & ! OUT
143                          ensFileName, ' ') ! IN
144
145  !- 1.5 Read NAMCONF namelist to find the mode
146  mode  = 'BHI'  ! default value
147
148  nulnam = 0
149  ierr   = fnom(nulnam,'./flnml','FTN+SEQ+R/O',0)
150  read (nulnam,nml=namconf)
151  write(*     ,nml=namconf)
152  ierr   = fclos(nulnam)
153
154  !
155  !- 2. Select and launch the appropriate mode
156  !
157
158  !- 2.1 Module initialization
159  if (hco_ens % global) then
160     call csg_setup( nens, hco_ens, vco_ens) ! IN
161  else
162     call csl_setup( nens, hco_ens, vco_ens, ip2) ! IN
163  end if
164
165  !- 2.2 Mode selection
166  select case(trim(mode))
167  case ('BHI')
168     if (hco_ens % global) then
169        call csg_computeBhi
170     else
171        call csl_computeBhi
172     end if
173  case ('TOOLBOX')
174     if (hco_ens % global) then
175        call csg_toolbox
176     else
177        call csl_toolbox
178     end if
179  case default
180     write(*,*)
181     write(*,*) 'Unknown value of MODE in global mode: ',mode
182     call utl_abort('midas-calcstats')
183  end select
184
185  !
186  !- 3.  Ending...
187  !
188
189  write(*,*)
190  write(*,*) '---------------------'
191  write(*,*) '> ENDING CALCBMATRIX '
192  write(*,*) '---------------------'
193
194  !
195  !- 4.  MPI, tmg finalize
196  !  
197  call utl_tmg_stop(0)
198
199  call tmg_terminate(mmpi_myid, 'TMG_INFO')
200  call rpn_comm_finalize(ierr) 
201
202end program midas_calcStats