We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Archive error for pop.dd files
The following tests are failing at the end of the runs.  Looks like this error was introduced with #3326.

    FAIL SMS_D.T62_g37.G1850ECO.cheyenne_intel.pop-cice_ecosys RUN time=233
    FAIL SMS_Ld20.T62_g17.G.cheyenne_intel.pop-performance_eval RUN time=93
    FAIL SMS_Ld2.f09_g17.B1850.cheyenne_intel.allactive-defaultio RUN time=160
    FAIL SMS_Ld2.f09_g17.BHIST.cheyenne_gnu.MS_Ld2.f09_g17.B1850.cheyenne_intelallactive-defaultio RUN time=499
    FAIL SMS.T62_g17.C1850ECO.cheyenne_intel.pop-ecosys RUN time=183
    FAIL SMS.T62_g37.C.cheyenne_intel.pop-default RUN time=20

This is the error message for the pop.dd files.  It's the same for all tests, just the test names
are different. 
ERROR: Failed to get extension for file 'SMS_Ld2.f09_g17.B1850.cheyenne_intel.allactive-defaultio.GC.01082020.pop.dd.0001-01-01-03600'


--- 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/XML/archive_base.py`
Content:
```
1 """
2 Base class for archive files.  This class inherits from generic_xml.py
3 """
4 from CIME.XML.standard_module_setup import *
5 from CIME.XML.generic_xml import GenericXML
6 
7 logger = logging.getLogger(__name__)
8 
9 class ArchiveBase(GenericXML):
10 
11     def get_entry(self, compname):
12         """
13         Returns an xml node corresponding to compname in comp_archive_spec
14         """
15         return self.scan_optional_child('comp_archive_spec',
16                                         attributes={"compname":compname})
17 
18     def _get_file_node_text(self, attnames, archive_entry):
19         """
20         get the xml text associated with each of the attnames
21         based at root archive_entry
22         returns a list of text entries or
23         an empty list if no entries are found
24         """
25         nodes = []
26         textvals = []
27         for attname in attnames:
28             nodes.extend(self.get_children(attname, root=archive_entry))
29         for node in nodes:
30             textvals.append(self.text(node))
31         return textvals
32 
33     def get_rest_file_extensions(self, archive_entry):
34         """
35         get the xml text associated with each of the rest_file_extensions
36         based at root archive_entry (root is based on component name)
37         returns a list of text entries or
38         an empty list if no entries are found
39         """
40         return self._get_file_node_text(['rest_file_extension'],archive_entry)
41 
42     def get_hist_file_extensions(self, archive_entry):
43         """
44         get the xml text associated with each of the hist_file_extensions
45         based at root archive_entry (root is based on component name)
46         returns a list of text entries or
47         an empty list if no entries are found
48         """
49         return self._get_file_node_text(['hist_file_extension'],archive_entry)
50 
51     def get_entry_value(self, name, archive_entry):
52         """
53         get the xml text associated with name under root archive_entry
54         returns None if no entry is found, expects only one entry
55         """
56         node = self.get_optional_child(name, root=archive_entry)
57         if node is not None:
58             return self.text(node)
59         return None
60 
61     def get_latest_hist_files(self, casename, model, from_dir, suffix="", ref_case=None):
62         """
63         get the most recent history files in directory from_dir with suffix if provided
64         """
65         test_hists = self.get_all_hist_files(casename, model, from_dir, suffix=suffix, ref_case=ref_case)
66         latest_files = {}
67         histlist = []
68         for hist in test_hists:
69             ext = _get_extension(model, hist)
70             latest_files[ext] = hist
71 
72         for key in latest_files.keys():
73             histlist.append(latest_files[key])
74         return histlist
75 
76     def get_all_hist_files(self, casename, model, from_dir, suffix="", ref_case=None):
77         """
78         gets all history files in directory from_dir with suffix (if provided)
79         ignores files with ref_case in the name if ref_case is provided
80         """
81         dmodel = model
82         if model == "cpl":
83             dmodel = "drv"
84         # remove when component name is changed
85         if model == "fv3gfs":
86             model = "fv3"
87         hist_files = []
88         extensions = self.get_hist_file_extensions(self.get_entry(dmodel))
89         if suffix and len(suffix) > 0:
90             has_suffix = True
91         else:
92             has_suffix = False
93 
94         # Strip any trailing $ if suffix is present and add it back after the suffix
95         for ext in extensions:
96             if ext.endswith('$') and has_suffix:
97                 ext = ext[:-1]
98             string = model+r'\d?_?(\d{4})?\.'+ext
99             if has_suffix:
100                 string += '.'+suffix+'$'
101 
102 
103             logger.debug ("Regex is {}".format(string))
104             pfile = re.compile(string)
105             hist_files.extend([f for f in os.listdir(from_dir) if pfile.search(f) and (f.startswith(casename) or f.startswith(model))])
106 
107         if ref_case:
108             expect(ref_case not in casename,"ERROR: ref_case name {} conflicts with casename {}".format(ref_case,casename))
109             hist_files = [h for h in hist_files if not (ref_case in os.path.basename(h))]
110 
111         hist_files = list(set(hist_files))
112         hist_files.sort()
113         logger.debug("get_all_hist_files returns {} for model {}".format(hist_files, model))
114 
115         return hist_files
116 
117 def _get_extension(model, filepath):
118     r"""
119     For a hist file for the given model, return what we call the "extension"
120 
121     model - The component model
122     filepath - The path of the hist file
123     >>> _get_extension("cpl", "cpl.hi.nc")
124     'hi'
125     >>> _get_extension("cpl", "cpl.h.nc")
126     'h'
127     >>> _get_extension("cpl", "cpl.h1.nc.base")
128     'h1'
129     >>> _get_extension("cpl", "TESTRUNDIFF.cpl.hi.0.nc.base")
130     'hi'
131     >>> _get_extension("cpl", "TESTRUNDIFF_Mmpi-serial.f19_g16_rx1.A.melvin_gnu.C.fake_testing_only_20160816_164150-20160816_164240.cpl.h.nc")
132     'h'
133     >>> _get_extension("clm","clm2_0002.h0.1850-01-06-00000.nc")
134     '0002.h0'
135     >>> _get_extension("pop","PFS.f09_g16.B1850.cheyenne_intel.allactive-default.GC.c2_0_b1f2_int.pop.h.ecosys.nday1.0001-01-02.nc")
136     'h'
137     >>> _get_extension("mom", "ga0xnw.mom6.frc._0001_001.nc")
138     'frc'
139     >>> _get_extension("mom", "ga0xnw.mom6.sfc.day._0001_001.nc")
140     'sfc.day'
141     >>> _get_extension("mom", "bixmc5.mom6.prog._0001_01_05_84600.nc")
142     'prog'
143     >>> _get_extension("mom", "bixmc5.mom6.hm._0001_01_03_42300.nc")
144     'hm'
145     >>> _get_extension("mom", "bixmc5.mom6.hmz._0001_01_03_42300.nc")
146     'hmz'
147     """
148     # Remove with component namechange
149     if model == "fv3gfs":
150         model = "fv3"
151     basename = os.path.basename(filepath)
152     m = None
153     ext_regexes = []
154 
155     # First add any model-specific extension regexes; these will be checked before the
156     # general regex
157     if model == "mom":
158         # Need to check 'sfc.day' specially: the embedded '.' messes up the
159         # general-purpose regex
160         ext_regexes.append(r'sfc\.day')
161 
162     # Now add the general-purpose extension regex
163     ext_regexes.append(r'\w+')
164 
165     for ext_regex in ext_regexes:
166         full_regex_str = model+r'\d?_?(\d{4})?\.('+ext_regex+r')[-\w\.]*\.nc\.?'
167         full_regex = re.compile(full_regex_str)
168         m = full_regex.search(basename)
169         if m is not None:
170             if m.group(1) is not None:
171                 result = m.group(1)+'.'+m.group(2)
172             else:
173                 result = m.group(2)
174             return result
175 
176     expect(m, "Failed to get extension for file '{}'".format(filepath))
177 
178     return result
179
```
--- 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/XML/archive_base.py b/scripts/lib/CIME/XML/archive_base.py
--- a/scripts/lib/CIME/XML/archive_base.py
+++ b/scripts/lib/CIME/XML/archive_base.py
@@ -144,6 +144,8 @@
     'hm'
     >>> _get_extension("mom", "bixmc5.mom6.hmz._0001_01_03_42300.nc")
     'hmz'
+    >>> _get_extension("pop", "casename.pop.dd.0001-01-02-00000")
+    'dd'
     """
     # Remove with component namechange
     if model == "fv3gfs":
@@ -166,6 +168,11 @@
         full_regex_str = model+r'\d?_?(\d{4})?\.('+ext_regex+r')[-\w\.]*\.nc\.?'
         full_regex = re.compile(full_regex_str)
         m = full_regex.search(basename)
+        if m is None:
+            # try without .nc part
+            full_regex_str = model+r'\d?_?(\d{4})?\.('+ext_regex+r')[-\w\.]*'
+            full_regex = re.compile(full_regex_str)
+            m = full_regex.search(basename)
         if m is not None:
             if m.group(1) is not None:
                 result = m.group(1)+'.'+m.group(2)

{"golden_diff": "diff --git a/scripts/lib/CIME/XML/archive_base.py b/scripts/lib/CIME/XML/archive_base.py\n--- a/scripts/lib/CIME/XML/archive_base.py\n+++ b/scripts/lib/CIME/XML/archive_base.py\n@@ -144,6 +144,8 @@\n     'hm'\n     >>> _get_extension(\"mom\", \"bixmc5.mom6.hmz._0001_01_03_42300.nc\")\n     'hmz'\n+    >>> _get_extension(\"pop\", \"casename.pop.dd.0001-01-02-00000\")\n+    'dd'\n     \"\"\"\n     # Remove with component namechange\n     if model == \"fv3gfs\":\n@@ -166,6 +168,11 @@\n         full_regex_str = model+r'\\d?_?(\\d{4})?\\.('+ext_regex+r')[-\\w\\.]*\\.nc\\.?'\n         full_regex = re.compile(full_regex_str)\n         m = full_regex.search(basename)\n+        if m is None:\n+            # try without .nc part\n+            full_regex_str = model+r'\\d?_?(\\d{4})?\\.('+ext_regex+r')[-\\w\\.]*'\n+            full_regex = re.compile(full_regex_str)\n+            m = full_regex.search(basename)\n         if m is not None:\n             if m.group(1) is not None:\n                 result = m.group(1)+'.'+m.group(2)\n", "issue": "Archive error for pop.dd files\nThe following tests are failing at the end of the runs.  Looks like this error was introduced with #3326.\r\n\r\n    FAIL SMS_D.T62_g37.G1850ECO.cheyenne_intel.pop-cice_ecosys RUN time=233\r\n    FAIL SMS_Ld20.T62_g17.G.cheyenne_intel.pop-performance_eval RUN time=93\r\n    FAIL SMS_Ld2.f09_g17.B1850.cheyenne_intel.allactive-defaultio RUN time=160\r\n    FAIL SMS_Ld2.f09_g17.BHIST.cheyenne_gnu.MS_Ld2.f09_g17.B1850.cheyenne_intelallactive-defaultio RUN time=499\r\n    FAIL SMS.T62_g17.C1850ECO.cheyenne_intel.pop-ecosys RUN time=183\r\n    FAIL SMS.T62_g37.C.cheyenne_intel.pop-default RUN time=20\r\n\r\nThis is the error message for the pop.dd files.  It's the same for all tests, just the test names\r\nare different. \r\nERROR: Failed to get extension for file 'SMS_Ld2.f09_g17.B1850.cheyenne_intel.allactive-defaultio.GC.01082020.pop.dd.0001-01-01-03600'\r\n\n", "before_files": [{"content": "\"\"\"\nBase class for archive files.  This class inherits from generic_xml.py\n\"\"\"\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.XML.generic_xml import GenericXML\n\nlogger = logging.getLogger(__name__)\n\nclass ArchiveBase(GenericXML):\n\n    def get_entry(self, compname):\n        \"\"\"\n        Returns an xml node corresponding to compname in comp_archive_spec\n        \"\"\"\n        return self.scan_optional_child('comp_archive_spec',\n                                        attributes={\"compname\":compname})\n\n    def _get_file_node_text(self, attnames, archive_entry):\n        \"\"\"\n        get the xml text associated with each of the attnames\n        based at root archive_entry\n        returns a list of text entries or\n        an empty list if no entries are found\n        \"\"\"\n        nodes = []\n        textvals = []\n        for attname in attnames:\n            nodes.extend(self.get_children(attname, root=archive_entry))\n        for node in nodes:\n            textvals.append(self.text(node))\n        return textvals\n\n    def get_rest_file_extensions(self, archive_entry):\n        \"\"\"\n        get the xml text associated with each of the rest_file_extensions\n        based at root archive_entry (root is based on component name)\n        returns a list of text entries or\n        an empty list if no entries are found\n        \"\"\"\n        return self._get_file_node_text(['rest_file_extension'],archive_entry)\n\n    def get_hist_file_extensions(self, archive_entry):\n        \"\"\"\n        get the xml text associated with each of the hist_file_extensions\n        based at root archive_entry (root is based on component name)\n        returns a list of text entries or\n        an empty list if no entries are found\n        \"\"\"\n        return self._get_file_node_text(['hist_file_extension'],archive_entry)\n\n    def get_entry_value(self, name, archive_entry):\n        \"\"\"\n        get the xml text associated with name under root archive_entry\n        returns None if no entry is found, expects only one entry\n        \"\"\"\n        node = self.get_optional_child(name, root=archive_entry)\n        if node is not None:\n            return self.text(node)\n        return None\n\n    def get_latest_hist_files(self, casename, model, from_dir, suffix=\"\", ref_case=None):\n        \"\"\"\n        get the most recent history files in directory from_dir with suffix if provided\n        \"\"\"\n        test_hists = self.get_all_hist_files(casename, model, from_dir, suffix=suffix, ref_case=ref_case)\n        latest_files = {}\n        histlist = []\n        for hist in test_hists:\n            ext = _get_extension(model, hist)\n            latest_files[ext] = hist\n\n        for key in latest_files.keys():\n            histlist.append(latest_files[key])\n        return histlist\n\n    def get_all_hist_files(self, casename, model, from_dir, suffix=\"\", ref_case=None):\n        \"\"\"\n        gets all history files in directory from_dir with suffix (if provided)\n        ignores files with ref_case in the name if ref_case is provided\n        \"\"\"\n        dmodel = model\n        if model == \"cpl\":\n            dmodel = \"drv\"\n        # remove when component name is changed\n        if model == \"fv3gfs\":\n            model = \"fv3\"\n        hist_files = []\n        extensions = self.get_hist_file_extensions(self.get_entry(dmodel))\n        if suffix and len(suffix) > 0:\n            has_suffix = True\n        else:\n            has_suffix = False\n\n        # Strip any trailing $ if suffix is present and add it back after the suffix\n        for ext in extensions:\n            if ext.endswith('$') and has_suffix:\n                ext = ext[:-1]\n            string = model+r'\\d?_?(\\d{4})?\\.'+ext\n            if has_suffix:\n                string += '.'+suffix+'$'\n\n\n            logger.debug (\"Regex is {}\".format(string))\n            pfile = re.compile(string)\n            hist_files.extend([f for f in os.listdir(from_dir) if pfile.search(f) and (f.startswith(casename) or f.startswith(model))])\n\n        if ref_case:\n            expect(ref_case not in casename,\"ERROR: ref_case name {} conflicts with casename {}\".format(ref_case,casename))\n            hist_files = [h for h in hist_files if not (ref_case in os.path.basename(h))]\n\n        hist_files = list(set(hist_files))\n        hist_files.sort()\n        logger.debug(\"get_all_hist_files returns {} for model {}\".format(hist_files, model))\n\n        return hist_files\n\ndef _get_extension(model, filepath):\n    r\"\"\"\n    For a hist file for the given model, return what we call the \"extension\"\n\n    model - The component model\n    filepath - The path of the hist file\n    >>> _get_extension(\"cpl\", \"cpl.hi.nc\")\n    'hi'\n    >>> _get_extension(\"cpl\", \"cpl.h.nc\")\n    'h'\n    >>> _get_extension(\"cpl\", \"cpl.h1.nc.base\")\n    'h1'\n    >>> _get_extension(\"cpl\", \"TESTRUNDIFF.cpl.hi.0.nc.base\")\n    'hi'\n    >>> _get_extension(\"cpl\", \"TESTRUNDIFF_Mmpi-serial.f19_g16_rx1.A.melvin_gnu.C.fake_testing_only_20160816_164150-20160816_164240.cpl.h.nc\")\n    'h'\n    >>> _get_extension(\"clm\",\"clm2_0002.h0.1850-01-06-00000.nc\")\n    '0002.h0'\n    >>> _get_extension(\"pop\",\"PFS.f09_g16.B1850.cheyenne_intel.allactive-default.GC.c2_0_b1f2_int.pop.h.ecosys.nday1.0001-01-02.nc\")\n    'h'\n    >>> _get_extension(\"mom\", \"ga0xnw.mom6.frc._0001_001.nc\")\n    'frc'\n    >>> _get_extension(\"mom\", \"ga0xnw.mom6.sfc.day._0001_001.nc\")\n    'sfc.day'\n    >>> _get_extension(\"mom\", \"bixmc5.mom6.prog._0001_01_05_84600.nc\")\n    'prog'\n    >>> _get_extension(\"mom\", \"bixmc5.mom6.hm._0001_01_03_42300.nc\")\n    'hm'\n    >>> _get_extension(\"mom\", \"bixmc5.mom6.hmz._0001_01_03_42300.nc\")\n    'hmz'\n    \"\"\"\n    # Remove with component namechange\n    if model == \"fv3gfs\":\n        model = \"fv3\"\n    basename = os.path.basename(filepath)\n    m = None\n    ext_regexes = []\n\n    # First add any model-specific extension regexes; these will be checked before the\n    # general regex\n    if model == \"mom\":\n        # Need to check 'sfc.day' specially: the embedded '.' messes up the\n        # general-purpose regex\n        ext_regexes.append(r'sfc\\.day')\n\n    # Now add the general-purpose extension regex\n    ext_regexes.append(r'\\w+')\n\n    for ext_regex in ext_regexes:\n        full_regex_str = model+r'\\d?_?(\\d{4})?\\.('+ext_regex+r')[-\\w\\.]*\\.nc\\.?'\n        full_regex = re.compile(full_regex_str)\n        m = full_regex.search(basename)\n        if m is not None:\n            if m.group(1) is not None:\n                result = m.group(1)+'.'+m.group(2)\n            else:\n                result = m.group(2)\n            return result\n\n    expect(m, \"Failed to get extension for file '{}'\".format(filepath))\n\n    return result\n", "path": "scripts/lib/CIME/XML/archive_base.py"}], "after_files": [{"content": "\"\"\"\nBase class for archive files.  This class inherits from generic_xml.py\n\"\"\"\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.XML.generic_xml import GenericXML\n\nlogger = logging.getLogger(__name__)\n\nclass ArchiveBase(GenericXML):\n\n    def get_entry(self, compname):\n        \"\"\"\n        Returns an xml node corresponding to compname in comp_archive_spec\n        \"\"\"\n        return self.scan_optional_child('comp_archive_spec',\n                                        attributes={\"compname\":compname})\n\n    def _get_file_node_text(self, attnames, archive_entry):\n        \"\"\"\n        get the xml text associated with each of the attnames\n        based at root archive_entry\n        returns a list of text entries or\n        an empty list if no entries are found\n        \"\"\"\n        nodes = []\n        textvals = []\n        for attname in attnames:\n            nodes.extend(self.get_children(attname, root=archive_entry))\n        for node in nodes:\n            textvals.append(self.text(node))\n        return textvals\n\n    def get_rest_file_extensions(self, archive_entry):\n        \"\"\"\n        get the xml text associated with each of the rest_file_extensions\n        based at root archive_entry (root is based on component name)\n        returns a list of text entries or\n        an empty list if no entries are found\n        \"\"\"\n        return self._get_file_node_text(['rest_file_extension'],archive_entry)\n\n    def get_hist_file_extensions(self, archive_entry):\n        \"\"\"\n        get the xml text associated with each of the hist_file_extensions\n        based at root archive_entry (root is based on component name)\n        returns a list of text entries or\n        an empty list if no entries are found\n        \"\"\"\n        return self._get_file_node_text(['hist_file_extension'],archive_entry)\n\n    def get_entry_value(self, name, archive_entry):\n        \"\"\"\n        get the xml text associated with name under root archive_entry\n        returns None if no entry is found, expects only one entry\n        \"\"\"\n        node = self.get_optional_child(name, root=archive_entry)\n        if node is not None:\n            return self.text(node)\n        return None\n\n    def get_latest_hist_files(self, casename, model, from_dir, suffix=\"\", ref_case=None):\n        \"\"\"\n        get the most recent history files in directory from_dir with suffix if provided\n        \"\"\"\n        test_hists = self.get_all_hist_files(casename, model, from_dir, suffix=suffix, ref_case=ref_case)\n        latest_files = {}\n        histlist = []\n        for hist in test_hists:\n            ext = _get_extension(model, hist)\n            latest_files[ext] = hist\n\n        for key in latest_files.keys():\n            histlist.append(latest_files[key])\n        return histlist\n\n    def get_all_hist_files(self, casename, model, from_dir, suffix=\"\", ref_case=None):\n        \"\"\"\n        gets all history files in directory from_dir with suffix (if provided)\n        ignores files with ref_case in the name if ref_case is provided\n        \"\"\"\n        dmodel = model\n        if model == \"cpl\":\n            dmodel = \"drv\"\n        # remove when component name is changed\n        if model == \"fv3gfs\":\n            model = \"fv3\"\n        hist_files = []\n        extensions = self.get_hist_file_extensions(self.get_entry(dmodel))\n        if suffix and len(suffix) > 0:\n            has_suffix = True\n        else:\n            has_suffix = False\n\n        # Strip any trailing $ if suffix is present and add it back after the suffix\n        for ext in extensions:\n            if ext.endswith('$') and has_suffix:\n                ext = ext[:-1]\n            string = model+r'\\d?_?(\\d{4})?\\.'+ext\n            if has_suffix:\n                string += '.'+suffix+'$'\n\n\n            logger.debug (\"Regex is {}\".format(string))\n            pfile = re.compile(string)\n            hist_files.extend([f for f in os.listdir(from_dir) if pfile.search(f) and (f.startswith(casename) or f.startswith(model))])\n\n        if ref_case:\n            expect(ref_case not in casename,\"ERROR: ref_case name {} conflicts with casename {}\".format(ref_case,casename))\n            hist_files = [h for h in hist_files if not (ref_case in os.path.basename(h))]\n\n        hist_files = list(set(hist_files))\n        hist_files.sort()\n        logger.debug(\"get_all_hist_files returns {} for model {}\".format(hist_files, model))\n\n        return hist_files\n\ndef _get_extension(model, filepath):\n    r\"\"\"\n    For a hist file for the given model, return what we call the \"extension\"\n\n    model - The component model\n    filepath - The path of the hist file\n    >>> _get_extension(\"cpl\", \"cpl.hi.nc\")\n    'hi'\n    >>> _get_extension(\"cpl\", \"cpl.h.nc\")\n    'h'\n    >>> _get_extension(\"cpl\", \"cpl.h1.nc.base\")\n    'h1'\n    >>> _get_extension(\"cpl\", \"TESTRUNDIFF.cpl.hi.0.nc.base\")\n    'hi'\n    >>> _get_extension(\"cpl\", \"TESTRUNDIFF_Mmpi-serial.f19_g16_rx1.A.melvin_gnu.C.fake_testing_only_20160816_164150-20160816_164240.cpl.h.nc\")\n    'h'\n    >>> _get_extension(\"clm\",\"clm2_0002.h0.1850-01-06-00000.nc\")\n    '0002.h0'\n    >>> _get_extension(\"pop\",\"PFS.f09_g16.B1850.cheyenne_intel.allactive-default.GC.c2_0_b1f2_int.pop.h.ecosys.nday1.0001-01-02.nc\")\n    'h'\n    >>> _get_extension(\"mom\", \"ga0xnw.mom6.frc._0001_001.nc\")\n    'frc'\n    >>> _get_extension(\"mom\", \"ga0xnw.mom6.sfc.day._0001_001.nc\")\n    'sfc.day'\n    >>> _get_extension(\"mom\", \"bixmc5.mom6.prog._0001_01_05_84600.nc\")\n    'prog'\n    >>> _get_extension(\"mom\", \"bixmc5.mom6.hm._0001_01_03_42300.nc\")\n    'hm'\n    >>> _get_extension(\"mom\", \"bixmc5.mom6.hmz._0001_01_03_42300.nc\")\n    'hmz'\n    >>> _get_extension(\"pop\", \"casename.pop.dd.0001-01-02-00000\")\n    'dd'\n    \"\"\"\n    # Remove with component namechange\n    if model == \"fv3gfs\":\n        model = \"fv3\"\n    basename = os.path.basename(filepath)\n    m = None\n    ext_regexes = []\n\n    # First add any model-specific extension regexes; these will be checked before the\n    # general regex\n    if model == \"mom\":\n        # Need to check 'sfc.day' specially: the embedded '.' messes up the\n        # general-purpose regex\n        ext_regexes.append(r'sfc\\.day')\n\n    # Now add the general-purpose extension regex\n    ext_regexes.append(r'\\w+')\n\n    for ext_regex in ext_regexes:\n        full_regex_str = model+r'\\d?_?(\\d{4})?\\.('+ext_regex+r')[-\\w\\.]*\\.nc\\.?'\n        full_regex = re.compile(full_regex_str)\n        m = full_regex.search(basename)\n        if m is None:\n            # try without .nc part\n            full_regex_str = model+r'\\d?_?(\\d{4})?\\.('+ext_regex+r')[-\\w\\.]*'\n            full_regex = re.compile(full_regex_str)\n            m = full_regex.search(basename)\n        if m is not None:\n            if m.group(1) is not None:\n                result = m.group(1)+'.'+m.group(2)\n            else:\n                result = m.group(2)\n            return result\n\n    expect(m, \"Failed to get extension for file '{}'\".format(filepath))\n\n    return result\n", "path": "scripts/lib/CIME/XML/archive_base.py"}]}