|
gimme-alpha 0.1
|
00001 /* 00002 ** nextnano_postprocessing.c 00003 ** 00004 ** Made by (Johnny Q. Hacker) 00005 ** Login <solarion@borkborkbork> 00006 ** 00007 00008 Copyright (C) 2009 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 Tue Mar 17 14:41:47 2009 Johnny Q. Hacker 00024 ** Last update Sun May 12 01:17:25 2002 Speed Blue 00025 */ 00026 00027 #include <stdlib.h> 00028 #include <glib.h> 00029 #include <libnextnano/nextnano_postprocessing.h> 00030 #include <libnextnano/read_nextnano_inputfile.h> 00031 #include <libcommon/gcc_hints.h> 00032 00033 void nextnano_region_d1_free(struct nextnano_region_d1 *r) { 00034 if(r->material != NULL) { 00035 g_string_free(r->material, TRUE); 00036 } 00037 free(r); 00038 } 00039 00040 void nextnano_region_free(struct nextnano_region *r) { 00041 if(r->storage != NULL) { 00042 switch(r->type){ 00043 case NNR_D1: 00044 nextnano_region_d1_free(r->storage); 00045 break; 00046 } 00047 } 00048 free(r); 00049 } 00050 00051 struct nextnano_region_d1* nextnano_region_d1_new() { 00052 struct nextnano_region_d1 *r; 00053 if(unlikely((r = (struct nextnano_region_d1*)malloc(sizeof(struct nextnano_region_d1))) == NULL)) return NULL; 00054 r->material = NULL; 00055 return r; 00056 } 00057 00058 struct nextnano_region* nextnano_region_new(enum nextnano_region_type type) { 00059 struct nextnano_region *r; 00060 if(unlikely((r = (struct nextnano_region*)malloc(sizeof(struct nextnano_region))) == NULL)) return NULL; 00061 r->type = type; 00062 switch(type){ 00063 case NNR_D1: 00064 r->storage = nextnano_region_d1_new(); 00065 break; 00066 } 00067 if(unlikely((r->storage) == NULL)) { 00068 free(r); 00069 } 00070 return r; 00071 } 00072 00073 /*ERROR TYPES 00074 * 0: Success 00075 * 1: Unsupported number of dimensions 00076 * 2: Failed to get new region 00077 * 3: failed to get new nextnano region. 00078 */ 00079 struct nanostructure* get_nanostructure(GHashTable* ifile, int* err) { 00080 int lerr; 00081 char *val; 00082 double *d; 00083 int *i; 00084 GList *regions = NULL; 00085 *err = 0; 00086 struct nanostructure *s; 00087 if(unlikely((s=nanostructure_new(NS_D1)) == NULL)) { 00088 *err = 2; 00089 return NULL; 00090 } 00091 struct nextnano_region *r; 00092 /*First, figure out what regions we have*/ 00093 i = read_nextnano_extract_item_typed(ifile, "simulation-dimension", 1, "dimension", &lerr, INT_TYPE); 00094 if((*i) != 1) { 00095 *err = 1; 00096 } 00097 for(int c=0; (i = read_nextnano_extract_item_typed(ifile, "regions", 1, "region-number", &lerr, INT_TYPE)) != NULL; c++) { 00098 if(unlikely((r=nextnano_region_new(NNR_D1)) == NULL)) { 00099 *err = 3; 00100 /*Continue; we're going to be missing a region; let the caller 00101 decide what to do*/ 00102 continue; 00103 } 00104 00105 } 00106 /*Any unclaimed sections of the overall nanostructure size are in 00107 the default material.*/ 00108 return s; 00109 }