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

"""script executed by populateWithData C++ ICE method.
Saves data form original file to new file
expects:
fitsFilenameOrig: filename of orignal file created by SASHA WS
fitsFilenameNew:  filename used to save file in archive"""

from astropy.io import fits
from util import shinsLogger
from util import variables as vars
import sys

logger = shinsLogger.get_logger(__name__)

try:
    with fits.open(filenameSASHA) as hdulOrig:
        with fits.open(filenameSHINS) as hdulNew:
            dataOrig   = hdulOrig[0].data
            hdulNew[0].data = dataOrig
    status = vars.EXIT_SUCCESS
except IOError as e:
    print ("ERROR")
    logger.error(e.errmsg)
    status = vars.EXIT_FAILURE
    raise e
