funkalicious 0.1

material_property.c File Reference

#include <stdio.h>
#include <glib-2.0/glib.h>
#include <gio/gio.h>
#include <libdotcode/matdb.h>
#include <libdotcode/displ.h>
#include <libdotcode/grid1.h>
#include "material_property_args.h"
Include dependency graph for material_property.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 19 of file material_property.c.

References DOTCODE_COORD_X, DOTCODE_COORD_Y, DOTCODE_COORD_Z, dotcode_displ_get_grid1(), dotcode_displ_get_matdb(), dotcode_grid1_get_property_at_site(), dotcode_grid1_get_property_at_site_cached(), dotcode_grid1_get_property_cache(), dotcode_grid1_get_property_grid(), dotcode_grid1_write_property_slice_text(), e, args::file, dotcode_grid1::N, args::points, process_args(), args::property, str, args::xslices, args::yslices, and args::zslices.

                                {
  g_type_init();
  GError *e = NULL;
  struct args* args = process_args(argc, argv, &e);
  if((args == NULL) || (e != NULL)) {
    fprintf(stderr, "ERROR: failed to read your input: %s\n", (e != NULL)?(e->message):"");
    return 1;
  }
  struct matdb* matdb = dotcode_displ_get_matdb(args->file, &e);
  if((matdb == NULL) || (e != NULL)) {
    fprintf(stderr, "Error reading matdb from input file (%s): %s\n", g_file_get_uri(args->file), (e!=NULL)?e->message:"(no extra information)");
    return 1;
  }
  struct dotcode_grid1* grid = dotcode_displ_get_grid1(args->file, &e);
  if((grid == NULL) || (e != NULL)) {
    fprintf(stderr, "Error reading grid from input file (%s): %s\n", g_file_get_uri(args->file), (e!=NULL)?e->message:"(no extra information)");
    return 1;
  }
  double* propmap = dotcode_grid1_get_property_grid(grid, matdb, args->property, &e);
  if((propmap == NULL) || (e != NULL)) {
    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)");
    return 1;
  }
  GFile *cwd = g_file_new_for_path(".");
  GList *ll;
  for(ll = args->xslices; ll != NULL; ll=ll->next) {
    e = NULL;
    dotcode_grid1_write_property_slice_text(grid, propmap, args->property, cwd, DOTCODE_COORD_X, *(int*)(ll->data), &e);
    if(e != NULL) {
      fprintf(stderr, "ERROR writing X slice at %d: %s\n", *(int*)(ll->data), e->message);
      g_error_free(e);
    }
  }
  for(ll = args->yslices; ll != NULL; ll=ll->next) {
    e = NULL;
    dotcode_grid1_write_property_slice_text(grid, propmap, args->property, cwd, DOTCODE_COORD_Y, *(int*)(ll->data), &e);
    if(e != NULL) {
      fprintf(stderr, "ERROR writing Y slice at %d: %s\n", *(int*)(ll->data), e->message);
      g_error_free(e);
    }
  }
  for(ll = args->zslices; ll != NULL; ll=ll->next) {
    e = NULL;
    dotcode_grid1_write_property_slice_text(grid, propmap, args->property, cwd, DOTCODE_COORD_Z, *(int*)(ll->data), &e);
    if(e != NULL) {
      fprintf(stderr, "ERROR writing Z slice at %d: %s\n", *(int*)(ll->data), e->message);
      g_error_free(e);
    }
  }

  char* str;
  e=NULL;
  double* propcache = dotcode_grid1_get_property_cache(grid, matdb, args->property, &e);
  if((propcache==NULL) || (e != NULL)) {
    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);
    g_free(str);
    return 4;
  }
  double ppt, val;
  for(ll = args->points; ll != NULL; ll=ll->next) {
    e = NULL;
    for(int i=0; i<3; i++) {
      if(((int*)(ll->data))[i] >= grid->N[i]) {
  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]);
  continue;
      }
    }
    ppt = dotcode_grid1_get_property_at_site_cached(grid, propcache, (int*)(ll->data));
    val=dotcode_grid1_get_property_at_site(grid, matdb, args->property, (int*)(ll->data), &e);
    if(e != NULL) {
      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);
      g_error_free(e);
    }
    if(val != ppt) {
      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);
    }
    printf("%d,%d,%d=%g\n", ((int*)(ll->data))[0], ((int*)(ll->data))[1], ((int*)(ll->data))[2], ppt);
  }
  return 0;
}

Here is the call graph for this function:

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines