old_contents: # -*- coding: utf-8 -*-
  """
  pytasa.io - read and write elastic constants data
  
  This module provides functions that read or write single elastic constant
  matrices represented as 6x6 numpy arrays (Voigt notation). 
  """
  import os
  import gzip
  import numpy as np
  
  
  def openfile(read_function):
      """Decorator to read data from files or file like instances.
  
         Adding the @openfile decorator to a function designed to read from a
         open file handle permits filenames to be given as arguments. If a string
         argument is given it is treated as a file name and opened prior to the 
         main read function being called. If the file name ends in .gz, the file
         is also uncompressed on the fly.
      """
      def wrapped_function(f):
          if isinstance(f, str):
              if os.path.splitext(f)[1] == '.gz':
                  with gzip.open(f, 'rb') as f:
                      return read_function(f)
              else:
                  with open(f, 'r') as f:
                      return read_function(f)
          else:
              return read_function(f)
  
      return wrapped_function
  
  
  @openfile
  def load_ematrix(fh):
      """Load an 'ematrix' file"""
      Cout = np.zeros((6,6))
  
      for i, line in enumerate(fh):
          # Skip the header...
          if i > 2:
              # We really should do some sanity checking...
              cijstr = line.split()
              for j in range(6):
                  Cout[i-3, j] = float(cijstr[j])
  
      # Units are Mbar - convert to GPa!
      Cout = Cout * 100.0
  
      return Cout
              
  
new_contents: # -*- coding: utf-8 -*-
  """
  pytasa.io - read and write elastic constants data
  
  This module provides functions that read or write single elastic constant
  matrices represented as 6x6 numpy arrays (Voigt notation). 
  """
  import os
  import gzip
  import numpy as np
  
  
  def openfile(read_function):
      """Decorator to read data from files or file like instances.
  
         Adding the @openfile decorator to a function designed to read from a
         open file handle permits filenames to be given as arguments. If a string
         argument is given it is treated as a file name and opened prior to the 
         main read function being called. If the file name ends in .gz, the file
         is also uncompressed on the fly.
      """
      def wrapped_function(f):
          if isinstance(f, str):
              if os.path.splitext(f)[1] == '.gz':
                  with gzip.open(f, 'rb') as f:
                      return read_function(f)
              else:
                  with open(f, 'r') as f:
                      return read_function(f)
          else:
              return read_function(f)
  
      return wrapped_function
  
  
  def convert_to_gpa(C, units):
      """Convert the elastic constants in C to GPa from specified units"""
      units = units.lower()
      if units == "gpa":
          pass
      elif units == "pa":
          C = C / 1.0E9
      elif units == "mbar":
          C = C * 100.0
      elif units == "bar":
          C = C / 10.0E3
      else:
          raise ValueError("Elasticity unit not recognised")
      return C
  
  
  def convert_to_kgm3(rho, units):
      """Convert the density to Kg/m^3 from specified units"""
      units = units.lower()
      if units == "kgm3":
          pass
      elif units == "gcc":
          rho = rho * 1.0E3
      else:
          raise ValueError("Density unit not recognised")
      return rho
  
  
  @openfile
  def load_ematrix(fh):
      """Load an 'ematrix' file"""
      Cout = np.zeros((6,6))
  
      for i, line in enumerate(fh):
          # Skip the header...
          if i > 2:
              # We really should do some sanity checking...
              cijstr = line.split()
              for j in range(6):
                  Cout[i-3, j] = float(cijstr[j])
  
      # Units are Mbar - convert to GPa!
      Cout = convert_to_gpa(Cout, "Mbar")
  
      return Cout
              
  
subject: Add unit converters to io module