Skip to content
Snippets Groups Projects
Select Git revision
  • fa34ae06ea779eeff9a29d07b153399805653e6e
  • master default
  • 1.1
  • 1.0
4 results

options.h

Blame
  • options.h 2.84 KiB
    #pragma once
    #include <string>
    #include <vector>
    #include <argp.h>
    #include "model.h"
    #include "log.h"
    #include "tokenize.h"
    
    const char *argp_program_version = "eisgenerator-1.0";
    const char *argp_program_bug_address = "<carl@uvos.xyz>";
    static char doc[] = "Application that generates EIS spectra from model strings";
    static char args_doc[] = "";
    
    static struct argp_option options[] =
    {
      {"verbose",   'v', 0,      0,  "Show debug messages" },
      {"quiet",     'q', 0,      0,  "only output data" },
      {"param",     'p', 0,      0,  "select parameter sweep mode" },
      {"model",      'm', "[STRING]",    0,  "set model string" },
      {"omega",      'o', "[START-END]", 0,  "set omega range" },
      {"omegasteps", 'c', "[COUNT]",     0,  "set omega range steps" },
      {"log",       'l', 0,      0,  "use logarithmic steps" },
      {"normalize", 'n', 0,      0,  "normalize values" },
      {"reduce",    'r', 0,      0,  "reduce values to \"interesting\" range" },
      {"hz",        'h', 0,      0,  "freqency values as temporal frequency instead of angular frequency"},
      {"invert",        'i', 0,      0,  "inverts the imaginary axis"},
      { 0 }
    };
    
    enum
    {
    	MODE_SWEEP = 0,
    	MODE_PARAM_SWEEP
    };
    
    struct Config
    {
    	std::string modelStr = "c{1e-6}r{1e3}-r{1e3}";
    	unsigned int mode = MODE_SWEEP;
    	eis::Range omegaRange;
    	bool normalize = false;
    	bool reduce = false;
    	bool hertz = false;
    	bool invert = false;
    
    	Config(): omegaRange(1, 1001, 1)
    	{}
    };
    
    static error_t
    parse_opt (int key, char *arg, struct argp_state *state)
    {
    	Config *config = reinterpret_cast<Config*>(state->input);
    
    	switch (key)
    	{
    	case 'q':
    		eis::Log::level = eis::Log::ERROR;
    		break;
    	case 'v':
    		eis::Log::level = eis::Log::DEBUG;
    		break;
    	case 's':
    		config->mode = MODE_SWEEP;
    		break;
    	case 'p':
    		config->mode = MODE_PARAM_SWEEP;
    		break;
    	case 'm':
    		config->modelStr.assign(arg);