stdlib_io: add print_array function to print arrays to output units#981
stdlib_io: add print_array function to print arrays to output units#981zoziha wants to merge 4 commits intofortran-lang:masterfrom
print_array function to print arrays to output units#981Conversation
There was a problem hiding this comment.
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
doc/specs/stdlib_io.md
Outdated
|
|
||
| `delimiter`: Shall be a character string of length 1 containing the delimiter between array elements. It is an `intent(in)` argument. The default is a `" "` (space). | ||
|
|
||
| `brief`: Shall be a logical flag. If `.true.`, the array is printed in a brief format. The default is `.true.`. |
There was a problem hiding this comment.
what is a "brief" format? Could you maybe provide a short definition?
There was a problem hiding this comment.
Okay. Details of the "brief" format were added, and an example was deliberately provided to illustrate the usage of the "brief" format.
| {!example/io/example_get_file.f90!} | ||
| ``` | ||
|
|
||
| ## `print_array` - Print an array to an output unit |
There was a problem hiding this comment.
Minor comment: the name could be discussed with the community. Personally, I would prefer disp.
|
Hi, The above code displayed For readability, it might be nicer to display them as in brackets or in a+bi form. One idea could be to add an optional complex_format flag (or similar) that controls whether complex numbers are printed as (a,b) or a + bi. |
There was a problem hiding this comment.
Thank you @zoziha. One suggestion:
Can each entry of complex type array be printed as (a,b) form instead of using a delimiter between the real and imaginary parts. For example, for an array
complex, dimension(2, 2) :: a = reshape([cmplx(1,2), cmplx(3,4), cmplx(5,6), cmplx(7,8)], [2,2])
can the output be displayed as:
(1.0,2.0) | (5.0,6.0)
(3.0,4.0) | (7.0,8.0)
instead of
1.0| 2.0| 5.0| 6.0
3.0| 4.0| 7.0| 8.0
where delimiter is |.
Description
Add
print_arraysubroutine, 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
savetxtin 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:
This PR will replace #520, and is related to #40, but is not sufficient to close #40.
Remaining to be discussed
print_array, it also includes thesavetxtroutine in stdlib_io.