A demo code explaining the usgae is given below:
int ebf_demo()
{
using namespace std;
using namespace ebf;
// create and initialize an efile structure/object
EbfFile efile;
EbfDataInfo dinfo;
// generate some test data
vector<float> x1(100);
vector<int32_t> x2(100);
vector<double> y1(100);
vector<int64_t> y2(100);
vector<double> y3(100);
int64_t dims[8];
for (size_t i = 0; i < x1.size(); ++i)
{
x1[i] = i;
x2[i] = i;
}
// Write array x1 to file check.ebf
Ebf_Write("check.ebf", "/x1", &x1[0], "w", "",x1.size());
// append to file check.ebf array x2 with unit m/s
Ebf_Write("check.ebf", "/x2", &x2[0], "a", "100 m/s", x1.size());
// Read data as long and double
// After openr(), one can allocate memory as y1=(double *)malloc(efile.elements()*8)
efile.Open("check.ebf", "/x1");
efile.Read(&y1[0], efile.elements());
efile.Close();
efile.Open("check.ebf", "/x2");
cout << "Units are " << efile.unit() << endl;
efile.Read(&y2[0], efile.elements());
efile.Close();
// Read data
if (Ebf_ContainsKey_Info("check.ebf", "/x1", &dinfo))
{
// one can allocate memory as y1=(double *)malloc(dinfo.elements*8)
Ebf_Read("check.ebf", "/x1", &y1[0], dinfo.elements);
}
// Write a 2d array. dim[0] is adjusted to fit dataszie other dims are fixed.
// 80 elements starting from x1[20] written as 8x10 array
dims[0] = 0;
dims[1] = 10;
efile.Open("check.ebf", "/x1", "w", Ebf_TypeS("float32"), "100 m/s", 2,
dims);
efile.Write(&x1[20], 80);
efile.Close();
/* print the data */
printf("%s \n", "Printing x1 x2 y1 y2");
for (size_t i = 70; i < 80; ++i)
cout << x1[i] << " " << x2[i] << " " << y1[i] << " " << y2[i] << endl;
// Write nsize elements of x1 and then of x2 as a double array
efile.Open("check.ebf", "/test/x1x2_double", "a", Ebf_TypeS("double"),
" 100 km/s");
efile.Write(&x1[0], x1.size());
efile.Write(&x2[0], x2.size());
efile.Close();
// Write elements 20 to 100 as 2x40 multi dimensional array
// the first dimension can be set to zero and is automatically set,
// depending upon the number of elements written, when Close() method is invoked.
// Also units are written. Can be set to blank string.
// 80 elements starting from x1[20] written as 2x40 array
dims[0] = 0; /* can be set to anything is adjusted when efile.Close() is called*/
dims[1] = 40;
efile.Open("check.ebf", "/test/x1_multi", "a", Ebf_TypeS("float32"),
"100 m/s", 2, dims);
efile.Write(&x1[20], 80);
efile.Close();
//Read all elements
efile.Open("check.ebf", "/x1");
// On can allocate memory as double *y3=(int64_t *)malloc(efile.elements()*8)
efile.Read(&y3[0], 80);
efile.Close();
//Read elements 0 to 19 then next 40 and then next 20
efile.Open("check.ebf", "/x1");
efile.Read(&y3[0], 20);
efile.Read(&y3[20], 40);
efile.Read(&y3[60], 20);
efile.Close();
//Read 10 elements with an offset of 20 (x[20] to x[29])
efile.Open("check.ebf", "/x1");
// efile.Seek(20);
efile.Read(&y3[20], 10);
efile.Close();
cout << "Units are " << efile.unit() << endl;
printf("%s \n", "printing values 20 to 30");
for (int i = 20; i < 30; ++i)
printf("%d %e \n", i, y3[i]);
// using the EbfVector container
EbfVector<float> y5("check.ebf", "/x1");
cout << "Rank=" << y5.rank() << "size=" << y5.size() << " dim(0)="
<< y5.dim(0) << " dim(1)=" << y5.dim(1) << endl;
cout << y5[9] << " " << y5[19] << endl;
cout << y5(0, 9) << " " << y5(1, 19) << endl;
// Write and Read a string
string mystr2;
vector<float> x123;
// same as Ebf_WriteChar("test2.ebf", "/mystr",mystr1, "w","",strlen(mystr1));
Ebf_WriteString("check.ebf", "/mystr", "Hello World!", "w");
Ebf_ReadString("check.ebf", "/mystr", mystr2);
cout << mystr2 << endl;
return 0;
}
A demo code explaining the usgae is given below:
int ebf_demo()
{
/* generate some test data */
int nsize;
float x1[100];
int32_t x2[100];
double y1[100];
int64_t y2[100];
double y3[100];
char mystr1[200];
char mystr2[200];
int64_t dims[8];
int i;
EbfDataInfo dinfo;
/* create and initialize an efile structure/object */
EbfFile efile = EbfFile_Create();
nsize = 100;
for (i = 0; i < nsize; ++i)
{
x1[i] = i;
x2[i] = i;
}
/* write array x1 to file check.ebf */
Ebf_WriteFloat32("check.ebf", "/x1", &x1[0], "w", "", nsize);
Ebf_WriteInt32("check.ebf", "/x2", &x2[0], "a", "100 m/s", nsize);
/* read data as long and double */
/* After openr(), one can allocate memory as y1=(double *)malloc(EbfFile_Elements(&efile)*8)*/
EbfFile_OpenR(&efile, "check.ebf", "/x1");
EbfFile_rFloat64(&efile, &y1[0], nsize);
EbfFile_Close(&efile);
EbfFile_OpenR(&efile, "check.ebf", "/x2");
printf("%s %s \n", "Units are", efile.ebfh.unit);
EbfFile_rInt64(&efile, &y2[0], nsize);
EbfFile_Close(&efile);
if (Ebf_ContainsKey_Info("check.ebf", "/x1", &dinfo))
{
/* one can allocate memory as y1=(double *)malloc(dinfo.elements*8)*/
Ebf_ReadFloat64("check.ebf", "/x1", &y1[0], dinfo.elements);
}
/* Write a 2d array. dim[0] is adjusted to fit dataszie other dims are fixed.*/
/* 80 elements starting from x1[20] written as 8x10 array*/
dims[0] = 0;
dims[1] = 10;
EbfFile_Open(&efile, "check.ebf", "/x1", "w", Ebf_TypeS("float32"),
"100 m/s", 2, dims);
EbfFile_wFloat32(&efile, &x1[20], 80);
EbfFile_Close(&efile);
/* print the data */
printf("%s \n", "Printing x1 x2 y1 y2");
for (i = 90; i < nsize; ++i)
printf("%f %f %f %f \n", (float) x1[i], (float) x2[i], (float) y1[i],
(float) y2[i]);
/* Write nsize elements of x1 and then of x2 as a double array*/
EbfFile_OpenW(&efile, "check.ebf", "/test/x1x2_double", "a",
Ebf_TypeS("double"), " 100 km/s");
EbfFile_wFloat32(&efile, &x1[0], nsize);
EbfFile_wInt32(&efile, &x2[0], nsize);
EbfFile_Close(&efile);
/*
Write elements 20 to 100 as 2x40 multi dimensional array
the first dimension can be set to zero and is automatically set,
depending upon the number of elements written, when close() method is invoked.
Also units are written. Can be set to blank string.
80 elements starting from x1[20] written as 2x40 array
*/
dims[0] = 0; /* can be set to anything is adjusted when EbfFile_Close() is called*/
dims[1] = 40;
EbfFile_Open(&efile, "check.ebf", "/test/x1_multi", "a",
Ebf_TypeS("float32"), "100 m/s", 2, dims);
EbfFile_wFloat32(&efile, &x1[20], 80);
EbfFile_Close(&efile);
/*Read all elements*/
EbfFile_OpenR(&efile, "check.ebf", "/x1");
/* On can allocate memory as double *y3=(int64_t *)malloc(EbfFile_Elements(&efile)*8)*/
EbfFile_rFloat64(&efile, &y3[0], 80);
EbfFile_Close(&efile);
/*Read elements 0 to 19 then next 40 and then next 40*/
EbfFile_OpenR(&efile, "check.ebf", "/x1");
EbfFile_rFloat64(&efile, &y3[0], 20);
EbfFile_rFloat64(&efile, &y3[20], 40);
EbfFile_rFloat64(&efile, &y3[60], 20);
EbfFile_Close(&efile);
/*Read 10 elements with an offset of 20 (x[20] to x[29])*/
EbfFile_OpenR(&efile, "check.ebf", "/x1");
EbfFile_Seek(&efile, 20);
EbfFile_rFloat64(&efile, &y3[20], 10);
EbfFile_Close(&efile);
printf("%s %s \n", "Units are", efile.ebfh.unit);
printf("%s \n", "printing values 20 to 30");
for (i = 20; i < 30; ++i)
printf("%d %e \n", i, y3[i]);
/* write and read a string*/
strcpy(mystr1, "Hello, World!");
/* same as Ebf_WriteChar("test2.ebf", "/mystr",mystr1, "w","",strlen(mystr1));*/
Ebf_WriteCString("check.ebf", "/mystr", mystr1, "w");
Ebf_ReadCString("check.ebf", "/mystr", mystr2, 200);
printf("%s \n", mystr2);
return 0;
}
A demo code explaining the usgae is given below:
public class EbfDemo {
public static void main(String[] args) {
// ebf_demo();
EbfTest.all();
}
public static void ebf_demo() {
// generate some test data
float[] x1 = new float[100];
int[] x2 = new int[100];
for (int i = 0; i < x1.length; ++i) {
x1[i] = i;
x2[i] = i;
}
// write array x1 to file test.ebf
Ebf.write("test.ebf", "/x1", x1);
// append to file test.ebf array x2 with unit m/s
Ebf.write("test.ebf", "/x2", x2, "a", "100 m/s");
// read data as long and double
long[] y1 = null;
double[] y2 = null;
y1 = Ebf.read("test.ebf", "/x1", y1);
y2 = Ebf.read("test.ebf", "/x2", y2);
// print the data
System.out.println("Printing x1 x2 y1 y2");
for (int i = 90; i < x1.length; ++i)
System.out.println(x1[i] + " " + x2[i] + " " + y1[i] + " " + y2[i]);
// Write x1 which is a long array as a double array
EbfFile efile = new EbfFile();
efile.open("test.ebf", "/test/x1_double", "a", Ebf.ebf_TypeS("float64"));
efile.write(x1, 0, 0);
efile.close();
// Write elements till end of array but starting with offset 20
// and with data type same as the data type of source array.
efile.open("test.ebf", "/test/x1_small1", "a", Ebf.ebf_TypeV(x1[0]));
efile.write(x1, 20, 0);
efile.close();
// write elements 20 to 100 in 4 steps
efile.open("test.ebf", "/test/x1_small2", "a", Ebf.ebf_TypeV(x1[0]),
"100 ms/s");
efile.write(x1, 20, 10);
efile.write(x1, 30, 10);
efile.write(x1, 40, 50);
efile.write(x1, 90, 0);
efile.close();
// Write elements 20 to 100 as 2x40 multi dimensional array
// the first dimension can be set to zero and is automatically set,
// depending upon the number of elements written, when close() method is
// invoked.
// Also units are written. Can be set to blank string.
List<Long> dims = new ArrayList<Long>();
dims.add((long) 0);
dims.add((long) 40);
efile = new EbfFile();
efile.open("test.ebf", "/test/x1_multi", "a", Ebf.ebf_TypeV(x1[0]),
"100 m/s", dims);
efile.write(x1, 20, 80);
efile.close();
// Read all elements
efile.open("test.ebf", "/x1");
double[] y3 = new double[(int) efile.elements()];
efile.read(y3);
efile.close();
// Read elements with an offset of 20 in an array till the end of array
efile.open("test.ebf", "/x1");
y3 = new double[30];
efile.read(y3, 20, 0);
efile.close();
System.out.println("printing values 20 to 30");
for (int i = 20; i < y3.length; ++i)
System.out.println(i + " " + y3[i]);
// Read first 10 elements with an offset of 20 in array
efile.open("test.ebf", "/x1");
y3 = new double[(int) efile.elements()];
efile.read(y3, 20, 10);
efile.close();
System.out.println("printing values 20 to 30");
for (int i = 20; i < 30; ++i)
System.out.println(i + " " + y3[i]);
// print units of a data object
System.out.println("units are: "
+ Ebf.unit("test.ebf", "/test/x1_multi"));
// Print a summary of the file
Ebf.info("test.ebf");
// write and read a string
Ebf.write("test2.ebf", "/mystr", "Hello, World !", "w");
String mystr = null;
mystr = Ebf.read("test2.ebf", "/mystr", mystr);
System.out.println(mystr);
}
}