Skip to content

Provide default initialization for members of the met_data derived type#1453

Open
mgduda wants to merge 1 commit intoMPAS-Dev:developfrom
mgduda:init_atmosphere/met_data_default_init
Open

Provide default initialization for members of the met_data derived type#1453
mgduda wants to merge 1 commit intoMPAS-Dev:developfrom
mgduda:init_atmosphere/met_data_default_init

Conversation

@mgduda
Copy link
Copy Markdown
Contributor

@mgduda mgduda commented May 7, 2026

This PR adds default initialization for the members of the met_data derived type in the init_atm_read_met module. Without well-defined values for some members, unpredictable floating-point exceptions were possible, e.g.,

  Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

  Backtrace for this error:
  #0  0x15494ec288ff in ???
  #1  0x59ddc0 in __init_atm_read_met_MOD_read_next_met_field
        at src/core_init_atmosphere/mpas_init_atm_read_met.F:388
  #2  0x4ccb7a in __init_atm_cases_MOD_init_atm_case_lbc
        at src/core_init_atmosphere/mpas_init_atm_cases.F:6218
  #3  0x58a373 in __init_atm_cases_MOD_init_atm_setup_case
        at src/core_init_atmosphere/mpas_init_atm_cases.F:327
  #4  0x497807 in __init_atm_core_MOD_init_atm_core_run
        at src/core_init_atmosphere/mpas_init_atm_core.F:92
  #5  0x406084 in __mpas_subdriver_MOD_mpas_run
        at src/driver/mpas_subdriver.F:416
  #6  0x4046da in mpas
        at src/driver/mpas.F:20
  #7  0x404745 in main
        at src/driver/mpas.F:10

By initializing the members of the met_data type, these unpredictable errors can be avoided.

This commit adds default initialization for the members of the met_data derived
type in the init_atm_read_met module. Without well-defined values for some
members, unpredictable floating-point exceptions were possible, e.g.,

  Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

  Backtrace for this error:
  #0  0x15494ec288ff in ???
  MPAS-Dev#1  0x59ddc0 in __init_atm_read_met_MOD_read_next_met_field
        at src/core_init_atmosphere/mpas_init_atm_read_met.F:388
  MPAS-Dev#2  0x4ccb7a in __init_atm_cases_MOD_init_atm_case_lbc
        at src/core_init_atmosphere/mpas_init_atm_cases.F:6218
  MPAS-Dev#3  0x58a373 in __init_atm_cases_MOD_init_atm_setup_case
        at src/core_init_atmosphere/mpas_init_atm_cases.F:327
  MPAS-Dev#4  0x497807 in __init_atm_core_MOD_init_atm_core_run
        at src/core_init_atmosphere/mpas_init_atm_core.F:92
  MPAS-Dev#5  0x406084 in __mpas_subdriver_MOD_mpas_run
        at src/driver/mpas_subdriver.F:416
  MPAS-Dev#6  0x4046da in mpas
        at src/driver/mpas.F:20
  MPAS-Dev#7  0x404745 in main
        at src/driver/mpas.F:10

By initializing the members of the met_data type, these unpredictable errors can
be avoided.
@mgduda mgduda requested a review from islas May 8, 2026 17:03
@mgduda mgduda added Atmosphere Documentation only Changes that impact code comments and documentation, but no executable code bug fix and removed Documentation only Changes that impact code comments and documentation, but no executable code labels May 8, 2026
character (len=25) :: units
character (len=32) :: map_source
character (len=46) :: desc
integer :: version = 5, & ! Format version (must =5 for WPS format)
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.

Given the specification of real32 for variables to use standardized format size, would it be worth using int32 as well for integers?

I know that's not quite in the scope of this PR to set default values, but I thought it may be worth mentioning here, especially as it seems like the specification of variable size as it pertains to reading binary data from a fortran record.

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.

It's a longer story why we use (kind=real32) for real variables but use the default integer kind. In short, MPAS-A has the ability to switch between default 32-bit reals or default 64-bit reals at compile time, but no similar option exists to switch between different default integer sizes. So the real members of the met_data derived type needed to be pinned to a fixed size, but it was (probably?) assumed at the time we made that change that integer variables could safely be assumed to always be the same size.

Anyway, as you said, adding (kind=int32) is probably outside the scope of this PR, which simply aims to ensure that all members have a reasonable default initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants