gimme-alpha 0.1

read_nextnano_bandstructure.h File Reference

#include <glib-2.0/glib.h>
#include <gio/gio.h>
#include <libcommon/gimme_alpha_types.h>
Include dependency graph for read_nextnano_bandstructure.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  bandstructure_file {
  CB_FILE, CB_L_FILE, CB_X_FILE, HH_FILE,
  LH_FILE, SO_FILE, POTENTIAL_FILE
}

Functions

double * read_nextnano_bandstructure_file (enum bandstructure_file f, GFile *base_dir, GHashTable *infile, GError **err, double **x, int *N)

Enumeration Type Documentation

Enumerator:
CB_FILE 
CB_L_FILE 
CB_X_FILE 
HH_FILE 
LH_FILE 
SO_FILE 
POTENTIAL_FILE 

Definition at line 23 of file read_nextnano_bandstructure.h.


Function Documentation

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:

 All Classes Files Functions Variables Enumerations Enumerator Defines