logo-header

 
 

syntax

  • ReadElems(sourceLines, ValuesUnit, startpositions, decimal-seperatorflag)

definition

ReadElems(sourceLines, ValuesUnit, startpositions, decimal-seperatorflag) results in an attribute for the domain unit of the first and third argument. The resulting data item contains the values from each string of the source attribute, starting at the startposition that have to be given for each element of the domain. Spaces, tabs, comma's(if comma is not configured as decimal seperator) and semicolons are used as field delimiters.  

This function also creates an extra UInt32 attribute for the same domain, called readPos, that contains the read positions after parsing a value from each line. The position is after reading the delimiter that ended the scanning of the read element, so this can be directly used to read the next field form a set of lines.

applies to

sourceLines is an attribute with string value type

ValuesUnit is the unit that is attributed to the resulting values and its value type.This type determines how characters are scanned, ie. integer are read until a non integer character is scanned, floating points can contain a decimal separator (default is the period) and can be in scientific notation (i.e. 1.23e+4). Strings can be quoted and quotes (single or double) will be removed during reading.

startpositions is a an attribute with uint32 value type

decimal-separator is an optional additional uint32 parameter with two possible values

  •  0(default value): indicates a point is interpreted as decimal seperator
  •  1: indicates a comma is interpreted as decimal seperator, see for example the TableChopper.

Planned additional optional parameters:

delimiters: a string parameter that specifies which character(s) should be used as field delimiter, which can be a combination of:

  • TAB, '\t';
  • COMMA, ';';
  • and SEMICOLON, ';'.

conditions

The domain of the sourceLines and startpositions arguments must match. 

example

container ReadElems
{
parameter<string>  File
: StorageName = "%projDir%/data/demand.ini"
, StorageType = "str";
unit<uint32> BDomain: nrofrows = 6;
parameter<float32> Body := ReadLines(File, BDomain, 0);
attribute<uint32> FirstColumn(ReadLine/BDomain) :=
ReadElems(Body, uint32, const(0, BDomain));
attribute<uint32> LastColumn(ReadLine/BDomain) :=
ReadElems(Body, uint32, FirstColumn/readPos);
}

Body:

             
25000 27500 11000 6100 14400 300 70
30000 32500 12000 6200 14500 320 72
35000 37500 13000 6300 14600 340 74
40000 42500 14000 6400 14700 360 76
45000 47500 15000 6500 14800 380 78
50000 52500 16000 6600 14900 400 80

 

FirstColumn LastColumn
25000 70
30000 72
35000 74
40000 76
45000 78
50000 80
BDomain, nr of rows = 6

see also


OBJECT VISION BV
Vrije Universiteit
De Boelelaan 1085
1081 HV Amsterdam
The Netherlands

tel: +31 (0)20 598 9083
fax:+31 (0)20 598 9904