#!/usr/bin/env python
# encoding: utf-8
#
# @Author: Jon Holtzman
# @Date: March 2018
# @Filename: mkgrid
# @License: BSD 3-Clause
# @Copyright: Jon Holtzman


from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import argparse
import os
import sys
import subprocess
import pdb

if __name__ == '__main__' :

    parser = argparse.ArgumentParser(
        prog=os.path.basename(sys.argv[0]),
        description='Wrapper to run IDL makecal')

    parser.add_argument('makecal', type=str, help='makecal argument')
    parser.add_argument("--done")
    parser.add_argument("--host")
    parser.add_argument("--vers")
    parser.add_argument("--telescope")
    #parser.add_argument("--clobber")
    parser.add_argument('--clobber', help='Overwrite files?',action="store_true")
    parser.add_argument("--flag",default='11111')
    args=parser.parse_args()

    if args.clobber: clobber='clobber=1'
    else : clobber='clobber=0'
    subprocess.call(["idl","-e","makecal,"+args.makecal+",vers='"+args.vers+"',telescope='"+args.telescope+"',"+clobber])

    if args.done is not None :
        subprocess.call(['setdone',args.done])
        try: 
            subprocess.call(['setdone',done])
        except: pass
        print('host', args.host)
        if args.host is not None :
            try: os.remove(args.done+'.'+args.host)
            except: pass
