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 ​

text_object ​

Cell text.

Components ​

NameTypeAttributesDescription
textcharacter(len=:)allocatableText, unquoted.

header_object ​

First row of a dataset, as text.

Components ​

NameTypeAttributesDescription
cellstype(text_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(text_object)allocatableText of column label_column of each row.
nrowsinteger(kind=I4P)Number of data rows.
nvaluesinteger(kind=I4P)Number of stored values.

Type-Bound Procedures ​

NameAttributesDescription
column_headerpass(self)Header name of a column.
columnspass(self)Extract a (x, y) series.
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.

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.

fortran
subroutine load(self, file, iostat, iomsg, separator, label_column)

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.

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.

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)

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.

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.

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

Functions ​

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

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