CMEPS icon indicating copy to clipboard operation
CMEPS copied to clipboard

Merge of megan namelist item from CAM and CTSM is failing even though there are only whitespace differences

Open ekluzek opened this issue 1 year ago • 10 comments

I have a case that's failing in the merge of the CAM and CTSM namelist for drv_flds_in in preview_namaelists even though the difference is only in whitespace. It's comparing a character array of strings. It's not recognizing that whitespace differences in the list of strings is valid in FORTRAN. This is in cmeps1_0_20 the latest version right now...

Here is the error I'm getting:

Create namelist for component sesp
   Calling /glade/derecho/scratch/erik/cam6_4_032/cime/CIME/non_py/src/components/stub_comps_nuopc/sesp/cime_config/buildnml
  2024-10-01 16:01:49 cpl 
Create namelist for component drv
   Calling /glade/derecho/scratch/erik/cam6_4_032/components/cmeps/cime_config/buildnml
Writing nuopc_runconfig for components ['CPL', 'ATM', 'LND', 'ICE', 'OCN', 'ROF']
Key: megan_specifier, 
 Value 1: 'CH2O = formaldehyde', 'CO = carbon_monoxide', 
 Value 2: 'CH2O = formaldehyde','CO = carbon_monoxide'
ERROR: incompatible settings in drv_flds_in from 
 /glade/derecho/scratch/erik/cam6_4_032/cime/scripts/SMS_D_Ln9.f19_f19_mg17.FWma2000climo.derecho_intel.cam-outfrq9s_waccm_ma_mam4.20241001_150352_n6ytq4/Buildconf/camconf/drv_flds_in 
 and 
 /glade/derecho/scratch/erik/cam6_4_032/cime/scripts/SMS_D_Ln9.f19_f19_mg17.FWma2000climo.derecho_intel.cam-outfrq9s_waccm_ma_mam4.20241001_150352_n6ytq4/Buildconf/clmconf/drv_flds_in

How to replicate this case:

  • Check out cesm3_0_alpha03d
  • cd ./cime/scripts
  • ./create_test SMS_D_Ln9.f19_f19_mg17.FWma2000climo.derecho_intel.cam-outfrq9s_waccm_ma_mam4 -r . --walltime 00:20:00 --no-build
  • cd
  • ./xmlchange LND_SETS_DUST_EMIS_DRV_FLDS=FALSE
  • ./preview_namelists

ekluzek avatar Oct 01 '24 22:10 ekluzek

@jedwards4b @billsacks this is a potential fix that does get it to work. But, I'm not sure it's the right thing to do. It simply removes the space character from the comparison.

diff --git a/cime_config/buildnml b/cime_config/buildnml
index 44116d98..91cb4f41 100755
--- a/cime_config/buildnml
+++ b/cime_config/buildnml
@@ -605,7 +605,7 @@ def compare_drv_flds_in(first, second, infile1, infile2):
     ###############################################################################
     sharedKeys = set(first.keys()).intersection(second.keys())
     for key in sharedKeys:
-        if first[key] != second[key]:
+        if first[key].replace(" ", "") != second[key].replace(" ", ""):
             print(
                 "Key: {}, \n Value 1: {}, \n Value 2: {}".format(
                     key, first[key], second[key]

The big caveat to this is that it also modifies the internal content of the strings.

ekluzek avatar Oct 01 '24 22:10 ekluzek

I'm not very familiar with the details of this, but the diff you give looks reasonable to me.

billsacks avatar Oct 02 '24 21:10 billsacks

@ekluzek I'm not sure I like this - whitespace should already be removed in buildnml lines 534 and 535:

     name = name.strip()                                                                                                                                
     var = var.strip()      

Why is it needed again?

jedwards4b avatar Oct 02 '24 22:10 jedwards4b

I see it's needed because in this case the extra space is in the middle of the string. I think that your fix is fine.

jedwards4b avatar Oct 02 '24 22:10 jedwards4b

Please submit a PR with the change.

jedwards4b avatar Oct 02 '24 22:10 jedwards4b

As discussed with @ekluzek - One step more robust might be to limit the replacement to spaces after a comma; something like this:

first_key = re.sub(r', +', ',', first[key])
second_key = re.sub(r', +', ',', second[key])
if first_key != second_key:

But as @ekluzek and I discussed, it's going to be very hard to get things totally robust in this check, and it probably isn't worth the time to do that (at least right now), and so we should get something decent and add a comment about its deficiencies.

billsacks avatar Oct 22 '24 20:10 billsacks

To comment on why my proposed fix is an incomplete hack is that it will fail for different scenarios.

  1. First, when the array of strings is broken up on separate lines in a different way from one to the other
  2. Second, if the whitespace content within the array of strings is significant.

In "1" it could fail to recognize that the merge is identical, and will abort needlessly. In "2" it could allow an important difference between the two. However, right now the only character arrays for drv_flds_in are ones where that isn't a problem. It doesn't show up for non-arrays, nor for non-string arrays.

Riffing off of Jim's example the strip statement on 535 could be changed to the substitute I have above. Although I think it might need something outside of the if statement as well.

ekluzek avatar Oct 22 '24 23:10 ekluzek

Louisa reports on a similar problem for a different case:

On Mon, Sep 29, 2025 at 11:00 AM Louisa Emmons <[email protected]> wrote: I got this error: ​ERROR: incompatible settings in drv_flds_in from /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/camconf/drv_flds_in and /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/clmconf/drv_flds_in

Just updating user_nl_cam was not sufficient. Where can I fix this in the code? thanks, Louisa

The only difference I see between the CAM drv_flds_in and CLM is a few missing namelists...

diff -c /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/camconf/drv_flds_in /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/clmconf/drv_flds_in
*** /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/camconf/drv_flds_in  2025-09-29 12:29:15.648754128 -0600
--- /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/clmconf/drv_flds_in  2025-09-29 12:29:17.024205000 -0600
***************
*** 1,6 ****
  &drydep_inparm
!  dep_data_file                = '/glade/campaign/cesm/cesmdata/inputdata/atm/cam/chem/trop_mozart/dvel/dep_data_c20221208.nc'
!  drydep_list          = 'ALKNIT', 'ALKOOH', 'BCARY', 'BENZENE', 'BENZOOH', 'BEPOMUC', 'BIGALD', 'BIGALD1', 'BIGALD2', 'BIGALD3', 'BIGALD4',
           'BIGALK', 'BIGENE', 'BZALD', 'BZOOH', 'C2H2', 'C2H4', 'C2H5OH', 'C2H5OOH', 'C2H6', 'C3H6', 'C3H7OOH',
           'C3H8', 'C6H5OOH', 'CH2O', 'CH3CHO', 'CH3CN', 'CH3COCH3', 'CH3COCHO', 'CH3COOH', 'CH3COOOH', 'CH3OH', 'CH3OOH',
           'CO', 'CRESOL', 'DMS', 'EOOH', 'GLYALD', 'GLYOXAL', 'H2O2', 'H2SO4', 'HCN', 'HCOOH', 'HNO3',
--- 1,6 ----
  &drydep_inparm
!  dep_data_file = '/glade/campaign/cesm/cesmdata/inputdata/atm/cam/chem/trop_mozart/dvel/dep_data_c20221208.nc'
!  drydep_list = 'ALKNIT', 'ALKOOH', 'BCARY', 'BENZENE', 'BENZOOH', 'BEPOMUC', 'BIGALD', 'BIGALD1', 'BIGALD2', 'BIGALD3', 'BIGALD4',
           'BIGALK', 'BIGENE', 'BZALD', 'BZOOH', 'C2H2', 'C2H4', 'C2H5OH', 'C2H5OOH', 'C2H6', 'C3H6', 'C3H7OOH',
           'C3H8', 'C6H5OOH', 'CH2O', 'CH3CHO', 'CH3CN', 'CH3COCH3', 'CH3COCHO', 'CH3COOH', 'CH3COOOH', 'CH3OH', 'CH3OOH',
           'CO', 'CRESOL', 'DMS', 'EOOH', 'GLYALD', 'GLYOXAL', 'H2O2', 'H2SO4', 'HCN', 'HCOOH', 'HNO3',
***************
*** 12,20 ****
           'XYLOL', 'XYLOLOOH'
  /
  &megan_emis_nl
!  megan_factors_file           = '/glade/campaign/cesm/cesmdata/inputdata/atm/cam/chem/trop_mozart/emis/megan21_emis_factors_78pft_c20161108.nc'
!  megan_mapped_emisfctrs               = .false.
!  megan_specifier              = 'ISOP = isoprene', 'MTERP = carene_3 + pinene_a + thujene_a + bornene + terpineol_4 + terpineol_a + terpinyl_ACT_a + myrtenal + sabinene + pinene_b + camphene + fenchene_a + limonene + phellandrene_a + terpinene_a + terpinene_g + terpinolene + phellandrene_b + linalool + ionone_b + geranyl_acetone + neryl_acetone + jasmone + verbenene + ipsenol + myrcene + ocimene_t_b + ocimene_al + ocimene_c_b + 2met_nonatriene',
           'BCARY = farnescene_a + caryophyllene_b + acoradiene + aromadendrene + bergamotene_a + bergamotene_b + bisabolene_a + bisabolene_b + bourbonene_b + cadinene_d + cadinene_g + cedrene_a + copaene_a + cubebene_a + cubebene_b + elemene_b + farnescene_b + germacrene_B + germacrene_D + gurjunene_b + humulene_a + humulene_g + isolongifolene + longifolene + longipinene + muurolene_a + muurolene_g + selinene_b + selinene_d + nerolidol_c + nerolidol_t', 'BIGALK = tricyclene + camphor + fenchone + thujone_a + thujone_b + cineole_1_8 + borneol + bornyl_ACT + cedrol + decanal + heptanal + heptane + hexane + nonanal + octanal + octanol + oxopentanal + pentane + hexanal + hexanol_1 + pentanal + heptanone',
           'BIGENE = 2met_styrene + estragole + piperitone + linalool_OXD_c + linalool_OXD_t + dodecene_1 + met_heptenone + nonenal + octenol_1e3ol + tetradecene_1 + butene + diallyl_2s + met_propenyl_2s + met_jasmonate + hexenal_c3 + hexenal_t2 + hexenol_c3 + hexenyl_ACT_c3', 'TOLUENE = toluene + met_benzoate + phenyl_CCO + met_salicylate + indole + anisole + benzyl-acetate + benzyl-alcohol + Napthalene',
           'XYLENES = cymene_p + cymene_o + homosalate + meta-cymenene', 'CH3OH = methanol',
--- 12,20 ----
           'XYLOL', 'XYLOLOOH'
  /
  &megan_emis_nl
!  megan_factors_file = '/glade/campaign/cesm/cesmdata/inputdata/atm/cam/chem/trop_mozart/emis/megan21_emis_factors_78pft_c20161108.nc'
!  megan_mapped_emisfctrs = .false.
!  megan_specifier = 'ISOP = isoprene', 'MTERP = carene_3 + pinene_a + thujene_a + bornene + terpineol_4 + terpineol_a + terpinyl_ACT_a + myrtenal + sabinene + pinene_b + camphene + fenchene_a + limonene + phellandrene_a + terpinene_a + terpinene_g + terpinolene + phellandrene_b + linalool + ionone_b + geranyl_acetone + neryl_acetone + jasmone + verbenene + ipsenol + myrcene + ocimene_t_b + ocimene_al + ocimene_c_b + 2met_nonatriene',
           'BCARY = farnescene_a + caryophyllene_b + acoradiene + aromadendrene + bergamotene_a + bergamotene_b + bisabolene_a + bisabolene_b + bourbonene_b + cadinene_d + cadinene_g + cedrene_a + copaene_a + cubebene_a + cubebene_b + elemene_b + farnescene_b + germacrene_B + germacrene_D + gurjunene_b + humulene_a + humulene_g + isolongifolene + longifolene + longipinene + muurolene_a + muurolene_g + selinene_b + selinene_d + nerolidol_c + nerolidol_t', 'BIGALK = tricyclene + camphor + fenchone + thujone_a + thujone_b + cineole_1_8 + borneol + bornyl_ACT + cedrol + decanal + heptanal + heptane + hexane + nonanal + octanal + octanol + oxopentanal + pentane + hexanal + hexanol_1 + pentanal + heptanone',
           'BIGENE = 2met_styrene + estragole + piperitone + linalool_OXD_c + linalool_OXD_t + dodecene_1 + met_heptenone + nonenal + octenol_1e3ol + tetradecene_1 + butene + diallyl_2s + met_propenyl_2s + met_jasmonate + hexenal_c3 + hexenal_t2 + hexenol_c3 + hexenyl_ACT_c3', 'TOLUENE = toluene + met_benzoate + phenyl_CCO + met_salicylate + indole + anisole + benzyl-acetate + benzyl-alcohol + Napthalene',
           'XYLENES = cymene_p + cymene_o + homosalate + meta-cymenene', 'CH3OH = methanol',
***************
*** 30,44 ****
  /
  &carma_inparm
  /
- &ndep_inparm
- /
- &ozone_coupling_nl
-  atm_ozone_frequency          = 'subdaily'
- /
- &lightning_coupling_nl
-  atm_provides_lightning               = .true.
- /
  &dust_emis_inparm
!  dust_emis_method             = 'Zender_2003'
!  zender_soil_erod_source              = 'atm'
  /
--- 30,43 ----
  /
  &carma_inparm
  /
  &dust_emis_inparm
!  dust_emis_method = 'Zender_2003'
!  zender_soil_erod_source = 'atm'
  /
+ !#--------------------------------------------------------------------------------------------------------------------------
+ !# drv_flds_in:: Comment:
+ !# This namelist was created using the following command-line:
+ !#     /glade/work/emmons/cesm_src_derecho/cesm3_0_beta06_megan/components/clm/bld/CLM build-namelist -cimeroot /glade/work/emmons/cesm_src_derecho/cesm3_0_beta06_megan/cime -infile /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/clmconf/namelist -csmdata /glade/campaign/cesm/cesmdata/inputdata -inputdata /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/ctsm.input_data_list -ignore_ic_year -namelist &clm_inparm  start_ymd=20230101 /  -no-megan -use_case 20thC_transient -res 0.9x1.25 -clm_start_type default -envxml_dir /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on -configuration clm -structure standard -glc_nec 10 -co2_ppmv 284.7 -co2_type diagnostic -config /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.clm6.drought_on/Buildconf/clmconf/config_cache.xml -driver nuopc --bgc sp --no-megan --no-drydep --no-fire_emis -clm_accelerated_spinup off -lnd_tuning_mode clm6_0_cam6.0 -mask gx1v7
+ !# 
+ !# For help on options use: /glade/work/emmons/cesm_src_derecho/cesm3_0_beta06_megan/components/clm/bld/CLM build-namelist -help

ekluzek avatar Sep 29 '25 18:09 ekluzek

Oh, wait in the above I removed whitespace differences, so it is the same problem! Editing above to correct.

ekluzek avatar Sep 29 '25 19:09 ekluzek

Sorry for the confusion - While Erik was looking at my case I updated my user_nl_cam and user_nl_clm to have identical dust, megan and drydep lists - so the camconf/drv_flds_in and clmconf/drv_flds_in were identical. That case is running now - the whitespace differences are not a problem. The original problem was that the dust schemes were different: Key: dust_emis_method, Value 1: 'Zender_2003', Value 2: 'Leung_2023' ERROR: incompatible settings in drv_flds_in from /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.cam6_clm6.test1/Buildconf/camconf/drv_flds_in and /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.cam6_clm6.test1/Buildconf/clmconf/drv_flds_in

Please see this case: /glade/u/home/emmons/derecho/cases_asiaaq/f.e3b06m.FCnudged.ts12.f09.cam6_clm6.test1/ I will not modify it.

lkemmons avatar Sep 29 '25 19:09 lkemmons