Skip to content

Clean up #ifndef _USE_LEGACY_LAND_ in atm_land_ice_flux_exchange_mod#174

Open
mlee03 wants to merge 9 commits intoNOAA-GFDL:mainfrom
mlee03:remove-macro
Open

Clean up #ifndef _USE_LEGACY_LAND_ in atm_land_ice_flux_exchange_mod#174
mlee03 wants to merge 9 commits intoNOAA-GFDL:mainfrom
mlee03:remove-macro

Conversation

@mlee03
Copy link
Copy Markdown
Contributor

@mlee03 mlee03 commented Feb 10, 2026

Many lines of duplicate codes in atm_land_ice_flux_exchange_mod, as shown below and linked here, are due to small differences in calls to FMS when the code is compiled with and without the -D_USE_LEGACY_LAND_ macro.

#ifndef _USE_LEGACY_LAND_
    call fms_data_override_ug ('LND', 't_surf',     Land%t_surf,     Time)
    call fms_data_override_ug ('LND', 't_ca',       Land%t_ca,       Time)
    call fms_data_override_ug ('LND', 'rough_mom',  Land%rough_mom,  Time)
    call fms_data_override_ug ('LND', 'rough_heat', Land%rough_heat, Time)
    call fms_data_override_ug ('LND', 'albedo', Land%albedo,     Time)
#else
    call fms_data_override ('LND', 't_surf',     Land%t_surf,     Time)
    call fms_data_override ('LND', 't_ca',       Land%t_ca,       Time)
    call fms_data_override ('LND', 'rough_mom',  Land%rough_mom,  Time)
    call fms_data_override ('LND', 'rough_heat', Land%rough_heat, Time)
    call fms_data_override ('LND', 'albedo', Land%albedo,     Time)
#endif

This PR removes the repetitive code by introducing a new macro defined at the top of the modulefile to be the appropriate subroutine name based on the #ifdef state of _USE_LEGACY_LAND_:

#undef  FMS_DATA_OVERRIDE_
#ifndef _USE_LEGACY_LAND_
#define FMS_DATA_OVERRIDE_ fms_data_override_ug
#else
#define FMS_DATA_OVERRIDE_ fms_data_override
#endif

With the above definition, the example body of code changes to a much more understandable code that is easier to maintain:

call FMS_DATA_OVERRIDE_('LND', 't_surf',     Land%t_surf,     Time)
call FMS_DATA_OVERRIDE_('LND', 't_ca',       Land%t_ca,       Time)
call FMS_DATA_OVERRIDE_ ('LND', 'rough_mom',  Land%rough_mom,  Time)
call FMS_DATA_OVERRIDE_('LND', 'rough_heat', Land%rough_heat, Time)
call FMS_DATA_OVERRIDE_('LND', 'albedo', Land%albedo,     Time)

The code has been hand-checked by comparing the pre-processed files with the below commands:

  1. gfortran -E -D_USE_LEGACY_LAND_ -Duse_AM3_physics atm_land_ice_flux_exchange.F90
  2. gfortran -E -Duse_AM3_physics atm_land_ice_flux_exchange.F90
  3. gfortran -E -D_USE_LEGACY_LAND_ atm_land_ice_flux_exchange.F90

@thomas-robinson
Copy link
Copy Markdown
Member

@Hallberg-NOAA this needs to be tested with the ocean tests to make sure the old atmosphere code still works as expected.

@wfcooke
Copy link
Copy Markdown
Contributor

wfcooke commented Feb 19, 2026

Replacing "gfortran -E" with "fpp" above seems to give the same output.
(As we typically compile with intel, and we know intel lets other issues slip through, it is better to check with fpp too)

I see
#ifdef SCM
in the code too, so is this being tested with a single column model? I doubt it will make a difference but just in case.

@mlee03
Copy link
Copy Markdown
Contributor Author

mlee03 commented Feb 19, 2026

@wfcooke, duly noted. Thank you for the review! I will check the preprocessed files with both GNU and Intel preprocessors, check the SCM code, and amend the PR description afterwards

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.

3 participants