funkalicious 0.1

get_vhartree_slice_args.c File Reference

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>
#include "config.h"
#include "get_vhartree_slice_args.h"
Include dependency graph for get_vhartree_slice_args.c:

Go to the source code of this file.

Defines

#define GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN   31900

Functions

void program_print_version (FILE *f)
void libdotcode_print_version (FILE *f)
double * new_double_from_string (const char *s, GError **err)
int * new_int_from_string (const char *s, GError **err)
struct argsprocess_args (int argc, char **argv, GError **err)

Variables

struct args args

Define Documentation

#define GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN   31900

Function Documentation

void libdotcode_print_version ( FILE *  f)
double* new_double_from_string ( const char *  s,
GError **  err 
)

Definition at line 49 of file get_vhartree_slice_args.c.

References GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN.

                                                            {
  double* d = (double*)malloc(sizeof(double));
  if(d == NULL) {
    *err = g_error_new(GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, 1, "getChainPotential_args.c::new_double_from_string: Error occurred converting string (%s) to double: out of memory/malloc failed", s);
    return NULL;
  }
  char *end;
  errno = 0;
  *d = strtod(s, &end);
  if(((end == s) && (*d == 0)) || (errno != 0)) {
    *err = g_error_new(GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, 2, "getChainPotential_args.c::new_double_from_string: Error occurred converting string (%s) to double: %s", s, strerror(errno));
    free(d);
    return NULL;
  }
  return d;
}
int* new_int_from_string ( const char *  s,
GError **  err 
)

Definition at line 66 of file get_vhartree_slice_args.c.

References GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN.

Referenced by process_args().

                                                      {
  int* d = (int*)malloc(sizeof(int));
  if(d == NULL) {
    *err = g_error_new(GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, 1, "getChainPotential_args.c::new_int_from_string: Error occurred converting string (%s) to int: out of memory/malloc failed", s);
    return NULL;
  }
  char *end;
  errno = 0;
  *d = strtod(s, &end);
  if(((end == s) && (*d == 0)) || (errno != 0)) {
    *err = g_error_new(GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, 2, "getChainPotential_args.c::new_int_from_string: Error occurred converting string (%s) to int: %s", s, strerror(errno));
    free(d);
    return NULL;
  }
  return d;
}

Here is the caller graph for this function:

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

Processes the arguments to process_args

Parameters:
argcargc from main
argvargv from main
Returns:
NULL if there was an error. Pointer to the args struct if success.

Definition at line 84 of file get_vhartree_slice_args.c.

Referenced by main().

                                                               {
  int errored = 0;
  gchar **file_names = NULL;
  gboolean print_version = FALSE;
  gchar** xslices = NULL;
  gchar** yslices = NULL;
  gchar** zslices = NULL;
  GOptionEntry options[] = {
    { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &file_names,},
    { "version", 'v', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &print_version, "Print version information about this program", NULL },
    { "xslice", 'X', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(xslices), "x coordinate (in grid sites) along which to output a 2D slice of the total density and the resulting potential", NULL},
    { "yslice", 'Y', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(yslices), "y coordinate (in grid sites) along which to output a 2D slice of the total density and the resulting potential", NULL},
    { "zslice", 'Z', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(zslices), "z coordinate (in grid sites) along which to output a 2D slice of the total density and the resulting potential", 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);

  args.xslices = NULL;
  int *d;
  GError *e = NULL;
  if(xslices != NULL) {
    for(int i=0; xslices[i] != NULL; i++) {
      if((d=new_int_from_string(xslices[i], &e)) != NULL) {
  args.xslices = g_list_append(args.xslices, d);
      }else{
  *err = e;
  return NULL;
      }
    }
  }
  args.yslices = NULL;
  e = NULL;
  if(yslices != NULL) {
    for(int i=0; yslices[i] != NULL; i++) {
      if((d=new_int_from_string(yslices[i], &e)) != NULL) {
  args.yslices = g_list_append(args.yslices, d);
      }else{
  *err = e;
  return NULL;
      }
    }
  }
  args.zslices = NULL;
  e = NULL;
  if(zslices != NULL) {
    for(int i=0; zslices[i] != NULL; i++) {
      if((d=new_int_from_string(zslices[i], &e)) != NULL) {
  args.zslices = g_list_append(args.zslices, d);
      }else{
  *err = e;
  return NULL;
      }
    }
  }

  gchar* htext = g_option_context_get_help(ctx, FALSE, NULL);
  g_option_context_free(ctx);

  args.struct_list = NULL;
  if(file_names != NULL) {
    for(int i = 0; file_names[i] != NULL; i++) {
      args.struct_list = g_list_append(args.struct_list, g_file_new_for_commandline_arg(file_names[i]));
    }
  }
  if(args.struct_list == NULL) {
    fprintf(stderr, "ERROR: you MUST give at least one grid to process!\n");
    errored=1;
  }

  if(errored){
    printf("%s", htext);
    printf("\n\n**For version and compilation information, run with --version***");
    *err = g_error_new(GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, 7, "\n");
    return NULL;
  }
  if(print_version){
    program_print_version(stdout);
    libdotcode_print_version(stdout);
    printf("autotools info:\n\tProject: %s\n\tVersion: %s\n", PACKAGE_NAME, VERSION);
    printf("Platform information:\n\tSize of int=%d double=%d\n\tEndianness: %s\n", SIZEOF_INT, SIZEOF_DOUBLE, 
#ifdef WORDS_BIGENDIAN
     "big"
#else
     "little"
#endif
     );
    *err = g_error_new(GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, 7, "\n");
    return NULL;
  }
  if(errored){
    return NULL;
  }
  return &args;
}

Here is the caller graph for this function:

void program_print_version ( FILE *  f)

Variable Documentation

struct args args
Initial value:
 {
  .struct_list = NULL,
  .xslices = NULL,
  .yslices = NULL,
  .zslices = NULL,
}

Definition at line 42 of file get_vhartree_slice_args.c.

Referenced by process_args().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines