Table of Contents

Name

get_atable, get_ftable, get_line, parse, strinsert - table manipulator routines

Synopsis


#include <stdinc.h>int get_atable(instr,ncol,colnr,coldat,ndat)stream instr;int
ncol;    int colnr[]; real *coldat[];int ndat;      
int get_ftable(instr,ncol,colpos,colfmt,coldat,ndat)stream
instr;  int ncol;      int colpos[];  string *colfmt[];real *coldat[];
 int ndat;        
int get_line (instr, line)stream instr;char *line;
int
parse(linenr, line, dat, ndat)int linenr;char *line;double *dat;int ndat;
int
strinsert(a, b, n)char *a;char *b;int n;
int iscomment(line)char *line;

Description

Both get_atable and get_ftable parse an ascii table, pointed by the instr stream, into ncol columns and up to ndat rows of real numbers into memory. The input table may contain comment lines, as well as columns which are not numbers. Badly parsed lines are simply skipped. Other common parameters to both routines are coldat, ncol and ndat: coldat is an array of ncol pointers to previously allocated data, each of them ndat real elements. The number of valid rows read is then returned. If this number is negative, it means more data is available, but could not be read because ndat was exhausted. Upon the next call ndat must be set to negative, to recover the last line read on the previous call, and continue reading the table without missing a line. CAVEAT: this only works if instr has not changed.

get_atable parses the table in free format. colnr an array of length ncol of the column numbers to read (1 being the first column), If any of the colnr is 0, it is interpreted as referring to the line number in the original input file (including/excluding comment and empty lines), 1 being the first line, and the corresponding entry in coldat is set as such. Columns are separated by whitespace or commas.

get_ftable parses the table in fixed format. colpos is an array with positions in the rows to start reading (1 being the first position), colfmt an array of pointers to the format string used to parse a real number (note real normally requires %lf). If any of the colpos is 0, it is interpreted as referring to the line number in the original input file (including comment lines), 1 being the first line, and the corresponding entry in coldat is set as such.

The get_line(3) gets the next line from a stream instr, stored into line. It returns the length of the string read, 0 if end of file.

parse parses the character string in line into the double array dat, which has at most ndat entries. Parsing means that %n refers to column n in the character string (n must be larger than 0. Also %0 may be referenced, meaning the current line number, to be entered in the argument linenr.

strinsert inserts the string b into a, replacing n characters of a.

iscomment returns 1 if the line appears to be a comment (starts with ’;’, ’#’, ’!’ or a blank/newline)

Diagnostics

Low-level catastrophies (eg, parsing errors, wrong delimiters) generate messages via error(3NEMO) .

See Also

table(5NEMO)

Files


src/kernel/tab      table.c gettab.c

Author

Peter Teuben

Update History


xx-sep-88    V1.0 written    PJT
6-aug-92    documented get_Xtable functions      PJT
1-sep-95    added iscomment()    PJT
12-jul-03    fixed reading large table buffereing    PJT


Table of Contents