Skip to content

Add optional arguments to savetxt #1076

@fiolj

Description

@fiolj

Motivation

Hello, I've been away from the project for a long time, and could not find discussions over some features of savetxt that I find useful, following mostly numpy savetxt behavior. I'd like to change the interface to something like. Please let me know
if there is any interest. As I said I could not find if it already was discussed and discarded.

I am proposing to add several arguments.

  1. Adding the possibility of providing a unit number in place of a filename gives flexibility to add partial tables to a file.
  2. fmt Gives the possibility of customize the output. In many cases complex calculations give only a few significant figures and I would like the number saved to express that. Should work in a similar way as it does in loadtxt().
  3. header and footer give the possibility to add information to the data files (column names, information on parameters used in calculations or measurements, etc). I find this very important because it allows to keep information together with data.
  4. Following numpy I find extremely useful if non-data information is commented or signaled in some form. This would be the use of the argument comments.
  5. I would propose to change the length of delimiter from len=1 to arbitrary length. For intstance, we may want a *.cvs file to be separated by a comma and one or more spaces ', '.

The spec would be something like:


savetxt - save a 2D array into a text file

Status

Experimental

Description

Saves a rank-2 array into a text file.

Syntax

call [[stdlib_io(module):savetxt(interface)]] (array [, filename | unit] [, delimiter] [, fmt] [, header] [, footer] [, comments])

Arguments

array: Shall be a rank-2 array of type real, complex or integer.

filename (optional): Shall be a character expression containing the name of the file , that will contain the 2D array. Present at the same time than unit will give an error.

unit (optional): Shall be an integer containing the unit of an already opened file. Present at the same time than filename will give an error.

delimiter (optional): Shall be a character expression of any length that contains the delimiter used to separate the columns. The default is a single space ' '.

fmt (optional): Fortran format specifier for the text save. Defaults to the write format for the data type.

header (optional): Shall be a character expression that will be written at the beginning of the file.

footer (optional): Shall be a character expression that will be written at the end of the file.

comments (optional): Shall be a character expression of (length 1 that will be prepended to the header and footer strings to mark them as comments. Default: # .


Prior Art

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaProposition of an idea and opening an issue to discuss it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions