Here is an exemple to show how simple it is to work with formated ASCII data files. The plan is to create a file containing different values of a double x and the corresponding sin(x). Then, we read this file and plot the data.
Here is the first part of the code.
and now the file sine.txt contains:
x= 0 ,y= 0
x= 0.01 ,y= 0.00999983
x= 0.02 ,y= 0.0199987
...
This code should read the file previously created.
- The function read creates an Array of strings where each element correspond to a line of the file.
- The function getField extract a given field of an array of string. At that stage, fields are only delimited by the space character; "x=" is here the first field, the second is the value of x, the third is ",y=", etc... That's why we extract here the fields 2 and 4.
IDIL Binary file format (.idil file) for Arrays.
-int: version, 0 at that stage
-int: object type, 1 for Array,
-int: element type
-char[32]: name
-char[256]: comments
-int: element size (sizeof(T))
-unsigned char: number of dimensions (usually six)
-long[# of dim]: dimension of the array
-data buffer