We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
mct interface defined twice
From tony craig:

There is an mct interface defined in share/csm_share/shr/mct_mod.F90 twice,

   use m_GlobalSegMap       ,only: mct_gsMap_OP           => OrderedPoints
   use m_GlobalSegMap       ,only: mct_gsMap_orderedPoints=> OrderedPoints

The mct_gsmap_orderedpoints is used throughout CESM.  The mct_gsmap_op
is used only in clm (which also uses mct_gsmap_orderedpoints by the way).

I suggest we modify the calls to mct_gsmap_op to mct_gsmap_orderedpoints
in clm and then delete that interface in mct_mod.F90.

I am using cesm15.beta06 right now, but assume it's still the case in the latest
version.  I see the string in the following places,

components/clm/src_clm40/main/GetGlobalValuesMod.F90:    call mct_gsmap_op(gsmap, iam, gsmap_ordered)
components/clm/src_clm40/main/ncdio_pio.F90.in:  use mct_mod , only : mct_gsMap, mct_gsMap_lsize, mct_gsMap_gsize, mct_gsMap_OP
components/clm/src_clm40/main/ncdio_pio.F90.in:    call mct_gsmap_OP(gsmap,iam,gsmOP)
components/clm/src/main/GetGlobalValuesMod.F90:    call mct_gsmap_op(gsmap, iam, gsmap_ordered)
components/clm/src/main/ncdio_pio.F90.in:  use mct_mod        , only : mct_gsMap, mct_gsMap_lsize, mct_gsMap_gsize, mct_gsMap_OP
components/clm/src/main/ncdio_pio.F90.in:    call mct_gsmap_OP(gsmap,iam,gsmOP)
components/clm/src/ED/main/EDRestVectorMod.F90:    use mct_mod, only : mct_gsMap, mct_gsmap_OP
components/clm/src/ED/main/EDRestVectorMod.F90:    call mct_gsmap_OP(gsmap, iam, gsmOP)
components/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90: public :: mct_gsMap_OP
components/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90: subroutine mct_gsMap_OP(GSMap, PEno, Points)
components/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90:    ! Stub routine that simply matches the signature of mct_gsMap_OP
components/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90:  end subroutine mct_gsMap_OP


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/lib/CIME/preview_namelists.py`
Content:
```
1 """
2 API for preview namelist
3 """
4 
5 from CIME.XML.standard_module_setup import *
6 
7 import glob, shutil, imp
8 logger = logging.getLogger(__name__)
9 
10 def create_dirs(case):
11     """
12     Make necessary directories for case
13     """
14     # Get data from XML
15     exeroot  = case.get_value("EXEROOT")
16     libroot  = case.get_value("LIBROOT")
17     incroot  = case.get_value("INCROOT")
18     rundir   = case.get_value("RUNDIR")
19     caseroot = case.get_value("CASEROOT")
20 
21     docdir = os.path.join(caseroot, "CaseDocs")
22     dirs_to_make = []
23     models = case.get_values("COMP_CLASSES")
24     for model in models:
25         dirname = model.lower()
26         dirs_to_make.append(os.path.join(exeroot, dirname, "obj"))
27 
28     dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])
29 
30     for dir_to_make in dirs_to_make:
31         if (not os.path.isdir(dir_to_make)):
32             try:
33                 logger.debug("Making dir '%s'" % dir_to_make)
34                 os.makedirs(dir_to_make)
35             except OSError as e:
36                 expect(False, "Could not make directory '%s', error: %s" % (dir_to_make, e))
37 
38     # As a convenience write the location of the case directory in the bld and run directories
39     for dir_ in (exeroot, rundir):
40         with open(os.path.join(dir_,"CASEROOT"),"w+") as fd:
41             fd.write(caseroot+"\n")
42 
43 def create_namelists(case):
44     """
45     Create component namelists
46     """
47     case.flush()
48 
49     create_dirs(case)
50 
51     casebuild = case.get_value("CASEBUILD")
52     caseroot = case.get_value("CASEROOT")
53     rundir = case.get_value("RUNDIR")
54 
55     docdir = os.path.join(caseroot, "CaseDocs")
56 
57     # Load modules
58     case.load_env()
59 
60     logger.info("Creating component namelists")
61 
62     # Create namelists - must have cpl last in the list below
63     # Note - cpl must be last in the loop below so that in generating its namelist,
64     # it can use xml vars potentially set by other component's buildnml scripts
65     models = case.get_values("COMP_CLASSES")
66     models += [models.pop(0)]
67     for model in models:
68         model_str = model.lower()
69         config_file = case.get_value("CONFIG_%s_FILE" % model_str.upper())
70         config_dir = os.path.dirname(config_file)
71         if model_str == "cpl":
72             compname = "drv"
73         else:
74             compname = case.get_value("COMP_%s" % model_str.upper())
75 
76         cmd = os.path.join(config_dir, "buildnml")
77         do_run_cmd = False
78         try:
79             with open(cmd, 'r') as f:
80                 first_line = f.readline()
81             if "python" in first_line:
82                 logger.info("   Calling %s buildnml"%compname)
83                 mod = imp.load_source("buildnml", cmd)
84                 mod.buildnml(case, caseroot, compname)
85             else:
86                 raise SyntaxError
87         except SyntaxError as detail:
88             if 'python' in first_line:
89                 expect(False, detail)
90             else:
91                 do_run_cmd = True
92         except AttributeError:
93             do_run_cmd = True
94         except:
95             raise
96 
97         if do_run_cmd:
98             logger.info("   Running %s buildnml"%compname)
99             case.flush()
100             output = run_cmd_no_fail("%s %s" % (cmd, caseroot), verbose=False)
101             logger.info(output)
102             # refresh case xml object from file
103             case.read_xml()
104 
105     logger.info("Finished creating component namelists")
106 
107     # Save namelists to docdir
108     if (not os.path.isdir(docdir)):
109         os.makedirs(docdir)
110         try:
111             with open(os.path.join(docdir, "README"), "w") as fd:
112                 fd.write(" CESM Resolved Namelist Files\n   For documentation only DO NOT MODIFY\n")
113         except (OSError, IOError) as e:
114             expect(False, "Failed to write %s/README: %s" % (docdir, e))
115 
116     for cpglob in ["*_in_[0-9]*", "*modelio*", "*_in",
117                    "*streams*txt*", "*stxt", "*maps.rc", "*cism.config*"]:
118         for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):
119             logger.debug("Copy file from '%s' to '%s'" % (file_to_copy, docdir))
120             shutil.copy2(file_to_copy, docdir)
121 
122     # Copy over chemistry mechanism docs if they exist
123     if (os.path.isdir(os.path.join(casebuild, "camconf"))):
124         for file_to_copy in glob.glob(os.path.join(casebuild, "camconf", "*chem_mech*")):
125             shutil.copy2(file_to_copy, docdir)
126
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/lib/CIME/preview_namelists.py b/scripts/lib/CIME/preview_namelists.py
--- a/scripts/lib/CIME/preview_namelists.py
+++ b/scripts/lib/CIME/preview_namelists.py
@@ -75,12 +75,14 @@
 
         cmd = os.path.join(config_dir, "buildnml")
         do_run_cmd = False
+        # This code will try to import and run each buildnml as a subroutine
+        # if that fails it will run it as a program in a seperate shell
         try:
             with open(cmd, 'r') as f:
                 first_line = f.readline()
             if "python" in first_line:
-                logger.info("   Calling %s buildnml"%compname)
                 mod = imp.load_source("buildnml", cmd)
+                logger.info("   Calling %s buildnml"%compname)
                 mod.buildnml(case, caseroot, compname)
             else:
                 raise SyntaxError

{"golden_diff": "diff --git a/scripts/lib/CIME/preview_namelists.py b/scripts/lib/CIME/preview_namelists.py\n--- a/scripts/lib/CIME/preview_namelists.py\n+++ b/scripts/lib/CIME/preview_namelists.py\n@@ -75,12 +75,14 @@\n \n         cmd = os.path.join(config_dir, \"buildnml\")\n         do_run_cmd = False\n+        # This code will try to import and run each buildnml as a subroutine\n+        # if that fails it will run it as a program in a seperate shell\n         try:\n             with open(cmd, 'r') as f:\n                 first_line = f.readline()\n             if \"python\" in first_line:\n-                logger.info(\"   Calling %s buildnml\"%compname)\n                 mod = imp.load_source(\"buildnml\", cmd)\n+                logger.info(\"   Calling %s buildnml\"%compname)\n                 mod.buildnml(case, caseroot, compname)\n             else:\n                 raise SyntaxError\n", "issue": "mct interface defined twice\nFrom tony craig:\r\n\r\nThere is an mct interface defined in share/csm_share/shr/mct_mod.F90 twice,\r\n\r\n   use m_GlobalSegMap       ,only: mct_gsMap_OP           => OrderedPoints\r\n   use m_GlobalSegMap       ,only: mct_gsMap_orderedPoints=> OrderedPoints\r\n\r\nThe mct_gsmap_orderedpoints is used throughout CESM.  The mct_gsmap_op\r\nis used only in clm (which also uses mct_gsmap_orderedpoints by the way).\r\n\r\nI suggest we modify the calls to mct_gsmap_op to mct_gsmap_orderedpoints\r\nin clm and then delete that interface in mct_mod.F90.\r\n\r\nI am using cesm15.beta06 right now, but assume it's still the case in the latest\r\nversion.  I see the string in the following places,\r\n\r\ncomponents/clm/src_clm40/main/GetGlobalValuesMod.F90:    call mct_gsmap_op(gsmap, iam, gsmap_ordered)\r\ncomponents/clm/src_clm40/main/ncdio_pio.F90.in:  use mct_mod , only : mct_gsMap, mct_gsMap_lsize, mct_gsMap_gsize, mct_gsMap_OP\r\ncomponents/clm/src_clm40/main/ncdio_pio.F90.in:    call mct_gsmap_OP(gsmap,iam,gsmOP)\r\ncomponents/clm/src/main/GetGlobalValuesMod.F90:    call mct_gsmap_op(gsmap, iam, gsmap_ordered)\r\ncomponents/clm/src/main/ncdio_pio.F90.in:  use mct_mod        , only : mct_gsMap, mct_gsMap_lsize, mct_gsMap_gsize, mct_gsMap_OP\r\ncomponents/clm/src/main/ncdio_pio.F90.in:    call mct_gsmap_OP(gsmap,iam,gsmOP)\r\ncomponents/clm/src/ED/main/EDRestVectorMod.F90:    use mct_mod, only : mct_gsMap, mct_gsmap_OP\r\ncomponents/clm/src/ED/main/EDRestVectorMod.F90:    call mct_gsmap_OP(gsmap, iam, gsmOP)\r\ncomponents/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90: public :: mct_gsMap_OP\r\ncomponents/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90: subroutine mct_gsMap_OP(GSMap, PEno, Points)\r\ncomponents/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90:    ! Stub routine that simply matches the signature of mct_gsMap_OP\r\ncomponents/clm/src/unit_test_stubs/csm_share/mct_mod_stub.F90:  end subroutine mct_gsMap_OP\r\n\n", "before_files": [{"content": "\"\"\"\nAPI for preview namelist\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\n\nimport glob, shutil, imp\nlogger = logging.getLogger(__name__)\n\ndef create_dirs(case):\n    \"\"\"\n    Make necessary directories for case\n    \"\"\"\n    # Get data from XML\n    exeroot  = case.get_value(\"EXEROOT\")\n    libroot  = case.get_value(\"LIBROOT\")\n    incroot  = case.get_value(\"INCROOT\")\n    rundir   = case.get_value(\"RUNDIR\")\n    caseroot = case.get_value(\"CASEROOT\")\n\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n    dirs_to_make = []\n    models = case.get_values(\"COMP_CLASSES\")\n    for model in models:\n        dirname = model.lower()\n        dirs_to_make.append(os.path.join(exeroot, dirname, \"obj\"))\n\n    dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])\n\n    for dir_to_make in dirs_to_make:\n        if (not os.path.isdir(dir_to_make)):\n            try:\n                logger.debug(\"Making dir '%s'\" % dir_to_make)\n                os.makedirs(dir_to_make)\n            except OSError as e:\n                expect(False, \"Could not make directory '%s', error: %s\" % (dir_to_make, e))\n\n    # As a convenience write the location of the case directory in the bld and run directories\n    for dir_ in (exeroot, rundir):\n        with open(os.path.join(dir_,\"CASEROOT\"),\"w+\") as fd:\n            fd.write(caseroot+\"\\n\")\n\ndef create_namelists(case):\n    \"\"\"\n    Create component namelists\n    \"\"\"\n    case.flush()\n\n    create_dirs(case)\n\n    casebuild = case.get_value(\"CASEBUILD\")\n    caseroot = case.get_value(\"CASEROOT\")\n    rundir = case.get_value(\"RUNDIR\")\n\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n\n    # Load modules\n    case.load_env()\n\n    logger.info(\"Creating component namelists\")\n\n    # Create namelists - must have cpl last in the list below\n    # Note - cpl must be last in the loop below so that in generating its namelist,\n    # it can use xml vars potentially set by other component's buildnml scripts\n    models = case.get_values(\"COMP_CLASSES\")\n    models += [models.pop(0)]\n    for model in models:\n        model_str = model.lower()\n        config_file = case.get_value(\"CONFIG_%s_FILE\" % model_str.upper())\n        config_dir = os.path.dirname(config_file)\n        if model_str == \"cpl\":\n            compname = \"drv\"\n        else:\n            compname = case.get_value(\"COMP_%s\" % model_str.upper())\n\n        cmd = os.path.join(config_dir, \"buildnml\")\n        do_run_cmd = False\n        try:\n            with open(cmd, 'r') as f:\n                first_line = f.readline()\n            if \"python\" in first_line:\n                logger.info(\"   Calling %s buildnml\"%compname)\n                mod = imp.load_source(\"buildnml\", cmd)\n                mod.buildnml(case, caseroot, compname)\n            else:\n                raise SyntaxError\n        except SyntaxError as detail:\n            if 'python' in first_line:\n                expect(False, detail)\n            else:\n                do_run_cmd = True\n        except AttributeError:\n            do_run_cmd = True\n        except:\n            raise\n\n        if do_run_cmd:\n            logger.info(\"   Running %s buildnml\"%compname)\n            case.flush()\n            output = run_cmd_no_fail(\"%s %s\" % (cmd, caseroot), verbose=False)\n            logger.info(output)\n            # refresh case xml object from file\n            case.read_xml()\n\n    logger.info(\"Finished creating component namelists\")\n\n    # Save namelists to docdir\n    if (not os.path.isdir(docdir)):\n        os.makedirs(docdir)\n        try:\n            with open(os.path.join(docdir, \"README\"), \"w\") as fd:\n                fd.write(\" CESM Resolved Namelist Files\\n   For documentation only DO NOT MODIFY\\n\")\n        except (OSError, IOError) as e:\n            expect(False, \"Failed to write %s/README: %s\" % (docdir, e))\n\n    for cpglob in [\"*_in_[0-9]*\", \"*modelio*\", \"*_in\",\n                   \"*streams*txt*\", \"*stxt\", \"*maps.rc\", \"*cism.config*\"]:\n        for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):\n            logger.debug(\"Copy file from '%s' to '%s'\" % (file_to_copy, docdir))\n            shutil.copy2(file_to_copy, docdir)\n\n    # Copy over chemistry mechanism docs if they exist\n    if (os.path.isdir(os.path.join(casebuild, \"camconf\"))):\n        for file_to_copy in glob.glob(os.path.join(casebuild, \"camconf\", \"*chem_mech*\")):\n            shutil.copy2(file_to_copy, docdir)\n", "path": "scripts/lib/CIME/preview_namelists.py"}], "after_files": [{"content": "\"\"\"\nAPI for preview namelist\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\n\nimport glob, shutil, imp\nlogger = logging.getLogger(__name__)\n\ndef create_dirs(case):\n    \"\"\"\n    Make necessary directories for case\n    \"\"\"\n    # Get data from XML\n    exeroot  = case.get_value(\"EXEROOT\")\n    libroot  = case.get_value(\"LIBROOT\")\n    incroot  = case.get_value(\"INCROOT\")\n    rundir   = case.get_value(\"RUNDIR\")\n    caseroot = case.get_value(\"CASEROOT\")\n\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n    dirs_to_make = []\n    models = case.get_values(\"COMP_CLASSES\")\n    for model in models:\n        dirname = model.lower()\n        dirs_to_make.append(os.path.join(exeroot, dirname, \"obj\"))\n\n    dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])\n\n    for dir_to_make in dirs_to_make:\n        if (not os.path.isdir(dir_to_make)):\n            try:\n                logger.debug(\"Making dir '%s'\" % dir_to_make)\n                os.makedirs(dir_to_make)\n            except OSError as e:\n                expect(False, \"Could not make directory '%s', error: %s\" % (dir_to_make, e))\n\n    # As a convenience write the location of the case directory in the bld and run directories\n    for dir_ in (exeroot, rundir):\n        with open(os.path.join(dir_,\"CASEROOT\"),\"w+\") as fd:\n            fd.write(caseroot+\"\\n\")\n\ndef create_namelists(case):\n    \"\"\"\n    Create component namelists\n    \"\"\"\n    case.flush()\n\n    create_dirs(case)\n\n    casebuild = case.get_value(\"CASEBUILD\")\n    caseroot = case.get_value(\"CASEROOT\")\n    rundir = case.get_value(\"RUNDIR\")\n\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n\n    # Load modules\n    case.load_env()\n\n    logger.info(\"Creating component namelists\")\n\n    # Create namelists - must have cpl last in the list below\n    # Note - cpl must be last in the loop below so that in generating its namelist,\n    # it can use xml vars potentially set by other component's buildnml scripts\n    models = case.get_values(\"COMP_CLASSES\")\n    models += [models.pop(0)]\n    for model in models:\n        model_str = model.lower()\n        config_file = case.get_value(\"CONFIG_%s_FILE\" % model_str.upper())\n        config_dir = os.path.dirname(config_file)\n        if model_str == \"cpl\":\n            compname = \"drv\"\n        else:\n            compname = case.get_value(\"COMP_%s\" % model_str.upper())\n\n        cmd = os.path.join(config_dir, \"buildnml\")\n        do_run_cmd = False\n        # This code will try to import and run each buildnml as a subroutine\n        # if that fails it will run it as a program in a seperate shell\n        try:\n            with open(cmd, 'r') as f:\n                first_line = f.readline()\n            if \"python\" in first_line:\n                mod = imp.load_source(\"buildnml\", cmd)\n                logger.info(\"   Calling %s buildnml\"%compname)\n                mod.buildnml(case, caseroot, compname)\n            else:\n                raise SyntaxError\n        except SyntaxError as detail:\n            if 'python' in first_line:\n                expect(False, detail)\n            else:\n                do_run_cmd = True\n        except AttributeError:\n            do_run_cmd = True\n        except:\n            raise\n\n        if do_run_cmd:\n            logger.info(\"   Running %s buildnml\"%compname)\n            case.flush()\n            output = run_cmd_no_fail(\"%s %s\" % (cmd, caseroot), verbose=False)\n            logger.info(output)\n            # refresh case xml object from file\n            case.read_xml()\n\n    logger.info(\"Finished creating component namelists\")\n\n    # Save namelists to docdir\n    if (not os.path.isdir(docdir)):\n        os.makedirs(docdir)\n        try:\n            with open(os.path.join(docdir, \"README\"), \"w\") as fd:\n                fd.write(\" CESM Resolved Namelist Files\\n   For documentation only DO NOT MODIFY\\n\")\n        except (OSError, IOError) as e:\n            expect(False, \"Failed to write %s/README: %s\" % (docdir, e))\n\n    for cpglob in [\"*_in_[0-9]*\", \"*modelio*\", \"*_in\",\n                   \"*streams*txt*\", \"*stxt\", \"*maps.rc\", \"*cism.config*\"]:\n        for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):\n            logger.debug(\"Copy file from '%s' to '%s'\" % (file_to_copy, docdir))\n            shutil.copy2(file_to_copy, docdir)\n\n    # Copy over chemistry mechanism docs if they exist\n    if (os.path.isdir(os.path.join(casebuild, \"camconf\"))):\n        for file_to_copy in glob.glob(os.path.join(casebuild, \"camconf\", \"*chem_mech*\")):\n            shutil.copy2(file_to_copy, docdir)\n", "path": "scripts/lib/CIME/preview_namelists.py"}]}