Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/pyclaw/io/ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def write(solution,frame,path,file_prefix='fort',write_aux=False,
- *options* - (dict) Dictionary of optional arguments dependent on
the format being written. ``default = {}``
"""
output_fields = options.get('output_fields',range(solution.num_eqn))

try:
# Create file name
file_name = '%s.t%s' % (file_prefix,str(frame).zfill(4))
Expand Down Expand Up @@ -69,7 +71,7 @@ def write(solution,frame,path,file_prefix='fort',write_aux=False,
else:
q = state.q

write_array(q_file, patch, q)
write_array(q_file, patch, q, output_fields)

if state.num_aux > 0 and write_aux:
write_patch_header(aux_file,state.patch)
Expand Down Expand Up @@ -115,31 +117,33 @@ def write_patch_header(f,patch):
f.write("\n")


def write_array(f,patch,q):
def write_array(f,patch,q,fields=None):
"""
Write a single array to output file f as ASCII text.

The variable q here may in fact refer to q or to aux.
"""
if fields is None:
fields = xrange(q.shape[0]) # Output all fields by default

dims = patch.dimensions
if patch.num_dim == 1:
for k in xrange(dims[0].num_cells):
for m in xrange(q.shape[0]):
for m in fields:
f.write("%18.8e" % q[m,k])
f.write('\n')
elif patch.num_dim == 2:
for j in xrange(dims[1].num_cells):
for k in xrange(dims[0].num_cells):
for m in xrange(q.shape[0]):
for m in fields:
f.write("%18.8e" % q[m,k,j])
f.write('\n')
f.write('\n')
elif patch.num_dim == 3:
for l in xrange(dims[2].num_cells):
for j in xrange(dims[1].num_cells):
for k in xrange(dims[0].num_cells):
for m in xrange(q.shape[0]):
for m in fields:
f.write("%18.8e" % q[m,k,j,l])
f.write('\n')
f.write('\n')
Expand Down