| title | io |
|---|
[TOC]
Experimental
Loads a rank-2 array from a text file.
call [[stdlib_io(module):loadtxt(interface)]] (filename, array [, comments] [, delimiter] [, skiplines] [, max_rows] [, usecols])
call [[stdlib_io(module):loadtxt(interface)]] (unit, array [, comments] [, delimiter] [, skiplines] [, max_rows] [, usecols])
filename or unit: Shall be a character expression containing the file name or an integer containing the unit of an already open file from which to load the rank-2 array.
array: Shall be an allocatable rank-2 array of type real, complex or integer.
comments (optional): Shall be a character expression of any length used to indicate the start of a comment. Default: #.
delimiter (optional): Shall be a character expression of length 1 that contains the delimiter used to separate the columns. The default is an empty string '' indicating that any number of whitespace will be considered a delimiter.
skiplines (optional): Skip the first skiplines lines from file, including comments. If skipping more lines than present, a 0-sized array will be returned. The default is 0.
max_rows (optional): Shall be an integer indicating that max_rows rows of data after skiprows will be read. A negative value results in reading all data. The default is to read all lines of data.
usecols (optional): Shall be an integer array indicating what columns will be read. For example, usecols = (1,3,5) will extract the first, third and fifth columns. The default is to read all columns.
Returns an allocated rank-2 array with the content of the file.
{!example/io/example_loadtxt.f90!}Experimental
Returns the unit number of a file opened to read, to write, or to read and write. The file might be a text file or a binary file. Text files are opened using a sequential access, while binary files are opened using a streamed access.
u = [[stdlib_io(module):open(function)]] (filename [, mode] [, iostat])
filename: Shall be a character expression containing the name of the file to open.
mode (optional): Shall be a character expression containing characters describing the way in which the file will be used. The available modes are:
| Character | Meaning |
|---|---|
'r' |
open for reading (default) |
'w' |
open for writing, truncating the file first |
'x' |
open for exclusive creation, failing if the file already exists |
'a' |
open for writing, appending to the end of the file if it exists |
'+' |
open for updating (reading and writing) |
'b' |
binary mode |
't' |
text mode (default) |
The default mode is 'rt' (i.e. open for reading a text file). The mode may include one of the four different methods for opening a file (i.e., 'r', 'w', 'x', and 'a'). These four methods can be associated with the character '+' to open the file for updating. In addition, it can be specified if the file should be handled as a binary file ('b') or a text file ('t').
iostat (optional): Shall be a scalar of type integer that receives the error status of open, if provided. If no error exists, iostat is zero.
u: Shall be a scalar of type integer that specifies the unit number associated with the file filename.
The result is a scalar of type integer.
{!example/io/example_open.f90!}Experimental
Saves a rank-2 array into a text file.
call [[stdlib_io(module):savetxt(interface)]] (filename, array [, delimiter])
filename: Shall be a character expression containing the name of the file that will contain the 2D array.
array: Shall be a rank-2 array of type real, complex or integer.
delimiter (optional): Shall be a character expression of length 1 that contains the delimiter used to separate the columns. The default is ' '.
Provides a text file called filename that contains the rank-2 array.
{!example/io/example_savetxt.f90!}Experimental
Loads an array from a npy formatted binary file.
call [[stdlib_io_npy(module):load_npy(interface)]] (filename, array[, iostat][, iomsg])
filename: Shall be a character expression containing the file name from which to load the array.
This argument is intent(in).
array: Shall be an allocatable array of any rank of type real, complex or integer.
This argument is intent(out).
iostat: Default integer, contains status of loading to file, zero in case of success.
It is an optional argument, in case not present the program will halt for non-zero status.
This argument is intent(out).
iomsg: Deferred length character value, contains error message in case iostat is non-zero.
It is an optional argument, error message will be dropped if not present.
This argument is intent(out).
Returns an allocated array with the content of filename in case of success.
{!example/io/example_loadnpy.f90!}Experimental
Saves an array into a npy formatted binary file.
call [[stdlib_io_npy(module):save_npy(interface)]] (filename, array[, iostat][, iomsg])
filename: Shall be a character expression containing the name of the file that will contain the array.
This argument is intent(in).
array: Shall be an array of any rank of type real, complex or integer.
This argument is intent(in).
iostat: Default integer, contains status of saving to file, zero in case of success.
It is an optional argument, in case not present the program will halt for non-zero status.
This argument is intent(out).
iomsg: Deferred length character value, contains error message in case iostat is non-zero.
It is an optional argument, error message will be dropped if not present.
This argument is intent(out).
Provides a npy file called filename that contains the rank-2 array.
{!example/io/example_savenpy.f90!}Experimental
Read a whole line from a formatted unit into a string variable
call [[stdlib_io(module):get_line(interface)]] (unit, line[, iostat][, iomsg])
call [[stdlib_io(module):get_line(interface)]] (line[, iostat][, iomsg])
unit: Formatted input unit.
This argument is intent(in).
If unit is not specified standard input is used.
line: Deferred length character or string_type variable.
This argument is intent(out).
iostat: Default integer, contains status of reading from unit, zero in case of success.
It is an optional argument, in case not present the program will halt for non-zero status.
This argument is intent(out).
iomsg: Deferred length character value, contains error message in case iostat is non-zero.
It is an optional argument, error message will be dropped if not present.
This argument is intent(out).
{!example/io/example_get_line.f90!}Experimental
Formatting constants for printing out integer, floating point, and complex numbers at their full precision.
Provides formats for all kinds as defined in the stdlib_kinds module.
{!example/io/example_fmt_constants.f90!}Experimental
This subroutine interface reads the entirety of a specified ASCII file and returns its content as a string or an allocatable character variable.
The function provides an optional error-handling mechanism via the state_type class. If the err argument is not provided, exceptions will trigger an error stop. The function also supports an optional flag to delete the file after reading.
call [[stdlib_io(module):get_file(subroutine)]] (filename, file [, err] [, delete=.false.])
Function
filename: Shall be a character input containing the path to the ASCII file to read. It is an intent(in) argument.
file: Shall be a type(string_type) or an allocatable character variable containing the full content of the specified file. It is an intent(out) argument.
err (optional): Shall be a type(state_type) variable. It is an intent(out) argument used for error handling.
delete (optional): Shall be a logical flag. If .true., the file is deleted after reading. Default is .false.. It is an intent(in) argument.
Output variable file will contain the full content of the specified file.
Raises STDLIB_IO_ERROR if the file is not found, cannot be opened, read, or deleted.
Exceptions trigger an error stop unless the optional err argument is provided.
{!example/io/example_get_file.f90!}