# -*- coding: utf-8 -*-

import Manyo as m
import Manyo.MLF as mlf


def DumpToFile( em, FileName ):

    fout = open( FileName, "w" )
    x = em( em.PutXKey() )
    y = em( em.PutYKey() )
    e = em( em.PutEKey() )
    
    if x.size() == y.size()+1:
        # if histogram type data
        for i in range( y.size() ):

            s = str( x[i] )   + " " + str( 0.0 ) + "\n"
            fout.write( s )
            
            s = str( x[i] )   + " " + str( y[i] ) + "\n"
            fout.write( s )
            s = str( x[i+1] ) + " " + str( y[i] ) + "\n"
            fout.write( s )
        s = str( x[ x.size()-1 ] )   + " " + str( 0.0 ) + "\n"
        fout.write( s )
            
    else:
        # if disperse type data
        s = str( x[i] )   + " " + str( y[i] ) + "\n"
        fout.write( s )
        
    fout.close()

def DumpToFileErr( em, FileName ):
    
    fout = open( FileName, "w" )
    x = em( em.PutXKey() )
    y = em( em.PutYKey() )
    e = em( em.PutEKey() )
    
    if x.size() == y.size()+1:
        # if histogram type data
        for i in range( y.size() ):
            s = str( ( x[i] + x[i+1] )/2.0 ) + " " + \
                str( y[i] ) + " " + \
                str( e[i] ) + "\n"
            fout.write( s )
            
    else:
        # if disperse type data
        s = str( x[i] ) + " " + \
            str( y[i] ) + " " + \
            str( e[i] ) + "\n"
        fout.write( s )
        
    fout.close()

    
