Skip to content

Commit

Permalink
A small fix needed to make pismi.py behave
Browse files Browse the repository at this point in the history
Before this it always created both foo.nc and foo.nc~ and failed to write *all* of its
outputs to foo.nc (some ended up in foo.nc~).
  • Loading branch information
ckhroulev committed May 27, 2021
1 parent cd07d15 commit 78e56e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/inverse/pismi.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python3
#
# Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 David Maxwell and Constantine Khroulev
# Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 David Maxwell and Constantine Khroulev
#
# This file is part of PISM.
#
Expand Down Expand Up @@ -567,8 +567,8 @@ def run():
vecs.add(residual, writing=True)
vecs.add(r_mag, writing=True)

# Write solution out to netcdf file
forward_run.write(output_filename, append=append_mode)
# Write solution out to netcdf file (always append because the file was created already)
forward_run.write(output_filename, append=True)
# If we're not in append mode, the previous command just nuked
# the output file. So we rewrite the siple log.
if not append_mode:
Expand Down
7 changes: 4 additions & 3 deletions site-packages/PISM/ssa.py
Expand Up @@ -124,14 +124,15 @@ def solve(self):

return self.ssa.velocity()

def write(self, filename):
def write(self, filename, append=False):
"""Saves all of :attr:`modeldata`'s vecs (and the solution) to an
output file."""
grid = self.grid
vecs = self.modeldata.vecs

pio = util.prepare_output(filename)
pio.close()
if not append:
pio = util.prepare_output(filename)
pio.close()

# Save time & command line
util.writeProvenance(filename)
Expand Down

0 comments on commit 78e56e7

Please sign in to comment.