|
gimme-alpha 0.1
|
#include <stdio.h>#include <glib.h>#include <gio/gio.h>#include <stdlib.h>#include <math.h>#include <gimmeprogs/process-gimme-density-args.h>#include <libnextnano/read_nextnano_inputfile.h>#include <libnextnano/read_nextnano_density.h>#include <gimmeprogs/argdefaults.h>#include <libcommon/density.h>
Include dependency graph for gimme-density.c:Go to the source code of this file.
Classes | |
| struct | integrand_range |
Functions | |
| static gint | coordinate_density_sorter (gconstpointer a, gconstpointer b) |
| static gint | approx_coordinate_density_sorter (gconstpointer a, gconstpointer b) |
| int | main (int argc, char *argv[]) |
| static gint approx_coordinate_density_sorter | ( | gconstpointer | a, |
| gconstpointer | b | ||
| ) | [static] |
Definition at line 57 of file gimme-density.c.
References CLOSE_ENOUGH.
Referenced by main().
{
double *c;
double *d;
if((c=g_hash_table_lookup((GHashTable*)a, "x")) == NULL) {
if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) return 0;
return -1;
}else if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) {
return 1;
}
//fprintf(stderr, "got x values c=%g(%p) and d=%g(%p) (a=%p,b=%p)\n", *c, c, *d, d, a, b);
if(fabs(*c - *d) < fabs(CLOSE_ENOUGH*(*c))) return 0;
if(*c < *d) return -1;
if(*c > *d) return 1;
return 0;
}
Here is the caller graph for this function:| static gint coordinate_density_sorter | ( | gconstpointer | a, |
| gconstpointer | b | ||
| ) | [static] |
Definition at line 42 of file gimme-density.c.
{
double *c;
double *d;
if((c=g_hash_table_lookup((GHashTable*)a, "x")) == NULL) {
if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) return 0;
return -1;
}else if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) {
return 1;
}
if(*c < *d) return -1;
if(*c > *d) return 1;
return 0;
}
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 73 of file gimme-density.c.
References approx_coordinate_density_sorter(), gimme_density_args::base_dir, gimme_density_args::dir, get_density_within_range(), gimme_density_args::material, process_gimme_density_args(), read_nextnano_dbfile(), read_nextnano_density_el(), read_nextnano_inputfile_stringy(), density_point::rho, unlikely, density_point::x, gimme_density_args::xmax, integrand_range::xmax, gimme_density_args::xmin, and integrand_range::xmin.
{
g_type_init();
GError *err = NULL;
struct gimme_density_args* arg = process_gimme_density_args(argc, argv);
if(arg == NULL) exit(2);
GList *l = NULL;
struct integrand_range *s;
if(arg->material != NULL) {
printf("MATERIAL-SPECIFIED RANGES NOT IMPLEMENTED YET\n");
exit(1);
}else{
s = (struct integrand_range*)malloc(sizeof(struct integrand_range));
s->xmin = arg->xmin;
s->xmax = arg->xmax;
l = g_list_append(l, s);
}
/*Read in the density information*/
//printf("Got xmin=%g xmax=%g\n", ((struct integrand_range*)(l->data))->xmin, ((struct integrand_range*)(l->data))->xmax);
GFile *keywords = g_file_get_child(arg->base_dir, "keywords.in");
GFile *database = g_file_get_child(arg->base_dir, "database.in");
GFileInputStream *db_istream = g_file_read(database, NULL, &err);
if(err != NULL) {
fprintf(stderr, "Got error opening database file %s: %s\n", arg->dir, err->message);
exit(1);
}
GHashTable *db = read_nextnano_dbfile(G_INPUT_STREAM(db_istream), &err);
if(err != NULL) {
fprintf(stderr, "Got error reading database file %s: %s\n", arg->dir, err->message);
exit(1);
}
GFile *input_file = g_file_get_child(arg->base_dir, "input_file1.in");
GFileInputStream *input_istream = g_file_read(input_file, NULL, &err);
if(err != NULL) {
fprintf(stderr, "Got error opening input file %s: %s\n", arg->dir, err->message);
exit(1);
}
GHashTable *ifile_hash = read_nextnano_inputfile_stringy(G_INPUT_STREAM(input_istream), &err);
GList *density_func = read_nextnano_density_el(arg->base_dir, ifile_hash);
if(density_func == NULL) {
fprintf(stderr, "ERROR: error reading in the density function.\n");
exit(4);
}
/*Ensure that we're ordered by point*/
density_func = g_list_sort(density_func, approx_coordinate_density_sorter);
int len = g_list_length(density_func);
struct density_point *dp;
if((dp = (struct density_point*)malloc(len*sizeof(struct density_point))) == NULL) {
fprintf(stderr, "ERROR: failed to allocate enough memory to store the density information\n");
exit(5);
}
int i;
GList *density_pt;
double *v;
for(i=0, density_pt=density_func; i<len; i++, density_pt = g_list_next(density_pt)) {
if(unlikely((v = g_hash_table_lookup((GHashTable*)(density_pt->data), "x")) == NULL)) {
fprintf(stderr, "INTERNAL ERROR: a density function point's x coordinate was NULL!\n");
}
dp[i].x = *v;
if(unlikely((v = g_hash_table_lookup((GHashTable*)(density_pt->data), "total")) == NULL)) {
fprintf(stderr, "INTERNAL ERROR: a density function point's total density was NULL!\n");
}
dp[i].rho = *v;
}
/*
printf("#x\trho\n");
for(i=0; i<len; i++) {
printf("%g\t%g\n", dp[i].x, dp[i].rho);
}
printf("GSL:%g\n", get_density_within_range(
*/
printf("%ge11 (cm^-2)\n", get_density_within_range(
((struct integrand_range*)l->data)->xmin,
((struct integrand_range*)l->data)->xmax,
dp,
len, 0));
/*
printf("const interpolation: %g\n", get_density_within_range(
((struct integrand_range*)l->data)->xmin,
((struct integrand_range*)l->data)->xmax,
dp,
len, 1));
printf("summation: %g\n", get_density_within_range(
((struct integrand_range*)l->data)->xmin,
((struct integrand_range*)l->data)->xmax,
dp,
len, 2));
*/
return 0;
}
Here is the call graph for this function: