FMS  2025.04
Flexible Modeling System
column_diagnostics.F90
1 !***********************************************************************
2 !* Apache License 2.0
3 !*
4 !* This file is part of the GFDL Flexible Modeling System (FMS).
5 !*
6 !* Licensed under the Apache License, Version 2.0 (the "License");
7 !* you may not use this file except in compliance with the License.
8 !* You may obtain a copy of the License at
9 !*
10 !* http://www.apache.org/licenses/LICENSE-2.0
11 !*
12 !* FMS is distributed in the hope that it will be useful, but WITHOUT
13 !* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
14 !* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 !* PARTICULAR PURPOSE. See the License for the specific language
16 !* governing permissions and limitations under the License.
17 !***********************************************************************
18 !> @defgroup column_diagnostics_mod column_diagnostics_mod
19 !> @ingroup column_diagnostics
20 !! @brief Module to locate and mark desired diagnostic columns
21 
22 !> @addtogroup column_diagnostics_mod
23 !> @{
24 module column_diagnostics_mod
25 
26 use fms_mod, only: fms_init, mpp_pe, mpp_root_pe, &
28  error_mesg, fatal, note, warning, &
30 use time_manager_mod, only: time_manager_init, month_name, &
32 use constants_mod, only: constants_init, pi, radian
33 use mpp_mod, only: input_nml_file
34 use platform_mod, only: r4_kind, r8_kind, fms_file_len
35 !-------------------------------------------------------------------
36 
37 implicit none
38 private
39 
40 !---------------------------------------------------------------------
41 ! module to locate and mark desired diagnostic columns
42 !
43 !
44 !--------------------------------------------------------------------
45 
46 
47 
48 
49 !---------------------------------------------------------------------
50 !----------- ****** VERSION NUMBER ******* ---------------------------
51 
52 
53 ! Include variable "version" to be written to log file.
54 #include<file_version.h>
55 
56 
57 
58 !---------------------------------------------------------------------
59 !------- interfaces --------
60 
65 
66 
68  module procedure initialize_diagnostic_columns_r4
69  module procedure initialize_diagnostic_columns_r8
71 
73  module procedure column_diagnostics_header_r4
74  module procedure column_diagnostics_header_r8
75 end interface column_diagnostics_header
76 
77 !private
78 
79 !--------------------------------------------------------------------
80 !---- namelist -----
81 
82 real(kind=r8_kind) :: crit_xdistance = 4.0_r8_kind !< model grid points must be within crit_xdistance in
83  !! longitude of the requested diagnostics point
84  !! coordinates in order to be flagged as the desired
85  !! point
86  !! [ degrees ]
87 real(kind=r8_kind) :: crit_ydistance = 4.0_r8_kind !< model grid points must be within crit_ydistance in
88  !! latitude of the requested diagnostics point
89  !! coordinates in order to be flagged as the desired
90  !! point
91  !! [ degrees ]
92 
93 namelist / column_diagnostics_nml / &
96 
97 !--------------------------------------------------------------------
98 !-------- public data -----
99 
100 
101 !--------------------------------------------------------------------
102 !------ private data ------
103 
104 
105 logical :: module_is_initialized = .false.
106 
107 !-------------------------------------------------------------------
108 !-------------------------------------------------------------------
109 
110 
111 
112  contains
113 
114 
115 
116 !####################################################################
117 
118 !> @brief Initialization routine for column_diagnostics_mod.
119 !!
120 !> Reads namelist and writes to log.
122 
123 !--------------------------------------------------------------------
124 ! column_diagnostics_init is the constructor for
125 ! column_diagnostics_mod.
126 !--------------------------------------------------------------------
127 
128 !--------------------------------------------------------------------
129 ! local variables:
130 !
131  integer :: iunit !< unit number for nml file
132  integer :: ierr !< error return flag
133  integer :: io !< error return code
134 
135 !--------------------------------------------------------------------
136 ! local variables:
137 !
138 ! unit unit number for nml file
139 ! ierr error return flag
140 ! io error return code
141 !
142 !---------------------------------------------------------------------
143 
144 !--------------------------------------------------------------------
145 ! if routine has already been executed, return.
146 !--------------------------------------------------------------------
147  if (module_is_initialized) return
148 
149 !---------------------------------------------------------------------
150 ! verify that all modules used by this module have been initialized.
151 !----------------------------------------------------------------------
152  call fms_init
153  call time_manager_init
154  call constants_init
155 
156 !---------------------------------------------------------------------
157 ! read namelist.
158 !---------------------------------------------------------------------
159  read (input_nml_file, column_diagnostics_nml, iostat=io)
160  ierr = check_nml_error(io, 'column_diagnostics_nml')
161 !---------------------------------------------------------------------
162 ! write version number and namelist to logfile.
163 !---------------------------------------------------------------------
164  call write_version_number("COLUMN_DIAGNOSTICS_MOD", version)
165  if (mpp_pe() == mpp_root_pe()) then
166  iunit = stdlog()
167  write (iunit, nml=column_diagnostics_nml)
168  endif
169 !--------------------------------------------------------------------
170  module_is_initialized = .true.
171 
172 
173 end subroutine column_diagnostics_init
174 
175 
176 !######################################################################
177 !> @brief close_column_diagnostics_units closes any open column_diagnostics
178 !! files associated with the calling module.
179 subroutine close_column_diagnostics_units (diag_units)
180 
181 !---------------------------------------------------------------------
182 ! close_column_diagnostics_units closes any open column_diagnostics
183 ! files associated with the calling module.
184 !----------------------------------------------------------------------
185 
186 !----------------------------------------------------------------------
187 integer, dimension(:), intent(in) :: diag_units !< array of column diagnostic unit numbers
188 !----------------------------------------------------------------------
189 
190 !--------------------------------------------------------------------
191 ! intent(in) variable:
192 !
193 ! diag_units array of column diagnostic unit numbers
194 !
195 !--------------------------------------------------------------------
196 
197 !--------------------------------------------------------------------
198 ! local variable
199 
200  integer :: nn !< do loop index
201  integer :: io
202 !--------------------------------------------------------------------
203 ! close the unit associated with each diagnostic column.
204 !--------------------------------------------------------------------
205  do nn=1, size(diag_units(:))
206  if (diag_units(nn) /= -1) then
207  close(diag_units(nn), iostat=io )
208  if(io/=0) call error_mesg('column_diagnostics_mod', 'Error in closing file ', fatal)
209  endif
210  end do
211 
212 !---------------------------------------------------------------------
213 
214 
215 end subroutine close_column_diagnostics_units
216 
217 
218 !#####################################################################
219 
220 #include "column_diagnostics_r4.fh"
221 #include "column_diagnostics_r8.fh"
222 
223 
224  end module column_diagnostics_mod
225 !@}
226 ! close documentation grouping
real(kind=r8_kind) crit_ydistance
model grid points must be within crit_ydistance in latitude of the requested diagnostics point coordi...
subroutine, public column_diagnostics_init
Initialization routine for column_diagnostics_mod.
real(kind=r8_kind) crit_xdistance
model grid points must be within crit_xdistance in longitude of the requested diagnostics point coord...
subroutine, public close_column_diagnostics_units(diag_units)
close_column_diagnostics_units closes any open column_diagnostics files associated with the calling m...
integer function, public check_nml_error(IOSTAT, NML_NAME)
Checks the iostat argument that is returned after reading a namelist and determines if the error code...
Definition: fms.F90:523
subroutine, public write_version_number(version, tag, unit)
Prints to the log file (or a specified unit) the version id string and tag name.
Definition: fms.F90:701
subroutine, public fms_init(localcomm, alt_input_nml_path)
Initializes the FMS module and also calls the initialization routines for all modules in the MPP pack...
Definition: fms.F90:286
subroutine, public error_mesg(routine, message, level)
Print notes, warnings and error messages; terminates program for warning and error messages....
Definition: fms.F90:441
integer function stdlog()
This function returns the current standard fortran unit numbers for log messages. Log messages,...
Definition: mpp_util.inc:58
integer function mpp_npes()
Returns processor count for current pelist.
Definition: mpp_util.inc:420
integer function mpp_pe()
Returns processor ID.
Definition: mpp_util.inc:406
subroutine, public get_date(time, year, month, day, hour, minute, second, tick, err_msg)
Gets the date for different calendar types. Given a time_interval, returns the corresponding date und...
subroutine, public time_manager_init()
Initialization routine. Writes the version information to the log file.
character(len=9) function, public month_name(n)
Returns a character string containing the name of the month corresponding to month number n.
Type to represent amounts of time. Implemented as seconds and days to allow for larger intervals.