|
funkalicious 0.1
|
00001 /* 00002 ** material_property.c 00003 ** 00004 ** Made by (Johnny Q. Hacker) 00005 ** Login <solarion@borkborkbork> 00006 ** 00007 ** Started on Wed Dec 9 13:32:00 2009 Johnny Q. Hacker 00008 ** Last update Sun May 12 01:17:25 2002 Speed Blue 00009 */ 00010 00011 #include <stdio.h> 00012 #include <glib-2.0/glib.h> 00013 #include <gio/gio.h> 00014 #include <libdotcode/matdb.h> 00015 #include <libdotcode/displ.h> 00016 #include <libdotcode/grid1.h> 00017 #include "material_property_args.h" 00018 00019 int main(int argc, char** argv) { 00020 g_type_init(); 00021 GError *e = NULL; 00022 struct args* args = process_args(argc, argv, &e); 00023 if((args == NULL) || (e != NULL)) { 00024 fprintf(stderr, "ERROR: failed to read your input: %s\n", (e != NULL)?(e->message):""); 00025 return 1; 00026 } 00027 struct matdb* matdb = dotcode_displ_get_matdb(args->file, &e); 00028 if((matdb == NULL) || (e != NULL)) { 00029 fprintf(stderr, "Error reading matdb from input file (%s): %s\n", g_file_get_uri(args->file), (e!=NULL)?e->message:"(no extra information)"); 00030 return 1; 00031 } 00032 struct dotcode_grid1* grid = dotcode_displ_get_grid1(args->file, &e); 00033 if((grid == NULL) || (e != NULL)) { 00034 fprintf(stderr, "Error reading grid from input file (%s): %s\n", g_file_get_uri(args->file), (e!=NULL)?e->message:"(no extra information)"); 00035 return 1; 00036 } 00037 double* propmap = dotcode_grid1_get_property_grid(grid, matdb, args->property, &e); 00038 if((propmap == NULL) || (e != NULL)) { 00039 fprintf(stderr, "Error getting property map for property (%s) from input file (%s): %s\n", args->property, g_file_get_uri(args->file), (e!=NULL)?e->message:"(no extra information)"); 00040 return 1; 00041 } 00042 GFile *cwd = g_file_new_for_path("."); 00043 GList *ll; 00044 for(ll = args->xslices; ll != NULL; ll=ll->next) { 00045 e = NULL; 00046 dotcode_grid1_write_property_slice_text(grid, propmap, args->property, cwd, DOTCODE_COORD_X, *(int*)(ll->data), &e); 00047 if(e != NULL) { 00048 fprintf(stderr, "ERROR writing X slice at %d: %s\n", *(int*)(ll->data), e->message); 00049 g_error_free(e); 00050 } 00051 } 00052 for(ll = args->yslices; ll != NULL; ll=ll->next) { 00053 e = NULL; 00054 dotcode_grid1_write_property_slice_text(grid, propmap, args->property, cwd, DOTCODE_COORD_Y, *(int*)(ll->data), &e); 00055 if(e != NULL) { 00056 fprintf(stderr, "ERROR writing Y slice at %d: %s\n", *(int*)(ll->data), e->message); 00057 g_error_free(e); 00058 } 00059 } 00060 for(ll = args->zslices; ll != NULL; ll=ll->next) { 00061 e = NULL; 00062 dotcode_grid1_write_property_slice_text(grid, propmap, args->property, cwd, DOTCODE_COORD_Z, *(int*)(ll->data), &e); 00063 if(e != NULL) { 00064 fprintf(stderr, "ERROR writing Z slice at %d: %s\n", *(int*)(ll->data), e->message); 00065 g_error_free(e); 00066 } 00067 } 00068 00069 char* str; 00070 e=NULL; 00071 double* propcache = dotcode_grid1_get_property_cache(grid, matdb, args->property, &e); 00072 if((propcache==NULL) || (e != NULL)) { 00073 fprintf(stderr, "ERROR getting property cache for property %s (file %s): %s", args->property, str=g_file_get_uri(args->file), (e==NULL)?"(no further information)":e->message); 00074 g_free(str); 00075 return 4; 00076 } 00077 double ppt, val; 00078 for(ll = args->points; ll != NULL; ll=ll->next) { 00079 e = NULL; 00080 for(int i=0; i<3; i++) { 00081 if(((int*)(ll->data))[i] >= grid->N[i]) { 00082 fprintf(stderr, "ERROR: Vector component %d (%d in %d,%d,%d) is out of bounds (>=%d)\n", i, ((int*)(ll->data))[i], ((int*)(ll->data))[0], ((int*)(ll->data))[1], ((int*)(ll->data))[2], grid->N[i]); 00083 continue; 00084 } 00085 } 00086 ppt = dotcode_grid1_get_property_at_site_cached(grid, propcache, (int*)(ll->data)); 00087 val=dotcode_grid1_get_property_at_site(grid, matdb, args->property, (int*)(ll->data), &e); 00088 if(e != NULL) { 00089 fprintf(stderr, "ERROR: Got error fetching property (%s) at point %d,%d,%d: %s\n", args->property, ((int*)(ll->data))[0], ((int*)(ll->data))[1], ((int*)(ll->data))[2], e->message); 00090 g_error_free(e); 00091 } 00092 if(val != ppt) { 00093 fprintf(stderr, "ERROR: property (%s) from property cache (%g) not the same as fetched from the matdb (%g)!\nThis is a programming error!\n", args->property, ppt, val); 00094 } 00095 printf("%d,%d,%d=%g\n", ((int*)(ll->data))[0], ((int*)(ll->data))[1], ((int*)(ll->data))[2], ppt); 00096 } 00097 return 0; 00098 }