FMS  2024.01.00
Flexible Modeling System
diag_output_mod

diag_output_mod is an integral part of diag_manager_mod. Its function is to write axis-meta-data, field-meta-data and field data. More...

Functions/Subroutines

subroutine, public diag_field_write (varname, buffer, static, file_num, fileobjU, fileobj, fileobjND, fnum_for_domain, time_in)
 Writes diagnostic data out using fms2_io routine. More...
 
subroutine, public diag_flush (file_num, fileobjU, fileobj, fileobjND, fnum_for_domain)
 Flushes the file into disk. More...
 
subroutine, public diag_output_init (file_name, file_title, file_unit, domain, domainU, fileobj, fileobjU, fileobjND, fnum_domain, attributes)
 Opens the output file. More...
 
subroutine, public diag_write_time (fileob, rtime_value, time_index, time_name)
 Writes the time data to the history file. More...
 
subroutine, public done_meta_data (file_unit)
 Writes axis data to file. More...
 
integer function get_axis_index (num)
 Return the axis index number. More...
 
subroutine, public get_diag_global_att (gAtt)
 Return the global attribute type.
 
subroutine, public set_diag_global_att (component, gridType, tileName)
 Set the global attribute type.
 
subroutine write_attribute_meta (file_unit, num_attributes, attributes, time_method, err_msg, varname, fileob)
 Write out attribute meta data to file. More...
 
subroutine, public write_axis_meta_data (file_unit, axes, fileob, time_ops, time_axis_registered)
 Write the axis meta data to file. More...
 
type(diag_fieldtype) function, public write_field_meta_data (file_unit, name, axes, units, long_name, range, pack, mval, avg_name, time_method, standard_name, interp_method, attributes, num_attributes, use_UGdomain, fileob)
 Write the field meta data to file. More...
 

Variables

integer, dimension(max_axis_num) axis_in_file
 
integer current_file_unit = -1
 
logical, dimension(max_axis_num) edge_axis_flag
 
integer, parameter max_axis_num = 20
 
integer, dimension(2, 2) max_range = RESHAPE((/ -32767, 32767, -127, 127 /), (/2,2/))
 
integer, dimension(2) missval = (/ -32768, -128 /)
 
logical module_is_initialized = .FALSE.
 
integer, parameter mxch = 128
 
integer, parameter mxchl = 256
 
integer, parameter netcdf1 = 1
 
integer num_axis_in_file = 0
 
logical, dimension(max_axis_num) time_axis_flag
 
character(len= *), parameter version = '2020.03'
 

Detailed Description

diag_output_mod is an integral part of diag_manager_mod. Its function is to write axis-meta-data, field-meta-data and field data.

Author
Seth Underwood

Function/Subroutine Documentation

◆ diag_field_write()

subroutine, public diag_output_mod::diag_field_write ( character(len=*), intent(in)  varname,
real, dimension(:,:,:,:), intent(inout)  buffer,
logical, intent(in)  static,
integer, intent(in)  file_num,
type(fmsnetcdfunstructureddomainfile_t), dimension(:), intent(inout)  fileobjU,
type(fmsnetcdfdomainfile_t), dimension(:), intent(inout)  fileobj,
type(fmsnetcdffile_t), dimension(:), intent(inout)  fileobjND,
character(len=2), intent(in)  fnum_for_domain,
integer, intent(in), optional  time_in 
)

Writes diagnostic data out using fms2_io routine.

Parameters
[in]varnameVariable name
[in,out]bufferBuffer containing the variable data
[in]staticFlag indicating if a variable is static
[in]file_numIndex in the fileobj* types array
[in,out]fileobjuArray of non domain decomposed fileobj
[in,out]fileobjArray of domain decomposed fileobj
[in,out]fileobjndArray of unstructured domain fileobj
[in]fnum_for_domainString indicating the type of domain "2d" domain decomposed "ug" unstructured domain decomposed "nd" no domain
[in]time_inTime index

Set up the time. Static field and default time is 0

If the variable is 1D, switch the buffer so that n_diurnal_samples is the second dimension (nx, n_diurnal_samples, 1, 1)

If the variable is 2D, switch the n_diurnal_samples and nz dimension, so local_buffer has dimension (nx, ny, n_diurnal_samples, 1).

Figure out which file object to write output to

Definition at line 802 of file diag_output.F90.

◆ diag_flush()

subroutine, public diag_output_mod::diag_flush ( integer, intent(in)  file_num,
type(fmsnetcdfunstructureddomainfile_t), dimension(:), intent(inout)  fileobjU,
type(fmsnetcdfdomainfile_t), dimension(:), intent(inout)  fileobj,
type(fmsnetcdffile_t), dimension(:), intent(inout)  fileobjND,
character(len=2), intent(in)  fnum_for_domain 
)

Flushes the file into disk.

Parameters
[in]file_numIndex in the fileobj* types array
[in,out]fileobjuArray of non domain decomposed fileobj
[in,out]fileobjArray of domain decomposed fileobj
[in,out]fileobjndArray of unstructured domain fileobj
[in]fnum_for_domainString indicating the type of domain "2d" domain decomposed "ug" unstructured domain decomposed "nd" no domain

Definition at line 930 of file diag_output.F90.

◆ diag_output_init()

subroutine, public diag_output_mod::diag_output_init ( character(len=*), intent(in)  file_name,
character(len=*), intent(in)  file_title,
integer, intent(out)  file_unit,
type(domain2d), intent(in)  domain,
type(domainug), intent(in)  domainU,
type(fmsnetcdfdomainfile_t), intent(inout), target  fileobj,
type(fmsnetcdfunstructureddomainfile_t), intent(inout), target  fileobjU,
type(fmsnetcdffile_t), intent(inout), target  fileobjND,
character(*), intent(out)  fnum_domain,
type(diag_atttype), dimension(:), intent(in), optional  attributes 
)

Opens the output file.

Parameters
[in]file_nameOutput file name
[in]file_titleDescriptive title for the file
[out]file_unitFile unit number assigned to the output file. Needed for subsuquent calls to diag_output_mod
[in]domainDomain associated with file, if domain decomposed
[in]domainuThe unstructure domain
[in,out]fileobjDomain decomposed fileobj
[in,out]fileobjuUnstructured domain fileobj
[in,out]fileobjndNon domain decomposed fileobj
[out]fnum_domainString indicating the type of fileobj was used: "2d" domain decomposed "ug" unstrucuted domain decomposed "nd" no domain
[in]attributesArray of global attributes to be written to file

Checks to make sure that only domain2D or domainUG is used. If both are not null, then FATAL

Check if there is an io_domain

Definition at line 87 of file diag_output.F90.

◆ diag_write_time()

subroutine, public diag_output_mod::diag_write_time ( class(fmsnetcdffile_t), intent(inout)  fileob,
real, intent(in)  rtime_value,
integer, intent(in)  time_index,
character(len=*), intent(in), optional  time_name 
)

Writes the time data to the history file.

Parameters
[in,out]fileobfms2_io file object
[in]rtime_valueThe value of time to be written
[in]time_indexThe index of the time variable
[in]time_nameThe name of the time variable

Get the name of the time variable

Write the time data

Cleanup

Definition at line 865 of file diag_output.F90.

◆ done_meta_data()

subroutine, public diag_output_mod::done_meta_data ( integer, intent(in)  file_unit)

Writes axis data to file.

Writes axis data to file. This subroutine is to be called once per file after all write_meta_data calls, and before the first diag_field_out call.

Parameters
[in]file_unitOutput file unit number

Definition at line 794 of file diag_output.F90.

◆ get_axis_index()

integer function diag_output_mod::get_axis_index ( integer, intent(in)  num)
private

Return the axis index number.

Returns
Integer index

Definition at line 888 of file diag_output.F90.

◆ write_attribute_meta()

subroutine diag_output_mod::write_attribute_meta ( integer, intent(in)  file_unit,
integer, intent(in)  num_attributes,
type(diag_atttype), dimension(:), intent(in)  attributes,
character(len=*), intent(in), optional  time_method,
character(len=*), intent(out), optional  err_msg,
character(len=*), intent(in), optional  varname,
class(fmsnetcdffile_t), intent(inout)  fileob 
)
private

Write out attribute meta data to file.

Write out the attribute meta data to file, for field and axes

Parameters
[in]file_unitFile unit number
[in]num_attributesNumber of attributes to write
[in]attributesArray of attributes
[in]time_methodTo include in cell_methods attribute if present
[out]err_msgReturn error message
[in]varnameThe name of the variable
[in,out]fileobFMS2_io fileobj

Definition at line 732 of file diag_output.F90.

◆ write_axis_meta_data()

subroutine, public diag_output_mod::write_axis_meta_data ( integer, intent(in)  file_unit,
integer, dimension(:), intent(in)  axes,
class(fmsnetcdffile_t), intent(inout)  fileob,
logical, intent(in), optional  time_ops,
logical, intent(inout), optional  time_axis_registered 
)

Write the axis meta data to file.

Parameters
[in]file_unitFile unit number
[in]axesArray of axis ID's, including the time axis
[in,out]fileobFMS2_io fileobj
[in]time_ops.TRUE. if this file contains any min, max, time_rms, or time_average
[in,out]time_axis_registered.TRUE. if the time axis was already written to the file

If the axis is domain decomposed and the type is FmsNetcdfFile_t, this is regional diagnostic So treat it as any other dimension

For regional subaxis add the "domain_decomposition" attribute, which is added fms2_io for (other) domains with sufficient decomposition info.

If the axis is domain decomposed and the type is FmsNetcdfDomainFile_t, this is a domain decomposed dimension so register it as one

If the axis is in unstructured domain and the type is FmsNetcdfUnstructuredDomainFile_t, this is an unstrucutred axis so register it as one

If the axis is not in a domain, register it as a normal dimension

Note
Check if the time variable is registered. It's possible that is_time_axis_registered is set to true if using time-templated files because they aren't closed when done writing. An alternative to this set up would be to put variable_exists into the if statement with an .or. so that it gets registered.

Add the attributes

If not a time axis, add the positive attribute and write the data

Write additional axis attributes, from diag_axis_add_attribute calls

Write additional attribute (calendar_type) for time axis -—

Note
calendar attribute is compliant with CF convention http://www.cgd.ucar.edu/cms/eaton/netcdf/CF-current.htm#cal

Deallocate attributes

Add edges axis with fms2_io

Definition at line 210 of file diag_output.F90.

◆ write_field_meta_data()

type(diag_fieldtype) function, public diag_output_mod::write_field_meta_data ( integer, intent(in)  file_unit,
character(len=*), intent(in)  name,
integer, dimension(:), intent(in)  axes,
character(len=*), intent(in)  units,
character(len=*), intent(in)  long_name,
real, dimension(2), intent(in), optional  range,
integer, intent(in), optional  pack,
real, intent(in), optional  mval,
character(len=*), intent(in), optional  avg_name,
character(len=*), intent(in), optional  time_method,
character(len=*), intent(in), optional  standard_name,
character(len=*), intent(in), optional  interp_method,
type(diag_atttype), dimension(:), intent(in), optional, allocatable  attributes,
integer, intent(in), optional  num_attributes,
logical, intent(in), optional  use_UGdomain,
class(fmsnetcdffile_t), intent(inout)  fileob 
)

Write the field meta data to file.

Returns
diag_fieldtype Field

The meta data for the field is written to the file indicated by file_unit

Parameters
[in]file_unitOutput file unit number
[in]axesArray of axis IDs
[in]nameField name
[in]unitsField units
[in]long_nameField's long name
[in]rangeValid range (min, max). If min > max, the range will be ignored
[in]mvalMissing value, must be within valid range
[in]packPacking flag. Only valid when range specified. Valid values:
Flag Size
1 64bit
2 32bit
4 16bit
8 8bit
[in]avg_nameName of variable containing time averaging info
[in]time_methodName of transformation applied to the time-varying data, i.e. "avg", "min", "max"
[in]standard_nameStandard name of field

Definition at line 468 of file diag_output.F90.