Skip to content

stdlib_io: add print_array function to print arrays to output units #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zoziha
Copy link
Contributor

@zoziha zoziha commented Apr 20, 2025

Description

Add print_array subroutine, which is used to print two-dimensional arrays of integer and floating-point types. These two types are more commonly used in Fortran. It supports arguments such as delimiter, output unit, output format, and whether to print briefly.

In the non-brief output mode, the print_array function can produce an output result style similar to that of savetxt in stdlib_io. The print_array function is mainly convenient for users to output to the screen (standard output) and is likely to be mostly used for code debugging.

Prior Art:

  • disp in Matlab;
  • The default print of Python and Julia;
  • brief_print in Armadillo.

This PR will replace #520, and is related to #40, but is not sufficient to close #40.

Remaining to be discussed

  • Is it necessary to support delimiters of any length, not just those with a length of 1? In addition to the print_array, it also includes the savetxt routine in stdlib_io.
  • Currently, print_array is designed to assist users in program debugging and does not provide file write error reports like savetxt does.

@zoziha zoziha requested a review from Copilot April 20, 2025 12:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds a new subroutine specification, print_array, to the stdlib_io module for printing 2D arrays to an output unit.

  • Introduces detailed documentation covering the subroutine’s syntax, argument descriptions, and an example.
  • Specifies default behaviors for output unit, delimiter, format, and brief mode.
Files not reviewed (7)
  • example/io/CMakeLists.txt: Language not supported
  • example/io/example_print_array.f90: Language not supported
  • src/CMakeLists.txt: Language not supported
  • src/stdlib_io.fypp: Language not supported
  • src/stdlib_io_print_array.fypp: Language not supported
  • test/io/CMakeLists.txt: Language not supported
  • test/io/test_print_array.f90: Language not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pretty printing of matrices (and multidimensional arrays)
1 participant