gimme-alpha 0.1

process-average-efield-args.c

Go to the documentation of this file.
00001 /*
00002 ** process-average-efield-args.c
00003 ** 
00004 ** Made by (Johnny Q. Hacker)
00005 ** Login   <solarion@borkborkbork>
00006 
00007     Copyright (C) 2009 Joseph Pingenot
00008 
00009     This program is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Affero General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Affero General Public License for more details.
00018 
00019     You should have received a copy of the GNU Affero General Public License
00020     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 ** 
00023 ** Started on  Fri Jul 17 16:02:34 2009 Johnny Q. Hacker
00024 ** Last update Sun May 12 01:17:25 2002 Speed Blue
00025 */
00026 
00027 #include <glib.h>
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <gio/gio.h>
00031 #include <gimmeprogs/argdefaults.h>
00032 #include <gimmeprogs/process-average-efield-args.h>
00033 
00034 extern void program_print_version(FILE* f);
00035 extern void libpostproccalx_print_version(FILE* f);
00036 extern void libnextnano_print_version(FILE* f);
00037 extern void libmodeling_print_version(FILE* f);
00038 extern void libcommon_print_version(FILE* f);
00039 
00040 void do_print_version() {
00041   program_print_version(stdout);
00042   libpostproccalx_print_version(stdout);
00043   libnextnano_print_version(stdout);
00044   libmodeling_print_version(stdout);
00045   libcommon_print_version(stdout);
00046 }
00047 
00048 /*Should be threadsafe here; we don't need multiple threads processing args!*/
00049 static struct args processed_args = {.base_dirs=NULL, .no_print_integration_error=0, .request_integration_abs_error=REQUESTED_QAG_PRECISION_ABSOLUTE, .request_integration_rel_error=REQUESTED_QAG_PRECISION_RELATIVE};
00050 
00051 struct args* process_args(int argc, char* argv[]) {
00052   gboolean print_version = FALSE;
00053   int errored=0;
00054   char **base_dir_names = NULL;
00055   GOptionEntry options[] = {
00056     { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &base_dir_names, "", NULL },
00057     { "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 },
00058     { "integration-abs-error", 'R', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.request_integration_abs_error), "Requested absolute integration error", NULL}, 
00059     { "integration-rel-error", 'r', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.request_integration_rel_error), "Requested relative integration error", NULL}, 
00060     { "version", 'v', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &print_version, "Print version information about this program", NULL },
00061     { NULL }
00062   };
00063   GOptionContext *ctx;
00064   ctx = g_option_context_new("- computes the expectation value of the electric field in a nanostructure for the ground state");
00065 
00066   g_option_context_add_main_entries(ctx, options, "Options");
00067   
00068   g_option_context_parse(ctx, &argc, &argv, NULL);
00069 
00070   if(print_version){
00071     do_print_version();
00072     return NULL;
00073   }
00074   
00075   gchar* htext = g_option_context_get_help(ctx, FALSE, NULL);
00076   
00077   g_option_context_free(ctx);
00078 
00079   /*Check to make sure what we want is there.*/
00080   GFile *bn;
00081   if(base_dir_names != NULL) {
00082     for(int i = 0; base_dir_names[i] != NULL; i++) {
00083       bn = g_file_new_for_commandline_arg(base_dir_names[i]);
00084       processed_args.base_dirs = g_list_append(processed_args.base_dirs, bn);
00085     }
00086   }
00087   if(processed_args.base_dirs == NULL) {
00088     fprintf(stderr, "ERROR: you MUST give at least one base directory\n");
00089     errored=1;
00090   }
00091 
00092   if(errored){
00093     int errored=0;
00094     printf("%s", htext);
00095     printf("**Run with --version for version and compilation information**\n");
00096     return NULL;
00097   }
00098 
00099   return &processed_args;
00100 }
 All Classes Files Functions Variables Enumerations Enumerator Defines