Open derry43 opened 1 year ago
For reading, we would need to pass in the field width information and the number of fields to delimit the data and at that point you might as well be specifying the G
edit descriptor which then does what you are asking.
For writing I think it could be done bu I can see a couple of obstacles here to overcome ...
To do this we would need to give Python some hints as to what kind of FORTRAN data type to use since there are far fewer Python data types. For example, python has only one float
type so we would need to know if we should use REAL
, REAL*8
or REAL*16
. We could use the biggest size by default but this could generate excessively large text files, too small risks losing important precision in some cases.
The CHARACTER
being variable length I think would provide some problems when outputting records since many FORTRAN outputs tend to rely on being fixed width rather than looking for delimiters - certainly this library wouldn't be able to re-read files with variable width
For both of these I think being able to configure globally which edit descriptor is used for each Python type would get around that. So there would be sensible defaults chosen from the list above but people could override them e.g.
config.DEFAULT_CHARACTER_EDIT_DESCRIPTOR= '32A'
or config.DEFAULT_FLOAT_EDIT_DESCRIPTOR = '1PE44.34E4'
Thoughts?
Found this to be incredibly useful for porting of Fortran code to python. Not sure how possible, but would be great if this module could handle default formats for output (and maybe input) e.g.
header_line = FortranRecordWriter(*)
or perhapsheader_line = FortranRecordWriter()
(for reading ...
header_line = FortranRecordReader(*)
or perhapsheader_line = FortranRecordReader()
)Where providing either an asterisk or empty argument list would use a set of default formats. For example, Oracle Fortran uses the following default formats for List Directed Output