Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ifdef cleanup #1049

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions diag_manager/diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ MODULE diag_manager_mod
USE diag_table_mod, ONLY: parse_diag_table
USE diag_output_mod, ONLY: get_diag_global_att, set_diag_global_att
USE diag_grid_mod, ONLY: diag_grid_init, diag_grid_end
#ifdef use_yaml
use fms_diag_yaml_mod, only: diag_yaml_object_init, diag_yaml_object_end, get_num_unique_fields, find_diag_field
#endif
use fms_diag_object_mod, only:fms_diag_object

USE constants_mod, ONLY: SECONDS_PER_DAY
Expand Down Expand Up @@ -3702,12 +3699,9 @@ SUBROUTINE diag_manager_end(time)
if (allocated(fileobjND)) deallocate(fileobjND)
if (allocated(fnum_for_domain)) deallocate(fnum_for_domain)

#ifdef use_yaml
if (use_modern_diag) then
call diag_yaml_object_end
call fms_diag_object%diag_end()
endif
#endif
END SUBROUTINE diag_manager_end

!> @brief Replaces diag_manager_end; close just one file: files(file)
Expand Down Expand Up @@ -3919,17 +3913,9 @@ SUBROUTINE diag_manager_init(diag_model_subset, time_init, err_msg)
END IF
END IF

#ifdef use_yaml
if (use_modern_diag) then
CALL diag_yaml_object_init(diag_subset_output)
CALL fms_diag_object%init(diag_subset_output)
CALL fms_diag_object%init(diag_subset_output)
endif
#else
if (use_modern_diag) &
call error_mesg("diag_manager_mod::diag_manager_init", &
& "You need to compile with -Duse_yaml if diag_manager_nml::use_modern_diag=.true.", FATAL)
#endif

if (.not. use_modern_diag) then
CALL parse_diag_table(DIAG_SUBSET=diag_subset_output, ISTAT=mystat, ERR_MSG=err_msg_local)
IF ( mystat /= 0 ) THEN
Expand Down
98 changes: 67 additions & 31 deletions diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module fms_diag_object_mod
#ifdef use_yaml
use fms_diag_file_object_mod, only: fmsDiagFileContainer_type, fmsDiagFile_type, fms_diag_files_object_init
use fms_diag_field_object_mod, only: fmsDiagField_type, fms_diag_fields_object_init
use fms_diag_yaml_mod, only: diag_yaml_object_init, find_diag_field, get_diag_files_id, diag_yaml
use fms_diag_yaml_mod, only: diag_yaml_object_init, diag_yaml_object_end, find_diag_field, &
& get_diag_files_id, diag_yaml
use fms_diag_axis_object_mod, only: fms_diag_axis_object_init, fmsDiagAxis_type, fmsDiagSubAxis_type, &
&diagDomain_t, get_domain_and_domain_type, diagDomain2d_t, &
&fmsDiagAxisContainer_type, fms_diag_axis_object_end, fmsDiagFullAxis_type
Expand Down Expand Up @@ -56,6 +57,7 @@ module fms_diag_object_mod
#endif
contains
procedure :: init => fms_diag_object_init
procedure :: diag_end => fms_diag_object_end
procedure :: fms_register_diag_field_scalar
procedure :: fms_register_diag_field_array
procedure :: fms_register_static_field
Expand All @@ -68,14 +70,13 @@ module fms_diag_object_mod
procedure :: fms_get_diag_field_id_from_name
procedure :: fms_get_axis_name_from_id
procedure :: fms_diag_send_complete
procedure :: diag_end => fms_diag_object_end
#ifdef use_yaml
procedure :: get_diag_buffer
#endif
end type fmsDiagObject_type

type (fmsDiagObject_type), target :: fms_diag_object
integer, private :: registered_variables !< Number of registered variables

public :: fms_register_diag_field_obj
public :: fms_register_diag_field_scalar
public :: fms_register_diag_field_array
Expand All @@ -84,6 +85,7 @@ module fms_diag_object_mod
public :: fms_get_diag_field_id_from_name
public :: fms_diag_object
public :: fmsDiagObject_type
integer, private :: registered_variables !< Number of registered variables
public :: dump_diag_obj

contains
Expand Down Expand Up @@ -132,6 +134,9 @@ subroutine fms_diag_object_end (this)
deallocate(this%FMS_diag_buffers)
this%axes_initialized = fms_diag_axis_object_end(this%diag_axis)
this%initialized = .false.
call diag_yaml_object_end
#else
call mpp_error(FATAL, "You can not call fms_diag_object%end without yaml")
#endif
end subroutine fms_diag_object_end

Expand Down Expand Up @@ -173,7 +178,11 @@ integer function fms_register_diag_field_obj &
integer, allocatable :: file_ids(:) !< The file IDs for this variable
integer :: i !< For do loops
integer, allocatable :: diag_field_indices(:) !< indices where the field was found in the yaml

#endif
#ifndef use_yaml
fms_register_diag_field_obj = DIAG_FIELD_NOT_FOUND
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
diag_field_indices = find_diag_field(varname, modname)
if (diag_field_indices(1) .eq. diag_null) then
!< The field was not found in the table, so return diag_null
Expand Down Expand Up @@ -227,8 +236,6 @@ integer function fms_register_diag_field_obj &
nullify (fileptr)
nullify (fieldptr)
deallocate(diag_field_indices)
#else
fms_register_diag_field_obj = diag_null
#endif
end function fms_register_diag_field_obj

Expand All @@ -251,15 +258,15 @@ INTEGER FUNCTION fms_register_diag_field_scalar(this,module_name, field_name, in
INTEGER, OPTIONAL, INTENT(in) :: area !< Id of the area field
INTEGER, OPTIONAL, INTENT(in) :: volume !< Id of the volume field
CHARACTER(len=*), OPTIONAL, INTENT(in) :: realm !< String to set as the modeling_realm attribute

#ifdef use_yaml
#ifndef use_yaml
fms_register_diag_field_scalar=diag_null
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
fms_register_diag_field_scalar = this%register(&
& module_name, field_name, init_time=init_time, &
& longname=long_name, units=units, missing_value=missing_value, varrange=var_range, &
& standname=standard_name, do_not_log=do_not_log, err_msg=err_msg, &
& area=area, volume=volume, realm=realm)
#else
fms_register_diag_field_scalar = diag_not_registered
#endif
end function fms_register_diag_field_scalar

Expand Down Expand Up @@ -291,14 +298,15 @@ INTEGER FUNCTION fms_register_diag_field_array(this, module_name, field_name, ax
INTEGER, OPTIONAL, INTENT(in) :: volume !< Id of the volume field
CHARACTER(len=*), OPTIONAL, INTENT(in) :: realm !< String to set as the modeling_realm attribute

#ifdef use_yaml
#ifndef use_yaml
fms_register_diag_field_array=diag_null
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
fms_register_diag_field_array = this%register( &
& module_name, field_name, init_time=init_time, &
& axes=axes, longname=long_name, units=units, missing_value=missing_value, varrange=var_range, &
& mask_variant=mask_variant, standname=standard_name, do_not_log=do_not_log, err_msg=err_msg, &
& interp_method=interp_method, tile_count=tile_count, area=area, volume=volume, realm=realm)
#else
fms_register_diag_field_array = diag_not_registered
#endif
end function fms_register_diag_field_array

Expand Down Expand Up @@ -332,15 +340,16 @@ INTEGER FUNCTION fms_register_static_field(this, module_name, field_name, axes,
CHARACTER(len=*), OPTIONAL, INTENT(in) :: realm !< String to set as the value to the
!! modeling_realm attribute

#ifdef use_yaml
#ifndef use_yaml
fms_register_static_field=diag_null
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
! Include static as optional variable to register here
fms_register_static_field = this%register( &
& module_name, field_name, axes=axes, &
& longname=long_name, units=units, missing_value=missing_value, varrange=range, &
& standname=standard_name, do_not_log=do_not_log, area=area, volume=volume, realm=realm, &
& static=.true.)
#else
fms_register_static_field = diag_not_registered
#endif
end function fms_register_static_field

Expand Down Expand Up @@ -370,7 +379,10 @@ FUNCTION fms_diag_axis_init(this, axis_name, axis_data, units, cart_name, long_n
INTEGER, INTENT(in), OPTIONAL :: domain_position !< Domain position, "NORTH" or "EAST"
integer :: id

#ifdef use_yaml
#ifndef use_yaml
id = diag_null
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
CHARACTER(len=:), ALLOCATABLE :: edges_name !< Name of the edges

this%registered_axis = this%registered_axis + 1
Expand Down Expand Up @@ -398,8 +410,6 @@ FUNCTION fms_diag_axis_init(this, axis_name, axis_data, units, cart_name, long_n

id = this%registered_axis
end select
#else
id = diag_null
#endif
end function fms_diag_axis_init

Expand All @@ -411,7 +421,9 @@ subroutine fms_diag_send_complete(this, time_step)

integer :: i !< For do loops

#ifdef use_yaml
#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
class(fmsDiagFileContainer_type), pointer :: diag_file !< Pointer to this%FMS_diag_files(i) (for convenience)

do i = 1, size(this%FMS_diag_files)
Expand All @@ -428,7 +440,9 @@ subroutine fms_diag_field_add_attribute(this, diag_field_id, att_name, att_value
integer, intent(in) :: diag_field_id !< Id of the axis to add the attribute to
character(len=*), intent(in) :: att_name !< Name of the attribute
class(*), intent(in) :: att_value(:) !< The attribute value to add
#ifdef use_yaml
#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
!TODO: Value for diag not found
if ( diag_field_id .LE. 0 ) THEN
RETURN
Expand All @@ -446,7 +460,9 @@ subroutine fms_diag_axis_add_attribute(this, axis_id, att_name, att_value)
character(len=*), intent(in) :: att_name !< Name of the attribute
class(*), intent(in) :: att_value(:) !< The attribute value to add

#ifdef use_yaml
#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
if (axis_id < 0 .and. axis_id > this%registered_axis) &
call mpp_error(FATAL, "diag_axis_add_attribute: The axis_id is not valid")

Expand All @@ -457,6 +473,7 @@ subroutine fms_diag_axis_add_attribute(this, axis_id, att_name, att_value)
#endif
end subroutine fms_diag_axis_add_attribute

#ifdef use_yaml
!> \brief Gets the diag field ID from the module name and field name.
!> \returns a copy of the ID of the diag field or DIAG_FIELD_NOT_FOUND if the field is not registered
PURE FUNCTION fms_get_diag_field_id_from_name(fms_diag_object, module_name, field_name) &
Expand All @@ -468,15 +485,29 @@ PURE FUNCTION fms_get_diag_field_id_from_name(fms_diag_object, module_name, fiel
integer :: i !< For looping
!> Initialize to not found
diag_field_id = DIAG_FIELD_NOT_FOUND
#ifdef use_yaml
!> Loop through fields to find it.
if (fms_diag_object%registered_variables < 1) return
do i=1,fms_diag_object%registered_variables
diag_field_id = fms_diag_object%FMS_diag_fields(i)%id_from_name(module_name, field_name)
if(diag_field_id .ne. DIAG_FIELD_NOT_FOUND) return
enddo
#endif
END FUNCTION fms_get_diag_field_id_from_name
#else
!> \brief This replaces the pure function when not compiled with yaml so that an error can be called
!> \returns Error
FUNCTION fms_get_diag_field_id_from_name(fms_diag_object, module_name, field_name) &
result(diag_field_id)
class(fmsDiagObject_type), intent (in) :: fms_diag_object !< The diag object
CHARACTER(len=*), INTENT(in) :: module_name !< Module name that registered the variable
CHARACTER(len=*), INTENT(in) :: field_name !< Variable name
integer :: diag_field_id
integer :: i !< For looping
!> Initialize to not found
diag_field_id = DIAG_FIELD_NOT_FOUND
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
END FUNCTION fms_get_diag_field_id_from_name
#endif


#ifdef use_yaml
!> returns the buffer object for the given id
Expand All @@ -498,7 +529,10 @@ type(domain2d) FUNCTION fms_get_domain2d(this, ids)
class(fmsDiagObject_type), intent (in) :: this !< The diag object
INTEGER, DIMENSION(:), INTENT(in) :: ids !< Axis IDs.

#ifdef use_yaml
#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
fms_get_domain2d = null_domain2d
#else
INTEGER :: type_of_domain !< The type of domain
CLASS(diagDomain_t), POINTER :: domain !< Diag Domain pointer

Expand All @@ -509,8 +543,6 @@ type(domain2d) FUNCTION fms_get_domain2d(this, ids)
type is (diagDomain2d_t)
fms_get_domain2d = domain%domain2
end select
#else
fms_get_domain2d = null_domain2d
#endif
END FUNCTION fms_get_domain2d

Expand All @@ -520,9 +552,12 @@ integer function fms_get_axis_length(this, axis_id)
class(fmsDiagObject_type), intent (in) :: this !< The diag object
INTEGER, INTENT(in) :: axis_id !< Axis ID of the axis to the length of

#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
fms_get_axis_length = 0
#else
fms_get_axis_length = 0

#ifdef use_yaml
if (axis_id < 0 .and. axis_id > this%registered_axis) &
call mpp_error(FATAL, "fms_get_axis_length: The axis_id is not valid")

Expand All @@ -542,16 +577,17 @@ function fms_get_axis_name_from_id (this, axis_id) &

character (len=:), allocatable :: axis_name

#ifdef use_yaml
#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
axis_name=" "
#else
if (axis_id < 0 .and. axis_id > this%registered_axis) &
call mpp_error(FATAL, "fms_get_axis_length: The axis_id is not valid")

select type (axis => this%diag_axis(axis_id)%axis)
type is (fmsDiagFullAxis_type)
axis_name = axis%get_axis_name()
end select
#else
axis_name = ""
#endif
end function fms_get_axis_name_from_id

Expand Down