# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/data_mgr/merge_headers.py 3277 2020-06-26 13:45:06Z depa $

"""Script executed by mergeHeaders C++ ICE method
Merges header of original file into new file
expects:
filenameSASHA: filename of orignal file created by SASHA WS
filenameSHINS:  filename used to save file in archive"""

from astropy.io import fits
from util import shinsLogger
import sys

try:
    with fits.open(filenameSASHA) as hdulOrig:
        with fits.open(filenameSHINS) as hdulNew:
            headerOrig = hdulOrig[0].header
            hdulNew[0].header.extend(cards=headerOrig[0:8])
            hdulNew[0].header.extend(cards=headerOrig[9:], bottom=True)
            hdulNew[0].header["CAMERA"] = "SHARK-NIR"
            # hdulNew[0].header.add_checksum()
    status = 0
except IOError as e:
    print ("ERROR")
    status = 1
    raise e
