/* *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* */
/* ** Copyright UCAR                                                         */
/* ** University Corporation for Atmospheric Research (UCAR)                 */
/* ** National Center for Atmospheric Research (NCAR)                        */
/* ** Boulder, Colorado, USA                                                 */
/* ** BSD licence applies - redistribution and use in source and binary      */
/* ** forms, with or without modification, are permitted provided that       */
/* ** the following conditions are met:                                      */
/* ** 1) If the software is modified to produce derivative works,            */
/* ** such modified software should be clearly marked, so as not             */
/* ** to confuse it with the version available from UCAR.                    */
/* ** 2) Redistributions of source code must retain the above copyright      */
/* ** notice, this list of conditions and the following disclaimer.          */
/* ** 3) Redistributions in binary form must reproduce the above copyright   */
/* ** notice, this list of conditions and the following disclaimer in the    */
/* ** documentation and/or other materials provided with the distribution.   */
/* ** 4) Neither the name of UCAR nor the names of its contributors,         */
/* ** if any, may be used to endorse or promote products derived from        */
/* ** this software without specific prior written permission.               */
/* ** DISCLAIMER: THIS SOFTWARE IS PROVIDED 'AS IS' AND WITHOUT ANY EXPRESS  */
/* ** OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED      */
/* ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.    */
/* *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* */
////////////////////////////////////////////
// Params.hh
//
// TDRP header file for 'Params' class.
//
// Code for program Grib2toMdv
//
// This header file has been automatically
// generated by TDRP, do not modify.
//
/////////////////////////////////////////////

/**
 *
 * @file Params.hh
 *
 * This class is automatically generated by the Table
 * Driven Runtime Parameters (TDRP) system
 *
 * @class Params
 *
 * @author automatically generated
 *
 */

#ifndef Params_hh
#define Params_hh

#include <tdrp/tdrp.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>

using namespace std;

// Class definition

class Params {

public:

  // enum typedefs

  typedef enum {
    TIMESTAMP_GEN_TIME = 0,
    TIMESTAMP_FCAST_TIME = 1
  } timestamp_t;

  typedef enum {
    ENCODING_ASIS = 0,
    ENCODING_INT8 = 1,
    ENCODING_INT16 = 2,
    ENCODING_FLOAT32 = 5
  } encoding_type_t;

  typedef enum {
    COMPRESSION_ASIS = -1,
    COMPRESSION_NONE = 0,
    COMPRESSION_RLE = 1,
    COMPRESSION_LZO = 2,
    COMPRESSION_ZLIB = 3,
    COMPRESSION_BZIP = 4,
    COMPRESSION_GZIP = 5
  } compression_type_t;

  typedef enum {
    NO_CHANGE = 0,
    MPS_TO_KNOTS = 1,
    M_TO_KM = 2,
    M_TO_100FT = 3,
    PASCALS_TO_MBAR = 4,
    KELVIN_TO_CELCIUS = 5,
    KGPKG_TO_GPKG = 6,
    PERCENT_TO_FRACTION = 7,
    FRACTION_TO_PERCENT = 8,
    M_TO_FT = 9,
    M_TO_MI = 10,
    M_TO_KFT = 11,
    MM_S_TO_MM_HR = 12
  } out_units_t;

  typedef enum {
    BAD_VALUE = 0,
    UNKNOWN_VALUE = 1,
    USER_DEFINED = 2
  } qc_default_t;

  typedef enum {
    PROJ_LATLON = 0,
    PROJ_LAMBERT_CONF = 3,
    PROJ_FLAT = 8
  } projection_t;

  // struct typedefs

  typedef struct {
    char* param;
    char* level;
    char* mdv_name;
    out_units_t units;
    double upper_range_limit;
    double lower_range_limit;
    encoding_type_t encoding_type;
    qc_default_t qc_default_type;
    double qc_default_value;
    int vert_level_min;
    int vert_level_max;
    int vert_level_dz;
    tdrp_bool_t use_additional_bad_data_value;
    double additional_bad_data_value;
    tdrp_bool_t use_additional_missing_data_value;
    double additional_missing_data_value;
  } out_field_t;

  typedef struct {
    tdrp_bool_t SpecifyScaling;
    double scale;
    double bias;
  } Scaling_info_t;

  typedef struct {
    projection_t type;
    double rotation;
    double origin_lat;
    double origin_lon;
    double ref_lat_1;
    double ref_lat_2;
  } projection_info_t;

  typedef struct {
    int nx;
    int ny;
    double minx;
    double miny;
    double dx;
    double dy;
  } grid_info_t;

  ///////////////////////////
  // Member functions
  //

  ////////////////////////////////////////////
  // Default constructor
  //

  Params ();

  ////////////////////////////////////////////
  // Copy constructor
  //

  Params (const Params&);

  ////////////////////////////////////////////
  // Destructor
  //

  ~Params ();

  ////////////////////////////////////////////
  // Assignment
  //

  void operator=(const Params&);

  ////////////////////////////////////////////
  // loadFromArgs()
  //
  // Loads up TDRP using the command line args.
  //
  // Check usage() for command line actions associated with
  // this function.
  //
  //   argc, argv: command line args
  //
  //   char **override_list: A null-terminated list of overrides
  //     to the parameter file.
  //     An override string has exactly the format of an entry
  //     in the parameter file itself.
  //
  //   char **params_path_p:
  //     If this is non-NULL, it is set to point to the path
  //     of the params file used.
  //
  //   bool defer_exit: normally, if the command args contain a 
  //      print or check request, this function will call exit().
  //      If defer_exit is set, such an exit is deferred and the
  //      private member _exitDeferred is set.
  //      Use exidDeferred() to test this flag.
  //
  //  Returns 0 on success, -1 on failure.
  //

  int loadFromArgs(int argc, char **argv,
                   char **override_list,
                   char **params_path_p,
                   bool defer_exit = false);

  bool exitDeferred() { return (_exitDeferred); }

  ////////////////////////////////////////////
  // loadApplyArgs()
  //
  // Loads up TDRP using the params path passed in, and applies
  // the command line args for printing and checking.
  //
  // Check usage() for command line actions associated with
  // this function.
  //
  //   const char *param_file_path: the parameter file to be read in
  //
  //   argc, argv: command line args
  //
  //   char **override_list: A null-terminated list of overrides
  //     to the parameter file.
  //     An override string has exactly the format of an entry
  //     in the parameter file itself.
  //
  //   bool defer_exit: normally, if the command args contain a 
  //      print or check request, this function will call exit().
  //      If defer_exit is set, such an exit is deferred and the
  //      private member _exitDeferred is set.
  //      Use exidDeferred() to test this flag.
  //
  //  Returns 0 on success, -1 on failure.
  //

  int loadApplyArgs(const char *params_path,
                    int argc, char **argv,
                    char **override_list,
                    bool defer_exit = false);

  ////////////////////////////////////////////
  // isArgValid()
  // 
  // Check if a command line arg is a valid TDRP arg.
  //

  static bool isArgValid(const char *arg);

  ////////////////////////////////////////////
  // isArgValid()
  // 
  // Check if a command line arg is a valid TDRP arg.
  // return number of args consumed.
  //

  static int isArgValidN(const char *arg);

  ////////////////////////////////////////////
  // load()
  //
  // Loads up TDRP for a given class.
  //
  // This version of load gives the programmer the option to load
  // up more than one class for a single application. It is a
  // lower-level routine than loadFromArgs, and hence more
  // flexible, but the programmer must do more work.
  //
  //   const char *param_file_path: the parameter file to be read in.
  //
  //   char **override_list: A null-terminated list of overrides
  //     to the parameter file.
  //     An override string has exactly the format of an entry
  //     in the parameter file itself.
  //
  //   expand_env: flag to control environment variable
  //               expansion during tokenization.
  //               If TRUE, environment expansion is set on.
  //               If FALSE, environment expansion is set off.
  //
  //  Returns 0 on success, -1 on failure.
  //

  int load(const char *param_file_path,
           char **override_list,
           int expand_env, int debug);

  ////////////////////////////////////////////
  // loadFromBuf()
  //
  // Loads up TDRP for a given class.
  //
  // This version of load gives the programmer the option to
  // load up more than one module for a single application,
  // using buffers which have been read from a specified source.
  //
  //   const char *param_source_str: a string which describes the
  //     source of the parameter information. It is used for
  //     error reporting only.
  //
  //   char **override_list: A null-terminated list of overrides
  //     to the parameter file.
  //     An override string has exactly the format of an entry
  //     in the parameter file itself.
  //
  //   const char *inbuf: the input buffer
  //
  //   int inlen: length of the input buffer
  //
  //   int start_line_num: the line number in the source which
  //     corresponds to the start of the buffer.
  //
  //   expand_env: flag to control environment variable
  //               expansion during tokenization.
  //               If TRUE, environment expansion is set on.
  //               If FALSE, environment expansion is set off.
  //
  //  Returns 0 on success, -1 on failure.
  //

  int loadFromBuf(const char *param_source_str,
                  char **override_list,
                  const char *inbuf, int inlen,
                  int start_line_num,
                  int expand_env, int debug);

  ////////////////////////////////////////////
  // loadDefaults()
  //
  // Loads up default params for a given class.
  //
  // See load() for more detailed info.
  //
  //  Returns 0 on success, -1 on failure.
  //

  int loadDefaults(int expand_env);

  ////////////////////////////////////////////
  // sync()
  //
  // Syncs the user struct data back into the parameter table,
  // in preparation for printing.
  //
  // This function alters the table in a consistent manner.
  // Therefore it can be regarded as const.
  //

  void sync() const;

  ////////////////////////////////////////////
  // print()
  // 
  // Print params file
  //
  // The modes supported are:
  //
  //   PRINT_SHORT:   main comments only, no help or descriptions
  //                  structs and arrays on a single line
  //   PRINT_NORM:    short + descriptions and help
  //   PRINT_LONG:    norm  + arrays and structs expanded
  //   PRINT_VERBOSE: long  + private params included
  //

  void print(FILE *out, tdrp_print_mode_t mode = PRINT_NORM);

  ////////////////////////////////////////////
  // checkAllSet()
  //
  // Return TRUE if all set, FALSE if not.
  //
  // If out is non-NULL, prints out warning messages for those
  // parameters which are not set.
  //

  int checkAllSet(FILE *out);

  //////////////////////////////////////////////////////////////
  // checkIsSet()
  //
  // Return TRUE if parameter is set, FALSE if not.
  //
  //

  int checkIsSet(const char *param_name);

  ////////////////////////////////////////////
  // arrayRealloc()
  //
  // Realloc 1D array.
  //
  // If size is increased, the values from the last array 
  // entry is copied into the new space.
  //
  // Returns 0 on success, -1 on error.
  //

  int arrayRealloc(const char *param_name,
                   int new_array_n);

  ////////////////////////////////////////////
  // array2DRealloc()
  //
  // Realloc 2D array.
  //
  // If size is increased, the values from the last array 
  // entry is copied into the new space.
  //
  // Returns 0 on success, -1 on error.
  //

  int array2DRealloc(const char *param_name,
                     int new_array_n1,
                     int new_array_n2);

  ////////////////////////////////////////////
  // freeAll()
  //
  // Frees up all TDRP dynamic memory.
  //

  void freeAll(void);

  ////////////////////////////////////////////
  // usage()
  //
  // Prints out usage message for TDRP args as passed
  // in to loadFromArgs().
  //

  static void usage(ostream &out);

  ///////////////////////////
  // Data Members
  //

  char _start_; // start of data region
                // needed for zeroing out data
                // and computing offsets

  int debug;

  char* instance;

  int procmap_register_interval_secs;

  char* input_dir;

  char* input_suffix;

  char* input_substring;

  char* *_input_substrings;
  int input_substrings_n;

  int max_input_data_age;

  tdrp_bool_t latest_data_info_avail;

  tdrp_bool_t recursive_search;

  tdrp_bool_t latest_file_only;

  int data_check_interval_secs;

  tdrp_bool_t printSec_is;

  tdrp_bool_t printSec_ids;

  tdrp_bool_t printSec_lus;

  tdrp_bool_t printSec_gds;

  tdrp_bool_t printSec_pds;

  tdrp_bool_t printSec_drs;

  tdrp_bool_t printSec_bms;

  tdrp_bool_t printSec_ds;

  tdrp_bool_t autoset_missing_value;

  tdrp_bool_t check_lead_time;

  int max_lead_time_secs;

  tdrp_bool_t lead_time_subsampling;

  int *_subsample_lead_times;
  int subsample_lead_times_n;

  tdrp_bool_t write_forecast;

  char* forecast_mdv_url;

  tdrp_bool_t write_non_forecast;

  char* non_forecast_mdv_url;

  timestamp_t non_forecast_timestamp;

  tdrp_bool_t data_is_non_forecast;

  tdrp_bool_t writeLdataInfo;

  char* data_set_info;

  char* data_set_name;

  char* data_set_source;

  tdrp_bool_t process_everything;

  out_field_t *_output_fields;
  int output_fields_n;

  encoding_type_t encoding_type;

  compression_type_t compression_type;

  Scaling_info_t output_scaling_info;

  tdrp_bool_t remap_output;

  projection_info_t out_projection_info;

  grid_info_t out_grid_info;

  char* override_vlevels;

  double *_vlevel_array;
  int vlevel_array_n;

  tdrp_bool_t interp_vlevels_to_height;

  char* height_field_mdv_name;

  double *_height_levels;
  int height_levels_n;

  tdrp_bool_t compute_heights_from_pressure_levels;

  double min_height_from_pressure_levels;

  char _end_; // end of data region
              // needed for zeroing out data

private:

  void _init();

  mutable TDRPtable _table[56];

  const char *_className;

  bool _exitDeferred;

};

#endif