funkalicious 0.1

dc_get_composition.c

Go to the documentation of this file.
00001 /**Gets the composition of a dotcode wavefunction
00002  
00003 
00004     Copyright (C) 2011 Joseph Pingenot
00005 
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Affero General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Affero General Public License for more details.
00015 
00016     You should have received a copy of the GNU Affero General Public License
00017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 #include <stdio.h>
00022 #include <glib-2.0/glib.h>
00023 #include <gio/gio.h>
00024 #include <libpostproc/lp_wavefunction.h>
00025 #include <libdotcode/dotcode_wavefunction.h>
00026 #include <libdotcode/wavefunction_simple_operations.h>
00027 #include <libdotcode/dotcode_data.h>
00028 #include <libpostproc/unit_conversion.h>
00029 
00030 int main(int argc, char** argv) {
00031   g_type_init();
00032   printf("#file\t%s", dotcode_band_short_names[0]);
00033   for(int band=1; band<8; band++) {
00034     printf("\t%s", dotcode_band_short_names[band]);
00035   }
00036   printf("\tSUM\tSTSUM re\tSTSUM im\tMTSUM re\tMTSUM im\n");
00037   for(int wfn=1; wfn<argc; ++wfn) {
00038     GList* l=NULL;
00039     GFile* f = g_file_new_for_commandline_arg(argv[wfn]);
00040     struct wavefunction wf = {.file=f, .charge=1, .N={0, 0, 0}, .dx={0, 0, 0}, .bands=0, .storage=NULL};
00041     l = g_list_append(l, &wf);
00042     GError *e = NULL;
00043     load_wavefunctions(l, &e);
00044     if(e == NULL) {
00045       double band_pcts[wf.bands];
00046       printf("%s", argv[wfn]);
00047       for(int band=0; band<wf.bands; band++) {
00048   band_pcts[band] = dotcode_wavefunction_get_percentage_in_band(&wf, band);
00049   printf("\t%g", band_pcts[band]);
00050       }
00051       double sum = band_pcts[0];
00052       for(int i=1; i<wf.bands; ++i) sum += band_pcts[i];
00053       printf("\t%g", sum);
00054       double im;
00055       dotcode_wavefunction_integrate_sum(&wf, NULL, &wf, &sum, &im, NULL);
00056       printf("\t%g\t%g", sum, im);
00057       dotcode_wavefunction_integrate_sum_parallel(&wf, NULL, &wf, &sum, &im, NULL);
00058       printf("\t%g\t%g\n", sum, im);
00059       dotcode_wavefunction_free_resources(&wf);
00060     }else{
00061       fprintf(stderr, "ERROR loading wavefunction (%s): %s", argv[wfn], e->message);
00062     }
00063     g_list_free(l);
00064     if(e != NULL) g_error_free(e);
00065   }
00066   return 0;
00067 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines