gimme-alpha 0.1

process-average-efield-args.h File Reference

#include <glib.h>
#include <gio/gio.h>
Include dependency graph for process-average-efield-args.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  args

Functions

struct argsprocess_args (int argc, char *argv[])

Function Documentation

struct args* process_args ( int  argc,
char *  argv[] 
) [read]

Definition at line 54 of file process-args.c.

References ARGDEFAULT_DEPRECATED_GROUP_HELPINFO, args::avg_hh_lh, args::base_dirs, args::del_psi2, do_print_version(), DOUBLE_TYPE, args::Ep, args::ifaces_sequences, args::instrument_efield_alpha, args::interfaces, args::no_efield_term, args::no_integrate, args::no_interface_term, args::no_print_integration_error, print_version(), processed_args, args::request_integration_abs_error, args::request_integration_rel_error, args::separate_terms, string_to_data(), string_to_data_x2(), and unlikely.

Referenced by main().

                                                  {
  gchar **interfaces = NULL;
  gboolean print_version = FALSE;
  gboolean no_avg_hh = FALSE;
  gboolean no_avg_lh = FALSE;
  int errored=0;
  gchar **base_dir_names = NULL;
  gchar **sequences = NULL;
  GOptionEntry options[] = {
    { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &base_dir_names, "", NULL },
    { "separate", 's', 0, G_OPTION_ARG_NONE, &(processed_args.separate_terms), "Print the alpha terms separately", NULL },
    { "no-interface", 'I', 0, G_OPTION_ARG_NONE, &(processed_args.no_efield_term), "Do not calculate the interface term", NULL },
    { "instrument_efield", 'f', 0, G_OPTION_ARG_NONE, &(processed_args.instrument_efield_alpha), "Instrument the electric field term in the Rashba coefficient, and writes out the alpha_efield_instrumentation_data.pdata file in the current working directory", NULL },
    { "no-electric-field", 'E', 0, G_OPTION_ARG_NONE, &(processed_args.no_interface_term), "Do not calculate the electric field term", NULL },
    { "no-print-integration-error", 'a', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(processed_args.no_print_integration_error), "Do not print estimation of integration error", NULL },
    { "integration-abs-error", 'R', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.request_integration_abs_error), "Requested absolute integration error", NULL}, 
    { "integration-rel-error", 'r', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.request_integration_rel_error), "Requested relative integration error", NULL}, 
    { "version", 'v', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &print_version, "Print version information about this program", NULL },
    { "no-hh-in-average", 'H', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &no_avg_hh, "Do not use the heavy hole in the averaging of heavy and light holes", NULL },
    { "no-lh-in-average", 'h', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &no_avg_lh, "Do not use the light hole in the averaging of heavy and light holes", NULL },
    { "no_integrate", 'N', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(processed_args.no_integrate), "do not perform the electric field integration (for dumping if calling gsl_integration_foo dies catastrophically)", NULL },
    { "Ep", 'p', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.Ep), "Ep of the well material", NULL}, 
    { "method2", '2', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(processed_args.del_psi2), "Use the \"Del |psi|^2\" method to calculate alpha, instead of the default, \"Del Bandterms\" method.", NULL}, 
    { NULL }
  };
  GOptionEntry deprecated_opts[] = {
    { "interface", 'i', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &interfaces, "Location of discrete interfaces", NULL },
    { "iface-sequence", 'q', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &sequences, "Discritized sequence of interfces (from:to), inclusive (i.e. -5:5 means that the materials are continuously varied from -5nm to 5nm)", NULL },
    { NULL }
  };
  GOptionContext *ctx;
  GOptionGroup *deprecated_group;
  ctx = g_option_context_new("- computes the Rashba spin-orbit parameter from the output of a nextnano well calculation.");
  deprecated_group = g_option_group_new("deprecated", ARGDEFAULT_DEPRECATED_GROUP_HELPINFO, "Show help about deprecated options", NULL, NULL);

  g_option_group_add_entries(deprecated_group, deprecated_opts);

  g_option_context_add_main_entries(ctx, options, "Options");
  g_option_context_add_group(ctx, deprecated_group);

  //fprintf(stderr, "process_args: about to process args.\n");
  
  g_option_context_parse(ctx, &argc, &argv, NULL);

  if(print_version){
    do_print_version();
    return NULL;
  }
  if(no_avg_hh) {
    processed_args.avg_hh_lh &= (~2);
  }
  if(no_avg_lh) {
    processed_args.avg_hh_lh &= (~1);
  }
  if(no_avg_hh && no_avg_lh) {
    fprintf(stderr, "ERROR: cannot remove BOTH HH and LH from the averaging!\n");
    errored=1;
  }
  
  if((processed_args.no_interface_term) && (processed_args.no_efield_term)) {
    fprintf(stderr, "ERROR: if you don't want an interface term and you don't want an electric field term, i.e. you don't want any of the Rashba terms, why are you running this program?!\n");
    errored=1;
  }

  //fprintf(stderr, "process_args: processed args.\n");
  
  gchar* htext = g_option_context_get_help(ctx, FALSE, NULL);
  
  double *d;
  if(interfaces != NULL) {
    for(int i=0; interfaces[i] != 0; i++) {
      if(unlikely((d = string_to_data(interfaces[i], DOUBLE_TYPE)) == NULL)) {
  fprintf(stderr, "ERROR: failed to convert an interface argument (%s) into double-precision number!\n", interfaces[i]);
  errored=1;
  break;
      }
      processed_args.interfaces = g_list_append(processed_args.interfaces, d);
    }
  }

  gchar** numbers;
  if(sequences != NULL) {
    for(int i=0; sequences[i] !=0; i++) {
      numbers = g_strsplit(sequences[0], ":", -1);
      if(numbers[2] != NULL) {
  fprintf(stderr, "ERROR: failed to convert sequence argument (%s) into two double-precision numbers: too many numbers (should be in the form a:b)\n", sequences[i]);
  g_strfreev(numbers);
  errored=1;
  break;
      }
      if(unlikely((d = string_to_data_x2(numbers[0], numbers[1], DOUBLE_TYPE)) == NULL)) {
  fprintf(stderr, "ERROR: failed to convert one of two interface sequence range strings (%s, %s) into double-precision number!\n", numbers[0], numbers[1]);
  g_strfreev(numbers);
  errored=1;
  break;
      }
      processed_args.ifaces_sequences = g_list_append(processed_args.ifaces_sequences, d);
      g_strfreev(numbers);
    }
  }

  //fprintf(stderr, "got help.\n");
  
  g_option_context_free(ctx);

  /*Check to make sure what we want is there.*/
  GFile *bn;
  if(base_dir_names != NULL) {
    for(int i = 0; base_dir_names[i] != NULL; i++) {
      bn = g_file_new_for_commandline_arg(base_dir_names[i]);
      processed_args.base_dirs = g_list_append(processed_args.base_dirs, bn);
    }
  }
  if(processed_args.base_dirs == NULL) {
    fprintf(stderr, "ERROR: you MUST give at least one base directory\n");
    errored=1;
  }

  if(errored){
    int errored=0;
    printf("%s", htext);
    printf("**run with --version for version and compilation information**\n");
    return NULL;
  }

  return &processed_args;
}

Here is the call graph for this function:

Here is the caller graph for this function:

 All Classes Files Functions Variables Enumerations Enumerator Defines