00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00021 #define _CRT_SECURE_NO_DEPRECATE
00022
00023 #include "yanera.h"
00024 #include "yanera_model_build.h"
00025 #include "yanera_xml_util.h"
00026 #include "yanera_postfix.h"
00027
00028 void yanera_complete_models(yanera_container *yanera)
00029 {
00030 short i;
00031 yanera_layer *component_pointer, *layer;
00032
00033
00034
00035
00036
00037
00038 for (i=0; i<yanera->number_of_models; i++)
00039 {
00040 layer = yanera->models_xml[i].first_layer;
00041 while (layer != NULL)
00042 {
00043 if (layer->rmag > -1)
00044 { layer->polarized = yanera->models_complete[i].polarized; }
00045 layer = layer->next;
00046 }
00047 }
00048
00049
00050
00051
00052
00053
00054 for (i=0; i<yanera->number_of_models; i++)
00055 {
00056 copyModel(&yanera->models_complete[i], &yanera->models_xml[0]);
00057 modifyModel(&yanera->models_complete[i], &yanera->models_xml[i]);
00058 }
00059
00060
00061
00062
00063 component_pointer = yanera->components;
00064 while (component_pointer != NULL)
00065 {
00066 for (i=0; i<yanera->number_of_models; i++)
00067 {
00068 modifyComponents(&yanera->models_complete[i], component_pointer);
00069 }
00070 component_pointer = component_pointer->next;
00071 }
00072
00073
00074
00075
00076 if (yanera->type == MODEL_FUNCTION)
00077 {
00078 for (i=0; i<yanera->number_of_models; i++)
00079 {
00080 layer = yanera->models_complete[i].first_layer;
00081 while (layer != NULL)
00082 {
00083 if (layer->type == LAYER_FUNCTION)
00084 {
00085 layer->func_postfix = initizlize_postfix_queue();
00086 parse_expression(layer->func_postfix, layer->func, \
00087 layer->parm_names, layer->parm_values);
00088 }
00089 layer = layer->next;
00090 }
00091 }
00092 }
00093
00094 return;
00095 }
00096
00097 void copyModel(yanera_model *destination, yanera_model *source)
00098 {
00099 yanera_layer *layer, *layer_pointer;
00100
00101
00102
00103 if (source->data_idref != NULL)
00104 {
00105 destination->data_idref = (char *)calloc((strlen(source->data_idref)+1), \
00106 sizeof(char));
00107 strcpy(destination->data_idref, source->data_idref);
00108 }
00109 else destination->data_idref = NULL;
00110
00111
00112
00113 if (source->name != NULL)
00114 {
00115 destination->name = (char *)calloc((strlen(source->name)+1), \
00116 sizeof(char));
00117 strcpy(destination->name, source->name);
00118 }
00119 else destination->name= NULL;
00120 destination->background = source->background;
00121 destination->polarized = source->polarized;
00122
00123
00124
00125 layer_pointer = source->first_layer;
00126 while (layer_pointer != NULL)
00127 {
00128 layer = copyLayer(layer_pointer);
00129 linkLayerIntoModel(layer, destination);
00130 layer_pointer = layer_pointer->next;
00131 }
00132
00133
00134
00135 return;
00136 }
00137
00138 void modifyModel(yanera_model *destination, yanera_model *source)
00139 {
00140 yanera_layer *source_layer;
00141 yanera_layer *destination_layer, *ptr;
00142 enum boolean found;
00143 short i1, i2;
00144
00145
00146
00147
00148 if (source->data_idref != NULL)
00149 {
00150 free(destination->data_idref);
00151 destination->data_idref = (char *)calloc((strlen(source->data_idref)+1), \
00152 sizeof(char));
00153 strcpy(destination->data_idref, source->data_idref);
00154 }
00155 if (source->name != NULL)
00156 {
00157 free(destination->name);
00158 destination->name = (char *)calloc((strlen(source->name)+1), \
00159 sizeof(char));
00160 strcpy(destination->name, source->name);
00161 }
00162 if (source->background > -1) destination->background = source->background;
00163 if (source->polarized != POLARIZED_NONE)
00164 {
00165 destination->polarized = source->polarized;
00166
00167
00168
00169 destination_layer = destination->first_layer;
00170 while (destination_layer != NULL)
00171 {
00172 if (destination_layer->rmag > -1)
00173 {
00174 destination_layer->polarized = source->polarized;
00175 }
00176 destination_layer = destination_layer->next;
00177 }
00178 }
00179
00180
00181
00182 source_layer = source->first_layer;
00183 while (source_layer != NULL)
00184 {
00185 destination_layer = destination->first_layer;
00186 while (destination_layer != NULL)
00187 {
00188
00189
00190
00191 found = NO;
00192 if ((source_layer->layer_idref != NULL) && \
00193 (destination_layer->layer_id != NULL))
00194 {
00195 if (strcmp(source_layer->layer_idref, \
00196 destination_layer->layer_id) == 0)
00197 {
00198 found = YES;
00199 }
00200 }
00201
00202
00203
00204
00205
00206 if (found == YES)
00207 {
00208 if (source_layer->component_idref != NULL)
00209 {
00210 free(destination_layer->component_idref);
00211 destination_layer->component_idref=(char *)calloc(\
00212 (strlen(source_layer->component_idref)+1),sizeof(char));
00213 strcpy(destination_layer->component_idref, \
00214 source_layer->component_idref);
00215 }
00216 if (source_layer->type > LAYER_LAYER)
00217 { destination_layer->type = source_layer->type; }
00218 if (source_layer->name != NULL)
00219 {
00220 free(destination_layer->name);
00221 destination_layer->name=(char *)calloc(\
00222 (strlen(source_layer->name)+1),sizeof(char));
00223 strcpy(destination_layer->name, source_layer->name);
00224 }
00225 if (source_layer->func != NULL)
00226 {
00227 free(destination_layer->func);
00228 destination_layer->func=(char *)calloc(\
00229 (strlen(source_layer->func)+1),sizeof(char));
00230 strcpy(destination_layer->func, source_layer->func);
00231 }
00232 if ((source_layer->parm_names != NULL) && \
00233 (source_layer->parm_values != NULL))
00234 {
00235 for(i1 = 0; i1 < source_layer->number_of_parm; i1++)
00236 {
00237 for (i2 = 0; i2 < destination_layer->number_of_parm; i2++)
00238 {
00239 if (source_layer->parm_names[i1] == \
00240 destination_layer->parm_names[i2])
00241 {
00242 destination_layer->parm_values[i2] = \
00243 source_layer->parm_values[i1];
00244 }
00245 }
00246 }
00247 }
00248 if (source_layer->thik > -1)
00249 destination_layer->thik = source_layer->thik;
00250 if (source_layer->sigz > -1)
00251 destination_layer->sigz = source_layer->sigz;
00252 if (source_layer->cntr > -1)
00253 destination_layer->cntr = source_layer->cntr;
00254 if (source_layer->rsld > -1)
00255 destination_layer->rsld = source_layer->rsld;
00256 if (source_layer->isld > -1)
00257 destination_layer->isld = source_layer->isld;
00258 if (source_layer->rmag > -1)
00259 destination_layer->rmag = source_layer->rmag;
00260 if (source_layer->repeat_flag > 0)
00261 destination_layer->repeat_flag = source_layer->repeat_flag;
00262
00263
00264
00265
00266
00267 if (source_layer->include_flag == NO)
00268 {
00269 ptr = destination->first_layer;
00270 while (ptr->next != destination_layer) ptr = ptr->next;
00271 ptr->next = destination_layer->next;
00272 free(destination_layer->layer_id);
00273 free(destination_layer->layer_idref);
00274 free(destination_layer->component_id);
00275 free(destination_layer->component_idref);
00276 free(destination_layer->name);
00277 free(destination_layer->func);
00278 free(destination_layer->parm_names);
00279 free(destination_layer->parm_values);
00280 free(destination_layer);
00281 destination_layer = ptr;
00282 }
00283
00284
00285
00286
00287 }
00288
00289
00290
00291
00292
00293
00294 destination_layer = destination_layer->next;
00295 }
00296
00297 source_layer = source_layer->next;
00298 }
00299
00300
00301 return;
00302 }
00303
00304 void modifyComponents(yanera_model *destination, yanera_layer *component)
00305 {
00306 yanera_layer *destination_layer;
00307 enum boolean found;
00308
00309
00310
00311 destination_layer = destination->first_layer;
00312 while (destination_layer != NULL)
00313 {
00314 found = NO;
00315
00316
00317
00318 if (destination_layer->component_idref != NULL)
00319 {
00320
00321
00322
00323 if (strcmp(destination_layer->component_idref, \
00324 component->component_id) == 0)
00325 {
00326 found = YES;
00327 }
00328 }
00329
00330
00331
00332
00333
00334 if (found == YES)
00335 {
00336 if (component->type > 0) destination_layer->type = component->type;
00337 if (component->name != NULL)
00338 {
00339 free(destination_layer->name);
00340 destination_layer->name=(char *)calloc((strlen(component->name)+1), \
00341 sizeof(char));
00342 strcpy(destination_layer->name, component->name);
00343 }
00344 if (component->thik > -1) destination_layer->thik = component->thik;
00345 if (component->sigz > -1) destination_layer->sigz = component->sigz;
00346 if (component->cntr > -1) destination_layer->cntr = component->cntr;
00347 if (component->rsld > -1) destination_layer->rsld = component->rsld;
00348 if (component->isld > -1) destination_layer->isld = component->isld;
00349 if (component->rmag > -1) destination_layer->rmag = component->rmag;
00350 }
00351
00352 destination_layer = destination_layer->next;
00353 }
00354 return;
00355 }