File I/O operations

I/O from an ASCII file

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.

How to save an Array as an ASCII file?

Here is the first part of the code.

    Array<double> x;
    //  x contains 1000 values, ranging from 0 to 10
    x = dindgen(1000)/100;
    //  now, we save x and sin(x) in the file "sine.txt"
    write("sine.txt","x= "+x+" ,y= "+sin(x));
and now the file sine.txt contains:
    x= 0 ,y= 0
    x= 0.01 ,y= 0.00999983
    x= 0.02 ,y= 0.0199987
    ...
    

How to read from an ASCII file?

This code should read the file previously created.

    Array<double> x,y;
    Array<string> s;

    s = read("sine.txt");
    x = getField<double>(s,2);
    y = getField<double>(s,4);

    plot(x,y);

I/O with binary data

Using the IDIL binary format

Specification of the idil binary format

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
    

Generated on Fri Oct 24 18:41:59 2008 for IDIL by  doxygen 1.5.5