prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Remove ESMF from driver code
  
  
  </issue>
  <code>
  [start of utils/python/CIME/SystemTests/pfs.py]
  1 """
  2 CIME performance test  This class inherits from SystemTestsCommon
  3 
  4 20 days performance test, no restart files written
  5 """
  6 
  7 from CIME.XML.standard_module_setup import *
  8 from system_tests_common import SystemTestsCommon
  9 
  10 logger = logging.getLogger(__name__)
  11 
  12 class PFS(SystemTestsCommon):
  13 
  14     def __init__(self, case):
  15         """
  16         initialize an object interface to the PFS system test
  17         """
  18         SystemTestsCommon.__init__(self, case)
  19 
  20     def run(self):
  21         self._case_set_value("STOP_OPTION", "ndays")
  22         self._case.set_value("STOP_N", 20)
  23         self._case.set_value("REST_OPTION","none")
  24         self._case.set_value("CONTINUE_RUN", False)
  25         self._case.flush()
  26 
  27         logger.info("doing an 20 day initial test, no restarts written")
  28         return SystemTestsCommon._run(self)
  29 
  30     def report(self):
  31         SystemTestsCommon.report(self)
  32
  [end of utils/python/CIME/SystemTests/pfs.py]
  [start of utils/python/CIME/preview_namelists.py]
  1 """
  2 API for preview namelist
  3 """
  4 
  5 from CIME.XML.standard_module_setup import *
  6 from CIME.utils import expect, run_cmd
  7 from CIME.XML.env_mach_specific import EnvMachSpecific
  8 
  9 import glob, shutil
  10 logger = logging.getLogger(__name__)
  11 
  12 def preview_namelists(case, dryrun=False, casedir=None):
  13     # refresh case xml files from object
  14     case.flush()
  15 
  16     # Get data from XML
  17     exeroot = case.get_value("EXEROOT")
  18     libroot = case.get_value("LIBROOT")
  19     incroot = case.get_value("INCROOT")
  20     rundir = case.get_value("RUNDIR")
  21     caseroot = case.get_value("CASEROOT")
  22     casebuild = case.get_value("CASEBUILD")
  23     testcase = case.get_value("TESTCASE")
  24 
  25     logger.debug("LID is: '%s'" % os.getenv("LID", ""))
  26     logger.debug("caseroot is: '%s'" % caseroot)
  27 
  28     dryrun = True if (testcase == "SBN") else dryrun
  29 
  30     models = ["atm", "lnd", "ice", "ocn", "glc", "wav", "rof", "cpl"]
  31     docdir = os.path.join(caseroot, "CaseDocs")
  32 
  33     if (dryrun):
  34         # Only create rundir
  35         try:
  36             os.makedirs(rundir)
  37         except OSError:
  38             logger.warning("Not able to create $RUNDIR, trying a subdirectory of $CASEROOT")
  39             rundir = os.path.join(caseroot, rundir)
  40             try:
  41                 os.makedirs(rundir)
  42                 logger.info("Success! Setting RUNDIR=%s" % rundir)
  43                 case.set_value("RUNDIR", rundir)
  44             except OSError:
  45                 expect(False, "Could not create rundir")
  46 
  47     else:
  48 
  49         # Load modules
  50         env_module = case._get_env("mach_specific")
  51         env_module.load_env_for_case(compiler=case.get_value("COMPILER"),
  52                                      debug=case.get_value("DEBUG"),
  53                                      mpilib=case.get_value("MPILIB"))
  54 
  55         # Make necessary directories
  56         dirs_to_make = [os.path.join(exeroot, model, "obj") for model in models]
  57         dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])
  58 
  59         for dir_to_make in dirs_to_make:
  60             if (not os.path.isdir(dir_to_make)):
  61                 try:
  62                     logger.debug("Making dir '%s'" % dir_to_make)
  63                     os.makedirs(dir_to_make)
  64                 except OSError as e:
  65                     expect(False, "Could not make directory '%s', error: %s" % (dir_to_make, e))
  66 
  67     # Create namelists
  68     for model in models:
  69         model_str = "drv" if model == "cpl" else model
  70         config_file = case.get_value("CONFIG_%s_FILE" % model_str.upper())
  71         config_dir = os.path.dirname(config_file)
  72         cmd = os.path.join(config_dir, "buildnml")
  73         logger.info("Running %s"%cmd)
  74         if (logger.level == logging.DEBUG):
  75             run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot))
  76         else:
  77             run_cmd("%s %s" % (cmd, caseroot))
  78     # refresh case xml object from file
  79     case.read_xml(caseroot)
  80     # Save namelists to docdir
  81     if (not os.path.isdir(docdir)):
  82         os.makedirs(docdir)
  83         try:
  84             with open(os.path.join(docdir, "README"), "w") as fd:
  85                 fd.write(" CESM Resolved Namelist Files\n   For documentation only DO NOT MODIFY\n")
  86         except (OSError, IOError) as e:
  87             expect(False, "Failed to write %s/README: %s" % (docdir, e))
  88 
  89 
  90     for cpglob in ["*_in_[0-9]*", "*modelio*", "*_in",
  91                    "*streams*txt*", "*stxt", "*maps.rc", "*cism.config*"]:
  92         for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):
  93             logger.debug("Copy file from '%s' to '%s'" % (file_to_copy, docdir))
  94             shutil.copy2(file_to_copy, docdir)
  95 
  96     # Copy over chemistry mechanism docs if they exist
  97     if (os.path.isdir(os.path.join(casebuild, "camconf"))):
  98         for file_to_copy in glob.glob(os.path.join(casebuild, "camconf", "*chem_mech*")):
  99             shutil.copy2(file_to_copy, docdir)
  100
  [end of utils/python/CIME/preview_namelists.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/utils/python/CIME/SystemTests/pfs.py b/utils/python/CIME/SystemTests/pfs.py
  --- a/utils/python/CIME/SystemTests/pfs.py
  +++ b/utils/python/CIME/SystemTests/pfs.py
  @@ -18,7 +18,7 @@
           SystemTestsCommon.__init__(self, case)
   
       def run(self):
  -        self._case_set_value("STOP_OPTION", "ndays")
  +        self._case.set_value("STOP_OPTION", "ndays")
           self._case.set_value("STOP_N", 20)
           self._case.set_value("REST_OPTION","none")
           self._case.set_value("CONTINUE_RUN", False)
  diff --git a/utils/python/CIME/preview_namelists.py b/utils/python/CIME/preview_namelists.py
  --- a/utils/python/CIME/preview_namelists.py
  +++ b/utils/python/CIME/preview_namelists.py
  @@ -72,9 +72,12 @@
           cmd = os.path.join(config_dir, "buildnml")
           logger.info("Running %s"%cmd)
           if (logger.level == logging.DEBUG):
  -            run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot))
  +            rc, out, err = run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot), ok_to_fail=True)
  +            expect(rc==0,"Command %s failed rc=%d\nout=%s\nerr=%s"%(cmd,rc,out,err))
           else:
  -            run_cmd("%s %s" % (cmd, caseroot))
  +            rc, out, err = run_cmd("%s %s" % (cmd, caseroot), ok_to_fail=True)
  +            expect(rc==0,"Command %s failed rc=%d\nout=%s\nerr=%s"%(cmd,rc,out,err))
  +
       # refresh case xml object from file
       case.read_xml(caseroot)
       # Save namelists to docdir
  
verification_info: {"golden_diff": "diff --git a/utils/python/CIME/SystemTests/pfs.py b/utils/python/CIME/SystemTests/pfs.py\n--- a/utils/python/CIME/SystemTests/pfs.py\n+++ b/utils/python/CIME/SystemTests/pfs.py\n@@ -18,7 +18,7 @@\n         SystemTestsCommon.__init__(self, case)\n \n     def run(self):\n-        self._case_set_value(\"STOP_OPTION\", \"ndays\")\n+        self._case.set_value(\"STOP_OPTION\", \"ndays\")\n         self._case.set_value(\"STOP_N\", 20)\n         self._case.set_value(\"REST_OPTION\",\"none\")\n         self._case.set_value(\"CONTINUE_RUN\", False)\ndiff --git a/utils/python/CIME/preview_namelists.py b/utils/python/CIME/preview_namelists.py\n--- a/utils/python/CIME/preview_namelists.py\n+++ b/utils/python/CIME/preview_namelists.py\n@@ -72,9 +72,12 @@\n         cmd = os.path.join(config_dir, \"buildnml\")\n         logger.info(\"Running %s\"%cmd)\n         if (logger.level == logging.DEBUG):\n-            run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot))\n+            rc, out, err = run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot), ok_to_fail=True)\n+            expect(rc==0,\"Command %s failed rc=%d\\nout=%s\\nerr=%s\"%(cmd,rc,out,err))\n         else:\n-            run_cmd(\"%s %s\" % (cmd, caseroot))\n+            rc, out, err = run_cmd(\"%s %s\" % (cmd, caseroot), ok_to_fail=True)\n+            expect(rc==0,\"Command %s failed rc=%d\\nout=%s\\nerr=%s\"%(cmd,rc,out,err))\n+\n     # refresh case xml object from file\n     case.read_xml(caseroot)\n     # Save namelists to docdir\n", "issue": "Remove ESMF from driver code\n\n", "before_files": [{"content": "\"\"\"\nCIME performance test  This class inherits from SystemTestsCommon\n\n20 days performance test, no restart files written\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\nfrom system_tests_common import SystemTestsCommon\n\nlogger = logging.getLogger(__name__)\n\nclass PFS(SystemTestsCommon):\n\n    def __init__(self, case):\n        \"\"\"\n        initialize an object interface to the PFS system test\n        \"\"\"\n        SystemTestsCommon.__init__(self, case)\n\n    def run(self):\n        self._case_set_value(\"STOP_OPTION\", \"ndays\")\n        self._case.set_value(\"STOP_N\", 20)\n        self._case.set_value(\"REST_OPTION\",\"none\")\n        self._case.set_value(\"CONTINUE_RUN\", False)\n        self._case.flush()\n\n        logger.info(\"doing an 20 day initial test, no restarts written\")\n        return SystemTestsCommon._run(self)\n\n    def report(self):\n        SystemTestsCommon.report(self)\n", "path": "utils/python/CIME/SystemTests/pfs.py"}, {"content": "\"\"\"\nAPI for preview namelist\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils import expect, run_cmd\nfrom CIME.XML.env_mach_specific import EnvMachSpecific\n\nimport glob, shutil\nlogger = logging.getLogger(__name__)\n\ndef preview_namelists(case, dryrun=False, casedir=None):\n    # refresh case xml files from object\n    case.flush()\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    casebuild = case.get_value(\"CASEBUILD\")\n    testcase = case.get_value(\"TESTCASE\")\n\n    logger.debug(\"LID is: '%s'\" % os.getenv(\"LID\", \"\"))\n    logger.debug(\"caseroot is: '%s'\" % caseroot)\n\n    dryrun = True if (testcase == \"SBN\") else dryrun\n\n    models = [\"atm\", \"lnd\", \"ice\", \"ocn\", \"glc\", \"wav\", \"rof\", \"cpl\"]\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n\n    if (dryrun):\n        # Only create rundir\n        try:\n            os.makedirs(rundir)\n        except OSError:\n            logger.warning(\"Not able to create $RUNDIR, trying a subdirectory of $CASEROOT\")\n            rundir = os.path.join(caseroot, rundir)\n            try:\n                os.makedirs(rundir)\n                logger.info(\"Success! Setting RUNDIR=%s\" % rundir)\n                case.set_value(\"RUNDIR\", rundir)\n            except OSError:\n                expect(False, \"Could not create rundir\")\n\n    else:\n\n        # Load modules\n        env_module = case._get_env(\"mach_specific\")\n        env_module.load_env_for_case(compiler=case.get_value(\"COMPILER\"),\n                                     debug=case.get_value(\"DEBUG\"),\n                                     mpilib=case.get_value(\"MPILIB\"))\n\n        # Make necessary directories\n        dirs_to_make = [os.path.join(exeroot, model, \"obj\") for model in models]\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    # Create namelists\n    for model in models:\n        model_str = \"drv\" if model == \"cpl\" else model\n        config_file = case.get_value(\"CONFIG_%s_FILE\" % model_str.upper())\n        config_dir = os.path.dirname(config_file)\n        cmd = os.path.join(config_dir, \"buildnml\")\n        logger.info(\"Running %s\"%cmd)\n        if (logger.level == logging.DEBUG):\n            run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot))\n        else:\n            run_cmd(\"%s %s\" % (cmd, caseroot))\n    # refresh case xml object from file\n    case.read_xml(caseroot)\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\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": "utils/python/CIME/preview_namelists.py"}]}