|
funkalicious 0.1
|
#include <stdlib.h>#include <errno.h>#include <string.h>#include <stdio.h>#include <glib-2.0/glib.h>#include <gio/gio.h>#include "material_property_args.h"#include "config.h"
Include dependency graph for material_property_args.c:Go to the source code of this file.
Defines | |
| #define | MATERIAL_PROPERTY_ARGS_DOMAIN 1026 |
Functions | |
| void | program_print_version (FILE *f) |
| void | libdotcode_print_version (FILE *f) |
| int * | vector_from_ints (char **ints, GError **err) |
| double * | new_double_from_string (const char *s, GError **err) |
| int * | new_int_from_string (const char *s, GError **err) |
| struct args * | process_args (int argc, char **argv, GError **err) |
Variables | |
| struct args | args |
| #define MATERIAL_PROPERTY_ARGS_DOMAIN 1026 |
Definition at line 39 of file material_property_args.c.
Referenced by new_double_from_string(), new_int_from_string(), process_args(), and vector_from_ints().
| void libdotcode_print_version | ( | FILE * | f | ) |
| double* new_double_from_string | ( | const char * | s, |
| GError ** | err | ||
| ) |
Definition at line 91 of file material_property_args.c.
References MATERIAL_PROPERTY_ARGS_DOMAIN.
{
double* d = (double*)malloc(sizeof(double));
if(d == NULL) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 1, "material_property_args_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(MATERIAL_PROPERTY_ARGS_DOMAIN, 2, "material_property_args_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 108 of file material_property_args.c.
References MATERIAL_PROPERTY_ARGS_DOMAIN.
{
int* d = (int*)malloc(sizeof(int));
if(d == NULL) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 1, "material_property_args_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(MATERIAL_PROPERTY_ARGS_DOMAIN, 2, "material_property_args_args.c::new_int_from_string: Error occurred converting string (%s) to int: %s", s, strerror(errno));
free(d);
return NULL;
}
return d;
}
| struct args* process_args | ( | int | argc, |
| char ** | argv, | ||
| GError ** | err | ||
| ) | [read] |
Processes the arguments to process_args
| argc | argc from main |
| argv | argv from main |
Definition at line 125 of file material_property_args.c.
References args, e, args::file, libdotcode_print_version(), MATERIAL_PROPERTY_ARGS_DOMAIN, new_int_from_string(), PACKAGE_NAME, args::points, print_version(), program_print_version(), args::property, SIZEOF_DOUBLE, SIZEOF_INT, vector_from_ints(), VERSION, args::xslices, args::yslices, and args::zslices.
{
int errored = 0;
gchar **file_names = NULL;
gboolean print_version = FALSE;
gchar** xslices = NULL;
gchar** yslices = NULL;
gchar** zslices = NULL;
gchar** points = 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 },
{ "parameter", 'p', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &(args.property), "Property to be looked up across the structure (point is \"x,y,z\", in gridsites, e.g. -p=3,7,15)", NULL },
{ "at", 'a', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(points), "point at which to output the specified parameter", 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 map of the property across the slice of the structure", 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 map of the property across the slice of the structure", 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 map of the property across the slice of the structure", NULL},
{NULL}
};
GOptionContext *ctx;
ctx = g_option_context_new("- output a parameter at given points in the structure");
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;
}
}
}
args.points = NULL;
e = NULL;
int* vec;
if(points != NULL) {
for(int i=0; points[i] != NULL; i++) {
if((vec=vector_from_ints(g_strsplit(points[i], ",", -1), &e)) != NULL) {
args.points = g_list_append(args.points, vec);
}else{
*err = e;
return NULL;
}
}
}
gchar* htext = g_option_context_get_help(ctx, FALSE, NULL);
g_option_context_free(ctx);
args.file = NULL;
if(file_names != NULL) {
if(file_names[1] != NULL) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 101, "more than one grid to process was given!");
errored=1;
}
args.file = g_file_new_for_commandline_arg(file_names[0]);
}
if(args.file == NULL) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 101, "You must give a grid to process!");
errored=1;
}
if(args.property == NULL) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 102, "No property was given!");
errored =1;
}
if(errored){
printf("%s", htext);
printf("\n\n**For version and compilation information, run with --version***");
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 7, "\n");
}
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
);
if(*err == NULL) *err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 7, "\n");
return NULL;
}
if(errored){
return NULL;
}
return &args;
}
Here is the call graph for this function:| void program_print_version | ( | FILE * | f | ) |
| int* vector_from_ints | ( | char ** | ints, |
| GError ** | err | ||
| ) |
Definition at line 55 of file material_property_args.c.
References MATERIAL_PROPERTY_ARGS_DOMAIN.
Referenced by process_args().
{
/*This little loop looks useless, but it counts the number of
entries (not the termination condition)*/
int i=0;
for(i=0; ints[i] != NULL; i++);
/*And then check the number of entries*/
if(i != 3) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 100, "Too %s vector components given (%d; expected %d)", (i<3)?"few":"many", i, 3);
g_strfreev(ints);
return NULL;
}
int* vec = (int*)malloc(3*sizeof(int));
if(vec == NULL) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 100, "Failed to allocated storage for 3 ints (the vector)");
g_strfreev(ints);
return NULL;
}
for(i=0; ints[i] != NULL; i++) {
int val=-1;
val = atoi(ints[i]);
#ifdef DEBUG1
fprintf(stderr, "ints[%d]=(%s) val=%d", i, ints[i], val);
#endif
if(val < 0) {
*err = g_error_new(MATERIAL_PROPERTY_ARGS_DOMAIN, 100, "Got an invalid (negative) vector component: %d", val);
free(vec);
g_strfreev(ints);
return NULL;
}
vec[i] = val;
}
g_strfreev(ints);
return vec;
}
Here is the caller graph for this function: {
.file=NULL,
.property=NULL,
.points = NULL,
.xslices = NULL,
.yslices = NULL,
.zslices = NULL,
.check_cached=TRUE
}
Definition at line 41 of file material_property_args.c.