Skip to content

Modifydiag_field_add_attribute to accept r4 and r8#1625

Merged
rem1776 merged 4 commits intoNOAA-GFDL:mainfrom
uramirez8707:diag_field_add_fix
Jan 2, 2025
Merged

Modifydiag_field_add_attribute to accept r4 and r8#1625
rem1776 merged 4 commits intoNOAA-GFDL:mainfrom
uramirez8707:diag_field_add_fix

Conversation

@uramirez8707
Copy link
Copy Markdown
Contributor

Description
Modifies diag_field_add_attribute to accept r4 and r8
Adds a test

Fixes #1621

How Has This Been Tested?
CI including new test

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included
  • make distcheck passes

Comment on lines +4568 to +4572
type is (real(kind=r4_kind))
call diag_field_add_attribute_scalar_r(diag_field_id, att_name, real(att_value))
type is (real(kind=r8_kind))
call diag_field_add_attribute_scalar_r(diag_field_id, att_name, real(att_value))
type is (integer(kind=i4_kind))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is enforcing the attribute value to be the same as the default precision specifiec at compile time, shouldn't it be the same as the incoming type-value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @bensonr is right here. If I build FMS as r4 then this:

    type is (real(kind=r8_kind))
      call diag_field_add_attribute_scalar_r(diag_field_id, att_name, real(att_value))

will cast the r8 real I pass down into an r4 (since that is what real means).

In my attempt at this, I essentially "doubled up" and made two diag_field_add_attribute_scalar_r4 and a diag_field_add_attribute_scalar_r8 (and similar for the r1d → r41d, r81d)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old diag manager, it ends up always writing the att_value as NF90_FLOAT.

CALL diag_field_attribute_init(diag_field_id, att_name, NF90_FLOAT, rval=att_value)

In 4829fe8, I made the changes so that the new diag manager uses the actual precision of att_value.

type is (real(kind=r4_kind))
CALL diag_field_attribute_init(diag_field_id, att_name, NF90_FLOAT, rval=real((/att_value/)))
type is (real(kind=r8_kind))
CALL diag_field_attribute_init(diag_field_id, att_name, NF90_FLOAT, rval=real((/att_value/)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a r8 value is coming in, shouldn't this be an NF90_DOUBLE in both?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both routines, not both lines, that is.

@rem1776 rem1776 merged commit b77aae9 into NOAA-GFDL:main Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Help with mixed-precision FMS (in GEOS)

4 participants