|
gimme-alpha 0.1
|
00001 /* 00002 ** read_nextnano_effectivemass_output.c 00003 ** 00004 ** Made by (Johnny Q. Hacker) 00005 ** Login <solarion@borkborkbork> 00006 ** 00007 00008 Copyright (C) 2008 Joseph Pingenot 00009 00010 This program is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Affero General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Affero General Public License for more details. 00019 00020 You should have received a copy of the GNU Affero General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 00023 ** Started on Wed Oct 22 09:37:38 2008 Johnny Q. Hacker 00024 ** Last update Sun May 12 01:17:25 2002 Speed Blue 00025 */ 00026 00027 #include <glib.h> 00028 #include <stdio.h> 00029 #include <libnextnano/read_nextnano_inputfile.h> 00030 #include <libnextnano/read_nextnano_effectivemass_output.h> 00031 #include <libcommon/textfile_common.h> 00032 #include <libcommon/gimme_alpha_types.h> 00033 #include <libnextnano/nextnano_wavefunction_conversion.h> 00034 00035 /*Size of buffer to use to hold nextnano ouput file field names when 00036 generating names, e.g. netnano_wavefunction_covnersion*/ 00037 #define NEXTNANO_FIELD_TITLE_BUFFER_LEN 32 00038 00039 /*Same,but for parts of an output file name*/ 00040 #define NEXTNANO_FILENAME_PART_BUFFER_LEN 32 00041 00042 GString* get_wavefunction_filename(enum bands band, short unsigned int cluster_num, short unsigned int schroedinger_num, short unsigned int subsolution_num, enum boundary_types boundary, short unsigned int Kz_num) { 00043 char buffer[NEXTNANO_FILENAME_PART_BUFFER_LEN]; 00044 char *leadin; 00045 switch (band) { 00046 case CB: 00047 leadin = "cb001_"; 00048 break; 00049 case CB_L: 00050 leadin = "cb002_"; 00051 break; 00052 case CB_X: 00053 leadin = "cb003_"; 00054 break; 00055 case HH: 00056 leadin = "vb001_"; 00057 break; 00058 case LH: 00059 leadin = "vb002_"; 00060 break; 00061 case SO: 00062 leadin = "vb003_"; 00063 break; 00064 default: 00065 fprintf(stderr, "read_effectivemass_complex_wavefunction2: INTERNAL ERROR: invalid band given (%d)\n", band); 00066 return NULL; 00067 } 00068 GString *wf_filename = g_string_new(leadin); 00069 snprintf(buffer, NEXTNANO_FILENAME_PART_BUFFER_LEN, "qc%03d_", cluster_num); 00070 buffer[NEXTNANO_FILENAME_PART_BUFFER_LEN-1] = '\0'; 00071 wf_filename = g_string_append(wf_filename, buffer); 00072 snprintf(buffer, NEXTNANO_FILENAME_PART_BUFFER_LEN, "sg%03d_", schroedinger_num); 00073 buffer[NEXTNANO_FILENAME_PART_BUFFER_LEN-1] = '\0'; 00074 wf_filename = g_string_append(wf_filename, buffer); 00075 snprintf(buffer, NEXTNANO_FILENAME_PART_BUFFER_LEN, "deg%03d_", subsolution_num); 00076 buffer[NEXTNANO_FILENAME_PART_BUFFER_LEN-1] = '\0'; 00077 wf_filename = g_string_append(wf_filename, buffer); 00078 switch (boundary) { 00079 case NEU: 00080 leadin = "neu_"; 00081 break; 00082 case DIR: 00083 leadin = "dir_"; 00084 break; 00085 default: 00086 fprintf(stderr, "read_effectivemass_complex_wavefunction2: INTERNAL ERROR: invalid boundary type given (%d)\n", boundary); 00087 return NULL; 00088 } 00089 wf_filename = g_string_append(wf_filename, leadin); 00090 snprintf(buffer, NEXTNANO_FILENAME_PART_BUFFER_LEN, "Kz%03d_", Kz_num); 00091 buffer[NEXTNANO_FILENAME_PART_BUFFER_LEN-1] = '\0'; 00092 wf_filename = g_string_append(wf_filename, buffer); 00093 wf_filename = g_string_append(wf_filename, "cmplx.dat"); 00094 return wf_filename; 00095 } 00096 00097 static void destroy_hash(gpointer hash, gpointer private) { 00098 g_hash_table_destroy((GHashTable*)hash); 00099 } 00100 00101 struct mstar_wavefunction_1d* read_effectivemass_complex_wavefunction2(enum bands band, short unsigned int cluster_num, short unsigned int schroedinger_num, short unsigned int subsolution_num, enum boundary_types boundary, short unsigned int Kz_num, short unsigned int soln_num, GFile* base, GHashTable *input, GError **error) { 00102 int err; 00103 *error = NULL; 00104 GList *titles = NULL; 00105 /*TODO: Provide sanity checks to make sure that the cluster, 00106 schroedinger, subsoln, and kz numbs requested should actually exist!*/ 00107 char *wf_dir_str = read_nextnano_extract_item(input, "output-1-band-schroedinger", 0, "destination-directory", &err); 00108 if(err != 0) { 00109 fprintf(stderr, "Error extracting output-densities destination-directory from nextnano input.\n"); 00110 return NULL; 00111 } 00112 GString *wf_filename = get_wavefunction_filename(band, cluster_num, schroedinger_num, subsolution_num, boundary, Kz_num); 00113 GFile *wf_dir = g_file_get_child(base, wf_dir_str); 00114 GFile *wf_file = g_file_get_child(wf_dir, wf_filename->str); 00115 GFileInputStream *wf_stream = g_file_read(wf_file, NULL, error); 00116 if(*error != NULL) { 00117 fprintf(stderr, "Error opening the wavefunction file (%s) for reading (error %s)\n", wf_filename->str, (*error)->message); 00118 return NULL; 00119 } 00120 GList *wf_list = read_titled_whitespaced_data(G_INPUT_STREAM(wf_stream), error, &titles, '!', DOUBLE_TYPE); 00121 struct mstar_wavefunction_1d *wf = convert_nextnano_mstar_wavefunction_to_general_1d(wf_list, "x-pos:", "ef_re(", "ef_im(", "):", soln_num); 00122 g_list_free(titles); 00123 g_list_foreach(wf_list, destroy_hash, NULL); 00124 g_list_free(wf_list); 00125 return wf; 00126 } 00127 00128 00129 /*The following funcs are deprecated.*/ 00130 GList* read_effectivemass_complex_wavefunctionfile(GInputStream *istream, GError **err, GList **titles) { 00131 /*String version of the data*/ 00132 *titles = NULL; 00133 return read_titled_whitespaced_data(istream, err, titles, '!', DOUBLE_TYPE); 00134 } 00135 00136 static void print_wavefunction_rowitem_by_title(gpointer title, gpointer row) { 00137 if(unlikely(row == NULL)) printf("%s\t", (char*)title); 00138 else printf("%g\t", *(double*)g_hash_table_lookup(row, title)); 00139 } 00140 00141 static void print_wavefunction_row(gpointer row, gpointer titles) { 00142 g_list_foreach(titles, print_wavefunction_rowitem_by_title, row); 00143 printf("\n"); 00144 } 00145 00146 void print_effectivemass_wavefunction(GList* titles, GList* rows) { 00147 g_list_foreach(titles, print_wavefunction_rowitem_by_title, NULL); 00148 printf("\n"); 00149 g_list_foreach(rows, print_wavefunction_row, titles); 00150 }