funkalicious 0.1

matdb.h File Reference

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

Go to the source code of this file.

Classes

struct  matdb_material
struct  matdb_bowing
struct  matdb

Functions

void print_matdb (const struct matdb *mdb)
void destroy_material_gpointer (gpointer data)
void destroy_bowing_gpointer (gpointer data)
void destroy_material (struct matdb_material *mat)
void destroy_bowing (struct matdb_bowing *bow)
void insert_external_material (struct matdb *matdb, const char *matname)
double get_property (const struct matdb *matdb, const char *ppt, const char *matstring, int *err)
double get_property1 (const struct matdb *matdb, const char *ppt, const char *mat, int *err)
double get_property2 (const struct matdb *matdb, const char *ppt, const char *mat, const char *mat2, double x, int *err)
double get_bowing (const struct matdb *matdb, const char *ppt, const char *mat1, const char *mat2, int *err)
GHashTable * get_material (const struct matdb *matdb, const char *mat1, const char *mat2, double x)

Function Documentation

void destroy_bowing ( struct matdb_bowing bow)

Definition at line 68 of file matdb.c.

References matdb_bowing::from, matdb_bowing::properties, and matdb_bowing::to.

Referenced by destroy_bowing_gpointer().

                                              {
#ifdef DEBUG
  fprintf(stderr, "destroy_bowing\n");
#endif
  g_string_free(bow->from, TRUE);
  g_string_free(bow->to, TRUE);
  g_hash_table_unref(bow->properties);
  free(bow);
}

Here is the caller graph for this function:

void destroy_bowing_gpointer ( gpointer  data)

Definition at line 57 of file matdb.c.

References destroy_bowing().

Referenced by read_matdb_dotcode(), and read_matdb_dotcode_gio().

                                            {
  destroy_bowing((struct matdb_bowing *)data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void destroy_material ( struct matdb_material mat)

Definition at line 60 of file matdb.c.

References matdb_material::name, and matdb_material::properties.

Referenced by destroy_material_gpointer().

                                                  {
#ifdef DEBUG
  fprintf(stderr, "destroy_material\n");
#endif
  g_string_free(mat->name, TRUE);
  g_hash_table_unref(mat->properties);
  free(mat);
}

Here is the caller graph for this function:

void destroy_material_gpointer ( gpointer  data)

Definition at line 54 of file matdb.c.

References destroy_material().

Referenced by read_matdb_dotcode(), and read_matdb_dotcode_gio().

                                              {
  destroy_material((struct matdb_material *)data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double get_bowing ( const struct matdb matdb,
const char *  ppt,
const char *  mat1,
const char *  mat2,
int *  err 
)

Definition at line 277 of file matdb.c.

References matdb::bowings.

                                                                                                            {
  void *rv;
  GHashTable *bowings;
  /*Look up and set bowings, if they exist.*/
  GHashTable *ht = (GHashTable*)g_hash_table_lookup(matdb->bowings, mat1);
  if(ht != NULL) {
    rv = g_hash_table_lookup(ht, mat2);
    if(rv != NULL) {
      bowings = ((struct matdb_bowing*)rv)->properties;
    }else{
      *err = 1;
      return nan("NaN");
    }
  }else{
    *err = 2;
    return nan("NaN");
  }
  double* bow;
  if((bow = (double*)g_hash_table_lookup(bowings, ppt)) == NULL) {
    *err = 3;
    return nan("NaN");
  }
  *err = 0;
  return *bow;
}
GHashTable* get_material ( const struct matdb matdb,
const char *  mat1,
const char *  mat2,
double  x 
)

Definition at line 124 of file matdb.c.

References foreach_datum::bowings, matdb::bowings, clone_each_property(), e, foreach_datum::mat1, foreach_datum::mat2, foreach_datum::mat2_ppts, matdb::materials, foreach_datum::new_table, and foreach_datum::x.

                                                                                                  {
  if((x < 0) || (x>1)) {
    fprintf(stderr, "matdb::get_material: material %s(%f)%s doesn't exist: x not in range [0, 1]\n", mat1, x, mat2);
    return NULL;
  }
  if(((!(fabs(x-1.0)) < 1e-8) && (mat2 == NULL))){
    fprintf(stderr, "matdb::get_material: material %s(%f)%s doesn't exist: x!=1 and mat2 is NULL\n", mat1, x, mat2);
    return NULL;
  }
  struct foreach_datum fd;
  void* rv;
  rv = g_hash_table_lookup(matdb->materials, mat1);
  GHashTable *ppts1 = NULL;
  if(rv == NULL) {
    fprintf(stderr, "matdb::get_material: unable to find material %s in materials database!\n", mat1);
    return NULL;
  } else {
    ppts1 = ((struct matdb_material*)rv)->properties;
  }
  if(mat2 == NULL) {
    fd.mat2_ppts = NULL;
  } else {
    rv = g_hash_table_lookup(matdb->materials, mat2);
    if(rv == NULL) {
      fprintf(stderr, "matdb::get_material: unable to find material %s in materials database!\n", mat2);
      return NULL;
    }
    fd.mat2_ppts = ((struct matdb_material*)rv)->properties;
  }
  fd.new_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
  /*We cast away the const-ness; we need to store these in a struct.*/
  fd.mat1 = (char*)mat1;
  fd.mat2 = (char*)mat2;
  fd.x = x;
  rv = NULL;
  /*Look up and set bowings, if they exist.*/
  if(mat2 != NULL) {
    GHashTable *ht = (GHashTable*)g_hash_table_lookup(matdb->bowings, mat1);
    if(ht != NULL) {
      rv = g_hash_table_lookup(ht, mat2);
      if(rv != NULL) {
  fd.bowings = ((struct matdb_bowing*)rv)->properties;
      }else{
  fd.bowings = NULL;
      }
    }else{
      fd.bowings = NULL;
    }
  }else{
    fd.bowings = NULL;
  }
  g_hash_table_foreach(ppts1, clone_each_property, &fd);
  /*Everything else is someone else's pointers, so we don't have to free anything.*/
  return fd.new_table;
}

Here is the call graph for this function:

double get_property ( const struct matdb matdb,
const char *  ppt,
const char *  matstring,
int *  err 
)

Definition at line 305 of file matdb.c.

References get_property1().

Referenced by dotcode_grid1_get_property_at_site(), dotcode_grid1_get_property_cache(), and dotcode_grid1_get_property_grid().

                                                                                                 {
  return get_property1(matdb, ppt, matstring, err);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double get_property1 ( const struct matdb matdb,
const char *  ppt,
const char *  mat,
int *  err 
)

Definition at line 180 of file matdb.c.

References matdb::materials.

Referenced by get_property().

                                                                                            {
  void* rv;
  GHashTable *ppts1;
  rv = g_hash_table_lookup(matdb->materials, mat);
  if(rv == NULL) {
    fprintf(stderr, "matdb::get_material: unable to find material %s in materials database!\n", mat);
    *err = 1;
    return nan("NaN");
  } else {
    ppts1 = ((struct matdb_material*)rv)->properties;
  }
  rv = g_hash_table_lookup(ppts1, ppt);
  if(rv == NULL) {
    fprintf(stderr, "matdb.c::get_property2: unable to find property %s in material %s\n", ppt, mat);
    *err = 4;
    return nan("NaN");
  }
  *err = 0;
  return *(double*)rv;
}

Here is the caller graph for this function:

double get_property2 ( const struct matdb matdb,
const char *  ppt,
const char *  mat,
const char *  mat2,
double  x,
int *  err 
)

Definition at line 200 of file matdb.c.

References matdb::bowings, interpolate_with_bowing(), interpolate_without_bowing(), and matdb::materials.

                                                                                                                        {
  if((x < 0) || (x>0) || ((x != 1.0) && (mat2 == NULL))){
    fprintf(stderr, "matdb::get_material: material %s(%e)%s doesn't exist: x not in range [0, 1], or x==1 and mat2 is NULL\n", mat1, x, mat2);
    *err = 1;
    return nan("NaN");
  }
  void* rv;
  rv = g_hash_table_lookup(matdb->materials, mat1);
  GHashTable *ppts1 = NULL;
  if(rv == NULL) {
    fprintf(stderr, "matdb::get_material: unable to find material %s in materials database!\n", mat1);
    *err = 2;
    return nan("NaN");
  } else {
    ppts1 = ((struct matdb_material*)rv)->properties;
  }
  GHashTable *ppts2;
  if(mat2 == NULL) {
    ppts2 = NULL;
  } else {
    rv = g_hash_table_lookup(matdb->materials, mat2);
    if(rv == NULL) {
      fprintf(stderr, "matdb::get_material: unable to find material %s in materials database!\n", mat2);
      *err = 3;
      return nan("NaN");
    }
    ppts2 = ((struct matdb_material*)rv)->properties;
  }
  rv = NULL;
  GHashTable *bowings;
  /*Look up and set bowings, if they exist.*/
  if(mat2 != NULL) {
    GHashTable *ht = (GHashTable*)g_hash_table_lookup(matdb->bowings, mat1);
    if(ht != NULL) {
      rv = g_hash_table_lookup(ht, mat2);
      if(rv != NULL) {
  bowings = ((struct matdb_bowing*)rv)->properties;
      }else{
  bowings = NULL;
      }
    }else{
      bowings = NULL;
    }
  }else{
    bowings=NULL;
  }
  rv = g_hash_table_lookup(ppts1, ppt);
  if(rv == NULL) {
    fprintf(stderr, "matdb.c::get_property2: unable to find property %s in material %s\n", ppt, mat1);
    *err = 4;
    return nan("NaN");
  }
  double* val1 = (double*)rv;
  double* val2;
  double* bow;
  double result;
  if(ppts2 != NULL) {
    val2 = (double*)g_hash_table_lookup(ppts2, ppt);
    if(val2 == NULL) {
      fprintf(stderr, "matdb.c::clone_each_property: WARNING material %s in material %s is not set in %s; skipping for their alloy.\n", ppt, mat1, mat2);
      *err = 5;
      return nan("NaN");
    }else{
      if((bow = (double*)g_hash_table_lookup(bowings, ppt)) == NULL) {
  result = interpolate_without_bowing(*val1, *val2, x);
      }else{
  result = interpolate_with_bowing(*val1, *val2, *bow, x);
      }
    }
  } else {
    val2=NULL;
    result = *val1;
  }
  /*Everything is someone else's pointers, so we don't have to free anything.*/
  *err = 0;
  return result;
}

Here is the call graph for this function:

void insert_external_material ( struct matdb matdb,
const char *  matname 
)

Definition at line 310 of file matdb.c.

References matdb::materials, matdb_material::name, and matdb_material::properties.

                                                                        {
  struct matdb_material* mat = (struct matdb_material*)malloc(sizeof(struct matdb_material));
  /*Create an empty hash table for the fake material.*/
  mat->name = g_string_new(matname);
  GString* s = g_string_new(matname);
  mat->properties = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
  g_hash_table_insert(matdb->materials, s->str, mat);
  g_string_free(s, FALSE);
}
void print_matdb ( const struct matdb mdb)

Definition at line 48 of file matdb.c.

References matdb::bowings, matdb::materials, print_bowing(), and print_material().

                                          {
  fprintf(stderr, "matdb:\n");
  g_hash_table_foreach(mdb->materials, &print_material, NULL);
  g_hash_table_foreach(mdb->bowings, &print_bowing, NULL);
}

Here is the call graph for this function:

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines