#!/usr/bin/python3.6
'''
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. For compositing, this executable hard-wires a quality-based composite algorithm where the last QC algorithm in the chain should be qi-total.")

    parser.add_option("-d", "--delete", action="store_false", dest="delete",
                      help="Deletes input files following their processing.")

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

    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.")

    parser.add_option("-D", "--write-pvols", action="store_true", dest="dump",
                      help="Write quality-controlled PVOLs to output path.")

    parser.add_option("-a", "--composite-area", dest="areaid",
                      help="The area identifier (string) of the output composite area to generate.")

    parser.add_option("-O", "--composite-file", dest="ofile", default="composite.h5",
                      help="The file name of the output composite that will be written to --opath. Default=composite.h5")

    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
                      help="If the different steps should be displayed. I.e. verbose information.")

    (options, args) = parser.parse_args()

    if options.procs == 0: options.procs=None

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

    generate(options)
