funkalicious 0.1

dc_sweep_n_slice_args.h File Reference

#include <libdotcode/dotcode_data.h>
#include <libpostproc/lp_wavefunction.h>
#include <glib-2.0/glib.h>
Include dependency graph for dc_sweep_n_slice_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

void get_args (int argc, char **argv, struct args *args, GError **err)

Function Documentation

void get_args ( int  argc,
char **  argv,
struct args args,
GError **  err 
)

Parses the options and sets up the args struct.

Parameters:
argcfrom main
argvfrom main
argspointer to struct to initialize
errpointer to pointer to GError to return error information (if any) GError code will be set to 1 if the user requested version information.

set defaults

Definition at line 76 of file dc_sweep_n_slice_args.c.

References args::axes, args::bands, DC_BAND_VOP, double_from_string(), e, wavefunction::file, GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, args::gridsite, int_from_string(), args::planes, args::point, print_version(), print_version_info(), args::sweeps, args::use_110_coordinates, args::use_gridsite, args::use_max_probability_point, and args::wavefunctions.

Referenced by main().

                                                                      {
  /**set defaults*/
  args->use_110_coordinates=FALSE;
  args->use_max_probability_point=TRUE;
  args->use_gridsite=FALSE;
  for(int i=0; i<3; i++) {
    args->axes[i]=FALSE;
    args->planes[i]=FALSE;
    args->point[i]=0;
    args->gridsite[i]=0;
    args->sweeps[i]=FALSE;
  }
  args->wavefunctions=NULL;
  args->bands=NULL;
  gboolean print_version;
  gchar* position = NULL;
  gchar* gridsite = NULL;
  gboolean each_band = FALSE;
  GOptionEntry options[] = {
    { "version", 'v', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &print_version, "Print version information about this program", NULL },
    //{ "110", '1', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->use_110_coordinates), "Use the (110) coordinate system instead of (100) (i.e. use coordinate system x->(110), y->(-110), z->(001))", NULL},
    { "xaxis", 'x', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->axes[0]), "Save the wavefunction along the x axis", NULL},
    { "yaxis", 'y', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->axes[1]), "Save the wavefunction along the y axis", NULL},
    { "zaxis", 'z', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->axes[2]), "Save the wavefunction along the z axis", NULL},
    { "sweepx", 'X', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->sweeps[0]), "Sweep (plot into a pbm each cooordinate of) the wavefunction along the x axis", NULL},
    { "sweepy", 'Y', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->sweeps[1]), "Sweep (plot into a pbm each cooordinate of) the wavefunction along the y axis", NULL},
    { "sweepz", 'Z', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->sweeps[2]), "Sweep (plot into a pbm each cooordinate of) the wavefunction along the z axis", NULL},
    { "xy", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->planes[0]), "Save the wavefunction in the xy plane", NULL},
    { "xz", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->planes[1]), "Save the wavefunction in the xz plane", NULL},
    { "yz", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &(args->planes[2]), "Save the wavefunction in the yz plane", NULL},
    { "all-bands", 'a', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &each_band, "Print all of the bands separately instead of the total probability density.", NULL},
    { "at", '@', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &position, "Position at which to print the wavefunction along the specified directions.  Point consists of comma-separted set of floats (will be snapped to gridsite).  If no site is given (either with -@ or -g), default is to get the maximum wavefunction prboability density.", NULL},
    { "gridsite", 'g', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &gridsite, "Gridsite at which to print the wavefunction along the specified directions.  Point consists of comma-separted set of integers.  If no site is given (either with -@ or -g), default is to get the maximum wavefunction prboability density.", NULL},
      {NULL}
  };
  GOptionContext *ctx;
  ctx = g_option_context_new("- create a dotcode potential for the specified grid of nearest neighbors");
  g_option_context_add_main_entries(ctx, options, "Options");
  g_option_context_parse(ctx, &argc, &argv, NULL);
  g_option_context_free(ctx);

  if(print_version) {
    print_version_info();
    *err = g_error_new(GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, 1, "No error; user just wanted version information. This shouldn't be printed.\nIf it was printed, then you have encountered a bug that needs fixed.");
    return;
  }

  
  if((gridsite != NULL) && (position != NULL)) {
    *err = g_error_new(GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, 2, "You must specify *either* --at OR --gridsite; NOT BOTH.");
    return;
  }
  if(gridsite != NULL) {
    args->use_max_probability_point=FALSE;
    args->use_gridsite=TRUE;
    char** gridsite_coords = g_strsplit(gridsite, ",", 3);
    for(int i=0; i<3; ++i) {
      if(gridsite_coords[i] == NULL) {
  *err = g_error_new(GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, 3, "There were only %d gridsite arguments (received string %s); there should be *three*, comma-separated integer arguments.", i, gridsite);
  g_strfreev(gridsite_coords);
  return;
      }
      GError *e = NULL;
      args->gridsite[i] = int_from_string(gridsite_coords[i], &e);
      if(e != NULL) {
  g_propagate_prefixed_error(err, e, "Error converting gridsite coordinate string (%s) (coordinate %d in original string %s) into integer: ", gridsite_coords[i], i, gridsite);
  return;
      }
    }
    g_strfreev(gridsite_coords);
  }else if(position != NULL) {
    args->use_max_probability_point=FALSE;
    args->use_gridsite=FALSE;
    char** position_coords = g_strsplit(position, ",", 3);
    for(int i=0; i<3; ++i) {
      if(position_coords[i] == NULL) {
  *err = g_error_new(GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, 3, "There were only %d position arguments (received string %s); there should be *three*, comma-separated integer arguments.", i, position);
  g_strfreev(position_coords);
  return;
      }
      GError *e = NULL;
      args->point[i] = double_from_string(position_coords[i], &e);
      if(e != NULL) {
  g_propagate_prefixed_error(err, e, "Error converting position coordinate string (%s) (coordinate %d in original string %s) into double: ", position_coords[i], i, position);
  return;
      }
    }
    g_strfreev(position_coords);
  }
  
  if(each_band) {
    for(int i=0; i<DC_BAND_VOP+1; ++i) {
      enum dotcode_band* band = (enum dotcode_band*)malloc(sizeof(enum dotcode_band));
      if(band == NULL) {
  *err = g_error_new(GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, 4, "Failed to allocate storage for a dotcode band.");
  return;
      }
      *band = i;
      args->bands = g_list_append(args->bands, band);
    }
  }

  for(int i=1; i<argc; ++i) {
    struct wavefunction* wf = (struct wavefunction*)malloc(sizeof(struct wavefunction));
    if(wf == NULL) {
      *err = g_error_new(GET_DC_SWEEP_N_SLICE_ARGS_DOMAIN, 4, "Failed to allocate storage for a dotcode wavefunction struct (file was %s).", argv[i]);
    }
    wf->file = g_file_new_for_commandline_arg(argv[i]);
    args->wavefunctions = g_list_append(args->wavefunctions, wf);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines