Skip to content

Provide precision-preserving edit descriptors #570

Closed
@milancurcic

Description

@milancurcic

Motivation

In #505 @epagone proposed:

Considering that these formats are more useful than only for savetxt and loadtxt, would it make sense to make them available on their own in stdlib_io and simply use them? I am thinking, for example, of any sort of I/O where round-trip accuracy is required (e.g. writing to a CSV, JSON, TOML, YAML, etc...) to override a default behaviour that might be less strict.

Prior Art

Currently the formats used for savetxt and loadtxt are private to the stdlib_io and not usable from the outside:

! Format strings with edit descriptors for each type and kind
character(*), parameter :: &
FMT_INT = '(*(i0,1x))', &
FMT_REAL_SP = '(*(es15.8e2,1x))', &
FMT_REAL_DP = '(*(es24.16e3,1x))', &
FMT_REAL_XDP = '(*(es26.18e3,1x))', &
FMT_REAL_QP = '(*(es44.35e4,1x))', &
FMT_COMPLEX_SP = '(*(es15.8e2,1x,es15.8e2))', &
FMT_COMPLEX_DP = '(*(es24.16e3,1x,es24.16e3))', &
FMT_COMPLEX_XDP = '(*(es26.18e3,1x,es26.18e3))', &
FMT_COMPLEX_QP = '(*(es44.35e4,1x,es44.35e4))'

They work with scalars and arrays alike:

print FMT_REAL_DP, 1.23d0
print FMT_REAL_DP, [1.23d0, 4.56d0]

outputs

 1.2300000000000000E+000
 1.2300000000000000E+000  4.5599999999999996E+000

So it seems to me that the solution could be to make the existing constants public. @epagone @certik do you foresee any scenario where it wouldn't work?

Additional Information

@epagone would you like to submit a PR for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIDiscussion on a specific API for a proposal (exploratory)enhancementNew feature or requestgood first issueGood for newcomersideaProposition of an idea and opening an issue to discuss ittopic: IOCommon input/output related features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions