#
#  Copyright (c) 2009-2015, Jack Poulson
#  All rights reserved.
#
#  This file is part of Elemental and is under the BSD 2-Clause License, 
#  which can be found in the LICENSE file in the root directory, or at 
#  http://opensource.org/licenses/BSD-2-Clause
#
from El.core import *
from El.blas_like import Copy, CopyFromRoot, CopyFromNonRoot, RealPart, ImagPart

# Input/Output
# ************

lib.ElPrint_i.argtypes = \
lib.ElPrint_s.argtypes = \
lib.ElPrint_d.argtypes = \
lib.ElPrint_c.argtypes = \
lib.ElPrint_z.argtypes = \
lib.ElPrintDist_i.argtypes = \
lib.ElPrintDist_s.argtypes = \
lib.ElPrintDist_d.argtypes = \
lib.ElPrintDist_c.argtypes = \
lib.ElPrintDist_z.argtypes = \
lib.ElPrintDistMultiVec_i.argtypes = \
lib.ElPrintDistMultiVec_s.argtypes = \
lib.ElPrintDistMultiVec_d.argtypes = \
lib.ElPrintDistMultiVec_c.argtypes = \
lib.ElPrintDistMultiVec_z.argtypes = \
lib.ElPrintGraph.argtypes = \
lib.ElPrintDistGraph.argtypes = \
lib.ElPrintSparse_i.argtypes = \
lib.ElPrintSparse_s.argtypes = \
lib.ElPrintSparse_d.argtypes = \
lib.ElPrintSparse_c.argtypes = \
lib.ElPrintSparse_z.argtypes = \
lib.ElPrintDistSparse_i.argtypes = \
lib.ElPrintDistSparse_s.argtypes = \
lib.ElPrintDistSparse_d.argtypes = \
lib.ElPrintDistSparse_c.argtypes = \
lib.ElPrintDistSparse_z.argtypes = \
  [c_void_p,c_char_p]

lib.ElPrint_i.restype = \
lib.ElPrint_s.restype = \
lib.ElPrint_d.restype = \
lib.ElPrint_c.restype = \
lib.ElPrint_z.restype = \
lib.ElPrintDist_i.restype = \
lib.ElPrintDist_s.restype = \
lib.ElPrintDist_d.restype = \
lib.ElPrintDist_c.restype = \
lib.ElPrintDist_z.restype = \
lib.ElPrintDistMultiVec_i.restype = \
lib.ElPrintDistMultiVec_s.restype = \
lib.ElPrintDistMultiVec_d.restype = \
lib.ElPrintDistMultiVec_c.restype = \
lib.ElPrintDistMultiVec_z.restype = \
lib.ElPrintGraph.restype = \
lib.ElPrintDistGraph.restype = \
lib.ElPrintSparse_i.restype = \
lib.ElPrintSparse_s.restype = \
lib.ElPrintSparse_d.restype = \
lib.ElPrintSparse_c.restype = \
lib.ElPrintSparse_z.restype = \
lib.ElPrintDistSparse_i.restype = \
lib.ElPrintDistSparse_s.restype = \
lib.ElPrintDistSparse_d.restype = \
lib.ElPrintDistSparse_c.restype = \
lib.ElPrintDistSparse_z.restype = \
  c_uint

def Print(A,title=''):
  args = [A.obj,title]
  if type(A) is Matrix:
    if   A.tag == iTag: lib.ElPrint_i(*args)
    elif A.tag == sTag: lib.ElPrint_s(*args)
    elif A.tag == dTag: lib.ElPrint_d(*args)
    elif A.tag == cTag: lib.ElPrint_c(*args)
    elif A.tag == zTag: lib.ElPrint_z(*args)
    else: DataExcept()
  elif type(A) is DistMatrix:
    if   A.tag == iTag: lib.ElPrintDist_i(*args)
    elif A.tag == sTag: lib.ElPrintDist_s(*args)
    elif A.tag == dTag: lib.ElPrintDist_d(*args)
    elif A.tag == cTag: lib.ElPrintDist_c(*args)
    elif A.tag == zTag: lib.ElPrintDist_z(*args)
    else: DataExcept()
  elif type(A) is DistMultiVec:
    if   A.tag == iTag: lib.ElPrintDistMultiVec_i(*args)
    elif A.tag == sTag: lib.ElPrintDistMultiVec_s(*args)
    elif A.tag == dTag: lib.ElPrintDistMultiVec_d(*args)
    elif A.tag == cTag: lib.ElPrintDistMultiVec_c(*args)
    elif A.tag == zTag: lib.ElPrintDistMultiVec_z(*args)
    else: DataExcept()
  elif type(A) is Graph:
    lib.ElPrintGraph(*args)
  elif type(A) is DistGraph:
    lib.ElPrintDistGraph(*args)
  elif type(A) is SparseMatrix:
    if   A.tag == iTag: lib.ElPrintSparse_i(*args)
    elif A.tag == sTag: lib.ElPrintSparse_s(*args)
    elif A.tag == dTag: lib.ElPrintSparse_d(*args)
    elif A.tag == cTag: lib.ElPrintSparse_c(*args)
    elif A.tag == zTag: lib.ElPrintSparse_z(*args)
    else: DataExcept()
  elif type(A) is DistSparseMatrix:
    if   A.tag == iTag: lib.ElPrintDistSparse_i(*args)
    elif A.tag == sTag: lib.ElPrintDistSparse_s(*args)
    elif A.tag == dTag: lib.ElPrintDistSparse_d(*args)
    elif A.tag == cTag: lib.ElPrintDistSparse_c(*args)
    elif A.tag == zTag: lib.ElPrintDistSparse_z(*args)
    else: DataExcept()
  else: TypeExcept()

lib.ElSetColorMap.argtypes = [c_uint]
lib.ElSetColorMap.restype = c_uint
def SetColorMap(colorMap):
  lib.ElSetColorMap(colorMap)

lib.ElGetColorMap.argtypes = [POINTER(c_uint)]
lib.ElGetColorMap.restype = c_uint
def ColorMap():
  colorMap = c_uint()
  lib.ElGetColorMap(pointer(colorMap))
  return colorMap