|
k-dot-p 0.1
|
Classes | |
| struct | generic_structure |
| struct | foreach_datum |
| struct | matdb_material |
| struct | matdb_bowing |
| struct | matdb |
| struct | index_struct |
| class | material |
Enumerations | |
| enum | material_property |
Functions | |
| static bool | material_is_same (material **a, material **b) |
| char * | material_to_string (libmodelxx::structure::material **value) |
| char * | double_to_string (double *value) |
| GError * | generic_structure_save (struct generic_structure *s, const char *filename) |
| GError * | generic_structure_restore (struct generic_structure **s, const char *filename) |
| GError * | generic_structure_dump (struct generic_structure *s, GFile *file) |
| struct generic_structure * | generic_structure_new (struct grid::grid *g) |
| GError * | generic_structure_free (struct generic_structure *s) |
| void | generic_structure_free_potential (struct generic_structure *s) |
| static void | destroy_string (gpointer data) |
| static void | destroy_double (gpointer data) |
| static void | destroy_inner_bowhash (gpointer data) |
| int | insert_into_matdb (struct matdb *mdb, struct matdb_material **mat, struct matdb_bowing **bow) |
| static void | prettify_line (char *line) |
| struct matdb * | read_matdb_dotcode (const GString *name, int *err) |
| static void | print_property (gpointer key, gpointer value, gpointer user_data) |
| static void | print_inner_bowing (gpointer key, gpointer value, gpointer user_data) |
| static void | print_material (gpointer key, gpointer value, gpointer user_data) |
| static void | print_bowing (gpointer key, gpointer value, gpointer user_data) |
| 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) |
| double * | new_double (double d) |
| double | interpolate_with_bowing (double mat1, double mat2, double bow, double x) |
| double | interpolate_without_bowing (double mat1, double mat2, double x) |
| void | clone_each_property (gpointer key, gpointer value, gpointer data) |
| GHashTable * | get_material (const struct matdb *matdb, const char *mat1, const char *mat2, double x) |
| 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 *mat1, 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) |
| void | insert_external_material (struct matdb *matdb, const char *matname) |
| int * | alloc_set_int (int v) |
| static void | index_properties (gpointer key, gpointer value, gpointer data) |
| bool | operator== (const material &m1, const material &m2) |
| bool | operator!= (const material &m1, const material &m2) |
Definition at line 32 of file material.h++.
{
};
| int* kdotp::libmodelxx::structure::alloc_set_int | ( | int | v | ) |
Definition at line 42 of file material.c++.
Referenced by index_properties().
{int* ptr = (int*)malloc(sizeof(int)); *ptr = v; return ptr;}
Here is the caller graph for this function:| void kdotp::libmodelxx::structure::clone_each_property | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | data | ||
| ) |
Definition at line 102 of file matdb.c++.
References kdotp::libmodelxx::structure::foreach_datum::bowings, interpolate_with_bowing(), interpolate_without_bowing(), kdotp::libmodelxx::structure::foreach_datum::mat1, kdotp::libmodelxx::structure::foreach_datum::mat2, kdotp::libmodelxx::structure::foreach_datum::mat2_ppts, new_double(), kdotp::libmodelxx::structure::foreach_datum::new_table, and kdotp::libmodelxx::structure::foreach_datum::x.
Referenced by get_material().
{
char* ppt = (char*)key;
double* val1 = (double*)value;
struct foreach_datum* fd = (struct foreach_datum*)data;
double* val2;
double* bow;
double result;
if(fd->mat2_ppts != NULL) {
if(fd->mat2_ppts == NULL) {
fprintf(stderr, "matdb.c++::clone_each_property: fd->mat2_ppts is NULL\n");
}
val2 = (double*)g_hash_table_lookup(fd->mat2_ppts, 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, fd->mat1, fd->mat2);
return;
}else{
if((fd->bowings == NULL) || ((bow = (double*)g_hash_table_lookup(fd->bowings, ppt)) == NULL)) {
result = interpolate_without_bowing(*val1, *val2, fd->x);
}else{
result = interpolate_with_bowing(*val1, *val2, *bow, fd->x);
}
}
} else {
val2=NULL;
result = *val1;
}
g_hash_table_insert(fd->new_table, g_strdup(ppt), new_double(result));
}
Here is the call graph for this function:
Here is the caller graph for this function:| void kdotp::libmodelxx::structure::destroy_bowing | ( | struct matdb_bowing * | bow | ) |
Definition at line 72 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb_bowing::from, kdotp::libmodelxx::structure::matdb_bowing::properties, and kdotp::libmodelxx::structure::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 kdotp::libmodelxx::structure::destroy_bowing_gpointer | ( | gpointer | data | ) |
Definition at line 61 of file matdb.c++.
References destroy_bowing().
Referenced by read_matdb_dotcode().
{
destroy_bowing((struct matdb_bowing *)data);
}
Here is the call graph for this function:
Here is the caller graph for this function:| static void kdotp::libmodelxx::structure::destroy_double | ( | gpointer | data | ) | [static] |
Definition at line 42 of file matdb-dotcode.c++.
Referenced by read_matdb_dotcode().
{
free((double*)data);
}
Here is the caller graph for this function:| static void kdotp::libmodelxx::structure::destroy_inner_bowhash | ( | gpointer | data | ) | [static] |
Definition at line 45 of file matdb-dotcode.c++.
Referenced by insert_into_matdb().
{
g_hash_table_unref((GHashTable*)data);
}
Here is the caller graph for this function:| void kdotp::libmodelxx::structure::destroy_material | ( | struct matdb_material * | mat | ) |
Definition at line 64 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb_material::name, and kdotp::libmodelxx::structure::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 kdotp::libmodelxx::structure::destroy_material_gpointer | ( | gpointer | data | ) |
Definition at line 58 of file matdb.c++.
References destroy_material().
Referenced by read_matdb_dotcode().
{
destroy_material((struct matdb_material *)data);
}
Here is the call graph for this function:
Here is the caller graph for this function:| static void kdotp::libmodelxx::structure::destroy_string | ( | gpointer | data | ) | [static] |
Definition at line 39 of file matdb-dotcode.c++.
Referenced by insert_into_matdb(), and read_matdb_dotcode().
{
free((char*)data);
}
Here is the caller graph for this function:| char* kdotp::libmodelxx::structure::double_to_string | ( | double * | value | ) |
Definition at line 41 of file generic_structure.c++.
References str.
Referenced by generic_structure_dump().
{
GString *s = g_string_new_len("", 1024);
g_string_printf(s, "%g", *value);
char* str = s->str;
g_string_free(s, FALSE);
return str;
}
Here is the caller graph for this function:| GError * kdotp::libmodelxx::structure::generic_structure_dump | ( | struct generic_structure * | s, |
| GFile * | file | ||
| ) |
Definition at line 67 of file generic_structure.c++.
References kdotp::libmodelxx::grid::grid::dimensions, kdotp::libmodelxx::structure::generic_structure::doping_grid, double_to_string(), kdp::constants::e, kdotp::libmodelxx::structure::generic_structure::g, kdotp::libmodelxx::structure::generic_structure::material_grid, material_is_same(), material_to_string(), kdotp::libmodelxx::structure::generic_structure::potential_grid, and kdotp::libmodelxx::grid::grid::t.
Referenced by main().
{
GError *e = NULL;
GFileOutputStream* gfos = g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &e);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_dump: failed to open file.");
return err;
}
e = grid::dump_indexed_grid<libmodelxx::structure::material*>((GOutputStream*)gfos, s->g->t, s->g->dimensions, s->material_grid, material_is_same, material_to_string);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_dump: failed to dump indexed material grid to file");
return err;
}
e = grid::dump_grid<double>((GOutputStream*)gfos, s->g->t, s->g->dimensions, s->potential_grid, double_to_string);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_dump: failed to dump potential grid to file");
return err;
}
e = grid::dump_grid<double>((GOutputStream*)gfos, s->g->t, s->g->dimensions, s->doping_grid, double_to_string);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_dump: failed to dump doping grid to file");
return err;
}
/*
e = grid::dump_grid<double, 6>((GOutputStream*)gfos, s->g->t, s->g->dimensions, s->strain_grid, double_to_string);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_dump: failed to dump strain grid to file");
return err;
}
*/
g_object_unref(gfos);
return NULL;
}
Here is the call graph for this function:
Here is the caller graph for this function:| GError * kdotp::libmodelxx::structure::generic_structure_free | ( | struct generic_structure * | s | ) |
Destroys a generic structure.
| *s | pointer to the structure to be freed. |
Definition at line 145 of file generic_structure.c++.
References kdotp::libmodelxx::grid::grid::dimensions, kdotp::libmodelxx::structure::generic_structure::doping_grid, kdp::constants::e, kdotp::libmodelxx::structure::generic_structure::g, kdotp::libmodelxx::structure::generic_structure::material_grid, kdotp::libmodelxx::structure::generic_structure::potential_grid, and kdotp::libmodelxx::grid::grid::t.
Referenced by main(), and kdotp::libmodelxx::continuous_structure::postprocess_structure().
{
/*TODO: hash out how to free specific arrays.*/
GError *e=NULL;
e=grid::free_grid_class<libmodelxx::structure::material*>(s->g->t, s->g->dimensions, s->material_grid);
if(e != NULL) return e;
e=grid::free_grid_class<double>(s->g->t, s->g->dimensions, s->potential_grid);
if(e != NULL) return e;
e=grid::free_grid_class<double>(s->g->t, s->g->dimensions, s->doping_grid);
if(e != NULL) return e;
/*
e=grid::free_grid_class<double, 6>(s->g->t, s->g->dimensions, s->strain_grid);
if(e != NULL) return e;
*/
free(s);
return NULL;
}
Here is the caller graph for this function:| void kdotp::libmodelxx::structure::generic_structure_free_potential | ( | struct generic_structure * | s | ) |
Definition at line 162 of file generic_structure.c++.
References kdotp::libmodelxx::grid::grid::dimensions, kdotp::libmodelxx::structure::generic_structure::g, kdotp::libmodelxx::structure::generic_structure::potential_grid, and kdotp::libmodelxx::grid::grid::t.
Referenced by alpha_efield_change_calculation_callback().
{
grid::free_grid_class<double>(s->g->t, s->g->dimensions, s->potential_grid);
s->potential_grid = NULL;
}
Here is the caller graph for this function:| struct generic_structure * kdotp::libmodelxx::structure::generic_structure_new | ( | struct grid::grid * | g | ) | [read] |
Definition at line 110 of file generic_structure.c++.
References kdotp::libmodelxx::structure::generic_structure::doping_grid, kdp::constants::e, g, kdotp::libmodelxx::structure::generic_structure::g, kdotp::libmodelxx::structure::generic_structure::material_grid, and kdotp::libmodelxx::structure::generic_structure::potential_grid.
Referenced by kdotp::libmodelxx::continuous_structure::postprocess_structure().
{
struct generic_structure *s = (struct generic_structure*)malloc(sizeof(struct generic_structure));
if(s == NULL) return NULL;
s->g = g;
GError *e = NULL;
//s->material_grid = grid::set_up_grid<libmodelxx::structure::material>(g, NULL, &e);
s->material_grid = grid::set_up_grid<libmodelxx::structure::material*>(g, NULL, &e);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_new: failed to create new material grid");
//return err;
}
s->potential_grid = grid::set_up_grid<double>(g, 0, &e);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_new: failed to create new potential grid");
//return err;
}
s->doping_grid = grid::set_up_grid<double>(g, 0, &e);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_new: failed to create new doping grid");
//return err;
}
/*
s->strain_grid = grid::set_up_grid<double, 6>(g, 0, &e);
if(e != NULL) {
GError *err = NULL;
g_propagate_prefixed_error(&err, e, "kdotp::libmodelxx::structure::generic_structure.c++::generic_structure_new: failed to create new strain grid");
//return err;
}
*/
return s;
}
Here is the caller graph for this function:| GError * kdotp::libmodelxx::structure::generic_structure_restore | ( | struct generic_structure ** | s, |
| const char * | filename | ||
| ) |
Definition at line 63 of file generic_structure.c++.
References GERROR_DOMAIN_GENERIC_STRUCTURE.
{
return g_error_new(GERROR_DOMAIN_GENERIC_STRUCTURE, 0, "kdotp::libmodelxx::structure::generic_structure::generic_structure_restore: this function is unimplemented.");
}
| GError * kdotp::libmodelxx::structure::generic_structure_save | ( | struct generic_structure * | s, |
| const char * | filename | ||
| ) |
Definition at line 49 of file generic_structure.c++.
References GERROR_DOMAIN_GENERIC_STRUCTURE.
{
/*
hid_t file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
herr_t status;
hsize_t one = 1;
*/
/*Create a one-item space*/
/*
hid_t dspace_id_single = H5Create_simple(1, &one, NULL);
hid_t dset_id_size;
*/
return g_error_new(GERROR_DOMAIN_GENERIC_STRUCTURE, 0, "kdotp::libmodelxx::structure::generic_structure::generic_structure_save: this function is unimplemented.");
}
| double kdotp::libmodelxx::structure::get_bowing | ( | const struct matdb * | matdb, |
| const char * | ppt, | ||
| const char * | mat1, | ||
| const char * | mat2, | ||
| int * | err | ||
| ) |
Definition at line 312 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb::bowings.
{
void *rv;
GHashTable *bowings;
/*Look up and set bowings, if they exist.*/
if(matdb->bowings == NULL) {
fprintf(stderr, "matdb.c++::get_bowing: bowings is NULL\n");
}
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(bowings == NULL) {
fprintf(stderr, "matdb.c++::get_bowing: bowings is NULL\n");
}
if((bow = (double*)g_hash_table_lookup(bowings, ppt)) == NULL) {
*err = 3;
return nan("NaN");
}
*err = 0;
return *bow;
}
| GHashTable * kdotp::libmodelxx::structure::get_material | ( | const struct matdb * | matdb, |
| const char * | mat1, | ||
| const char * | mat2, | ||
| double | x | ||
| ) |
Definition at line 132 of file matdb.c++.
References kdotp::libmodelxx::structure::foreach_datum::bowings, kdotp::libmodelxx::structure::matdb::bowings, clone_each_property(), kdp::constants::e, kdotp::libmodelxx::structure::foreach_datum::mat1, kdotp::libmodelxx::structure::foreach_datum::mat2, kdotp::libmodelxx::structure::foreach_datum::mat2_ppts, kdotp::libmodelxx::structure::matdb::materials, kdotp::libmodelxx::structure::foreach_datum::new_table, and kdotp::libmodelxx::structure::foreach_datum::x.
Referenced by kdotp::libmodelxx::structure::material::material().
{
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;
if(matdb->materials == NULL) {
fprintf(stderr, "matdb.c++::get_material: matdb->materials is NULL\n");
}
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) {
if(matdb->bowings == NULL) {
fprintf(stderr, "matdb.c++::get_material: matdb->bowings is NULL\n");
}
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:
Here is the caller graph for this function:| double kdotp::libmodelxx::structure::get_property1 | ( | const struct matdb * | matdb, |
| const char * | ppt, | ||
| const char * | mat, | ||
| int * | err | ||
| ) |
Definition at line 194 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb::materials.
{
void* rv;
GHashTable *ppts1;
if(matdb->materials == NULL) {
fprintf(stderr, "matdb.c++::get_property1: matdb->materials is NULL\n");
}
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;
}
if(ppts1 == NULL) {
fprintf(stderr, "matdb.c++::get_property1: ppts1 is NULL\n");
}
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;
}
| double kdotp::libmodelxx::structure::get_property2 | ( | const struct matdb * | matdb, |
| const char * | ppt, | ||
| const char * | mat1, | ||
| const char * | mat2, | ||
| double | x, | ||
| int * | err | ||
| ) |
Definition at line 220 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb::bowings, interpolate_with_bowing(), interpolate_without_bowing(), and kdotp::libmodelxx::structure::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;
if(matdb->materials == NULL) {
fprintf(stderr, "matdb.c++::get_property2: matdb->materials is NULL\n");
}
rv = g_hash_table_lookup(matdb->materials, mat1);
GHashTable *ppts1 = NULL;
if(rv == NULL) {
fprintf(stderr, "matdb::get_property2: 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 {
if(matdb->materials == NULL) {
fprintf(stderr, "matdb.c++::get_property2: matdb->materials is NULL\n");
}
rv = g_hash_table_lookup(matdb->materials, mat2);
if(rv == NULL) {
fprintf(stderr, "matdb::get_property2: 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) {
if(matdb->bowings == NULL) {
fprintf(stderr, "matdb.c++::get_property2: matdb->bowings is NULL\n");
}
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;
}
if(ppts1 == NULL) {
fprintf(stderr, "matdb.c++::get_property2: ppts1 is NULL\n");
}
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(bowings == NULL) {
fprintf(stderr, "matdb.c++::get_property2: bowings is NULL\n");
}
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:| static void kdotp::libmodelxx::structure::index_properties | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | data | ||
| ) | [static] |
Indexes the properties of a material (used as a callback in a g_hash_table_foreach call
Definition at line 48 of file material.c++.
References kdotp::libmodelxx::structure::index_struct::a, alloc_set_int(), kdotp::libmodelxx::structure::index_struct::ht, and kdotp::libmodelxx::structure::index_struct::next.
Referenced by kdotp::libmodelxx::structure::material::material().
{
struct index_struct* idxs = (struct index_struct*)data;
idxs->a[idxs->next] = *(double*)value;
g_hash_table_insert(idxs->ht, g_strdup((gchar*)key), alloc_set_int(idxs->next));
(idxs->next)++;
}
Here is the call graph for this function:
Here is the caller graph for this function:| void kdotp::libmodelxx::structure::insert_external_material | ( | struct matdb * | matdb, |
| const char * | matname | ||
| ) |
Definition at line 344 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb::materials, kdotp::libmodelxx::structure::matdb_material::name, and kdotp::libmodelxx::structure::matdb_material::properties.
Referenced by main().
{
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);
}
Here is the caller graph for this function:| int kdotp::libmodelxx::structure::insert_into_matdb | ( | struct matdb * | mdb, |
| struct matdb_material ** | mat, | ||
| struct matdb_bowing ** | bow | ||
| ) |
Definition at line 49 of file matdb-dotcode.c++.
References kdotp::libmodelxx::structure::matdb::bowings, destroy_inner_bowhash(), destroy_string(), and kdotp::libmodelxx::structure::matdb::materials.
Referenced by read_matdb_dotcode().
{
if((*mat) != NULL) {
#ifdef DEBUG
fprintf(stderr, "inserting material %s\n", (*mat)->name->str);
#endif
g_hash_table_insert(mdb->materials, (gpointer)g_strdup((*mat)->name->str), (gpointer)(*mat));
(*mat) = NULL;
}
if((*bow) != NULL) {
#ifdef DEBUG
fprintf(stderr, "inserting bowing %s:%s\n", (*bow)->from->str, (*bow)->to->str);
#endif
/*Inner table*/
GHashTable *it;
if((it=(GHashTable*)g_hash_table_lookup(mdb->bowings, (*bow)->from->str)) == NULL) {
if((it = g_hash_table_new_full(&g_str_hash, &g_str_equal, &destroy_string, &destroy_inner_bowhash)) == NULL) {
(*bow) = NULL;
return 1;
}
g_hash_table_insert(mdb->bowings, (*bow)->from->str, it);
#ifdef DEBUG
fprintf(stderr, "Got new hash table (from=%s)\n", (*bow)->from->str);
#endif
}
g_hash_table_insert(it, (gpointer)g_strdup((*bow)->to->str), (gpointer)(*bow));
(*bow) = NULL;
}
return 0;
}
Here is the call graph for this function:
Here is the caller graph for this function:| double kdotp::libmodelxx::structure::interpolate_with_bowing | ( | double | mat1, |
| double | mat2, | ||
| double | bow, | ||
| double | x | ||
| ) |
Definition at line 94 of file matdb.c++.
Referenced by clone_each_property(), and get_property2().
{
return x*mat1 + (1-x)*mat2 - x*(1-x)*bow;
}
Here is the caller graph for this function:| double kdotp::libmodelxx::structure::interpolate_without_bowing | ( | double | mat1, |
| double | mat2, | ||
| double | x | ||
| ) |
Definition at line 98 of file matdb.c++.
Referenced by clone_each_property(), and get_property2().
{
return x*mat1 + (1-x)*mat2;
}
Here is the caller graph for this function:| static bool kdotp::libmodelxx::structure::material_is_same | ( | material ** | a, |
| material ** | b | ||
| ) | [static] |
Definition at line 33 of file generic_structure.c++.
Referenced by generic_structure_dump().
{
return **a == **b;
}
Here is the caller graph for this function:| char* kdotp::libmodelxx::structure::material_to_string | ( | libmodelxx::structure::material ** | value | ) |
Definition at line 37 of file generic_structure.c++.
Referenced by generic_structure_dump().
{
return (*value)->get_name();
}
Here is the caller graph for this function:| double* kdotp::libmodelxx::structure::new_double | ( | double | d | ) |
Definition at line 82 of file matdb.c++.
Referenced by clone_each_property().
{double* D = (double*)malloc(sizeof(double)); *D = d; return D;}
Here is the caller graph for this function:| bool kdotp::libmodelxx::structure::operator!= | ( | const material & | m1, |
| const material & | m2 | ||
| ) |
Definition at line 132 of file material.c++.
References kdotp::libmodelxx::structure::material::m_x, kdotp::libmodelxx::structure::material::matname1, and kdotp::libmodelxx::structure::material::matname2.
{
if(!(g_strcmp0(m1.matname1, m2.matname1))) return true;
if(!(g_strcmp0(m1.matname2, m2.matname2))) return true;
return m1.m_x != m2.m_x;
}
| bool kdotp::libmodelxx::structure::operator== | ( | const material & | m1, |
| const material & | m2 | ||
| ) |
Definition at line 122 of file material.c++.
References kdotp::libmodelxx::structure::material::m_x, kdotp::libmodelxx::structure::material::matname1, and kdotp::libmodelxx::structure::material::matname2.
{
if(g_strcmp0(m1.matname1, m2.matname1)) return false;
if(g_strcmp0(m1.matname2, m2.matname2)) return false;
return m1.m_x == m2.m_x;
}
| static void kdotp::libmodelxx::structure::prettify_line | ( | char * | line | ) | [static] |
Definition at line 81 of file matdb-dotcode.c++.
Referenced by read_matdb_dotcode().
{
register char *look;
register char *write;
register int in_whitespace;
register int leading_whitespace;
for(look=write=line, in_whitespace=0, leading_whitespace=1; *look != '\0'; look++) {
#ifdef DEBUG_2
fprintf(stderr, " look=%d(%c) write=%d(%c) in_whitespace=%d leading_whitespace=%d: ", (look-line), *look, (write-line), *write, in_whitespace, leading_whitespace);
#endif
if(*look == '#') {
#ifdef DEBUG_2
fprintf(stderr, "comment\n");
#endif
*write = '\0';
break;
}
switch(*look) {
case ' ':
case '\n':
case '\t':
#ifdef DEBUG_2
fprintf(stderr, "whitespace\n");
#endif
if((!leading_whitespace) && (!in_whitespace)) *write++ = '\t';
in_whitespace=1;
break;
default:
#ifdef DEBUG_2
fprintf(stderr, "default\n");
#endif
*write++ = *look;
in_whitespace=leading_whitespace=0;
}
}
*write='\0';
for(look=write=line; *look != '\0'; look++) {
switch(*look) {
case ' ':
case '\n':
case '\t':
if(*(look+1) == '\0') {
*look = '\0';
}
}
}
}
Here is the caller graph for this function:| static void kdotp::libmodelxx::structure::print_bowing | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) | [static] |
Definition at line 47 of file matdb.c++.
References print_inner_bowing().
Referenced by print_matdb().
{
GHashTable *ht = (GHashTable*)value;
g_hash_table_foreach(ht, &print_inner_bowing, key);
}
Here is the call graph for this function:
Here is the caller graph for this function:| static void kdotp::libmodelxx::structure::print_inner_bowing | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) | [static] |
Definition at line 37 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb_bowing::from, print_property(), kdotp::libmodelxx::structure::matdb_bowing::properties, and kdotp::libmodelxx::structure::matdb_bowing::to.
Referenced by print_bowing().
{
struct matdb_bowing *bowing = (struct matdb_bowing*)value;
fprintf(stderr, "\tbowing %s:%s[%s:%s]:\n", bowing->from->str, bowing->to->str, (char*)user_data, (char*)key);
g_hash_table_foreach(bowing->properties, &print_property, NULL);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void kdotp::libmodelxx::structure::print_matdb | ( | const struct matdb * | mdb | ) |
Definition at line 52 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb::bowings, kdotp::libmodelxx::structure::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:| static void kdotp::libmodelxx::structure::print_material | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) | [static] |
Definition at line 42 of file matdb.c++.
References kdotp::libmodelxx::structure::matdb_material::name, print_property(), and kdotp::libmodelxx::structure::matdb_material::properties.
Referenced by print_matdb().
{
struct matdb_material *mat = (struct matdb_material*)value;
fprintf(stderr, "\tmaterial %s(%s):\n", mat->name->str, (char*)key);
g_hash_table_foreach(mat->properties, &print_property, NULL);
}
Here is the call graph for this function:
Here is the caller graph for this function:| static void kdotp::libmodelxx::structure::print_property | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) | [static] |
Definition at line 34 of file matdb.c++.
Referenced by print_inner_bowing(), and print_material().
{
fprintf(stderr, "\t\t%s=%g:\n", (char*)key, *(double*)value);
}
Here is the caller graph for this function:| struct matdb * kdotp::libmodelxx::structure::read_matdb_dotcode | ( | const GString * | name, |
| int * | err | ||
| ) | [read] |
Definition at line 145 of file matdb-dotcode.c++.
References kdotp::libmodelxx::structure::matdb::bowings, destroy_bowing_gpointer(), destroy_double(), destroy_material_gpointer(), destroy_string(), kdotp::libmodelxx::structure::matdb_bowing::from, insert_into_matdb(), kdotp::libmodelxx::structure::matdb::materials, kdotp::libmodelxx::structure::matdb_material::name, and prettify_line().
Referenced by main().
{
#ifdef DEBUG_2
fprintf(stderr, "in read_matdb_dotcode(%s, %d)\n", name->str, *err);
#endif
*err=0;
struct matdb *mdb = (struct matdb*)malloc(sizeof(struct matdb));
if(mdb == NULL) {*err = 1; return NULL;}
double *value;
if((mdb->materials = g_hash_table_new_full(&g_str_hash, &g_str_equal, &destroy_string, &destroy_material_gpointer)) == NULL) {
*err = 1;
free(mdb);
return NULL;
}
if((mdb->bowings = g_hash_table_new_full(&g_str_hash, &g_str_equal, &destroy_string, &destroy_bowing_gpointer)) == NULL) {
*err = 1;
g_hash_table_unref(mdb->materials);
free(mdb);
return NULL;
}
struct matdb_material *mat = NULL;
struct matdb_bowing *bow = NULL;
/*Valid sections:
* 0 (no/global section)
* 1 (material)
* 2 (bow)
*/
int section=0;
size_t n;
char *line;
FILE *infile = fopen(name->str, "r");
if(infile == NULL) {
g_hash_table_unref(mdb->materials);
g_hash_table_unref(mdb->bowings);
free(mdb);
*err=2;
return NULL;
#ifdef DEBUG_2
}else{
fprintf(stderr, "infile=%x\n", (unsigned int)infile);
#endif
}
int val;
while(!feof(infile)) {
#ifdef DEBUG
fprintf(stderr, "mat=%x(%s), bow=%x(%s:%s)\n", (unsigned int)mat, mat?mat->name->str:"", (unsigned int)bow, bow?bow->from->str:"", bow?bow->to->str:"");
#endif
line=NULL;
if((val = getline(&line, &n, infile)) == -1) {
#ifdef DEBUG_2
fprintf(stderr, "getline returned %d\n", val);
#endif
if(!feof(infile)) *err = 4;
//fclose(infile);
break;
}
#ifdef DEBUG_2
fprintf(stderr, "line=(%s)\n", line);
#endif
prettify_line(line);
#ifdef DEBUG
fprintf(stderr, "%d: prettified line=(%s)\n", section, line);
#endif
if(*line == '\0') {
free(line);
continue;
}
char *i = index(line, '\t');
if(i == NULL) {
*err &= 8;
}
*i++ = '\0';
/*At this point, we have line which stores the first word on the
line, and i which stores the second word on the line.
*/
char *to;
GHashTable *ht;
#ifdef DEBUG_2
fprintf(stderr, "part_a=(%s) part_b=(%s)\n", line, i);
#endif
/*If we have a material or bowing underway, save it off*/
if(strcasecmp(line, "material") == 0) {
insert_into_matdb(mdb, &mat, &bow);
if((mat = (struct matdb_material*)malloc(sizeof(struct matdb_material))) == NULL) {
*err &= 32;
}
if((mat->name = g_string_new(i)) == NULL) {
*err &= 32;
free(mat);
section=0;
continue;
}
if((mat->properties = g_hash_table_new_full(&g_str_hash, &g_str_equal, &destroy_string, &destroy_double)) == NULL) {
*err &= 32;
g_string_free(mat->name, TRUE);
free(bow);
section=0;
continue;
}
#ifdef DEBUG_2
fprintf(stderr, "new material (%s):\n", i);
#endif
section=1;
}else if(strcasecmp(line, "bow") == 0) {
insert_into_matdb(mdb, &mat, &bow);
if((bow = (struct matdb_bowing*)malloc(sizeof(struct matdb_bowing))) == NULL) {
*err &= 128;
}
if((to = index(i, ':')) == NULL) {
*err &= 1024;
free(bow);
section=0;
continue;
}
*to++ = '\0';
/*Same trick as before, but i now stores the from material,
and to the to material
*/
if((bow->from = g_string_new(i)) == NULL) {
*err &= 128;
free(bow);
section=0;
continue;
}
if((bow->to = g_string_new(to)) == NULL) {
*err &= 128;
g_string_free(bow->from, TRUE);
free(bow);
section=0;
continue;
}
if((bow->properties = g_hash_table_new_full(&g_str_hash, &g_str_equal, &destroy_string, &destroy_double)) == NULL) {
*err &= 128;
g_string_free(bow->to, TRUE);
g_string_free(bow->from, TRUE);
free(bow);
section=0;
continue;
}
#ifdef DEBUG_2
fprintf(stderr, "new bowing (%s:%s):\n", i, to);
#endif
section=2;
}else{
#ifdef DEBUG
fprintf(stderr, "\t%d/%s\t", section, line);
#endif
/*Process a property.*/
switch(section) {
case 1:
#ifdef DEBUG
fprintf(stderr, "(1)\t");
#endif
ht = mat->properties;
break;
case 2:
#ifdef DEBUG
fprintf(stderr, "(2)\t");
#endif
ht = bow->properties;
break;
default:
#ifdef DEBUG
fprintf(stderr, "(default)\t");
#endif
*err &= 16;
section = 0;
}
if(section == 0) {
#ifdef DEBUG
fprintf(stderr, "section was 0\n");
#endif
continue;
}
if((value = (double*)malloc(sizeof(double))) == NULL) {
*err &= 2048;
#ifdef DEBUG
fprintf(stderr, "malloc of value failed\n");
#endif
continue;
}
int num;
if((num=sscanf(i, " %lg", value)) != 1) {
*err &= 2048;
free(value);
#ifdef DEBUG
fprintf(stderr, "bad sscanf to get value (scanned \"%s\", returned %d)\n", i, num);
#endif
continue;
}
g_hash_table_insert(ht, g_strdup(line), value);
#ifdef DEBUG
fprintf(stderr, "%g(%s)\n", *value, line);
#endif
}
free(line);
line=i=to=NULL;
value=NULL;
}
fclose(infile);
insert_into_matdb(mdb, &mat, &bow);
return mdb;
}
Here is the call graph for this function:
Here is the caller graph for this function: