#!/usr/bin/env python
'''
Copyright (C) 2012- Swedish Meteorological and Hydrological Institute (SMHI)

This file is part of RAVE.

RAVE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RAVE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with RAVE.  If not, see <http://www.gnu.org/licenses/>.
'''

## Stub binary

## @file
## @author Daniel Michelson, SMHI
## @date 2012-11-05

import sys, types
from odc_generate import generate


if __name__ == "__main__":
    from optparse import OptionParser

    description = "Command-line tool for QC-processing polar data for Odyssey"

    usage = "usage: %prog -i <inpath> -o <outpath> -q <algorithm-list> [-p <processes>] [h]"
    parser = OptionParser(usage=usage, description=description)

    parser.add_option("-i", "--ipath", dest="ipath",
                      help="Input path containing polar data.")

    parser.add_option("-o", "--opath", dest="opath",
                      help="Output path for writing data.")

    parser.add_option("-q", "--qc", dest="qc",
                      help="Comma-separated list of which QC algorithms to run, e.g. 'ropo,beamb'. No white spaces between these names.")

    parser.add_option("-d", "--delete", dest="delete", default=False,
                      help="Deletes input files following their processing. Default=False")

    parser.add_option("-c", "--check", dest="check", default=True,
                      help="Checks for the presence of output files. If an output file already exists, do nothing and move on to the next. Default=True")

    parser.add_option("-p", "--procs", dest="procs", type="int", default=0,
                      help="Number of concurrent worker processes to run. Defaults to the maximum number of logical CPUs supported on your hardware, but can be constrained or raised as you wish. Use off-line for benchmarking.")

    (options, args) = parser.parse_args()

    if options.procs == 0: options.procs=None
    if type(options.delete) is types.StringType:
        options.delete = eval(options.delete)
    if type(options.check) is types.StringType:
        options.check = eval(options.check)

    if not options.ipath or not options.opath or not options.qc:
        parser.print_help()
        sys.exit(1)

    generate(options)
