def hist(x, bins, mi=-9999, ma=-9999, ps=0, norm=0, color='k'):
   """calculates/plots histogram
   
   arguments:
   x    -- data array (required)
   bins -- uniform bin width (required)
   mi   -- start of first bin (optional)
   ma   -- end of last bin (optional)
   ps   -- histogram is saved as ps-file (default 0)
   norm -- output as p.d.f. (default 0)
   color-- color of histogram (default = 'k': black)
   
   output: 
   h  -- histogram array
   xx -- centered bin-values           
   """
   import numpy as np
   import matplotlib.pyplot as plt

   if mi == -9999:
       mi=min(x)
   if ma == -9999:
       ma=max(x)

# assure that min(x) and max(x) are inside range mi and ma
   ma=max(ma,max(x))
   mi=min(mi,min(x))

   nd=(ma-mi)/bins
   ma=mi+(nd+1)*bins
   
   bin=np.arange(mi,ma+1.e-6,bins)
   
   if norm == 1:
     h,b,a=plt.hist(x,bins=bin,range=[mi,ma],histtype='step',density=True,color=color)
   else:
     h,b,a=plt.hist(x,bins=bin,range=[mi,ma],histtype='step',color=color)
   
   if ps == 1:
     plt.savefig('histogram_py.ps')
            
#   plt.show()  #in case, use this statement in calling routine
     
   nh=h.size
#  example: bin=[0,10,20,30,40,50,60,70,80,90,100] size=11
#           size(h)=10
#  -> xx(centered) = [5,15,25,35,45,55,65,75,85,95] size=10
   
   xx=np.arange(nh, dtype=float)
   
   for i in range(0,nh):    #since <nh, i=0,...,9 (10 times)
       xx[i]=0.5*(b[i]+b[i+1]) #xx[0]...xx[9], max_index(b)=10 
   
   return h,xx
