XPRBreadarrlinecb
XPRBreadarrlinecb |
Purpose
Synopsis
int XPRBreadarrlinecb(char *(*fgs)(char *,int,void *), void *file, int length, const char *format, void *arrc, int size);
Arguments
fgs
|
|||||||||||||
file
|
Pointer to a data file.
|
||||||||||||
length
|
Maximum length of any text string to be read.
|
||||||||||||
format
|
String indicating the format of the data file to be read, consisting of one of the listed values followed by a separator sign:
|
||||||||||||
arrc
|
Array of size at least
size that receives the data that are read.
|
||||||||||||
size
|
Maximum number of data items to be read.
|
Return value
Number of data items read.
Example
double vlist[10]; FILE *datafile; ... datafile=fopen("filename", "r"); XPRBreadlinecb(XPRB_FGETS, datafile, 120, "g ", vlist, 6); fclose(datafile);
This opens a data file and reads a line of six double values separated by spaces, before closing the file.
Further information
This function reads tables from data files in a format compatible with the
diskdata command of mp-model and Mosel. Data lines in the input file may be continued over several lines by using the line continuation sign
&. The input file may also contain comments (preceded by
!) and empty lines, both of which are skipped over. The data file is accessed with standard C functions (
fopen,
fclose). The function reads up to
size data items of the type indicated by the format parameter. All string types in the format may (optionally) be followed by the maximum string length to be read. Otherwise the maximum length is assumed to be
length. The type of separator signs (
e.g.
,
;
:) used in the data file needs to be given after the format option(s). Array
arrc is an array of the same type as the data to be read (
int *,
char *, or
double *) and of size at least
size. With function
XPRBsetdecsign the decimal sign used in the data input may be changed, for instance to use a decimal comma.
Related topics