gimme-alpha 0.1

process-gimme-density-args.c

Go to the documentation of this file.
00001 /*
00002 ** process-integrator-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 ** Started on  Fri Feb 27 16:19:26 2009 Johnny Q. Hacker
00023 ** Last update Sun May 12 01:17:25 2002 Speed Blue
00024 */
00025 
00026 
00027 #include <glib.h>
00028 #include <stdio.h>
00029 #include <gio/gio.h>
00030 #include <gimmeprogs/process-gimme-density-args.h>
00031 #include <gimmeprogs/argdefaults.h>
00032 #include <math.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 gimme_density_args processed_args = {.dir=NULL, .base_dir=NULL, .xmin=NAN, .xmax=NAN, .input_gfile=NULL, .material=NULL};
00050 
00051 struct gimme_density_args* process_gimme_density_args(int argc, char* argv[]) {
00052   gboolean print_version = FALSE;
00053   GOptionEntry options[] = {
00054     { "dir", 'd', 0, G_OPTION_ARG_FILENAME, &(processed_args.dir), "Directory with nextnano output", NULL },
00055     { "material", 'm', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &(processed_args.material), "Calculate the total charge in this region (NOT IMPLEMENTED YET)", NULL },
00056     { "version", 'v', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &print_version, "Print version information about this program", NULL },
00057     { NULL }
00058   };
00059   GOptionEntry deprecated_opts[] = {
00060     { "xmin", 'x', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.xmin), "x coordinate from which to integrate the charge density", NULL },
00061     { "xmax", 'X', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_DOUBLE, &(processed_args.xmax), "x coordinate to which to integrate the charge density", NULL },
00062     { NULL }
00063   };
00064   GOptionContext *ctx;
00065   GOptionGroup *deprecated_group;
00066   
00067   ctx = g_option_context_new("- computes the Rashba spin-orbit parameter from the output of a nextnano well calculation.");
00068   deprecated_group = g_option_group_new("deprecated", ARGDEFAULT_DEPRECATED_GROUP_HELPINFO, "Show help about deprecated options.", NULL, NULL);
00069 
00070   g_option_group_add_entries(deprecated_group, deprecated_opts);
00071 
00072   g_option_context_add_main_entries(ctx, options, "Options");
00073   g_option_context_add_group(ctx, deprecated_group);
00074 
00075   g_option_context_parse(ctx, &argc, &argv, NULL);
00076   
00077 
00078   if(print_version){
00079     do_print_version();
00080     return NULL;
00081   }
00082 
00083   gchar* htext = g_option_context_get_help(ctx, FALSE, NULL);
00084 
00085   int errored=0;
00086   if(((isnan(processed_args.xmin)  || isnan(processed_args.xmax))) && (processed_args.material == NULL)) {
00087     fprintf(stderr, "ERROR: You MUST specify either --material or --xmin and --xmax!\n");
00088     errored=1;
00089   }
00090   if((!((isnan(processed_args.xmin)  || isnan(processed_args.xmax)))) && (processed_args.material != NULL)) {
00091     fprintf(stderr, "ERROR: You MAY ONLY specify either --material or --xmin and --xmax, not both!\n");
00092     errored=1;
00093   }
00094 
00095   g_option_context_free(ctx);
00096 
00097   if(errored){
00098     int errored=0;
00099     printf("%s", htext);
00100     printf("**Run with --version for version and compilation information**\n");
00101     return NULL;
00102   }
00103 
00104   /*Check to make sure what we want is there.*/
00105   processed_args.base_dir = g_file_new_for_commandline_arg(processed_args.dir);
00106   /*
00107   if(processed_args.base_dir != NULL)
00108     fprintf(stderr, "base_dir OK\n");
00109   else
00110     fprintf(stderr, "base_dir NULL!!\n");
00111   */
00112   return &processed_args;
00113 }
 All Classes Files Functions Variables Enumerations Enumerator Defines