f90nml icon indicating copy to clipboard operation
f90nml copied to clipboard

end commas when patching

Open 2wyck3d opened this issue 5 years ago • 5 comments

When patching a existing namelist with trailing commas, the commas are not preserved.

I tried a similar technique to #79 and it did not work

patch = {
    'data': {
        'a': 1,
        'b'': 2
    },
    '_end_comma': True
}

f90nml.patch('input_file.inp', patch, 'output_file.out')

I've also tried patching with a Namelist object, which also does not work.

nml = f90nml.namelist.Namelist()
nml.end_comma = True
nml['data'] = {'a': 1, 'b': 2}

parser = f90nml.Parser()
parser.read('input_file.inp', patch, 'output_file.out')

Is there something perhaps I'm missing or is this feature not available yet?

Thanks!

2wyck3d avatar Jul 16 '19 20:07 2wyck3d

I'm pretty sure it's just never been implemented. It would not be too difficult to add it, though. I'll have a look tonight.

marshallward avatar Jul 16 '19 21:07 marshallward

Sweet. Thank you!

2wyck3d avatar Jul 16 '19 21:07 2wyck3d

I've just realized that this is not a simple change. This is because patch is not creating a new data output. Rather, it's catching the input stream, modifying the values, and then streaming that data to the output.

To do this correctly, we'd also have to know that we're at the end of a record, which may not be possible since the current patch may have already written its output.

This is a limitation of patch that I was hoping to address with more aggressive lookahead and a new parser, but that project has been stalled for a long time.

I'll have a bit deeper look and see if this one is easy enough to catch, but just a heads up that it may not be simple, if even possible.

marshallward avatar Jul 17 '19 13:07 marshallward

Thanks for the update. Appreciate you looking into this. Would be awesome if this could be implemented but I understand if the amount of work involved to get there isn't worth it.

2wyck3d avatar Jul 17 '19 17:07 2wyck3d

No worries, I will keep the issue open as a feature request.

marshallward avatar Jul 17 '19 17:07 marshallward