!>----------------------------------------------------------
!! Very simple radiation code modeled after the description in Finch and Best(2004?)
!! of Reiff et al. 1984 shortwave and Idso and Jackson (1969) longwave.
!!
!! Clearsky Shortwave radiation is calculated as a function of day of year and time of day.
!! Cloudy Shortwave is calculated as clearsky SW * f(cloud cover) [0.25-1]
!!
!! Cloud cover is calculated as in Xu and Randal (1996) as f(surface_RH, qc+qs+qr)
!!
!! Clearsky Longwave radiation is calculated as f(Tair)
!! Cloudy longwave is scaled up by a f(cloud cover) [1-1.2]
!!
!! The entry point to the code is ra_simple.
!!
!! <pre>
!! Call tree graph :
!! ra_simple->
!!  [cloudfrac->],
!!  [shortwave->],
!!  [longwave->]
!!
!! High level routine descriptions / purpose
!!   ra_simple           - loops over X,Y grid cells, calls cloudfrac, shortwave,longwave on columns
!!   cloudfrac           - calculates the cloud fraction following Xu and Randall (1996)
!!   shortwave           - calculates shortwave at the surface following Reiff et al (1984)
!!   longwave            - calculates longwave at the surface following Idso and Jackson (1969)
!!
!! Driver inputs: p,th,pii,rho,qv,qc,qr,qs,rain,snow,dt,dz,nx,ny,nz
!!   p   = pressure                      - 3D - input  - Pa     - (nx,nz,ny)
!!   th  = potential temperature         - 3D - in/out - K      - (nx,nz,ny)
!!   pii = inverse exner function        - 3D - input  - []     - (nx,nz,ny)
!!   rho = air density                   - 3D - input  - kg/m^3 - (nx,nz,ny)
!!   qv  = specific humidity             - 3D - input  - kg/kg  - (nx,nz,ny)
!!   qc  = cloud water content           - 3D - input  - kg/kg  - (nx,nz,ny)
!!   qr  = rain water content            - 3D - input  - kg/kg  - (nx,nz,ny)
!!   qs  = snow water content            - 3D - input  - kg/kg  - (nx,nz,ny)
!!   swdown = shortwave down at surface  - 2D - output - W/m^2  - (nx,ny)
!!   lwdown = longwave down at surface   - 2D - output - W/m^2  - (nx,ny)
!!   dt = time step                      - 0D - input  - seconds    - scalar
!! </pre>
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!----------------------------------------------------------


!  Program Name:
!  Author(s)/Contact(s):
!  Abstract:
!  History Log:
!
!  Usage:
!  Parameters: <Specify typical arguments passed>
!  Input Files:
!        <list file names and briefly describe the data they include>
!  Output Files:
!        <list file names and briefly describe the information they include>
!
!  Condition codes:
!        <list exit condition or error codes returned >
!        If appropriate, descriptive troubleshooting instructions or
!        likely causes for failures could be mentioned here with the
!        appropriate error code
!
!  User controllable options: <if applicable>


!***********************************************************************
!*                   GECROS for early and late covering crops          *
!*     Genotype-by-Environment interaction on CROp growth Simulator    *
!*                                                                     *
!*                         Author: Xinyou YIN                          *
!*                      Crop and Weed Ecology Group                    *
!*                Wageningen University & Research Centre              *
!*               PO Box 430, 6700 AK Wageningen, Netherlands           *
!*                                                                     *
!*                Modified and extended for winter crops               *
!*                         by Joachim INGWERSEN                        *
!*                         Biogeophysics Group                         *
!*                       University of Hohenheim                       *
!*                                                                     *
!***********************************************************************


!> -----------------------
!! Provides a timer object that can be used to monitor how long sections of code are taking
!!
!! Similar functionality can be gained from a profiling system, but sometimes profiling is too much detail
!!
!! Note that the current implementation utilizes the fortran CPU_time function.  This function only counts time actually
!! spent running on the CPU, not wallclock.  In addition, the time for all threads in the process are included.
!!
!! ------------------------


!>------------------------------------------------
!! Defines the interface for a variable dictionary
!!
!! Dictionary can be accessed by string keys
!! Dictionary stores variable_t types
!!
!!------------------------------------------------


!>------------------------------------------------
!! Defines model constants (e.g. gravity, and MAXFILELENGTH)
!!
!!------------------------------------------------


!>----------------------------------------------------------
!!  Define the interface for the ioserver
!!
!!  The I/O server serves as a parallelized interface between the main program
!!  and the I/O routines. The I/O server handles the buffering and exchange
!!  of data between the processes of the main program (child processes)
!!  and the I/O processes (parent processes)
!!
!!  @author
!!  Dylan Reynolds (dylan.reynolds@slf.ch)
!!
!!----------------------------------------------------------


!>----------------------------------------------------------
!!  Handle reading and writing Linear wind Look up tables to/from disk
!!
!!  Look up tables are written from disk in a documented netCDF file (e.g. with all LUT options)
!!  When a LUT is read from disk, the options stored in that file are checked against the options
!!  specified for the current run. If they are compatible (x, y, and z shape) the LUT will be read
!!  If the options for the current run are not the same as those in the file, a warning is printed
!!  but and an error will be thrown, the model will continue, it will just use the options
!!  stored in the file so the LUT does not need to be regenerated.
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!----------------------------------------------------------


!>----------------------------------------------------------
!!  Define the interface for the output object
!!
!!  Output objects store all of the data and references to data necessary to write
!!  an output file.  This includes primarily internal netcdf related IDs.
!!  Output objects also store an array of variables to output.
!!  These variables maintain pointers to the data to be output as well as
!!  Metadata (e.g. dimension names, units, other attributes)
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!----------------------------------------------------------


!>----------------------------------------------------------
!!  Define the interface for the ioclient
!!
!!  The I/O client serves as a parallelized interface between the main program
!!  and the I/O routines. The I/O client handles the buffering and exchange
!!  of data between the processes of the main program (child processes)
!!  and the I/O processes (parent processes)
!!
!!  @author
!!  Dylan Reynolds (dylan.reynolds@slf.ch)
!!
!!----------------------------------------------------------


!>------------------------------------------------------------
!!  Basic file input/output routines
!!
!!  @details
!!  Primary use is io_read2d/3d
!!  io_write* routines are more used for debugging
!!  model output is performed in the output module
!!
!!  Generic interfaces are supplied for io_read and io_write
!!  but most code still uses the explicit read/write 2d/3d/etc.
!!  this keeps the code a little more obvious (at least 2D vs 3D)
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!------------------------------------------------------------


!>------------------------------------------------------------
!! Test to confirm the geographic interpolation routines work
!! Hasn't been updated in a while but should still work
!! Requires two input files with XLAT,XLONG 2D variables
!!
!! Writes 5 output files
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!------------------------------------------------------------


! ------------------------------------------------------------------------------
!  copied from WRF/var/da/da_physics/da_sfc_wtq.inc to support the YSU pbl scheme.
!  Specifically the calculation of psim, psih, which are made output vars here.
!
!  Bert Kruyt 2022
!
! ------------------------------------------------------------------------------


!>------------------------------------------------------------
!!  date / time module
!!
!!  Defines a Time_type object
!!
!!  Contains various utilities for working with dates and times.
!!  Utilities are capable of handling multiple model calendars.
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!------------------------------------------------------------


!>------------------------------------------------------------
!!  Various functions to convert a number to a string and a string
!!  to a number
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!------------------------------------------------------------


!>------------------------------------------------------------
!! Fortran interface to FFTW
!!
!!  @author
!!  The FFTW team.
!!
!!------------------------------------------------------------


!>----------------------------------------------------------
!! This module provides basic atmospheric utility functions.
!!
!!  Utilities exist to convert u, v into speed and direction (and vice versa)
!!  Compute the dry and moist lapse rates and Brunt Vaisalla stabilities
!!  Compute the terrain blocking froude number (U / (terrain_height * brunt_vaisalla_frequency ))
!!  Compute the fraction of flow that is blocked (linear interpolation between froude_max and froude_min)
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!----------------------------------------------------------


!>------------------------------------------------------------
!! Supplies 1D and 2D FFT shift procedures ala matlab fftshift
!!
!! Uses a generic interface so that procedures can be called with
!! any variation of complex, real, 1D or 2D arrays
!! 2D can also be called with C_DOUBLE_COMPLEX variables
!!
!! fftshift swaps the left and right sides of an array.  For a
!!  2D array, the top and bottom halves are also swapped.
!!
!!  @author
!!  Ethan Gutmann (gutmann@ucar.edu)
!!
!!------------------------------------------------------------


! Copyright (c) 2016-2021 Julien Peloton, Giulio Fabbian.
!
! This file is part of s4cmb
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Ju@Sussex
! FORTRAN routines to compute low level products while injecting systematics.
! Main purposes is interfacing with python (using f2py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


! Copyright (c) 2016-2021 Julien Peloton, Giulio Fabbian.
!
! This file is part of s4cmb
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Ju@Sussex
! FORTRAN routines to compute low level products while computing detector
! pointing.
! Main purposes is interfacing with python (using f2py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


! Copyright (c) 2016-2021 Julien Peloton, Giulio Fabbian.
!
! This file is part of s4cmb
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Ju@Sussex
! FORTRAN routines to compute low level products while generating
! the scanning strategy.
! Main purposes is interfacing with python (using f2py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


! Copyright (c) 2016-2021 Julien Peloton, Giulio Fabbian.
!
! This file is part of s4cmb
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Ju@Sussex
! FORTRAN routines to compute low level products
! Main purposes is interfacing with python (using f2py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


! jcarron March 2021


!! **** IO units handling


!--------------------------------------------------------------------------------
!
!       OPACFRACTAL version 3.0
!
!--------------------------------------------------------------------------------
!
! OPACFRACTAL v3.0 computes light scattering properties of randomly oriented
! fractal dust aggregates by means of the modified mean field theory developed
! in Tazaki & Tanaka (2018). This code is also capable of computing the light
! scattering solution based on the Rayleigh-Gans-Debye theory and the Mean field
! theory.
!
! If you wish to publish a paper that contains results obtained by this code,
! please acknowledge this code and cite relevant papers.
!
! Disclaimer:
! I reject all responsibility for the use of this code. Although it has been
! tested, the code may still contain a bug. I am not responsible for any damages
! caused by the use of the code. If you find a bug, please let me know.
!
!                                                   Ryo Tazaki (2020/Nov/11)
!                                                   email: r.tazaki -at- uva.nl
!
!--------------------------------------------------------------------------------
!
! LIMITATION OF THE CODE
!
!--------------------------------------------------------------------------------
!
! Here, I summarize some limitations of the code for each approximation (iqsca).
! The limitation can be simply judged by the phase shift induced by an aggregate
! (Equation 9 in Tazaki & Tanaka 2018; see also Section 3.2 in this paper).
!
! iqsca=1: All outputs would be physically reasonable for the phase shift <~ 1.
!
! iqsca=2: The extinction cross section would be calculated without limitation.
!          However, the other outputs would be reliable for the phase shift < ~1.
!
! iqsca=3: The extinction cross section would be calculated without limitation.
!          Scattering and absorption cross sections could be calculated
!          for the phase shift > 1, however too large phase shift may
!          cause some problem.
!          The asymmetry parameter and the sattering matrix elements would be
!          reliable for the phase shift < ~1.
!
! For the two-point correlation function, I suggest to use iqcor=1 because
! it is numerically stable and is likely to reproduce optical properties
! of fractal aggregates.
!
!--------------------------------------------------------------------------------
!
! IMPORTANT REFERENCES
!
!--------------------------------------------------------------------------------
!
! If you wish to publish a paper by using this code, following references should
! be cited depending on the code options (iqsca and iqcor) you used.
!
! Light scattering solver:
! iqsca = 1     : Tazaki et al. 2016, ApJ, 823, 70
! iqsca = 2     : Botet et al. 1997, ApOpt, 36, 8791
! iqsca = 3     : Tazaki & Tanaka 2018, ApJ, 860, 79
!
! The two-point correlation function of monomers:
! iqcor = 1     : Tazaki et al. 2016, ApJ, 823, 70
! iqcor = 2     : Berry & Percival 1986, AcOpt, 33, 577
! iqcor = 3     : Botet et al. 1995, JPhA, 28, 297
!
! The geometric cross section of aggregates (to be used when iqsca=3):
! iqgeo = 2     : Okuzumi et al. 2009, ApJ, 707, 1247
! iqgeo = 3     : Tazaki (submitted)
!
!--------------------------------------------------------------------------------
!
! LIST OF SUBROUTINES BY OTHER AUTHORS
!
!--------------------------------------------------------------------------------
!
! OPACFRACTAL v3.0 contains following subroutines provided by other authors.
! I thank the authors for the availability of the subroutines.
!
! lorenz_mie  : BHMIE written by Bruce T. Draine with modifications
! renorm_mie  : BHMIE written by Bruce T. Draine with modifications
! gamma       : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! chgm        : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! lpmns       : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! lpn         : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! ludcmp      : Press, W. H. et al. (1997), "Numerical Recipes in Fortran 77"
! lubksb      : Press, W. H. et al. (1997), "Numerical Recipes in Fortran 77"
! gauleg      : Press, W. H. et al. (1997), "Numerical Recipes in Fortran 77"
! geofrac     : Tazaki (submitted to MNRAS)
!
!--------------------------------------------------------------------------------
!
! INPUT PARAMETERS
!
!--------------------------------------------------------------------------------
!
! lmd           : wavelength     (micron)
! R0            : monomer radius (micron)
! Df            : fractal dimension
! PN            : number of monomers
! k0            : fractal prefactor; PN = k0 (Rg/R0)^Df
! refrel        : complex refractive index of a monomer particle
! nang          : Number of angular grid between 0 ang 90 degrees.
!                 If nang=91, then angular width is 1 degree.
!                 <TIPS>
!                 For iqsca=3, I suggest the users to check the convergence
!                 of the results by changing nang.
! iqsca         : Switch for the light scattering solver
!                 iqsca = 1  : Rayleigh-Gans-Debye theory
!                 iqsca = 2  : Mean-field theory
!                 iqsca = 3  : Modified mean-field theory
! iqcor         : Switch for the two-point correlation function
!                 iqcor = 1  : Gaussian cutoff
!                 iqcor = 2  : Exponential cutoff
!                 iqcor = 3  : Fractal dimension cutoff
! iqgeo         : Switch for the two-point correlation function
!                 iqgeo = 1  : pi * rc^2, rc is the characteristic radius
!                 iqgeo = 2  : Okuzumi et al. (2009)
!                 iqgeo = 3  : Tazaki (submitted)
! iquiet        : Switch for standard output during a calculation
!                 iquiet = 0 : show stdout
!                 iquiet = 1 : suppress stdout (including warnings)
!
!--------------------------------------------------------------------------------
!
! OUTPUT PARAMETERS
!
!--------------------------------------------------------------------------------
!
! Cext               : extinction cross section (micron^2)
! Csca               : scattering cross section (micron^2)
! Cabsp              : absorption cross section (micron^2)
! Gsca               : asymmetry parameter
! Smat(4,2*nang-1)   : Scattering matrix elements S_ij
!                      where S_ij obeys Bohren & Huffman's definition.
!                      The first column contains each element of scat. matrix
!                        Smat(1,:) : S_11,
!                        Smat(2,:) : S_12,
!                        Smat(3,:) : S_33,
!                        Smat(4,:) : S_34,
!                      and the second column contains values at each scattering
!                      angle from 0 deg to 180 deg with 2*nang-1 grid points.
! dphi               : Phase shift induced by the aggregates
!
!--------------------------------------------------------------------------------
!
! HISTORY
!
!--------------------------------------------------------------------------------
!
! version 1.0 (July 24 2017)
! - Initial release
!
! version 2.2 (Oct. 24 2017)
! - Implemented geometrical optics approximation (Modified Mean Field; MMF)
! - Implemented a stable algorithm for computations of the spherical Bessel
!   function of the first kind at large order and/or large argument.
! - Fixed bug of Legendre polynomial calculations with large order.
! - Implemented dynamic allocation for some special function calculations.
! - Fixed bug about compiler dependence (ifort or gfortran)
!
! version 2.3 (Dec. 05 2017)
! - Implemented efficient computation of $a(\nu,n,p)$ and $b(\nu,n,p)$
!   using the parity arguments.
!
! version 2.5 (May. 31 2020)
! - Fixed a bug about initialization of Qsca and gsca in (renormalized)
!   Lorentz-Mie routine. This does not change the results, since both of
!   them are not used to obtain final results.
!
! version 3.0 (Jan. 19, 2020)
! - BUG fixed: Add a simple prescription for negative S(q) for iqcor=3.
! - Fixed a code crush for OpenMP mode.
! - Fixed a few type mismatchs and over/underflow signals.
! - Unified notation for Cabs in iqsca=1 for safety.
! - Updated f77 subroutines to f90.
! - Implemented parameterized real precision
! - Implemented more efficient loop structure at calculations of
!   gaunt coefficients : a(nu,n,p) and b(nu,n,p).
! - Removed the iqcor=4 option because it is practically unimportant.
! - Added a return variable "phase shift"
! - Added models of for geometric cross sections (iqgeo option)
! - Implemented geofractal code (called by iqgeo=3)
!
!--------------------------------------------------------------------------------
!       Some constants
!--------------------------------------------------------------------------------


!>
!! \brief This module contains data and routines for Merge-sort ranking of an array
!!
!! \b Author: ?
!!
!! \b Date:
!!
!! \b Version:
!!


!>
!! \brief This module contains parameters specific for C2-Ray
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! Note: this file contains parameters for different versions
!!       of C2-Ray (dimensions, single/multiple sources), so
!!       not all parameters will be used.


!>
!! \brief This module contains radiation-related physical constants
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date:
!!
!! \b Version: cgs units
!!


!>
!! \brief This module contains mathematical constants
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! Author: Garrelt Mellema
!!
!! Date: 2003-12-09
!!
!! This module is also accepted by the F compiler (Dec 9, 2003)
!<


!>
!! \short This module contains variables and routines for dealing with
!!   cpu and wall clocks
!!
!! This module uses calls to the Fortran 2003 internal routines cpu_time
!! and system_clock. To get the time passed between two events, one has
!! to call these twice, once at the start and once at the end.
!! To avoid overflowing the variable (which can happen for codes that run
!! for many hours or days), this module provides "update" routines that
!! update hour and minute counters. These should be called at regular
!! intervals. The module also comes with its own reporting routines.
!!
!! General module
!!
!! Dependencies:
!!   - file_admin module (for the unit of the log file where to write the report)
!!   - my_mpi (for the value of rank, the MPI id of the current processor, reporting is only done for the rank 0 processor)
!!
!! Author: Garrelt Mellema
!!
!! Date: 2010-03-08
!!
!! Version: 1.0
!!
!<


!>
!! \brief This module contains definitions of physical constants
!! and conversion factors, as well as routines to set recombination
!! and collisional ionization coefficients.
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema, Martina M. Friedrich
!!
!! \b Date: 2015-06-30 (previously undated)
!!
!! \b Version: cgs units
!!


!>
!! \brief This module contains routines for string manipulation
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: August 17, 1989


!     This module contains data and routines which deal with radiative
!     effects. Its main part deal with photo-ionizing radiation, but it
!     also initializes other radiative properties, such as cooling (which
!     are contained in different modules).
!     It can be used in hydrodynamic or stand-alone radiative transfer
!     calculations.


!     This module sets the sizes of radiation quantities


!>
!! \brief This module contains routines for calculating the ionization evolution of a single grid point.
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema, Martina M. Friedrich
!!
!! \b Date:
!!
!!


!>
!! \brief This module contains data and subroutines for radiative cooling
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date:
!!
!! \b Version: Non-equilibrium H-only cooling


!>
!!    \brief This module contains the floating point precision definitions
!!    in a machine
!!    independent way
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! Author: Garrelt Mellema
!!
!! Date: 2003-12-09
!!
!! This module is also accepted by the F compiler (Dec 9, 2003)
!<


!>
!! \brief This module contains definitions of cosmological parameters
!!
!! Module for C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 05-Oct-2008
!!
!! Version: WMAP3+


!>
!! \brief This module contains routines having to do with the calculation of
!!  temperature and electron density.
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2010-Mar-08 (but older)
!!
!! \b Doxygen \b note: This module contains "elemental" functions (i.e.
!! functions without side effects working on scalars). Doxygen does not
!! recognize these as functions, and therefore does not list them.
!!
!! The elemental functions in this module are:
!! - temper2pressr (calculates pressure from temperature, density and electron density).
!! - pressr2temper (calculates temperature from pressure, density and electron density).
!! - rho2n (calculates number density from mass density)
!! - n2rho (calculates mass density from number density)
!!


!>
!! \brief This module contains data and subroutines for radiative cooling
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date:
!!
!! \b Version: Collisional Ionization Equilibrium cooling


!>
!! \short This module contains variables and routines for reporting
!!   the memory usage of a code
!!
!! This module uses the file /proc/self/status to establish the memory
!! use of the code using it. This works only on linux systems but Fortran
!! does not supply any internal routines for memory checking, so this
!! seems to be the best way.
!!
!! The file /proc/self/status contains a lot of information about a
!! running process. Here we only extract the memory information.
!! The relevant fields are (see
!! https://www.kernel.org/doc/Documentation/filesystems/proc.txt):
!! VmPeak                      peak virtual memory size
!! VmSize                      total program size
!! VmLck                       locked memory size
!! VmHWM                       peak resident set size ("high water mark")
!! VmRSS                       size of memory portions
!! VmData                      size of data, stack, and text segments
!! VmStk                       size of data, stack, and text segments
!! VmExe                       size of text segment
!! VmLib                       size of shared library code
!! VmPTE                       size of page table entries
!! VmSwap                      size of swap usage (the number of referred swapents)
!! Of these this module reports VmPeak, VmSize, VmRSS, VmHWM
!!
!! General module
!!
!! Dependencies: ISO_FORTRAN_ENV module (supplied by system).
!!
!! Author: Garrelt Mellema
!!
!! Date: 2013-08-07
!!
!! Version: 1.0
!!
!<


!>
!! \brief This module contains parameters ans routines having to do
!!  with file in/ouput
!!
!! Module for C2-Ray/Capreole (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2008-05-27
!!
!! This module is also accepted by the F compiler (Dec 9, 2003)
!<


!>
!! \brief This module contains SED parameters
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! Note: this file contains parameters for spectral energy distributions
!!       (SEDs) for different types of SEDs:
!!       - Black body
!!       - General power law
!!       - Quasar power law


!>
!! \brief This module sets elemental abundances
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2008-05-27
!!
!! This module is also accepted by the F compiler (Dec 9, 2003)
!<


!>
!! \brief This module contains data and routines for cosmological problems
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date:
!!
!! This module keeps track of the current redshift
!!


!>
!! \brief This module contains Romberg integration routines.
!!
!! \b Author: Frank Robijn / Garrelt Mellema
!!
!! \b Date: August 17, 1989
!!


!>
!! \brief This module contains atomic constants and parameter definitions
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! Author: Garrelt Mellema
!!
!! Date: 2003-06-01
!!
!! Version: cgs units
!!
!! This module is also accepted by the F compiler (Dec 9, 2003)
!<


!>
!! \brief This module contains data and routines for permuting arrays randomly, but leaving elements close to their initial locations
!!
!! \b Author:  Michel Olagnon
!!
!! \b Date: May 2000
!!
!! \b Version:
!!


! This module contains routines having to do with the calculation of
! the thermal evolution of a single point/cell.


!     This module contains data and routines for tables with photoionization
!     and heating rates
!
!     These can be used in hydrodynamic or stand-alone radiative transfer
!     calculations.


!>
!! \brief This module contains astronomical constants and units
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2003-06-01
!!
!! \b Version: cgs units
!!
!! This module is also accepted by the F compiler (Dec 9, 2003)


!>
!! \brief This module contains routines for file output
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2012-10-13 (but older)
!!
!! \b Version: 1D, radial (spherically symmetric) grid, ydrogen + helium


!>
!! \brief This module contains basic size parameter definitions
!!
!! Module for C2-Ray
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2006-08-20


!>
!! \brief This module contains data and routines for calculating the photon statistics
!!
!! Module for C2-Ray
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 05-Mar-2010
!!
!! \b Version: 1D


!>
!! \brief This module contains data and routines for calculating the photon statistics
!!
!! Module for C2-Ray
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date:  26-Feb-2008
!!
!! \b Version:


!>
!! \brief This module contains routines for calculating the column density
!! for a point on a 3D grid
!!
!! Module for Capreole / C2-Ray (f90)
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date: 2013-09-05
!!
!! \b Version: 3D, H + He


!>
!! \brief This module contains data and routines for calculating the photon statistics
!!
!! Module for C2-Ray
!!
!! \b Author: Garrelt Mellema
!!
!! \b Date:  26-Feb-2008
!!
!! \b Version: 3D


!----------------------------------------------------------------------------------85
! Note: fargo_factor is caclulated in subroutinr rhs which is contained
! rhs.f90


!----------------------------------------------------------------------------------85
! Form of sponge: - (q - q_basic) / tau_sponge
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! The artificial pressure treatment is the same as the artificial bulk viscosity
! treatment suggested by Cook and Cabot (though our implementation may be a little
! different).
! p_art = - beta_Delta div u, where beta_Delta is the bulk viscosity.
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! This module is used to store a basic state so fluctuation statistics can be computed
! if desired.  The arrays are allocated in subroutine initialize and given values
! in subroutine store_basic_state (for a non-restart).
! For a restart from a type 1 restart file, these arrays are given values in
! subroutine read_restart.  This is now deprecated and it is reccomended that
! the basic state be specified for each run, restart or not.


!----------------------------------------------------------------------------------85
! Note: This runs in serial mode only.
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! As a diagnostic, compute and output for plotting, the terms in the vorticity
! transport equation.
!----------------------------------------------------------------------------------85


! Use these to improve code readability.


!module pade_filter
!   logical :: apply_pade_filter, filter_relative_to_basic_state
!   ! Three characters ('tau' or 'eps').
!   ! 'eps' : use the specified eps_filter
!   ! 'tau' : determine eps_filter from tau.
!   character(3) :: eps_or_tau
!   real(8) eps_filter, tau_filter
!end module pade_filter


! Conservative variable array and pressure.


! For summation-by-parts z derivative using the Carpenter et al. scheme.
! Not currently used.


! Similarly, this module was created to avoid dynamic storage allocations and
! deallocations.  These are allocated in...


! This module was created to avoid dynamic storage allocations and deallocations
! everytime rk4 is called.  These arrays are allocated in subroutine initialize.


!----------------------------------------------------------------------------------85
! Note for non-reflective BC: The flag ibalanced (0 or 1) when set to zero gives
! sets the rate of incoming waves to zero.  When set to 1, we say the rate of
! change of the the incoming waves is set by hydrostatic balance
! in z and centrifugal balance in r.  The flag "ibalanced" sits in
! module boundary_conditions.
! subroutine set_up_boundary_conditions is located in set_up_routines.f90
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! Note for non-reflective BC: The flag ibalanced (0 or 1) when set to zero gives
! sets the rate of incoming waves to zero.  When set to 1, we say the rate of
! change of the the incoming waves is set by hydrostatic balance
! in z and centrifugal balance in r.  The flag "ibalanced" sits in
! module boundary_conditions.
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! phi_avg_statistics_and_history_diagnostics.f90
! Note: If the z-direction is periodic then you can perform a further average
!       in z by calling phi_Reynolds_averages with average_in_z = .true.
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! See also subroutine activate_gravity in activate_routines.f90
!----------------------------------------------------------------------------------85


!----------------------------------------------------------------------------------85
! This file contains routines for the treatment of viscosity, thermal conductivity, and
! viscous heating.
! Currently you can choose one of:
! (1) Laminar
! The sub-grid models due to:
! (2) Moin et. al., Phys. Fluids A, 3(11), p. 2746, (1991) ---  note we use the non-dynamic version.
! (3) Vreman,       Phys. Fluids   16(10), p. 3670, (2004).
! (4) Dilatation dependent shear viscosity to capture shear layers caused by shocks.
! For the internal energy eq. see Batchelor, p. 153.
! Our internal energy is rho Cv T.
! Heat conduction term on rhs of internal energy eq. = d/dx_i (k dT/dx_i).
! Viscous heating term is 2 mu S_ij^2 + (mu_b - 2/3 mu) Dilatation^2
!----------------------------------------------------------------------------------85


! Viscosity and conductivity arising from molecular terms or subgrid scale model or dilatation-dependent shear-viscosity.


!
! CloudCoeff_Binary_IO
!
! Module containing routines to read and write Binary format
! CloudCoeff files.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 24-Jun-2004
!                       paul.vandelst@ssec.wisc.edu
!


!
! String_Utility
!
! Module containing string utility routines
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 18-Oct-1999
!                       paul.vandelst@ssec.wisc.edu
!


!
! ASvar_Define
!
! Module defining the CRTM AerosolScatter module internal
! variable object.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 14-Feb-2012
!                       paul.vandelst@noaa.gov
!


!
! CRTM_CloudCoeff
!
! Module containing the shared CRTM scattering coefficient data
! (CloudCoeff) and their load/destruction routines.
!
! PUBLIC DATA:
!       CloudC:  Data structure containing the cloud bulk optical
!                properties data
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure CloudC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 24-Jun-2004
!                       paul.vandelst@noaa.gov
!


!
! CRTM_IR_Land_SfcOptics
!
! Module to compute the surface optical properties for LAND surfaces at
! infrared frequencies required for determining the LAND surface
! contribution to the radiative transfer.
!
! This module is provided to allow developers to "wrap" their existing
! codes inside the provided functions to simplify integration into
! the main CRTM_SfcOptics module.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Jun-2005
!                       paul.vandelst@noaa.gov
!


!
! CRTM_SpcCoeff
!
! Module containing the shared CRTM spectral coefficients (SpcCoeff)
! and their load/destruction routines.
!
! PUBLIC DATA:
!       SC:  Data structure array containing the spectral coefficient
!            data for the requested sensors.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure SC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 12-Jun-2000
!                       paul.vandelst@noaa.gov
!


!
! CRTM_IRwaterCoeff
!
! Module containing the shared CRTM infrared water surface emissivity
! data and their load/destruction routines.
!
! PUBLIC DATA:
!   IRwaterC:  Data structure containing the infrared water surface
!              emissivity data.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure IRwaterC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 04-May-2012
!                       paul.vandelst@noaa.gov
!


!
! NESDIS_SSMIS_SnowEM_Module
!
! Module containing the SSMIS microwave snow emissivity model
!
! References:
!       Yan,B., F.Weng, and K.Okamoto, 2004, A microwave snow emissivity model,
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
!       Yan,B., F.Weng, and H.Meng, 2008, Retrieval of Snow Surface Microwave
!         Emissivity from Advanced Microwave Sounding Unit (AMSU),
!         J. Geophys. Res., 113, D19206, doi:10.1029/2007JD009559
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 22-Apr-2008, banghua.yan@noaa.gov
!                       Fuzhong Weng, fuzhong.weng@noaa.gov
!
!


!
! Small_Scale_Correction_Module
!
! Module containing the small-scale correction procedures for the
! CRTM implementations of FASTEM4 and FASTEM5
!
! Equation (A4) of
!
!   Liu, Q. et al. (2011) An Improved Fast Microwave Water
!     Emissivity Model, TGRSS, 49, pp1238-1250
!
! describes the fitting of the small-scale correction formulation
! given in equation (17a,b) of
!
!   Liu, Q. et al. (1998) Monte Carlo simulations of the microwave
!     emissivity of the sea surface, JGR, 103, pp24983-24989
!
! and originally in equation (30) of
!
!   Guissard,A. and P.Sobieski (1987) An approximate model
!     for the microwave brightness temperature of the sea,
!     Int.J.Rem.Sens., 8, pp1607-1627.
!
!
! CREATION HISTORY:
!       Written by:     Original FASTEM authors
!
!       Refactored by:  Paul van Delst, November 2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_RTSolution
!
! Module containing the CRTM radiative transfer solution routines.
!
!
! CREATION HISTORY:
!       Written by:     Quanhua Liu,    QSS at JCSDA;    Quanhua.Liu@noaa.gov
!                       Yong Han,       NOAA/NESDIS;     Yong.Han@noaa.gov
!                       Paul van Delst, CIMSS/SSEC;      paul.vandelst@ssec.wisc.edu
!                       08-Jun-2004


!
! CRTM_AtmOptics_Define
!
! Module defining the CRTM AtmOptics object.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 11-Oct-2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_Predictor
!
! Module containing routines to compute the predictors for the regression
! model algorithms that compute the optical depth profile due to gaseous
! absorption.
!


!
! NESDIS_SSMIS_SeaIceEM_Module
!
! Module containing the SSMIS microwave sea ice emissivity model
!
! References:
!       Yan,B., F.Weng, and K.Okamoto, 2004, A microwave snow emissivity model,
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
!       Yan,B., F.Weng, and H.Meng, 2008, Retrieval of Snow Surface Microwave
!         Emissivity from Advanced Microwave Sounding Unit (AMSU),
!         J. Geophys. Res., 113, D19206, doi:10.1029/2007JD009559
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 22-Apr-2008, banghua.yan@noaa.gov
!                       Fuzhong Weng, fuzhong.weng@noaa.gov
!
!


!
! RTV_Define
!
! Module containing the intermediate variables for RTSolution module.
!
!
! NOTE: Modified as generic "bucket" for all RT-related algorithm,
!       ADA, AMOM, and SOI.
!       This is initial step in truly separating out the algorithms
!       into their own modules. Currently each algorithm ties into
!       the same RTV components (not good.)
!
!
!
! CREATION HISTORY:
!       Written by:     Quanhua Liu,    QSS at JCSDA;    Quanhua.Liu@noaa.gov
!                       Yong Han,       NOAA/NESDIS;     Yong.Han@noaa.gov
!                       Paul van Delst, paul.vandelst@noaa.gov
!                       08-Jun-2004


!
! Helper module containing the foam-related utility routines for the
! CRTM implementation of FASTEM4 and FASTEM5
!
!
! CREATION HISTORY:
!       Written by:     Original FASTEM1-5 authors
!
!       Refactored by:  Paul van Delst, November 2011
!                       paul.vandelst@noaa.gov
!


!
! ADA_Module
!
! Module containing the Adding Doubling Adding (ADA) radiative
! transfer solution procedures used in the CRTM.
!
!
! CREATION HISTORY:
!       Written by:     Quanhua Liu, QSS at JCSDA; quanhua.liu@noaa.gov
!                       Yong Han,    NOAA/NESDIS;  yong.han@noaa.gov
!                       Paul van Delst; CIMMS/SSEC; paul.vandelst@noaa.gov
!                       08-Jun-2004


!
! CRTM_Atmosphere_Define
!
! Module defining the CRTM Atmosphere structure and containing routines to
! manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Feb-2004
!                       paul.vandelst@noaa.gov
!


!
! CRTM_Adjoint_Module
!
! Module containing the CRTM adjoint model function.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 28-Jan-2005
!                       paul.vandelst@noaa.gov
!


!
! Search_Utility
!
! Module containing data searching routines
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 06-Oct-2006
!                       paul.vandelst@noaa.gov
!


!
! CRTM_IR_Snow_SfcOptics
!
! Module to compute the surface optical properties for ICE surfaces at
! infrared frequencies required for determining the ICE surface
! contribution to the radiative transfer.
!
! This module is provided to allow developers to "wrap" their existing
! codes inside the provided functions to simplify integration into
! the main CRTM_SfcOptics module.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Jun-2005
!                       paul.vandelst@noaa.gov
!


!
! Helper module containing the azimuth emissivity routines for the
! CRTM implementation of FASTEM6
!
!
! CREATION HISTORY:
!       Written by:     Original FASTEM1-5 authors, and Masahiro Kazumori
!                       for the new azimuthal emissivity model.
!
!       Refactored by:  Paul van Delst, January 2015
!                       paul.vandelst@noaa.gov
!


!
! ACCoeff_Binary_IO
!
! Module containing routines to read and write Binary format
! ACCoeff data files.
!
!
! CREATION HISTORY:
!       Written by:  Paul van Delst, 08-Jun-2007
!                    paul.vandelst@noaa.gov
!


!
! TauCoeff_Define
!
! Module defining the TauCoeff data structure and containing routines to
! manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 18-Mar-2002
!                       paul.vandelst@noaa.gov
!
!       Updated by:     David Groff, EMC/SAIC Oct-2009
!                       david.groff@noaa.gov
!


!
! Ellison Ocean Permittivity module.
!
! Module containing routines to compute the complex permittivities for
! sea water based on
!
!   Ellison, W.J. et al. (2003) A comparison of ocean emissivity models
!     using the Advanced Microwave Sounding Unit, the Special Sensor
!     Microwave Imager, the TRMM Microwave Imager, and airborne radiometer
!     observations. Journal of Geophysical Research, v108, D21, Pages ACL 1,1-14
!     doi:10.1029/2002JD0032132
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 11-Apr-2007
!                       paul.vandelst@noaa.gov
!


!
! Spectral_Units_Conversion
!
! Module containing functions to convert between various spectral units.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 14-Jan-2002
!                       paul.vandelst@noaa.gov
!
!


!
! ODZeeman_TauCoeff
!
! Module containing the shared absorption coefficients (TauCoeff)
! and their load/destruction routines for the Optical Depth Pressure
! Space (ODPS).
!
! PUBLIC DATA:
!       TC:  Data structure array containing the transmittance model
!            coefficient data for the requested sensors.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure TC.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 12-Jun-2000
!                       paul.vandelst@ssec.wisc.edu
!
!       Modifed by:     Yong Han, NESDIS/STAR 10-July-2008
!                       yong.han@noaa.gov
!


!
! SOI_Module
!
! Module containing the Successive Order of Interation (SOI) radiative
! transfer solution procedures used in the CRTM.
!
!
! CREATION HISTORY:
!       Written by:     Tom Greenwald, CIMSS/SSEC; tom.greenwald@ssec.wisc.edu
!                       Paul van Delst;            paul.vandelst@noaa.gov
!                       20-Jan-2010


!
! CRTM_MW_Snow_SfcOptics
!
! Module to compute the surface optical properties for SNOW surfaces at
! microwave frequencies required for determining the SNOW surface
! contribution to the radiative transfer.
!
! This module is provided to allow developers to "wrap" their existing
! codes inside the provided functions to simplify integration into
! the main CRTM_SfcOptics module.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Jun-2005
!                       paul.vandelst@noaa.gov
!
!       Modified by:    Banghua Yan, 03-Oct-2007
!                       Banghua.Yan@noaa.gov
!
!       Modified by:    Yong Chen. 09-Jul-212
!                       Yong.Chen@noaa.gov


!
! NLTECoeff_Define
!
! Module defining the NLTECoeff structure and containing routines to
! manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han, 08-05-2010
!                       yong.han@noaa.gov
!
!       Refactored by:  Paul van Delst, 19-Jan-2011
!                       paul.vandelst@noaa.gov
!


!
! DateTime_Utility
!
! Module defining the DateTime structure and utility routines.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 14-Sep-2007
!                       paul.vandelst@noaa.gov
!


!
! CRTM_Aerosol_Define
!
! Module defining the CRTM Aerosol structure and containing
! routines to manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han,       yong.han@noaa.gov
!                       Quanhua Liu,    quanhua.liu@noaa.gov
!                       Paul van Delst, paul.vandelst@noaa.gov
!                       22-Feb-2005
!


!
! FitCoeff_Define
!
! Module defining the FitCoeff objects.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 17-Nov-2011
!                       paul.vandelst@noaa.gov


!
! CRTM_VISiceCoeff
!
! Module containing the shared CRTM visible ice surface emissivity
! data and their load/destruction routines.
!
! PUBLIC DATA:
!   VISiceC:  Data structure containing the visible ice surface
!             emissivity data.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure VISiceC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 20-Jan-2012
!                       paul.vandelst@noaa.gov
!


!
! CRTM_LifeCycle
!
! Module containing CRTM life cycle functions to initialize and destroy
! the CRTM space.
!
! Written by:     Paul van Delst, 21-May-2004
!                 paul.vandelst@noaa.gov
!


!
! ODPS_CoordinateMapping
!
! Module containing routines to perform data mapping from user pressure space to
! internal pressure space for the ODPS algorithm.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han & Yong Chen, JCSDA, NOAA/NESDIS 10-NOV-2009


!
! ODAS_TauCoeff
!
! Module containing the shared absorption coefficients (TauCoeff)
! and their load/destruction routines for the Optical Depth Absorber
! Space (ODAS).
!
! PUBLIC DATA:
!       TC:  Data structure array containing the transmittance model
!            coefficient data for the requested sensors.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure TC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 12-Jun-2000
!                       paul.vandelst@ssec.wisc.edu
!
!       Modifed by:     Yong Han, NESDIS/STAR 26-June-2008
!                       yong.han@noaa.gov
!


!
! SpcCoeff_Define
!
! Module defining the SpcCoeff data structure and routines
! to manipulate them.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 18-Mar-2002
!                       paul.vandelst@noaa.gov
!


!
! AerosolCoeff_Binary_IO
!
! Module containing routines to read and write Binary format
! AerosolCoeff files.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 24-Jun-2004
!                       paul.vandelst@noaa.gov
!


!
! Liu Ocean Permittivity module.
!
! Module containing routines to compute the complex permittivities for
! sea water based on
!
!   Liu, Q. et al. (2010) An improved fast microwave water emissivity model.
!      IEEE Trans. Geosci. Remote Sensing, accepted June 25, 2010
!
!
! CREATION HISTORY:
!       Written by:     Quanhua (Mark) Liu, JCSDA 30-Jul-2009
!                       Quanhua.Liu@noaa.gov


!
! CRTM_MW_Ice_SfcOptics
!
! Module to compute the surface optical properties for ICE surfaces at
! microwave frequencies required for determining the ICE surface
! contribution to the radiative transfer.
!
! This module is provided to allow developers to "wrap" their existing
! codes inside the provided functions to simplify integration into
! the main CRTM_SfcOptics module.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Jun-2005
!                       paul.vandelst@noaa.gov
!
!       Modified by:    Banghua Yan, 03-Oct-2007
!                       Banghua.Yan@noaa.gov
!


!
! SpcCoeff_Binary_IO
!
! Module containing routines to read and write Binary format
! SpcCoeff data files.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 18-Mar-2002
!                       paul.vandelst@noaa.gov
!


!
! NESDIS_AMSRE_SNOWEM_Module
!
! Module containing the AMSR-E microwave snow emissivity model
!
! References:
!       Yan,B., F.Weng and K.Okamoto,2004: "A microwave snow emissivity model",
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 26-May-2005, banghua.yan@noaa.gov
!                       Fuzhong Weng, fuzhong.weng@noaa.gov
!
!       Modified by:    Banghua Yan, 10-Sep-2005
!                       Quanhua Liu, quanhua.liu@noaa.gov
!                       Yong Han, yong.han@noaa.gov
!


!
! Guillou Ocean Permittivity module.
!
! Module containing routines to compute the complex permittivities for
! sea water based on
!
!   Guillou, C. et al. (1998) Impact of new permittivity measurements
!      on sea surface emissivity modeling in microwaves.
!      Radio Science, Volume 33, Number 3, Pages 649-667
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 11-Apr-2007
!                       paul.vandelst@noaa.gov
!


!
! CRTM_VIS_Water_SfcOptics
!
! Module to compute the surface optical properties for WATER surfaces at
! visible frequencies required for determining the WATER surface
! contribution to the radiative transfer.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 17-Dec-2008
!                       paul.vandelst@noaa.gov
!


!
! SSU_Input_Define
!
! Module containing the structure definition and associated routines
! for CRTM inputs specific to SSU
!
!
! CREATION HISTORY:
!       Written by:     Yong Han, NOAA/NESDIS, Oct 6, 2009
!                       yong.han@noaa.gov
!
!                       Paul van Delst, 20-Oct-2009
!                       paul.vandelst@noaa.gov
!


!
! NESDIS_SSMI_Module
!
! Module containing the SSM/I microwave snow and sea ice  emissivity model
!
! References:
!       Yan,B., F.Weng, and K.Okamoto, 2004, A microwave snow emissivity model,
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 16-May-2005, banghua.yan@noaa.gov
!                       Fuzhong Weng, fuzhong.weng@noaa.gov
!
!


!
! iAtm_Define
!
! Module for defining the Atmosphere module internal data object
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 07-Apr-2009
!                       paul.vandelst@noaa.gov
!


!
! NLTE_Parameters
!
! Module defining parameters used in the various NLTE applications.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han, 08-05-2010
!                       yong.han@noaa.gov
!
!       Refactored by:  Paul van Delst, 18-Jan-2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_VIS_Snow_SfcOptics
!
! Module to compute the surface optical properties for SNOW surfaces at
! visible frequencies required for determining the SNOW surface
! contribution to the radiative transfer.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 31-Jan-2012
!                       paul.vandelst@noaa.gov
!


!
! CRTM_Forward_Module
!
! Module containing the CRTM forward model function.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 29-Jun-2004
!                       paul.vandelst@noaa.gov
!


!
! CRTM_AtmOptics
!
! Application module for AtmOptics objects.
!
! CREATION HISTORY:
!       Written by:     Quanhua Liu,    quanhua.liu@noaa.gov
!                       Yong Han,       yong.han@noaa.gov
!                       Paul van Delst, paul.vandelst@noaa.gov
!                       08-Jun-2005
!


!
! ODSSU_AtmAbsorption
!
! Module containing routines to compute the optical depth profile for SSUs
!
!
! CREATION HISTORY:
!       Based on CRTM_AtmAbsorption_ssu     by:  Quanhua Liu, JCSDA,      Dec  1, 2007
!       Rewritten for CRTMv2.0              by:  Yong Han, NOAA/NESDIS,   Oct  6, 2009
!       Revised                             by:  Paul van Delst, , JCSDA, Oct 26, 2009
!       Revised                             by:  Quanhua Liu, JCSDA,      Oct 29, 2009
!       Revised                             by:  Yong Chen, JCSDA,        Nov  9, 2009
!


!
! CRTM_GeometryInfo
!
! Application module for the GeometryInfo structure.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 19-May-2004
!                       paul.vandelst@noaa.gov
!
!                       Yong Chen, CSU/CIRA 10-May-2006
!                       Yong.Chen@noaa.gov
!


!
! Subset_Define
!
! Module containing the subset type definition and routines
! to manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 26-May-2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_VISwaterCoeff
!
! Module containing the shared CRTM visible water surface emissivity
! data and their load/destruction routines.
!
! PUBLIC DATA:
!   VISwaterC:  Data structure containing the visible water surface
!               emissivity data.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure VISwaterC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 20-Jan-2012
!                       paul.vandelst@noaa.gov
!


!
! MWwaterLUT_Define
!
! Module defining the MWwaterLUT object containing the
! Look-Up Table (LUT) for the microWave (MW) sea surface emissivity
! model.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 10-Nov-2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_NLTECorrection
!
! Module containing routines to correct radiances for the NLTE effect
!
!
! CREATION HISTORY:
!       Written by:     Yong Han, 05-Aug-2010
!                       yong.han@noaa.gov
!


!
! ODAS_Predictor_Define
!
! Module defining the Predictor object for the Optical Depth in
! Absorber Space (ODAS) algorithm and containing routines to
! manipulate it.
!
! CREATION HISTORY:
!       Written by:    Paul van Delst, 22-Dec-2006
!                      paul.vandelst@noaa.gov
!
!       Modifed by:    Yong Han, 25-June-2008
!                      yong.han@noaa.gov
!


!
! NESDIS_AMSRE_SICEEM_Module
!
! Module containing the AMSR-E microwave sea ice emissivity model
!
! References:
!       Yan,B., F.Weng and K.Okamoto,2004: "A microwave snow emissivity model",
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 28-May-2005
!                       banghua.yan@noaa.gov
!                       Fuzhong Weng
!                       fuzhong.weng@noaa.gov
!


!
! CRTM_VISlandCoeff
!
! Module containing the shared CRTM visible land surface emissivity
! data and their load/destruction routines.
!
! PUBLIC DATA:
!   VISlandC:  Data structure containing the visible land surface
!              emissivity data.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure VISlandC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 20-Jan-2012
!                       paul.vandelst@noaa.gov
!


!
! CRTM_IR_Ice_SfcOptics
!
! Module to compute the surface optical properties for ICE surfaces at
! infrared frequencies required for determining the ICE surface
! contribution to the radiative transfer.
!
! This module is provided to allow developers to "wrap" their existing
! codes inside the provided functions to simplify integration into
! the main CRTM_SfcOptics module.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Jun-2005
!                       paul.vandelst@noaa.gov
!


!
! CRTM_Options_Define
!
! Module defining the CRTM Options optional argument data structure
! and containing routines to manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 25-Sep-2004
!                       paul.vandelst@noaa.gov
!


!
! Helper module conmtaining the reflection correction routines for the
! CRTM implementation of FASTEM4 and FASTEM5
!
!
! CREATION HISTORY:
!       Written by:     Original FASTEM1/2/3 authors
!
!       Modified by:    Quanhua Liu, Quanhua.Liu@noaa.gov
!                       Stephen English, Stephen.English@metoffice.gov.uk
!                       July, 2009
!
!       Modified by:    Quanhua Liu, Quanhua.Liu@noaa.gov
!                       Stephen English, Stephen.English@metoffice.gov.uk
!                       August 16, 2011
!
!       Refactored by:  Paul van Delst, November 2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_RTSolution_Define
!
! Module defining the CRTM RTSolution structure and containing routines
! to manipulate it.
!
!
! CREATION HISTORY:
!   Written by:     Paul van Delst, 13-May-2004
!                   paul.vandelst@noaa.gov
!


!
! NESDIS_AMSU_SnowEM_Module
!
! Module containing the AMSU microwave snow emissivity model
!
! References:
!       Yan,B., F.Weng, and K.Okamoto, 2004, A microwave snow emissivity model,
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 03-Jun-2005, banghua.yan@noaa.gov
!                       Fuzhong Weng, fuzhong.weng@noaa.gov
!


!
! CRTM_SfcOptics
!
! Module to compute the surface optical properties required for
! determining the surface contribution to the radiative transfer.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han,       NOAA/NESDIS;     Yong.Han@noaa.gov
!                       Quanhua Liu,    QSS Group, Inc;  Quanhua.Liu@noaa.gov
!                       Paul van Delst, CIMSS/SSEC;      paul.vandelst@ssec.wisc.edu
!                       02-Apr-2004
!


!
! CRTM_LowFrequency_MWSSEM
!
! Module containgin routines to compute microwave ocean emissivity components
! (FWD, TL, and AD) for low frequencies.
!
!
! CREATION HISTORY:
!       Written by:     Masahiro Kazumori, JCSDA 31-Jul-2006
!                       Masahiro.Kazumori@noaa.gov
!                       Quanhua Liu, QSS Group Inc.
!                       Quanhua.Liu@noaa.gov
!
!       Refactored by:  Paul van Delst, CIMSS/SSEC, April 2007
!                       paul.vandelst@ssec.wisc.edu
!


!
! ODZeeman_AtmAbsorption
!
! Module containing routines to compute the optical depth profile
! due to gaseous absorption affected by Zeeman spilitting in
! the Optical Depth Pressure Space (ODPS).
!
!
! CREATION HISTORY:
!       Written by:     Yong Han, 10-Nov-2009
!                       yong.han@noaa.gov
!


!
! CRTM_SensorInfo
!
! Module of sensor information parameters definitions for the CRTM.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 26-Jun-2005
!                       paul.vandelst@ssec.wisc.edu


!
! CRTM_SensorData_Define
!
! Module defining the CRTM SensorData structure and containing
! routines to manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 23-Jul-2004
!                       paul.vandelst@noaa.gov
!


!
! ODAS_Predictor
!
! Module continaing routines to compute the predictors for the
! Optical Depth in Absorber Space (ODAS) .
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 29-Aug-2006
!                       paul.vandelst@noaa.gov
!
!       Modified by:    Yong Han, 25-June-2008
!                       yong.han@noaa.gov
!


!
! NLTE_Predictor_IO
!
! Module containing routines to read and write Binary format
! NLTE_Predictor data files.
!
!
! CREATION HISTORY:
!       Written by:  Paul van Delst, 15-Mar-2011
!                    paul.vandelst@noaa.gov
!


!
! CRTM_Cloud_Define
!
! Module defining the CRTM Cloud structure and containing routines to
! manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han,       yong.han@noaa.gov
!                       Quanhua Liu,    quanhua.liu@noaa.gov
!                       Paul van Delst, paul.vandelst@noaa.gov
!                       20-Feb-2004
!


!
! NESDIS_SEAICE_PHYEM_MODULE
!
! Module containing the NESDIS microwave seaice emissivity physical model
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 13-Jun-2005, banghua.yan@noaa.gov
!                       Fuzhong Weng, fuzhong.weng@noaa.gov
!


!
! CRTM_Surface_Define
!
! Module defining the CRTM Surface structure and containing routines
! to manipulate it.
!
!
! CREATION HISTORY:
!       Written by:  Yong Han,       yong.han@noaa.gov
!                    Quanhua Liu,    quanhua.liu@noaa.gov
!                    Paul van Delst, paul.vandelst@noaa.gov
!                    07-May-2004
!


!--------------------------------------------------------------------------------
!M+
! NAME:
!       NESDIS_ATMS_SnowEM_Module
!
! PURPOSE:
!       Module containing the snow-typing algorithms. A general interface is used to call one of the
!       snow-typing algorithms in !terms of the input arguments. This Module is used together with
!       NESDIS_SnowEM_ATMS_Parameters Module to implement the library-based snow emissivity  model.
!
! REFERENCES:
!       Yan, B., F. Weng and K.Okamoto,2004: "A microwave snow emissivity model, 8th Specialist Meeting on
!
!       Microwave Radiometry and Remote Sension Applications,24-27 February, 2004, Rome, Italy.
!
! CATEGORY:
!       Surface : MW Surface Snow Emissivity of ATMS
!
! LANGUAGE:
!       Fortran-95
!
! CALLING SEQUENCE:
!
!       USE NESDIS_ATMS_SnowEM_Module
!
! MODULES:
!       Type_Kinds:               Module containing definitions for kinds of variable types
!
!       NESDIS_LandEM_Module:     Module containing the microwave land emissivity model
!
!       NESDIS_SnowEM_Parameters: Module containing the predefined microwave snow emissivity spectra
!
! CONTAINS:
!
! PUBLIC SUNPROGRAMS:
!
!       NESDIS_ATMS_SNOWEM:       Subroutine to calculate the microwave snow emissivity from ATMS
!
!
! PRIVATE SUBPROGRAMS:
!       These subroutines are used to determine the snow types from the brightness temperatures(TB)
!       of five ATMS window channels( 23.8 GHz, 31.4 GHz, 50.3 GHz, 88.2 GHz, 165.5 GHz) and/or
!       surface temperature plus snow depth. The five channels are further divided into two
!       groups: Group-1 ( 23.8 GHz, 31.4 GHz, 50.3 GHz, 88.2 GHz) and Group-2 (88.2 GHz, 165.5GHz),
!       corresponding to the window channels of AMSU-A and AMSU-B, respectively.
!       Different combinations of available ATMS window-channel and surface observations result
!       in differenet snow-typing algotrithms:
!
!       ATMS_SNOW_ByTB_A      : by ATMS TBs of Group-1 channels
!       ATMS_SNOW_ByTB_B      : by ATMS TBs of Group-2 channels
!       ATMS_SNOW_ByTBs       : by the TBs  of all the five ATMS channels
!       ATMS_SNOW_ByTBTs_A    : by ATMS TBs of Group-1 channels and surface temperature
!       ATMS_SNOW_ByTBTs_B    : by ATMS TBs of Group-2 channels and surface temperature
!       ATMS_SNOW_ByTBTs      : by the TBs  of all the five ATMS channels and surface temperature (regression-based)
!       ATMS_SNOW_ByTBTs_D    : by the TBs  of all the five ATMS channels and surface temperature (diagnosis-based)
!       ATMS_SNOW_ByTypes     : bydefault surface type (4)
!       ATMS_ALandEM_Snow     : Subroutine to initilize the vaiables to default values
!       em_initialization     : Subroutine to initialization snow emissivity
!       em_interpolate        : Subroutine to perform frequency interpolation of snow emissivity
!
! INCLUDE FILES:
!       None.
!
! EXTERNALS:
!       None.
!
! COMMON BLOCKS:
!       None.
!
! FILES ACCESSED:
!       None.
!
! CREATION HISTORY:
!       Written by:     Ming Chen, IMSG Inc., Banghua.Yan@noaa.gov (04-28-2012)
!
!
!       and             Fuzhong Weng, NOAA/NESDIS/ORA, Fuzhong.Weng@noaa.gov
!
!  Copyright (C) 2012 Fuzhong Weng and Ming Chen
!
!  This program is free software; you can redistribute it and/or modify it under the terms of the GNU
!  General Public License as published by the Free Software Foundation; either version 2 of the License,
!  or (at your option) any later version.
!
!  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
!  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
!  License for more details.
!
!  You should have received a copy of the GNU General Public License along with this program; if not, write
!  to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
!M-
!--------------------------------------------------------------------------------


!
! Zeeman_Input_Define
!
! Module containing the structure definition and associated routines
! for CRTM inputs specific to Zeeman
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 26-Oct-2009
!                       paul.vandelst@noaa.gov
!


!
! CRTM_AntennaCorrection
!
! Module containgin routines to apply the antenna correction to the
! RTSolution brightness temperatures.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 20-Jul-2007
!                       paul.vandelst@noaa.gov
!


!
! AerosolCoeff_Define
!
! Module defining the AerosolCoeff data structure and containing routines to
! manipulate it.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 04-Feb-2005
!                       paul.vandelst@noaa.gov
!       Modified by:    Quanhua Liu, QSS Group, Inc;  quanhua.liu@noaa.gov
!                       David Groff, SAIC;            david.groff@noaa.gov
!


! Utility to define a timing structure and
! timing utility routines.
!


!
! CRTM_AncillaryInput_Define
!
! Module defining a container for CRTM ancillary input.
!
!
! CREATION HISTORY:
!       Modifed by:     Paul van Delst, 08-Dec-2009
!                       paul.vandelst@noaa.gov


!
! NESDIS_MHS_SICEEM_Module
!
! Module containing the MHS microwave sea ice emissivity model
!
! References:
!       Yan,B., F.Weng and K.Okamoto,2004: "A microwave snow emissivity model",
!         8th Specialist Meeting on Microwave Radiometry and Remote Sensing Applications,
!         24-27 February, 2004, Rome, Italy.
!
!       Yan,B., F.Weng, H.Meng, and N.Grody, 2007: "Retrieval of Snow Surface Microwave
!         Emissivity from Advanced Microwave Sounding Unit (AMSU),
!         submitted to J.G.R.
!
!
! CREATION HISTORY:
!       Written by:     Banghua Yan, 05-Oct-2007, banghua.yan@noaa.gov
!


!
! NLTECoeff_Binary_IO
!
! Module containing routines to inquire, read, and write Binary
! NLTECoeff object datafiles.
!
!
! CREATION HISTORY:
!       Written by:     Yong Han, 08-05-2010
!                       yong.han@noaa.gov
!
!       Refactored by:  Paul van Delst, 20-Jan-2011
!                       paul.vandelst@noaa.gov
!


!
! CRTM_MoleculeScatter
!
! Module to compute molecule optical properties.
!
!
! CREATION HISTORY:
!       Written by:     Quanhua Liu, 03-Oct-2008
!                       Quanhua.Liu@noaa.gov
!


!
! CRTM_AerosolCoeff
!
! Module containing the shared CRTM aerosol coefficients (AerosolCoeff)
! and their load/destruction routines.
!
! PUBLIC DATA:
!       AeroC:  Data structure containing the aerosol bulk optical
!               properties data
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure AeroC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 24-Jun-2004
!                       paul.vandelst@noaa.gov
!


!
! SEcategory_Define
!
! Module defining the SEcategory object.
!
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 17-Aug-2011
!                       paul.vandelst@noaa.gov


!
! ODSSU_TauCoeff
!
! Module containing the shared absorption coefficients (TauCoeff)
! and their load/destruction routines for the ODSSU algorithm
!
! PUBLIC DATA:
!       TC:  Data structure array containing the transmittance model
!            coefficient data for the requested sensors.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure TC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, CIMSS/SSEC 12-Jun-2000
!                       paul.vandelst@ssec.wisc.edu
!
!       Modifed by:     Yong Han, NESDIS/STAR 26-June-2008
!                       yong.han@noaa.gov
!


!
! CRTM_IRlandCoeff
!
! Module containing the shared CRTM infrared land surface emissivity
! data and their load/destruction routines.
!
! PUBLIC DATA:
!   IRlandC:  Data structure containing the infrared land surface
!             emissivity data.
!
! SIDE EFFECTS:
!       Routines in this module modify the contents of the public
!       data structure IRlandC.
!
! RESTRICTIONS:
!       Routines in this module should only be called during the
!       CRTM initialisation.
!
! CREATION HISTORY:
!       Written by:     Paul van Delst, 19-Aug-2011
!                       paul.vandelst@noaa.gov
!


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Data_Output_Gridded.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi
!
! Created on May 6, 2015, 4:36 PM
! Last update on February 09, 2023 10:30 AM
!
! Module to save output results (only NC is supported!!!).
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Data_Forcing_Gridded.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi
!
! Created on April 22, 2015, 5:19 PM
! Last update on Dec 15, 2023 09:30 AM
!
! Module to read forcing map.
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Phys.f90
! Author: Fabio Delogu.
!
! Created on April 2, 2014, 5:19 PM
! Last update on Sep 06, 2018 11:00 AM
!
! Snow physics module
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Tools_Generic.f90
! Author: Fabio Delogu, Francesco Avanzi.
!
! Created on March 24, 2014, 1:25 PM
! Last update on Dec 15, 2023 09:30 AM
!
! Module to define generic tools
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module header


!------------------------------------------------------------------------------------
! File:      S3M_Module_Vars_Loader.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani.
!
! Created on March, 4 2015, 9:57 AM
!
! Module to import global variable(s)
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!--------------------------------------------------------------------------------
! File:   S3M_Module_Info_Time.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani.
!
! Created on November, 06 2015, 8:42 AM
!
! Module to get info time
!--------------------------------------------------------------------------------
!--------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow_Apps_Glaciers.f90
! Author:   Francesco Avanzi, Fabio Delogu.
!
! Created on October 07, 2020 6:00 PM
! Last update on October 27, 2020 10:16 AM
!
! Glacier-physics application module
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow_Apps_Hydraulics.f90
! Author:   Francesco Avanzi
!
! Created on June 10, 2020 5:00 PM
! Last update on October 27, 2020 10:45 AM
!
! Snow-hydraulics application module
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Data_AssSWE_Gridded.f90
! Author(s): Francesco Avanzi
!
! Created on September 05, 2018, 11:00 AM
! Last update on October 26, 2020 08:55 AM
!
! Module to read assimilated SWE map.
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:      S3M_Module_Tools_Interp.f90
! Author(s): Fabio Delogu.
!
! Created on April 28, 2017, 4:12 PM
!
! Module to define interpolation tools
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Data_Static_Gridded.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi.
!
! Created on April 30, 2015, 9:45 AM
! Last update on Dec 10, 2020 10:00 AM
!
! Module to read static data.
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:      S3M_Module_Tools_Time.f90
! Author(s): Fabio Delogu.
!
! Created on March 24, 2014, 1:25 PM
!
! Module to define time information
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Info_Gridded.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi.
!
! Created on May, 20 2014, 9:57 AM
! Last update on December 15, 2023 03:00 PM
!
! Module to get info gridded
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!--------------------------------------------------------------------------------
! File:   S3M_Module_Args.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi
!
! Created on February 15, 2017, 4:40 PM
! Last update on Oct 27, 2020 11:45 AM
!
! Module to read argument(s) defined by command-line
!--------------------------------------------------------------------------------
!--------------------------------------------------------------------------------
! Module Args


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow.f90
! Author:   Francesco Avanzi, Fabio Delogu, Simone Gabellani.
!
! Created on Jul 15, 2015 11:00 AM
! Last update on February 09, 2023 10:30 AM
!
! Snow- and glacier-physics subroutine for S3M
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Tools_Debug.f90
! Author: Fabio Delogu.
!
! Created on May 12, 2015, 2:54 PM
!
! Module to define debug tools
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow_Apps_PhasePart.f90
! Author:   Simone Gabellani, Fabio Delogu, Francesco Avanzi.
!
! Created on June 10, 2020 5:00 PM
! Last update on October 27, 2020 11:06 AM
!
! Precipitation phase-partitioning application module
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow_Apps_Assimilation.f90
! Author:   Simone Gabellani, Fabio Delogu, Francesco Avanzi.
!
! Created on June 10, 2020 5:00 PM
! Last update on October 26, 2020 5:00 PM
!
! Assimilation application module
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow_Apps_Density.f90
! Author:   Simone Gabellani, Fabio Delogu, Francesco Avanzi.
!
! Created on June 10, 2020 5:00 PM
! Last update on October 26, 2020 5:04 PM
!
! Snow-density applications module
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!--------------------------------------------------------------------------------
! File:   S3M_Module_Namelist.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi.
!
! Created on May, 20 2014, 9:57 AM
! Last update on October 26, 2020 03:14 PM
!
! Module to allocate and read namelist
!--------------------------------------------------------------------------------
!--------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------
! File:      S3M_Module_Vars_Manager.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi
!
! Created on February 11 2015, 9:57 AM
! Last update on May 20, 2021 11:00 AM
!
! Module to allocate and initialize global variable(s)
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


! Author: Alexey Kuznetsov
! Modified: 28/12/2008
! this Fortran90 module contains a collection of subroutines for plotting data,
! including 2D, 3D plots, surfaces, polar coordinates, histograms
! it is a modification of the GNUFOR interface written by John Burkardt:
! http://orion.math.iastate.edu/burkardt/g_src/gnufor/gnufor.html
!***********************************************************************************
!    This program is free software: you can redistribute it and/or modify
!    it under the terms of the GNU General Public License as published by
!    the Free Software Foundation, version 3 of the License.
!    This program is distributed in the hope that it will be useful,
!    but WITHOUT ANY WARRANTY; without even the implied warranty of
!    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!    GNU General Public License for more details.
!    <http://www.gnu.org/licenses/>.
!***********************************************************************************


!------------------------------------------------------------------------------------
! File:      S3M_Module_Function_IO.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani.
!
! Created on May 11, 2015, 10:27 AM
! Last update on Nov 19, 2020 8:30 AM
!
! Module to perform IO actions
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------
! File:   S3M_Module_Phys_Snow_Apps_Melting.f90
! Author:   Simone Gabellani, Fabio Delogu, Francesco Avanzi.
!
! Created on June 10, 2020 5:00 PM
! Last update on October 27, 2020 10:56 AM
!
! Snow-melt application module
!------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Data_Restart_Gridded.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi.
!
! Created on May 7, 2015, 1:27 PM
! Last update on November 13, 2024 10:55 AM
!
! Module to read restart data.
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header


!------------------------------------------------------------------------------------------
! File:   S3M_Module_Data_Updating_Gridded.f90
! Author(s): Fabio Delogu, Valerio Basso, Francesco Avanzi.
!
! Created on December 19, 2017, 1:19 PM
! Last update on December 15, 2023 10:30 PM
!
! Module to read the snow-depth-assimilation data: SH (snow depth), SQA (quality), SCA, kernel.
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header


! X-means, Pelleg, Moore


!     A GENERAL HARTREE-FOCK PROGRAM
!
!                    C O P Y R I G H T 2008
!
!     by C. Froese Fischer
!        Vanderbilt University
!        Nashville, TN 37235 USA
!
!     August, 2008
!
!     This is a FORTRAN 90/95 version of the HF Fortran 77  program
!     published in Computer Physics Communications, Vol. 43, 355-365 (1987)
!
!     The Pacific Sierra f77tof90 translater was used to produce an initial
!     version in which
!        i) Named COMMON were replacd by a module
!       ii) INTERFACE modules are used to check calling sequences
!      iii) Many obsolete features were removed.
!
!     Incomplete translations and the removal of EQUIVALENCE  and DATA
!     statements were dealt with by the author.
!     ------------------------------------------------------------------
!
!     All comments in the program listing assume the radial function P
!     is the solution of an equation of the form
!
!      P" + ( 2Z/R - Y - L(L+1)/R**2 - E)P = X + T
!
!     where Y is called a potential function
!           X is called an exchange function, and
!           T includes contributions from off-diagonal energy parameter
!
!     The program uses LOG(Z*R) as independent variable and
!                      P/SQRT(R) as dependent variable.
!     As a result all equations must be transformed as described in
!     Sec. 6-2 and 6-4 of the book - ``The Hartree-Fock Method for
!     Atoms'',Wiley Interscience, 1977, by Charlotte FROESE FISCHER.
!     (All references to equations and sections refer to this book.)
!
!     Examples on the use of this version may be found in the book
!     "Computational Atomic Structure: An MCHF approach"
!     by C. Froese Fischer, T. Brage, and P. J\"onssn
!     Institute of Physics Publishing, 1997
!
!     Numerical procedures are the same as those for MCHF and are
!     described in Computer Physics Reports, Vol. 3, 273--326 (1986).
!
!     ------------------------------------------------------------------
!     M O D U L E S
!     ------------------------------------------------------------------
!     Defining data types


!     ------------------------------------------------------------------
!     C O M M O N   M O D U L E S
!     ------------------------------------------------------------------


!     ------------------------------------------------------------------
!     I N T E R F A C E  M O D U L E S
!     ------------------------------------------------------------------


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!
! $Id$


! Template instances of integer kinds for "is"


! Template instances of real kinds for "is"


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!>@todo the channel location_mod.html needs to be written.


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> common routines which can write netcdf arrays no matter which
!> location module is compiled in.
!>@todo FIXME  there is no documentation for this module.
!>@todo FIXME  define ALL the VERTISXXX here, add a call to has_vertical_choice
!>to the xxx/location_mod, and if no, return without needing routines
!>in each of the specific location routines.  if yes, call query and
!>match it with the type to return true/false.  remove vert_is_xxx from
!>all the other location routines!!!  :)
!>will have to replicate the VERTISxxx in the location modules because
!>fortran doesn't allow circular 'use's between modules.  ugh.
!>@todo There is no documentation for this module.


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> Implements location interfaces for a three dimensional spherical shell
!> with a choice of vertical coordinates.
!> Horizontal coordinates are always latitude and longitude.
!> Vertical coordinate choices include pressure, height, model level,
!> scale height, surface, and non-specific (column-integrated values, or
!> with no logically defined vertical location, e.g. hurricane vortex center)
!> The internal representation of the location is stored as
!> radians from 0 to 2 PI for longitude and -PI/2 to PI/2 for latitude to
!> minimize computational cost for distances. However, the external
!> representation is longitude in degrees from 0 to 360 and latitude
!> from -90 to 90 for consistency with most applications in the field.
!>
!> This version supports multiple cutoff distances in an efficient manner.
!> Smaller cutoff values will do less searching than larger ones.  (This was
!> not true in earlier implementations of this code.)
!>


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!------------------------------------------------------------------------------
!> forward_operator_mod.f90
!>
!> This module contains routines related to the forward operator.
!>
!------------------------------------------------------------------------------


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> @{
!> @brief Manage lists of observations
!>
!> Time-ordered sequences of observations.
!> get expected obs is in here
!> @}


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> Should only have fortran "kinds" - number of bytes/precision - for
!> integer, real, etc.  the constants should go into their own module,
!> or this should be renamed 'constants' or something more descriptive
!> than 'types' (which overlaps with dart's use of kinds and types).


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> This module supports both the obs_impact_tool and reading in the
!> table at runtime for use during the assimilation phase, to
!> alter the impact of observations on the state vector.
!>
!> these routines build a table(ntypes, nqtys) which can be
!> indexed quickly at runtime.  this happens in the assimilation
!> loop so performance matters.


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> Random number and random sequence routines.  Can generate random draws
!> from a uniform distribution or random draws from differently shaped
!> distributions (e.g. gaussian, gamma, exponential)


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> Aim: collection of assertions for use in test code


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> A selection of sorting routines. The simplest version sorts a given array
!> of values and returns a copy of the array with the items in ascending sorted
!> order.  This works on integer and real(r8) arrays.
!>
!> Another version returns an integer index array.  Accessing the original
!> list using these indices will traverse the array in sorted order.
!>
!> The final version of the sort routine is similar to the index sort
!> but a compare routine is supplied by the user, allowing this code
!> to sort a list of any kinds of items.
!>
!> @todo FIXME - some routines work in place and some return copies.
!> this affects the calling code in a very visible way.  can we make
!> these consistent?  or add an optional argument that says copy or no?
!> (hard to do because some are functions that return the copy; some
!> are subroutines that work in place.  would need to change the calling
!> code to be all subroutines and pass in either a single array for
!> "in place" or a src and dst array for copy.


! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download
!> Window without cray pointer. Should you point the window at contigous memory?