funkalicious 0.1

get_vhartree_slice.c File Reference

#include <glib-2.0/glib.h>
#include <gio/gio.h>
#include <stdio.h>
#include <stdlib.h>
#include <libdotcode/displ.h>
#include <libdotcode/read_binary_data.h>
#include <libdotcode/binary_data_common.h>
#include <libpostproc/postproc_generic.h>
#include <libpostproc/write_ascii_slice.h>
#include "get_vhartree_slice_args.h"
Include dependency graph for get_vhartree_slice.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 37 of file get_vhartree_slice.c.

References dotcode_tensor::data, dotcode_grid::data, DOTCODE_FLOAT8, dotcode_free_type(), DOTCODE_GRID, dotcode_string_from_type(), dotcode_string_from_type2(), dotcode_type_to_postproc_type(), e, args::file, dotcode_grid::gridsites, dotcode_tensor::indices, dotcode_tensor::Nd, dotcode_grid::Ng, postproc_write_ascii_slice(), POSTPROC_X, POSTPROC_Y, POSTPROC_Z, process_args(), read_dotcode_generic_file(), args::struct_list, dotcode_tensor::t, args::xslices, args::yslices, and args::zslices.

                                {
  g_type_init();
  GError *e = NULL;
  struct args *args = process_args(argc, argv, &e);
  if(e != NULL) {
    fprintf(stderr, "ERROR processing args: %s\n", e->message);
    return 2;
  }
  if(args == NULL) return 1;
  for(GList *file = args->struct_list; file != NULL; file=file->next ) {
    GFile* f = (GFile*)file->data;
    GError *e = NULL;
    enum dotcode_type t;
    void* structure = read_dotcode_generic_file(&t, f, &e);
    if(e != NULL) {
      fprintf(stderr, "ERROR: unable to find file %s: %s\n", (char*)file->data, e->message);
      g_error_free(e);
      return 3;
    }
    if(structure == NULL) {
      fprintf(stderr, "ERROR: structure from file (%s) was NULL\n", (char*)file->data);
      g_error_free(e);
      return 4;
    }
    if(t != DOTCODE_GRID) {
      fprintf(stderr, "ERROR: file (%s) was type %s, not Grid!\n", (char*)file->data, dotcode_string_from_type2(t));
      g_error_free(e);
      return 5;
    }
    struct dotcode_grid* g = (struct dotcode_grid*)structure;
    for(int i=0; i<3; i++) {
      printf("dim %d imin=%d imax=%d Ng=%d\n", i, (g->gridsites)[i]->imin, (g->gridsites)[i]->imax, g->Ng[i]);
      for(int j=0; j<((g->gridsites)[i]->imax - (g->gridsites)[i]->imin + 1); j++) {
  printf("\t%d=%g\n", j, ((double*)((g->gridsites)[i]->storage))[j]);
      }
    }

    if(g->data->t != DOTCODE_FLOAT8) {
      fprintf(stderr, "ERROR: tensor in grid is not a double (is a %d (%s))\n", g->data->t, dotcode_string_from_type(g->data->t));
      return 7;
    }
    
    int Nz =((g->data->indices)[5] - (g->data->indices)[4] + 1);
    int Ny =((g->data->indices)[3] - (g->data->indices)[2] + 1);
    int Nx =((g->data->indices)[1] - (g->data->indices)[0] + 1);
    for(int k=0; k<Nz; k++) {
      for(int j=0; j<Ny; j++) {
  for(int i=0; i<Nx; i++) {
    printf("%d/%d/%d=%g\n", i, j, k, ((double*)(g->data->data))[i + Nx*(j + Ny*k)]);
  }
      }
    }
    return 0;


    /*Now write the results out.*/
    GList *ll;
    int *adjusted_indices = (int*)malloc((g->data->Nd)*sizeof(int));
    if(adjusted_indices == NULL) {
      fprintf(stderr, "ERROR: failed to allocate memory for adjusted_indices!\n");
      return 6;
    }
    for(int i=0; i<(g->data->Nd); i++) adjusted_indices[i] = ((g->data->indices)[2*i+1] - (g->data->indices)[2*i]);
    GFile *base = g_file_new_for_path(".");

    for(ll = args->xslices; ll != NULL; ll=ll->next) {
      GError *err = postproc_write_ascii_slice(g->data->Nd, adjusted_indices, dotcode_type_to_postproc_type(g->data->t), g->data->data, POSTPROC_X, *(int*)(ll->data), base);
      if(err != NULL) {
  fprintf(stderr, "ERROR writing X slice at %d: %s\n", *(int*)(ll->data), err->message);
  g_error_free(err);
      }
    }
    for(ll = args->yslices; ll != NULL; ll=ll->next) {
      GError *err = postproc_write_ascii_slice(g->data->Nd, adjusted_indices, dotcode_type_to_postproc_type(g->data->t), g->data->data, POSTPROC_Y, *(int*)(ll->data), base);
      if(err != NULL) {
  fprintf(stderr, "ERROR writing Y slice at %d: %s\n", *(int*)(ll->data), err->message);
  g_error_free(err);
      }
    }
    for(ll = args->zslices; ll != NULL; ll=ll->next) {
      GError *err = postproc_write_ascii_slice(g->data->Nd, adjusted_indices, dotcode_type_to_postproc_type(g->data->t), g->data->data, POSTPROC_Z, *(int*)(ll->data), base);
      if(err != NULL) {
  fprintf(stderr, "ERROR writing Z slice at %d: %s\n", *(int*)(ll->data), err->message);
  g_error_free(err);
      }
    }
    GError *err = NULL;
    dotcode_free_type(t, structure, 1, &err, TRUE);
    if(err != NULL) {
      fprintf(stderr, "Error freeing structure from file (%s) after use: %s\n", (char*)(file->data), e->message);
      return 7;
    }
  }
  return 0;
}

Here is the call graph for this function:

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines