Skip to content

foresight_datafile ​

foresight_datafile, gnuplot-style text data files.

Format, as gnuplot's default: whitespace separated numeric columns; # starts a comment; one blank line ends a block (plotted lines are broken there), two blank lines end a dataset (selected by index, 0-based); cells that are ?, NaN, inf, empty or not numbers are missing values (gaps). Pseudo-column 0 numbers the selected points of each dataset from 0 (with every, only the points it keeps are counted, as gnuplot).

With label_column N, the text of column N of every row is kept too (labels, table(..., labels=...)): the text labels of using ...:xtic(N); blanks around a cell and double quotes are removed, a missing cell is blank.

The first row of each dataset is kept as text too: with headers in use (table(..., header=.true.)) it names the columns, for using 1:"name" and title columnhead, and is not data; else it is a row as any other.

A cell is read as gnuplot does, by C strtod: its longest leading number counts and the rest is ignored (3abc is 3, 1.2.3 is 1.2, 1d3 is 1), hexadecimal included (0x10 is 16, 0x1.8p1 is 3); a value beyond the real range is a gap.

With a separator (gnuplot set datafile separator, e.g. , for CSV) every one of its characters ends a cell: two separators in a row leave an empty cell, a trailing one an empty last cell; blanks around a cell are ignored and a cell in double quotes is read without them ("7" is 7), its separators kept. Without one, a double quoted cell may hold blanks and is not a number, as gnuplot.

Values are stored flattened, rows by offsets, with capacities doubled on growth: a large monitoring log costs one real per value plus three integers per row.

Source: src/lib/foresight_datafile.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
TABcharacter(len=1)parameterTab character.

Derived Types ​

header_object ​

First row of a dataset, as text.

Components

NameTypeAttributesDescription
cellstype(name_object)allocatableCells.

datafile_object ​

Data file content.

Components

NameTypeAttributesDescription
filecharacter(len=:)allocatableFile name.
valuesreal(kind=R8P)allocatableRow values, flattened.
firstinteger(kind=I4P)allocatableIndex in values of the first value of each row (+1 sentinel).
datasetinteger(kind=I4P)allocatableDataset (0-based) of each row.
blockinteger(kind=I4P)allocatableBlock (global counter) of each row.
headerstype(header_object)allocatableFirst row of each dataset as text, by dataset from 1.
label_columninteger(kind=I4P)Column kept as text in labels, 0 for none.
labelstype(name_object)allocatableText of column label_column of each row.
has_textlogicalThe cell texts are kept, in texts.
textstype(name_object)allocatableText of each cell (unquoted, as values), with has_text.
nrowsinteger(kind=I4P)Number of data rows.
nvaluesinteger(kind=I4P)Number of stored values.
missing_cellsinteger(kind=I4P)allocatableIndexes in values of the cells holding the missing data string (gnuplot set datafile missing), ascending.
invalid_cellsinteger(kind=I4P)allocatableIndexes in values of the cells holding no number (empty, ?, words; not NaN, inf), ascending.

Type-Bound Procedures

NameAttributesDescription
column_headerpass(self)Header name of a column.
columnspass(self)Extract a (x, y) series.
leading_cellspass(self)Cells of the first row.
default_usingpass(self)gnuplot default columns.
header_namespass(self)Header names of a dataset.
loadpass(self)Read a file.
matrixpass(self)Values as a matrix (gnuplot matrix).
missing_namepass(self)A header name of the fields found nowhere.
tablepass(self)Evaluate using fields.
table_linespass(self)The rows as gnuplot's plot with table writes them.

Interfaces ​

push ​

Append an item through a temporary: nvfortran 26.9 corrupts list = [list, item] (and any list = f(list)) when the items hold deferred-length characters.

Module procedures: push_header, push_text

Subroutines ​

load ​

Read file, replacing the current content; cells are separated by whitespace, or by any of the separator characters when given and not empty; with label_column > 0 the text of that column of each row is kept. The cells equal to missing (blanks and double quotes around them removed; none if empty) are missing data, the points reading them left out (gnuplot set datafile missing); comments are the characters starting a comment (# by default, none if empty: gnuplot set datafile commentschars). With keep_text the text of every cell is kept (gnuplot's strcol). With content the lines are those of that text (a gnuplot datablock, $D << EOD, named file), not of a file. With skip its first lines are not read (gnuplot plot 'f' skip N).

fortran
subroutine load(self, file, iostat, iomsg, separator, label_column, missing, comments, keep_text, content, skip)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inoutData.
filecharacter(len=*)inFile name.
iostatinteger(kind=I4P)out0 on success.
iomsgcharacter(len=:)outallocatableError message.
separatorcharacter(len=*)inoptionalCell separator characters.
label_columninteger(kind=I4P)inoptionalColumn kept as text, 0 for none.
missingcharacter(len=*)inoptionalMissing data string, empty for none.
commentscharacter(len=*)inoptionalComment characters.
keep_textlogicalinoptionalKeep the text of every cell.
contentcharacter(len=*)inoptionalLines to read instead of the file's.
skipinteger(kind=I4P)inoptionalFirst lines not read.

Call graph

default_using ​

gnuplot default columns: 1:2, or 0:1 for single-column data.

Attributes: pure

fortran
subroutine default_using(self, ux, uy)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
uxinteger(kind=I4P)outAbscissa column.
uyinteger(kind=I4P)outOrdinate column.

Call graph

columns ​

Series of columns (ux, uy) of dataset index (all if negative), one point every every in each block.

fortran
subroutine columns(self, ux, uy, index, every, x, y)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
uxinteger(kind=I4P)inAbscissa column, 0 for the point number.
uyinteger(kind=I4P)inOrdinate column, 0 for the point number.
indexinteger(kind=I4P)inDataset, 0-based; negative for all.
everyinteger(kind=I4P)inPoint stride within each block.
xreal(kind=R8P)outallocatableAbscissae.
yreal(kind=R8P)outallocatableOrdinates.

Call graph

table ​

Values of the using fields on the rows of dataset index (all if negative) selected by every: values(point, field).

With header the first row of each dataset names the columns: it is skipped, neither a point nor counted, and the column header names of the fields are resolved on the header of each dataset. labels returns the text of the label column (see load) of each point, blank for breaks or without a label column; with label they are the texts of that field instead (evaluate_text: xtic(strcol(1)), the text of labels).

every is gnuplot's point_incr:block_incr:start_point:start_block:end_point:end_block, an end negative for none. Points are numbered within their block, blocks within their dataset, from 0.

A NaN point is inserted where a block or dataset changes, so that lines are broken as in gnuplot. Missing cells, rows too short for a column and undefined expressions give NaN values (gaps).

fortran
subroutine table(self, fields, index, every, values, header, labels, label, sets)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
fieldstype(expression_object)inusing fields.
indexinteger(kind=I4P)inDataset, 0-based; negative for all.
everyinteger(kind=I4P)ingnuplot every fields.
valuesreal(kind=R8P)outallocatablePoints.
headerlogicalinoptionalThe first row of each dataset is a header.
labelscharacter(len=:)outallocatable, optionalText labels of the points.
labeltype(expression_object)inoptionalField of the labels.
setsinteger(kind=I4P)outallocatable, optionalDataset of each point (from 0), -1 for the breaks (gnuplot's scans of splot are the runs between them).

Call graph

table_lines ​

gnuplot's plot ... with table: a line per row of dataset index (all if negative) selected by every, headers skipped (header), with condition true if given (if COND), the using fields each a string as it is, a number as %g, nan if undefined; no fields, the leading numeric cells of the row. As gnuplot, each field is written after a blank and joined by separator, for a datablock (block) a string field without the blank and the separator after one. Blank lines and comments are not written, no row is left out for a bad cell.

fortran
subroutine table_lines(self, fields, index, every, header, separator, block, text, condition)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
fieldstype(expression_object)inusing fields, none for the leading numeric cells.
indexinteger(kind=I4P)inDataset, 0-based; negative for all.
everyinteger(kind=I4P)ingnuplot every fields.
headerlogicalinThe first row of each dataset is a header.
separatorcharacter(len=1)inField separator.
blocklogicalinWritten to a datablock.
textcharacter(len=:)outallocatableLines, each ended by a new line.
conditiontype(expression_object)inoptionalif condition.

Call graph

matrix ​

Values of dataset index (all if negative) as gnuplot matrix data: z(column, row), the column the x index and the row the y index, both from 0 in the file order; every row must have the same number of values.

Attributes: pure

fortran
subroutine matrix(self, index, z, message)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
indexinteger(kind=I4P)inDataset, 0-based; negative for all.
zreal(kind=R8P)outallocatableValues.
messagecharacter(len=:)outallocatableProblem, empty if none.

Call graph

header_names ​

Header names of the columns of dataset set (from 0), blank padded; none if no such dataset.

A subroutine: a function with this deferred length array result, called in an internal procedure, is an internal compiler error of gfortran 16.

Attributes: pure

fortran
subroutine header_names(self, set, names)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
setinteger(kind=I4P)inDataset.
namescharacter(len=:)outallocatableNames of columns 1, 2, ...

Call graph

read_line ​

Read a whole line of any length; eof is set on the last one, which may still carry text.

fortran
subroutine read_line(unit, line, eof, iostat)

Arguments

NameTypeIntentAttributesDescription
unitinteger(kind=I4P)inFile unit.
linecharacter(len=:)outallocatableLine.
eoflogicaloutEnd of file reached.
iostatinteger(kind=I4P)out0, or an I/O error code.

Call graph

push_header ​

Append item to list (an unallocated list is empty), through a temporary: see push.

Attributes: pure

fortran
subroutine push_header(list, item)

Arguments

NameTypeIntentAttributesDescription
listtype(header_object)inoutallocatableList.
itemtype(header_object)inNew item.

push_text ​

Append item to list (an unallocated list is empty), through a temporary: see push.

Attributes: pure

fortran
subroutine push_text(list, item)

Arguments

NameTypeIntentAttributesDescription
listtype(name_object)inoutallocatableList.
itemtype(name_object)inNew item.

Functions ​

leading_cells ​

The cells of the first data row, 0 without data.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function leading_cells(self) result(n)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.

column_header ​

Header name of column c (from 1) of dataset set (from 0), empty if none.

Attributes: pure

Returns: character(len=:)

fortran
function column_header(self, set, c) result(name)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
setinteger(kind=I4P)inDataset.
cinteger(kind=I4P)inColumn.

missing_name ​

First column header name of the fields that no header of dataset index (all if negative) has, empty if none.

Attributes: pure

Returns: character(len=:)

fortran
function missing_name(self, fields, index) result(name)

Arguments

NameTypeIntentAttributesDescription
selfclass(datafile_object)inData.
fieldstype(expression_object)inusing fields.
indexinteger(kind=I4P)inDataset, 0-based; negative for all.

Call graph

clean ​

cell without the blanks around it and its double quotes.

Attributes: pure

Returns: character(len=:)

fortran
function clean(cell) result(text)

Arguments

NameTypeIntentAttributesDescription
cellcharacter(len=*)inCell text.

Call graph

cell_value ​

Number in a separated cell: blanks around it ignored, then double quotes around it; NaN if empty or not a number.

Returns: real(kind=R8P)

fortran
function cell_value(cell) result(v)

Arguments

NameTypeIntentAttributesDescription
cellcharacter(len=*)inCell text.

Call graph

no_number ​

Whether token starts with no number, as C strtod reads it: neither a decimal nor a hexadecimal one, nor nan or inf (which are numbers, undefined); empty included. gnuplot skips such a cell in a plain column.

Attributes: pure

Returns: logical

fortran
function no_number(token) result(none)

Arguments

NameTypeIntentAttributesDescription
tokencharacter(len=*)inCell text.

Call graph

to_real ​

Value of the longest number at the start of token, as C strtod: [+-] then decimal D[.D][e[+-]D] or .D..., or hexadecimal 0xH[.H][p[+-]D]; NaN if there is none (empty, ?, NaN, inf) or it is out of range.

Returns: real(kind=R8P)

fortran
function to_real(token) result(v)

Arguments

NameTypeIntentAttributesDescription
tokencharacter(len=*)inCell text.

Call graph

hexadecimal ​

Value of the hexadecimal number at the start of text (after 0x): digits, an optional point and digits, an optional binary exponent p[+-]D; false if no digit follows the 0x. Out of range is NaN, never an IEEE overflow.

Returns: logical

fortran
function hexadecimal(text, v) result(found)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText after 0x.
vreal(kind=R8P)outValue.

Call graph

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.