# Path: pyneb/utils/misc.py
# def int_to_roman(input_):
#     """
#     Convert an integer to Roman numerals.
#     
#     Examples:
#     >>> int_to_roman(0)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(-1)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(1.5)
#     Traceback (most recent call last):
#     TypeError: expected integer, got <type 'float'>
#     
#     >>> print int_to_roman(2000)
#     MM
# 
#     >>> print int_to_roman(1999)
#     MCMXCIX
# 
#     """
#     if type(input_) != type(1):
#         #raise TypeError, "expected integer, got %s" % type(input_)
#         return None
#     if not 0 < input_ < 4000:
#         #raise ValueError, "Argument must be between 1 and 3999"
#         return None
#     ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
#     nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
#     result = ""
#     for i in range(len(ints)):
#         count = int(input_ / ints[i])
#         result += nums[i] * count
#         input_ -= ints[i] * count
#     return result
# 
# def roman_to_int(input_):
#     """
#     Convert a roman numeral to an integer.
#     
#     >>> r = range(1, 4000)
#     >>> nums = [int_to_roman(i) for i in r]
#     >>> ints = [roman_to_int(n) for n in nums]
#     >>> print r == ints
#     1
#     
#     >>> roman_to_int('VVVIV')
#     Traceback (most recent call last):
#      ...
#     ValueError: input is not a valid roman numeral: VVVIV
# 
#     >>> roman_to_int(1)
#     Traceback (most recent call last):
#      ...
#     TypeError: expected string, got <type 'int'>
# 
#     >>> roman_to_int('a')
#     Traceback (most recent call last):
#      ...
#     ValueError: input is not a valid roman numeral: A
# 
#     >>> roman_to_int('IL')
#     Traceback (most recent call last):
#      ...
#     ValueError: input is not a valid roman numeral: IL
# 
#     """   
#     if type(input_) != type(""):
#         #raise TypeError, "expected string, got %s" % type(input_)
#         return None
#     input_ = input_.upper()
#     nums = ['M', 'D', 'C', 'L', 'X', 'V', 'I']
#     ints = [1000, 500, 100, 50, 10, 5, 1]
#     places = []
#     for c in input_:
#         if not c in nums:
#             #raise ValueError, "input is not a valid roman numeral: %s" % input_
#             return None
#     for i in range(len(input_)):
#         c = input_[i]
#         value = ints[nums.index(c)]
#         # If the next place holds a larger number, this value is negative.
#         try:
#             nextvalue = ints[nums.index(input_[i + 1])]
#             if nextvalue > value:
#                 value *= -1
#         except IndexError:
#             # there is no next place.
#             pass
#         places.append(value)
#     sum_ = 0
#     for n in places: sum_ += n
#     # Easiest test for validity...
#     if int_to_roman(sum_) == input_:
#         return sum_
#     else:
#         #raise ValueError, 'input is not a valid roman numeral: %s' % input_
#         return None


import os, sys
import pyneb as pn
import numpy as np
    import pyfits
        import astropy.io.fits as pyfits
from pyneb.utils.misc import int_to_roman, roman_to_int
from physics import sym2name, gsFromAtom
try:
except:
    try:
    except:
        pn.log_.error('pyfits not installed')

    
def _updateHeader(hdu, input_file, content, elem, spec):
    """
    Update the header of the output fits file

    Parameters: 
        - hdu          pyfits file
        - input_file   name of the ascii files containing the original data
        - content      type of physical quantities contained in the file
        - elem         symbol of the selected element
        - spec         ionization stage in spectroscopic notation (I = 1, II = 2, etc.)
        
    """
    hdu.header.update('ORIGIN', 'File {0}, PyNeb v{1}'.format(input_file, pn.__version__))
    hdu.header.update('CONTENT', content)
    hdu.header.update('ATOM', sym2name[elem.capitalize()])
    hdu.header.update('SPECTRUM', roman_to_int(spec))

# Path: pyneb/utils/misc.py
# def int_to_roman(input_):
#     """
#     Convert an integer to Roman numerals.
#     
#     Examples:
#     >>> int_to_roman(0)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(-1)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(1.5)
#     Traceback (most recent call last):
#     TypeError: expected integer, got <type 'float'>
#     
#     >>> print int_to_roman(2000)
#     MM
# 
#     >>> print int_to_roman(1999)
#     MCMXCIX
# 
#     """
#     if type(input_) != type(1):
#         #raise TypeError, "expected integer, got %s" % type(input_)
#         return None
#     if not 0 < input_ < 4000:
#         #raise ValueError, "Argument must be between 1 and 3999"
#         return None
#     ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
#     nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
#     result = ""
#     for i in range(len(ints)):
#         count = int(input_ / ints[i])
#         result += nums[i] * count
#         input_ -= ints[i] * count
#     return result
# 
# def roman_to_int(input_):
#     """
#     Convert a roman numeral to an integer.
#     
#     >>> r = range(1, 4000)
#     >>> nums = [int_to_roman(i) for i in r]
#     >>> ints = [roman_to_int(n) for n in nums]
#     >>> print r == ints
#     1
#     
#     >>> roman_to_int('VVVIV')
#     Traceback (most recent call last):
#      ...
#     ValueError: input is not a valid roman numeral: VVVIV
# 
#     >>> roman_to_int(1)
#     Traceback (most recent call last):
#      ...
#     TypeError: expected string, got <type 'int'>
# 
#     >>> roman_to_int('a')
#     Traceback (most recent call last):
#      ...
#     ValueError: input is not a valid roman numeral: A
# 
#     >>> roman_to_int('IL')
#     Traceback (most recent call last):
#      ...
#     ValueError: input is not a valid roman numeral: IL
# 
#     """   
#     if type(input_) != type(""):
#         #raise TypeError, "expected string, got %s" % type(input_)
#         return None
#     input_ = input_.upper()
#     nums = ['M', 'D', 'C', 'L', 'X', 'V', 'I']
#     ints = [1000, 500, 100, 50, 10, 5, 1]
#     places = []
#     for c in input_:
#         if not c in nums:
#             #raise ValueError, "input is not a valid roman numeral: %s" % input_
#             return None
#     for i in range(len(input_)):
#         c = input_[i]
#         value = ints[nums.index(c)]
#         # If the next place holds a larger number, this value is negative.
#         try:
#             nextvalue = ints[nums.index(input_[i + 1])]
#             if nextvalue > value:
#                 value *= -1
#         except IndexError:
#             # there is no next place.
#             pass
#         places.append(value)
#     sum_ = 0
#     for n in places: sum_ += n
#     # Easiest test for validity...
#     if int_to_roman(sum_) == input_:
#         return sum_
#     else:
#         #raise ValueError, 'input is not a valid roman numeral: %s' % input_
#         return None


# Path: pyneb/utils/fits.py
import os, sys
import pyneb as pn
import numpy as np
    import pyfits
        import astropy.io.fits as pyfits
from pyneb.utils.misc import int_to_roman, roman_to_int
from physics import sym2name, gsFromAtom

try:
except:
    try:
    except:
        pn.log_.error('pyfits not installed')

    
def _updateHeader(hdu, input_file, content, elem, spec):
    """
    Update the header of the output fits file

    Parameters: 
        - hdu          pyfits file
        - input_file   name of the ascii files containing the original data
        - content      type of physical quantities contained in the file
        - elem         symbol of the selected element
        - spec         ionization stage in spectroscopic notation (I = 1, II = 2, etc.)
        
    """
    hdu.header.update('ORIGIN', 'File {0}, PyNeb v{1}'.format(input_file, pn.__version__))
    hdu.header.update('CONTENT', content)
    hdu.header.update('ATOM', sym2name[elem.capitalize()])
    hdu.header.update('SPECTRUM', roman_to_int(spec))

    atom = elem.capitalize() + str(roman_to_int(spec))