import Manyo.MLF

e = Manyo.ElementContainer()
e.Add("x",[0,1,2,3,4,5,6,7,8,9])
e.Add("y",[5,2,7,8,2,1,3,4,7])
e.Add("err",[1,1,1,1,1,1,1,1,1])
e.SetKeys("x","y","err")

ew = Manyo.ElementContainer()
ew.Add("x",[0.1,1.1,2.1,3.1,4.1,5,6,7,8.1,9.1])
ew.Add("y",[5,2,7,8,2,1,3,4,7])
ew.Add("err",[1,1,1,1,1,1,1,1,1])
ew.SetKeys("x","y","err")

ep = ew+e

#####################################

# Making the class object of the wrapper of file I/O. 
ne1 = Manyo.NeXusFileIO()

# ( data_object_of_Manyo_library, file_name, User_name )
ne1.Write( ep, "test.nx", "suzuki" )

# close data file
del ne1

###### writing NeXus file finished

# Making the class object of the wrapper of file I/O.
ne2 = Manyo.NeXusFileIO()

# reading data file with the file name
e2 = ne2.ReadElementContainer( "test.nx" )

# close data file
del ne2

####################################

# Making the class object of the wrapper of file I/O. 
Mout = Manyo.WriteSerializationFileBinary( "test.bin" )

# writing data containers.
# You can write many data objects into a file,
# but you shoud read the file in the correct sequence.
Mout.Save( e2 )
# close data file.
del( Mout )

# Reading the data file wrote in above lines.
# Making the class object of the wrapper of file I/O.
Min = Manyo.ReadSerializationFileBinary( "test.bin" )

# Making data object for reading data file.
e3 = Manyo.ElementContainer()


# Reading data files.
Min.Load( e3 )
del( Min )

###################################

#( ep - e3 ).Dump()

e_out = ep - e3 * ep / e3
TestVal =  e_out.Sum()
TestValErr = e_out.Sum( "err" )

import os
os.system( "rm test.bin test.nx" )


