|
gimme-alpha 0.1
|
#include <unistd.h>#include <stdio.h>#include <glib.h>#include <gio/gio.h>#include <math.h>#include <stdlib.h>#include <libnextnano/read_nextnano_bandstructure.h>#include <libcommon/textfile_common.h>#include <libcommon/gcc_hints.h>
Include dependency graph for read_nextnano_bandstructure.c:Go to the source code of this file.
Defines | |
| #define | CLOSE_ENOUGH 1e-8 |
Functions | |
| static gint | coordinate_density_sorter (gconstpointer a, gconstpointer b) |
| static gint | approx_coordinate_density_sorter (gconstpointer a, gconstpointer b) |
| double * | read_nextnano_bandstructure_file (enum bandstructure_file f, GFile *base_dir, GHashTable *infile, GError **err, double **x, int *N) |
| #define CLOSE_ENOUGH 1e-8 |
Definition at line 21 of file read_nextnano_bandstructure.c.
Referenced by approx_coordinate_density_sorter().
| static gint approx_coordinate_density_sorter | ( | gconstpointer | a, |
| gconstpointer | b | ||
| ) | [static] |
Definition at line 38 of file read_nextnano_bandstructure.c.
References CLOSE_ENOUGH.
Referenced by read_nextnano_bandstructure_file().
{
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 24 of file read_nextnano_bandstructure.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;
}
| double* read_nextnano_bandstructure_file | ( | enum bandstructure_file | f, |
| GFile * | base_dir, | ||
| GHashTable * | infile, | ||
| GError ** | err, | ||
| double ** | x, | ||
| int * | N | ||
| ) |
Definition at line 54 of file read_nextnano_bandstructure.c.
References approx_coordinate_density_sorter(), CB_FILE, CB_L_FILE, CB_X_FILE, DOUBLE_TYPE, HH_FILE, LH_FILE, POTENTIAL_FILE, read_titled_whitespaced_data(), SO_FILE, and unlikely.
Referenced by main().
{
gchar* filename;
switch (f) {
case CB_FILE: filename = "cb1D_001.dat"; break;
case CB_L_FILE: filename = "cb1D_002.dat"; break;
case CB_X_FILE: filename = "cb1D_003.dat"; break;
case HH_FILE: filename = "vb1D_001.dat"; break;
case LH_FILE: filename = "vb1D_002.dat"; break;
case SO_FILE: filename = "vb1D_003.dat"; break;
case POTENTIAL_FILE: filename = "potential1D.dat"; break;
default:
fprintf(stderr, "ERROR in read_nextnano_bandstructure_file: unknown band type %d\n", f);
return NULL;
}
GList *chunk;
GHashTable *kv_set;
GList *values;
chunk = g_hash_table_lookup(infile, "output-bandstructure");
g_assert(chunk != NULL);
kv_set = g_list_first(chunk)->data;
g_assert(kv_set != NULL);
values = g_list_first(g_hash_table_lookup(kv_set, "destination-directory"));
GFile *bandstructure_dir = g_file_get_child(base_dir, values->data);
GFile *band_file = g_file_get_child(bandstructure_dir, filename);
GFileInputStream *istream = g_file_read(band_file, NULL, err);
if((*err) != NULL) {
fprintf(stderr, "Error: unable to open potential file.\n");
return NULL;
}
GList *titles = g_list_append(NULL, "x");
titles = g_list_append(titles, "energy");
GList *result = read_titled_whitespaced_data((GInputStream*)istream, err, &titles, '!', DOUBLE_TYPE);
g_input_stream_close((GInputStream*)istream, NULL, err);
/*Now allocate and move the list info into a band structure file.*/
double *data;
*N = g_list_length(result);
if(unlikely((data = (double*)malloc((*N)*sizeof(double))) == NULL)) {
fprintf(stderr, "ERROR in read_nextnano_bandstructure_file: failed to allocate storage for data\n");
return NULL;
}
if(unlikely(((*x) = (double*)malloc((*N)*sizeof(double))) == NULL)) {
fprintf(stderr, "ERROR in read_nextnano_bandstructure_file: failed to allocate storage for data\n");
free(data);
return NULL;
}
/*sort the data by coordinate*/
result = g_list_sort(result, approx_coordinate_density_sorter);
GList* point;
double *v;
int i;
for(i=0, point=result; i<(*N); i++, point = g_list_next(point)) {
if(unlikely((v = g_hash_table_lookup((GHashTable*)(point->data), "x")) == NULL)) {
fprintf(stderr, "INTERNAL ERROR: a density function point's x coordinate was NULL!\n");
}
(*x)[i] = *v;
if(unlikely((v = g_hash_table_lookup((GHashTable*)(point->data), "energy")) == NULL)) {
fprintf(stderr, "INTERNAL ERROR: a density function point's total density was NULL!\n");
}
data[i] = *v;
}
return data;
}
Here is the call graph for this function:
Here is the caller graph for this function: