funkalicious 0.1

get_vhartree_slice.c

Go to the documentation of this file.
00001 /*
00002 ** get_vhartree_slice.c
00003 ** 
00004 ** Made by (Johnny Q. Hacker)
00005 ** Login   <solarion@borkborkbork>
00006 ** 
00007     Copyright (C) 2010 Joseph Pingenot
00008 
00009     This program is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Affero General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Affero General Public License for more details.
00018 
00019     You should have received a copy of the GNU Affero General Public License
00020     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 ** Started on  Wed Feb 24 17:04:30 2010 Johnny Q. Hacker
00023 ** Last update Sun May 12 01:17:25 2002 Speed Blue
00024 */
00025 
00026 #include <glib-2.0/glib.h>
00027 #include <gio/gio.h>
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <libdotcode/displ.h>
00031 #include <libdotcode/read_binary_data.h>
00032 #include <libdotcode/binary_data_common.h>
00033 #include <libpostproc/postproc_generic.h>
00034 #include <libpostproc/write_ascii_slice.h>
00035 #include "get_vhartree_slice_args.h"
00036 
00037 int main(int argc, char** argv) {
00038   g_type_init();
00039   GError *e = NULL;
00040   struct args *args = process_args(argc, argv, &e);
00041   if(e != NULL) {
00042     fprintf(stderr, "ERROR processing args: %s\n", e->message);
00043     return 2;
00044   }
00045   if(args == NULL) return 1;
00046   for(GList *file = args->struct_list; file != NULL; file=file->next ) {
00047     GFile* f = (GFile*)file->data;
00048     GError *e = NULL;
00049     enum dotcode_type t;
00050     void* structure = read_dotcode_generic_file(&t, f, &e);
00051     if(e != NULL) {
00052       fprintf(stderr, "ERROR: unable to find file %s: %s\n", (char*)file->data, e->message);
00053       g_error_free(e);
00054       return 3;
00055     }
00056     if(structure == NULL) {
00057       fprintf(stderr, "ERROR: structure from file (%s) was NULL\n", (char*)file->data);
00058       g_error_free(e);
00059       return 4;
00060     }
00061     if(t != DOTCODE_GRID) {
00062       fprintf(stderr, "ERROR: file (%s) was type %s, not Grid!\n", (char*)file->data, dotcode_string_from_type2(t));
00063       g_error_free(e);
00064       return 5;
00065     }
00066     struct dotcode_grid* g = (struct dotcode_grid*)structure;
00067     for(int i=0; i<3; i++) {
00068       printf("dim %d imin=%d imax=%d Ng=%d\n", i, (g->gridsites)[i]->imin, (g->gridsites)[i]->imax, g->Ng[i]);
00069       for(int j=0; j<((g->gridsites)[i]->imax - (g->gridsites)[i]->imin + 1); j++) {
00070   printf("\t%d=%g\n", j, ((double*)((g->gridsites)[i]->storage))[j]);
00071       }
00072     }
00073 
00074     if(g->data->t != DOTCODE_FLOAT8) {
00075       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));
00076       return 7;
00077     }
00078     
00079     int Nz =((g->data->indices)[5] - (g->data->indices)[4] + 1);
00080     int Ny =((g->data->indices)[3] - (g->data->indices)[2] + 1);
00081     int Nx =((g->data->indices)[1] - (g->data->indices)[0] + 1);
00082     for(int k=0; k<Nz; k++) {
00083       for(int j=0; j<Ny; j++) {
00084   for(int i=0; i<Nx; i++) {
00085     printf("%d/%d/%d=%g\n", i, j, k, ((double*)(g->data->data))[i + Nx*(j + Ny*k)]);
00086   }
00087       }
00088     }
00089     return 0;
00090 
00091 
00092     /*Now write the results out.*/
00093     GList *ll;
00094     int *adjusted_indices = (int*)malloc((g->data->Nd)*sizeof(int));
00095     if(adjusted_indices == NULL) {
00096       fprintf(stderr, "ERROR: failed to allocate memory for adjusted_indices!\n");
00097       return 6;
00098     }
00099     for(int i=0; i<(g->data->Nd); i++) adjusted_indices[i] = ((g->data->indices)[2*i+1] - (g->data->indices)[2*i]);
00100     GFile *base = g_file_new_for_path(".");
00101 
00102     for(ll = args->xslices; ll != NULL; ll=ll->next) {
00103       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);
00104       if(err != NULL) {
00105   fprintf(stderr, "ERROR writing X slice at %d: %s\n", *(int*)(ll->data), err->message);
00106   g_error_free(err);
00107       }
00108     }
00109     for(ll = args->yslices; ll != NULL; ll=ll->next) {
00110       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);
00111       if(err != NULL) {
00112   fprintf(stderr, "ERROR writing Y slice at %d: %s\n", *(int*)(ll->data), err->message);
00113   g_error_free(err);
00114       }
00115     }
00116     for(ll = args->zslices; ll != NULL; ll=ll->next) {
00117       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);
00118       if(err != NULL) {
00119   fprintf(stderr, "ERROR writing Z slice at %d: %s\n", *(int*)(ll->data), err->message);
00120   g_error_free(err);
00121       }
00122     }
00123     GError *err = NULL;
00124     dotcode_free_type(t, structure, 1, &err, TRUE);
00125     if(err != NULL) {
00126       fprintf(stderr, "Error freeing structure from file (%s) after use: %s\n", (char*)(file->data), e->message);
00127       return 7;
00128     }
00129   }
00130   return 0;
00131 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines