|
gimme-alpha 0.1
|
00001 /* 00002 * 00003 * read nextnano 8-band k-dot-p output 00004 * 00005 Copyright (C) 2008 Joseph Pingenot 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Affero General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Affero General Public License for more details. 00016 00017 You should have received a copy of the GNU Affero General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include <stdio.h> 00022 #include <stdlib.h> 00023 #include <libnextnano/read_nextnano_8x8kp_output.h> 00024 #include <libnextnano/read_nextnano_inputfile.h> 00025 #include <libcommon/textfile_common.h> 00026 #include <libcommon/gimme_alpha_types.h> 00027 00028 int read_nextnano_8x8kp_get_filename(char* buffer, int bufflen, int bands, int electron, int qcluster, int eignum, int kpar, int kz, int neumann, int wavefunc) { 00029 return snprintf(buffer, bufflen, "kp_%dx%d_%s1D_qc%03d_%s%03d_kpar%04d_Kz%03d_%s.dat", bands, bands, (electron?"el":"hl"), qcluster, (wavefunc?"wv":"ev"), eignum, kpar, kz, (neumann?"neu":"dir")); 00030 } 00031 00032 int read_nextnano_8x8kp_get_eigvals_filename(char* buffer, int bufflen, int bands, int electron, int qcluster, int kpar, int neumann) { 00033 return snprintf(buffer, bufflen, "kp_%dx%deigenvalues_qc%03d_%s_kpar%04d_1D_%s.dat", bands, bands, qcluster, (electron?"el":"hl"), kpar, (neumann?"neu":"dir")); 00034 } 00035 00036 GList *read_nextnano_8x8kp_get_eigfunc(GFile* base, GHashTable *input, int num, GList **titles) { 00037 int err; 00038 char *kpdir_s = read_nextnano_extract_item(input, "output-kp-data", 0, "destination-directory", &err); 00039 if(err != 0) { 00040 fprintf(stderr, "Error extracting item from nextnano input.\n"); 00041 return NULL; 00042 } 00043 GFile *kpdir = g_file_get_child(base, kpdir_s); 00044 char eigfunc_file[1024] = {'\0'}; 00045 read_nextnano_8x8kp_get_filename(eigfunc_file, 1024, 8, 1, 1, num, 1, 1, 1, 1); 00046 //fprintf(stderr, "got eigenfunction file of %s\n", eigfunc_file); 00047 GFile *eigfunc_f = g_file_get_child(kpdir, eigfunc_file); 00048 GError *err_func; 00049 GFileInputStream *eigfunc_stream = g_file_read(eigfunc_f, NULL, &err_func); 00050 if(eigfunc_stream == NULL) { 00051 fprintf(stderr, "failed top open the eigenfunction file (%s): eigfunc error was %s\n", eigfunc_file, err_func->message); 00052 g_object_unref(kpdir); 00053 g_object_unref(eigfunc_f); 00054 return NULL; 00055 } 00056 *titles = NULL; 00057 GList *eigfunc = read_titled_whitespaced_data(G_INPUT_STREAM(eigfunc_stream), &err_func, titles, '!', DOUBLE_TYPE); 00058 /*free the data structures*/ 00059 g_object_unref(kpdir); 00060 g_object_unref(eigfunc_f); 00061 g_object_unref(eigfunc_stream); 00062 return eigfunc; 00063 } 00064 00065 00066 GList *read_nextnano_8x8kp_get_eigvals(GFile* base, GHashTable *input) { 00067 int err; 00068 char *kpdir_s = read_nextnano_extract_item(input, "output-kp-data", 0, "destination-directory", &err); 00069 if(err != 0) { 00070 fprintf(stderr, "Error extracting item from nextnano input.\n"); 00071 return NULL; 00072 } 00073 GFile *kpdir = g_file_get_child(base, kpdir_s); 00074 char eigval_file[1024] = {'\0'}; 00075 read_nextnano_8x8kp_get_eigvals_filename(eigval_file, 1024, 8, 1, 1, 1, 1); 00076 GFile *eigval_f = g_file_get_child(kpdir, eigval_file); 00077 GError *err_val; 00078 GFileInputStream *eigval_stream = g_file_read(eigval_f, NULL, &err_val); 00079 if(eigval_stream==NULL) { 00080 fprintf(stderr, "failed to open the eigvalues stream (file %s): err was %s\n", eigval_file, err_val->message); 00081 return NULL; 00082 } 00083 GList *eigval_titles = g_list_append(NULL, "num"); 00084 eigval_titles = g_list_append(eigval_titles, "value"); 00085 GList *eigvals = read_titled_whitespaced_data(G_INPUT_STREAM(eigval_stream), &err_val, &eigval_titles, '!', DOUBLE_TYPE); 00086 /*Re-purpose the list so that it's a list of values.*/ 00087 GList *l; 00088 GHashTable *t; 00089 double *v; 00090 for(l=g_list_first(eigvals); l != NULL; l = g_list_next(l)) { 00091 t = l->data; 00092 fprintf(stderr, " key=%g value=%g\n", *((double*)g_hash_table_lookup(t, "num")), *((double*)g_hash_table_lookup(t, "value"))); 00093 v = g_hash_table_lookup(t, "value"); 00094 l->data = malloc(sizeof(double)); 00095 *(double*)(l->data) = *(double*)v; 00096 g_hash_table_unref(t); 00097 } 00098 /*Free our datastructures.*/ 00099 g_list_free(eigval_titles); 00100 g_object_unref(kpdir); 00101 g_object_unref(eigval_f); 00102 g_object_unref(eigval_stream); 00103 return eigvals; 00104 }