00001
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include <errno.h>
00012 #include <math.h>
00013
00014 #include "impedance_dump.h"
00015
00017
00019
00020 CLASS* impedance_dump::oclass = NULL;
00021
00022 impedance_dump::impedance_dump(MODULE *mod)
00023 {
00024 if (oclass==NULL)
00025 {
00026
00027 oclass = gl_register_class(mod,"impedance_dump",sizeof(impedance_dump),PC_AUTOLOCK);
00028 if (oclass==NULL)
00029 GL_THROW("unable to register object class implemented by %s",__FILE__);
00030
00031
00032 if (gl_publish_variable(oclass,
00033 PT_char32,"group",PADDR(group),PT_DESCRIPTION,"the group ID to output data for (all links if empty)",
00034 PT_char256,"filename",PADDR(filename),PT_DESCRIPTION,"the file to dump the current data into",
00035 PT_timestamp,"runtime",PADDR(runtime),PT_DESCRIPTION,"the time to check voltage data",
00036 PT_int32,"runcount",PADDR(runcount),PT_ACCESS,PA_REFERENCE,PT_DESCRIPTION,"the number of times the file has been written to",
00037 NULL)<1) GL_THROW("unable to publish properties in %s",__FILE__);
00038 }
00039 }
00040
00041 int impedance_dump::create(void)
00042 {
00043 group.erase();
00044 runcount = 0;
00045 return 1;
00046 }
00047
00048 int impedance_dump::init(OBJECT *parent)
00049 {
00050 if(filename[0] == '\0'){
00051 gl_error("No filename was specified. Unable to open file for righting.");
00052 return 0;
00053
00054
00055
00056 }
00057
00058 return 1;
00059 }
00060
00061 int impedance_dump::isa(char *classname)
00062 {
00063 return strcmp(classname,"impedance_dump")==0;
00064 }
00065
00066 complex * impedance_dump::get_complex(OBJECT *obj, char *name)
00067 {
00068 PROPERTY *p = gl_get_property(obj,name);
00069 if (p==NULL || p->ptype!=PT_complex)
00070 return NULL;
00071 return (complex*)GETADDR(obj,p);
00072 }
00073
00074 int impedance_dump::dump(TIMESTAMP t)
00075 {
00076 FINDLIST *capacitors, *fuses, *ohlines, *reclosers, *regulators, *relays, *sectionalizers, *series_reactors, *switches, *transformers, *tplines, *uglines;
00077 OBJECT *obj = NULL;
00078 char buffer[1024];
00079 FILE *fn = NULL;
00080 int index = 0;
00081 int count = 0;
00082 int x = 0;
00083 int y = 0;
00084 CLASS *obj_class;
00085 char timestr[64];
00086 PROPERTY *xfmrconfig;
00087
00088
00089 if(group[0] == '\0'){
00090 fuses = gl_find_objects(FL_NEW,FT_CLASS,SAME,"fuse",FT_END);
00091 ohlines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"overhead_line",FT_END);
00092 reclosers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"recloser",FT_END);
00093 regulators = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator",FT_END);
00094 relays = gl_find_objects(FL_NEW,FT_CLASS,SAME,"relay",FT_END);
00095 sectionalizers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"sectionalizer",FT_END);
00096 series_reactors = gl_find_objects(FL_NEW,FT_CLASS,SAME,"series_reactor",FT_END);
00097 switches = gl_find_objects(FL_NEW,FT_CLASS,SAME,"switch",FT_END);
00098 transformers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"transformer",FT_END);
00099 tplines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"triplex_line",FT_END);
00100 uglines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"underground_line",FT_END);
00101 capacitors = gl_find_objects(FL_NEW,FT_CLASS,SAME,"capacitor",FT_END);
00102 } else {
00103 fuses = gl_find_objects(FL_NEW,FT_CLASS,SAME,"fuse",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00104 ohlines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"overhead_line",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00105 reclosers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"recloser",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00106 regulators = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00107 relays = gl_find_objects(FL_NEW,FT_CLASS,SAME,"relay",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00108 sectionalizers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"sectionalizer",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00109 series_reactors = gl_find_objects(FL_NEW,FT_CLASS,SAME,"series_reactor",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00110 switches = gl_find_objects(FL_NEW,FT_CLASS,SAME,"switch",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00111 transformers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"transformer",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00112 tplines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"triplex_line",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00113 uglines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"underground_line",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00114 capacitors = gl_find_objects(FL_NEW,FT_CLASS,SAME,"capacitor",AND,FT_GROUPID,SAME,group.get_string(),FT_END);
00115 }
00116 if(fuses == NULL && ohlines == NULL && reclosers == NULL && regulators == NULL && relays == NULL && sectionalizers == NULL && series_reactors == NULL && switches == NULL && transformers == NULL && tplines == NULL && uglines == NULL){
00117 gl_error("No link objects were found.");
00118 return 0;
00119
00120
00121
00122 }
00123
00124
00125 fn = fopen(filename,"w");
00126 if(fn == NULL){
00127 gl_error("Unable to open %s for writing.",(char *)(&filename));
00128 return 0;
00129 }
00130
00131
00132 fprintf(fn,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
00133 fprintf(fn,"<?xml-stylesheet href=\"C:\\Projects\\GridLAB-D_Builds\\ticket_704\\VS2005\\gridlabd-2_0.xsl\" type=\"text/xsl\"?>\n");
00134 fprintf(fn,"<gridlabd>\n");
00135
00136 gl_printtime(t, timestr, 64);
00137 fprintf(fn,"\t<Time>%s</Time>\n",timestr);
00138
00139 if(fuses != NULL){
00140 pFuse = (link_object **)gl_malloc(fuses->hit_count*sizeof(link_object*));
00141 if(pFuse == NULL){
00142 gl_error("Failed to allocate fuse array.");
00143 return TS_NEVER;
00144 }
00145 while(obj = gl_find_next(fuses,obj)){
00146 if(index >= fuses->hit_count){
00147 break;
00148 }
00149 pFuse[index] = OBJECTDATA(obj,link_object);
00150 if(pFuse[index] == NULL){
00151 gl_error("Unable to map object as a link object.");
00152 return 0;
00153 }
00154
00155
00156 fprintf(fn,"\t<fuse>\n");
00157
00158
00159 if(obj->name[0] != 0){
00160 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
00161 } else {
00162 fprintf(fn,"\t\t<name>NA</name>\n");
00163 }
00164
00165
00166 fprintf(fn,"\t\t<id>fuse:%d</id>\n",obj->id);
00167
00168
00169 if(pFuse[index]->from->name[0] != 0){
00170 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pFuse[index]->from->oclass->name,pFuse[index]->from->name);
00171 } else {
00172 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pFuse[index]->from->oclass->name,pFuse[index]->from->id);
00173 }
00174
00175
00176 if(pFuse[index]->to->name[0] != 0){
00177 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pFuse[index]->to->oclass->name,pFuse[index]->to->name);
00178 } else {
00179 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pFuse[index]->to->oclass->name,pFuse[index]->to->id);
00180 }
00181
00182
00183 if(pFuse[index]->has_phase(PHASE_A)){
00184 node_voltage = get_complex(pFuse[index]->from,"voltage_A");
00185 } else if(pFuse[index]->has_phase(PHASE_B)){
00186 node_voltage = get_complex(pFuse[index]->from,"voltage_B");
00187 } else if(pFuse[index]->has_phase(PHASE_C)){
00188 node_voltage = get_complex(pFuse[index]->from,"voltage_C");
00189 }
00190
00191 if(node_voltage == NULL){
00192 gl_error("From node has no voltage.");
00193 return 0;
00194 }
00195
00196 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
00197
00198
00199 if(pFuse[index]->has_phase(PHASE_A)){
00200 node_voltage = get_complex(pFuse[index]->to,"voltage_A");
00201 } else if(pFuse[index]->has_phase(PHASE_B)){
00202 node_voltage = get_complex(pFuse[index]->to,"voltage_B");
00203 } else if(pFuse[index]->has_phase(PHASE_C)){
00204 node_voltage = get_complex(pFuse[index]->to,"voltage_C");
00205 }
00206
00207 if(node_voltage == NULL){
00208 gl_error("From node has no voltage.");
00209 return 0;
00210 }
00211
00212 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
00213
00214
00215 if(pFuse[index]->phases == 0x0001){
00216 fprintf(fn,"\t\t<phases>A</phases>\n");
00217 }
00218 if(pFuse[index]->phases == 0x0002){
00219 fprintf(fn,"\t\t<phases>B</phases>\n");
00220 }
00221 if(pFuse[index]->phases == 0x0004){
00222 fprintf(fn,"\t\t<phases>C</phases>\n");
00223 }
00224 if(pFuse[index]->phases == 0x0009){
00225 fprintf(fn,"\t\t<phases>AN</phases>\n");
00226 }
00227 if(pFuse[index]->phases == 0x000a){
00228 fprintf(fn,"\t\t<phases>BN</phases>\n");
00229 }
00230 if(pFuse[index]->phases == 0x000c){
00231 fprintf(fn,"\t\t<phases>CN</phases>\n");
00232 }
00233 if(pFuse[index]->phases == 0x0071){
00234 fprintf(fn,"\t\t<phases>AS</phases>\n");
00235 }
00236 if(pFuse[index]->phases == 0x0072){
00237 fprintf(fn,"\t\t<phases>BS</phases>\n");
00238 }
00239 if(pFuse[index]->phases == 0x0074){
00240 fprintf(fn,"\t\t<phases>CS</phases>\n");
00241 }
00242 if(pFuse[index]->phases == 0x0003){
00243 fprintf(fn,"\t\t<phases>AB</phases>\n");
00244 }
00245 if(pFuse[index]->phases == 0x0006){
00246 fprintf(fn,"\t\t<phases>BC</phases>\n");
00247 }
00248 if(pFuse[index]->phases == 0x0005){
00249 fprintf(fn,"\t\t<phases>AC</phases>\n");
00250 }
00251 if(pFuse[index]->phases == 0x000b){
00252 fprintf(fn,"\t\t<phases>ABN</phases>\n");
00253 }
00254 if(pFuse[index]->phases == 0x000e){
00255 fprintf(fn,"\t\t<phases>BCN</phases>\n");
00256 }
00257 if(pFuse[index]->phases == 0x000d){
00258 fprintf(fn,"\t\t<phases>ACN</phases>\n");
00259 }
00260 if(pFuse[index]->phases == 0x0007){
00261 fprintf(fn,"\t\t<phases>ABC</phases>\n");
00262 }
00263 if(pFuse[index]->phases == 0x000f){
00264 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
00265 }
00266 if(pFuse[index]->phases == 0x0107){
00267 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
00268 }
00269
00270
00271 fprintf(fn,"\t\t<a_matrix>\n");
00272 for(x = 0; x < 3; x++){
00273 for(y = 0; y < 3; y++){
00274 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pFuse[index]->a_mat[x][y].Re(),pFuse[index]->a_mat[x][y].Im(),x+1,y+1);
00275 }
00276 }
00277 fprintf(fn,"\t\t</a_matrix>\n");
00278
00279
00280 fprintf(fn,"\t\t<b_matrix>\n");
00281 for(x = 0; x < 3; x++){
00282 for(y = 0; y < 3; y++){
00283 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pFuse[index]->b_mat[x][y].Re(),pFuse[index]->b_mat[x][y].Im(),x+1,y+1);
00284 }
00285 }
00286 fprintf(fn,"\t\t</b_matrix>\n");
00287
00288
00289 fprintf(fn,"\t\t<c_matrix>\n");
00290 for(x = 0; x < 3; x++){
00291 for(y = 0; y < 3; y++){
00292 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pFuse[index]->c_mat[x][y].Re(),pFuse[index]->c_mat[x][y].Im(),x+1,y+1);
00293 }
00294 }
00295 fprintf(fn,"\t\t</c_matrix>\n");
00296
00297
00298 fprintf(fn,"\t\t<d_matrix>\n");
00299 for(x = 0; x < 3; x++){
00300 for(y = 0; y < 3; y++){
00301 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pFuse[index]->d_mat[x][y].Re(),pFuse[index]->d_mat[x][y].Im(),x+1,y+1);
00302 }
00303 }
00304 fprintf(fn,"\t\t</d_matrix>\n");
00305
00306
00307 fprintf(fn,"\t\t<A_matrix>\n");
00308 for(x = 0; x < 3; x++){
00309 for(y = 0; y < 3; y++){
00310 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pFuse[index]->A_mat[x][y].Re(),pFuse[index]->A_mat[x][y].Im(),x+1,y+1);
00311 }
00312 }
00313 fprintf(fn,"\t\t</A_matrix>\n");
00314
00315
00316 fprintf(fn,"\t\t<B_matrix>\n");
00317 for(x = 0; x < 3; x++){
00318 for(y = 0; y < 3; y++){
00319 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pFuse[index]->B_mat[x][y].Re(),pFuse[index]->B_mat[x][y].Im(),x+1,y+1);
00320 }
00321 }
00322 fprintf(fn,"\t\t</B_matrix>\n");
00323
00324 fprintf(fn,"\t</fuse>\n");
00325
00326 ++index;
00327 }
00328 }
00329
00330 index = 0;
00331
00332 if(ohlines != NULL){
00333 pOhLine = (line **)gl_malloc(ohlines->hit_count*sizeof(line*));
00334 if(pOhLine == NULL){
00335 gl_error("Failed to allocate fuse array.");
00336 return TS_NEVER;
00337 }
00338 while(obj = gl_find_next(ohlines,obj)){
00339 if(index >= ohlines->hit_count){
00340 break;
00341 }
00342 pOhLine[index] = OBJECTDATA(obj,line);
00343 if(pOhLine[index] == NULL){
00344 gl_error("Unable to map object as overhead_line object.");
00345 return 0;
00346 }
00347
00348
00349 fprintf(fn,"\t<overhead_line>\n");
00350
00351
00352 if(obj->name[0] != 0){
00353 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
00354 } else {
00355 fprintf(fn,"\t\t<name>NA</name>\n");
00356 }
00357
00358
00359 fprintf(fn,"\t\t<id>overhead_line:%d</id>\n",obj->id);
00360
00361
00362 if(pOhLine[index]->from->name[0] != 0){
00363 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pOhLine[index]->from->oclass->name,pOhLine[index]->from->name);
00364 } else {
00365 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pOhLine[index]->from->oclass->name,pOhLine[index]->from->id);
00366 }
00367
00368
00369 if(pOhLine[index]->to->name[0] != 0){
00370 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pOhLine[index]->to->oclass->name,pOhLine[index]->to->name);
00371 } else {
00372 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pOhLine[index]->to->oclass->name,pOhLine[index]->to->id);
00373 }
00374
00375
00376 if(pOhLine[index]->has_phase(PHASE_A)){
00377 node_voltage = get_complex(pOhLine[index]->from,"voltage_A");
00378 } else if(pOhLine[index]->has_phase(PHASE_B)){
00379 node_voltage = get_complex(pOhLine[index]->from,"voltage_B");
00380 } else if(pOhLine[index]->has_phase(PHASE_C)){
00381 node_voltage = get_complex(pOhLine[index]->from,"voltage_C");
00382 }
00383
00384 if(node_voltage == NULL){
00385 gl_error("From node has no voltage.");
00386 return 0;
00387 }
00388
00389 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
00390
00391
00392 if(pOhLine[index]->has_phase(PHASE_A)){
00393 node_voltage = get_complex(pOhLine[index]->to,"voltage_A");
00394 } else if(pOhLine[index]->has_phase(PHASE_B)){
00395 node_voltage = get_complex(pOhLine[index]->to,"voltage_B");
00396 } else if(pOhLine[index]->has_phase(PHASE_C)){
00397 node_voltage = get_complex(pOhLine[index]->to,"voltage_C");
00398 }
00399
00400 if(node_voltage == NULL){
00401 gl_error("From node has no voltage.");
00402 return 0;
00403 }
00404
00405 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
00406
00407
00408 if(pOhLine[index]->phases == 0x0001){
00409 fprintf(fn,"\t\t<phases>A</phases>\n");
00410 }
00411 if(pOhLine[index]->phases == 0x0002){
00412 fprintf(fn,"\t\t<phases>B</phases>\n");
00413 }
00414 if(pOhLine[index]->phases == 0x0004){
00415 fprintf(fn,"\t\t<phases>C</phases>\n");
00416 }
00417 if(pOhLine[index]->phases == 0x0009){
00418 fprintf(fn,"\t\t<phases>AN</phases>\n");
00419 }
00420 if(pOhLine[index]->phases == 0x000a){
00421 fprintf(fn,"\t\t<phases>BN</phases>\n");
00422 }
00423 if(pOhLine[index]->phases == 0x000c){
00424 fprintf(fn,"\t\t<phases>CN</phases>\n");
00425 }
00426 if(pOhLine[index]->phases == 0x0071){
00427 fprintf(fn,"\t\t<phases>AS</phases>\n");
00428 }
00429 if(pOhLine[index]->phases == 0x0072){
00430 fprintf(fn,"\t\t<phases>BS</phases>\n");
00431 }
00432 if(pOhLine[index]->phases == 0x0074){
00433 fprintf(fn,"\t\t<phases>CS</phases>\n");
00434 }
00435 if(pOhLine[index]->phases == 0x0003){
00436 fprintf(fn,"\t\t<phases>AB</phases>\n");
00437 }
00438 if(pOhLine[index]->phases == 0x0006){
00439 fprintf(fn,"\t\t<phases>BC</phases>\n");
00440 }
00441 if(pOhLine[index]->phases == 0x0005){
00442 fprintf(fn,"\t\t<phases>AC</phases>\n");
00443 }
00444 if(pOhLine[index]->phases == 0x000b){
00445 fprintf(fn,"\t\t<phases>ABN</phases>\n");
00446 }
00447 if(pOhLine[index]->phases == 0x000e){
00448 fprintf(fn,"\t\t<phases>BCN</phases>\n");
00449 }
00450 if(pOhLine[index]->phases == 0x000d){
00451 fprintf(fn,"\t\t<phases>ACN</phases>\n");
00452 }
00453 if(pOhLine[index]->phases == 0x0007){
00454 fprintf(fn,"\t\t<phases>ABC</phases>\n");
00455 }
00456 if(pOhLine[index]->phases == 0x000f){
00457 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
00458 }
00459 if(pOhLine[index]->phases == 0x0107){
00460 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
00461 }
00462
00463
00464 fprintf(fn,"\t\t<length>%.15f</length>\n",pOhLine[index]->length);
00465
00466
00467 fprintf(fn,"\t\t<a_matrix>\n");
00468 for(x = 0; x < 3; x++){
00469 for(y = 0; y < 3; y++){
00470 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pOhLine[index]->a_mat[x][y].Re(),pOhLine[index]->a_mat[x][y].Im(),x+1,y+1);
00471 }
00472 }
00473 fprintf(fn,"\t\t</a_matrix>\n");
00474
00475
00476 fprintf(fn,"\t\t<b_matrix>\n");
00477 for(x = 0; x < 3; x++){
00478 for(y = 0; y < 3; y++){
00479 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pOhLine[index]->b_mat[x][y].Re(),pOhLine[index]->b_mat[x][y].Im(),x+1,y+1);
00480 }
00481 }
00482 fprintf(fn,"\t\t</b_matrix>\n");
00483
00484
00485 fprintf(fn,"\t\t<c_matrix>\n");
00486 for(x = 0; x < 3; x++){
00487 for(y = 0; y < 3; y++){
00488 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pOhLine[index]->c_mat[x][y].Re(),pOhLine[index]->c_mat[x][y].Im(),x+1,y+1);
00489 }
00490 }
00491 fprintf(fn,"\t\t</c_matrix>\n");
00492
00493
00494 fprintf(fn,"\t\t<d_matrix>\n");
00495 for(x = 0; x < 3; x++){
00496 for(y = 0; y < 3; y++){
00497 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pOhLine[index]->d_mat[x][y].Re(),pOhLine[index]->d_mat[x][y].Im(),x+1,y+1);
00498 }
00499 }
00500 fprintf(fn,"\t\t</d_matrix>\n");
00501
00502
00503 fprintf(fn,"\t\t<A_matrix>\n");
00504 for(x = 0; x < 3; x++){
00505 for(y = 0; y < 3; y++){
00506 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pOhLine[index]->A_mat[x][y].Re(),pOhLine[index]->A_mat[x][y].Im(),x+1,y+1);
00507 }
00508 }
00509 fprintf(fn,"\t\t</A_matrix>\n");
00510
00511
00512 fprintf(fn,"\t\t<B_matrix>\n");
00513 for(x = 0; x < 3; x++){
00514 for(y = 0; y < 3; y++){
00515 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pOhLine[index]->B_mat[x][y].Re(),pOhLine[index]->B_mat[x][y].Im(),x+1,y+1);
00516 }
00517 }
00518 fprintf(fn,"\t\t</B_matrix>\n");
00519
00520 fprintf(fn,"\t</overhead_line>\n");
00521
00522 ++index;
00523 }
00524 }
00525
00526 index = 0;
00527
00528 if(reclosers != NULL){
00529 pRecloser = (link_object **)gl_malloc(reclosers->hit_count*sizeof(link_object*));
00530 if(pRecloser == NULL){
00531 gl_error("Failed to allocate fuse array.");
00532 return TS_NEVER;
00533 }
00534 while(obj = gl_find_next(reclosers,obj)){
00535 if(index >= reclosers->hit_count){
00536 break;
00537 }
00538 pRecloser[index] = OBJECTDATA(obj,link_object);
00539 if(pRecloser[index] == NULL){
00540 gl_error("Unable to map object as a link object.");
00541 return 0;
00542 }
00543
00544
00545 fprintf(fn,"\t<recloser>\n");
00546
00547
00548 if(obj->name[0] != 0){
00549 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
00550 } else {
00551 fprintf(fn,"\t\t<name>NA</name>\n");
00552 }
00553
00554
00555 fprintf(fn,"\t\t<id>recloser:%d</id>\n",obj->id);
00556
00557
00558 if(pRecloser[index]->from->name[0] != 0){
00559 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pRecloser[index]->from->oclass->name,pRecloser[index]->from->name);
00560 } else {
00561 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pRecloser[index]->from->oclass->name,pRecloser[index]->from->id);
00562 }
00563
00564
00565 if(pRecloser[index]->to->name[0] != 0){
00566 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pRecloser[index]->to->oclass->name,pRecloser[index]->to->name);
00567 } else {
00568 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pRecloser[index]->to->oclass->name,pRecloser[index]->to->id);
00569 }
00570
00571
00572 if(pRecloser[index]->has_phase(PHASE_A)){
00573 node_voltage = get_complex(pRecloser[index]->from,"voltage_A");
00574 } else if(pRecloser[index]->has_phase(PHASE_B)){
00575 node_voltage = get_complex(pRecloser[index]->from,"voltage_B");
00576 } else if(pRecloser[index]->has_phase(PHASE_C)){
00577 node_voltage = get_complex(pRecloser[index]->from,"voltage_C");
00578 }
00579
00580 if(node_voltage == NULL){
00581 gl_error("From node has no voltage.");
00582 return 0;
00583 }
00584
00585 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
00586
00587
00588 if(pRecloser[index]->has_phase(PHASE_A)){
00589 node_voltage = get_complex(pRecloser[index]->to,"voltage_A");
00590 } else if(pRecloser[index]->has_phase(PHASE_B)){
00591 node_voltage = get_complex(pRecloser[index]->to,"voltage_B");
00592 } else if(pRecloser[index]->has_phase(PHASE_C)){
00593 node_voltage = get_complex(pRecloser[index]->to,"voltage_C");
00594 }
00595
00596 if(node_voltage == NULL){
00597 gl_error("From node has no voltage.");
00598 return 0;
00599 }
00600
00601 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
00602
00603
00604 if(pRecloser[index]->phases == 0x0001){
00605 fprintf(fn,"\t\t<phases>A</phases>\n");
00606 }
00607 if(pRecloser[index]->phases == 0x0002){
00608 fprintf(fn,"\t\t<phases>B</phases>\n");
00609 }
00610 if(pRecloser[index]->phases == 0x0004){
00611 fprintf(fn,"\t\t<phases>C</phases>\n");
00612 }
00613 if(pRecloser[index]->phases == 0x0009){
00614 fprintf(fn,"\t\t<phases>AN</phases>\n");
00615 }
00616 if(pRecloser[index]->phases == 0x000a){
00617 fprintf(fn,"\t\t<phases>BN</phases>\n");
00618 }
00619 if(pRecloser[index]->phases == 0x000c){
00620 fprintf(fn,"\t\t<phases>CN</phases>\n");
00621 }
00622 if(pRecloser[index]->phases == 0x0071){
00623 fprintf(fn,"\t\t<phases>AS</phases>\n");
00624 }
00625 if(pRecloser[index]->phases == 0x0072){
00626 fprintf(fn,"\t\t<phases>BS</phases>\n");
00627 }
00628 if(pRecloser[index]->phases == 0x0074){
00629 fprintf(fn,"\t\t<phases>CS</phases>\n");
00630 }
00631 if(pRecloser[index]->phases == 0x0003){
00632 fprintf(fn,"\t\t<phases>AB</phases>\n");
00633 }
00634 if(pRecloser[index]->phases == 0x0006){
00635 fprintf(fn,"\t\t<phases>BC</phases>\n");
00636 }
00637 if(pRecloser[index]->phases == 0x0005){
00638 fprintf(fn,"\t\t<phases>AC</phases>\n");
00639 }
00640 if(pRecloser[index]->phases == 0x000b){
00641 fprintf(fn,"\t\t<phases>ABN</phases>\n");
00642 }
00643 if(pRecloser[index]->phases == 0x000e){
00644 fprintf(fn,"\t\t<phases>BCN</phases>\n");
00645 }
00646 if(pRecloser[index]->phases == 0x000d){
00647 fprintf(fn,"\t\t<phases>ACN</phases>\n");
00648 }
00649 if(pRecloser[index]->phases == 0x0007){
00650 fprintf(fn,"\t\t<phases>ABC</phases>\n");
00651 }
00652 if(pRecloser[index]->phases == 0x000f){
00653 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
00654 }
00655 if(pRecloser[index]->phases == 0x0107){
00656 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
00657 }
00658
00659
00660 fprintf(fn,"\t\t<a_matrix>\n");
00661 for(x = 0; x < 3; x++){
00662 for(y = 0; y < 3; y++){
00663 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pRecloser[index]->a_mat[x][y].Re(),pRecloser[index]->a_mat[x][y].Im(),x+1,y+1);
00664 }
00665 }
00666 fprintf(fn,"\t\t</a_matrix>\n");
00667
00668
00669 fprintf(fn,"\t\t<b_matrix>\n");
00670 for(x = 0; x < 3; x++){
00671 for(y = 0; y < 3; y++){
00672 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pRecloser[index]->b_mat[x][y].Re(),pRecloser[index]->b_mat[x][y].Im(),x+1,y+1);
00673 }
00674 }
00675 fprintf(fn,"\t\t</b_matrix>\n");
00676
00677
00678 fprintf(fn,"\t\t<c_matrix>\n");
00679 for(x = 0; x < 3; x++){
00680 for(y = 0; y < 3; y++){
00681 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pRecloser[index]->c_mat[x][y].Re(),pRecloser[index]->c_mat[x][y].Im(),x+1,y+1);
00682 }
00683 }
00684 fprintf(fn,"\t\t</c_matrix>\n");
00685
00686
00687 fprintf(fn,"\t\t<d_matrix>\n");
00688 for(x = 0; x < 3; x++){
00689 for(y = 0; y < 3; y++){
00690 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pRecloser[index]->d_mat[x][y].Re(),pRecloser[index]->d_mat[x][y].Im(),x+1,y+1);
00691 }
00692 }
00693 fprintf(fn,"\t\t</d_matrix>\n");
00694
00695
00696 fprintf(fn,"\t\t<A_matrix>\n");
00697 for(x = 0; x < 3; x++){
00698 for(y = 0; y < 3; y++){
00699 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pRecloser[index]->A_mat[x][y].Re(),pRecloser[index]->A_mat[x][y].Im(),x+1,y+1);
00700 }
00701 }
00702 fprintf(fn,"\t\t</A_matrix>\n");
00703
00704
00705 fprintf(fn,"\t\t<B_matrix>\n");
00706 for(x = 0; x < 3; x++){
00707 for(y = 0; y < 3; y++){
00708 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pRecloser[index]->B_mat[x][y].Re(),pRecloser[index]->B_mat[x][y].Im(),x+1,y+1);
00709 }
00710 }
00711 fprintf(fn,"\t\t</B_matrix>\n");
00712
00713 fprintf(fn,"\t</recloser>\n");
00714
00715 ++index;
00716 }
00717 }
00718
00719 index = 0;
00720
00721 if(regulators != NULL){
00722 pRegulator = (regulator **)gl_malloc(regulators->hit_count*sizeof(regulator*));
00723 if(pRegulator == NULL){
00724 gl_error("Failed to allocate fuse array.");
00725 return TS_NEVER;
00726 }
00727 while(obj = gl_find_next(regulators,obj)){
00728 if(index >= regulators->hit_count){
00729 break;
00730 }
00731 pRegulator[index] = OBJECTDATA(obj,regulator);
00732 if(pRegulator[index] == NULL){
00733 gl_error("Unable to map object as a link object.");
00734 return 0;
00735 }
00736
00737
00738 fprintf(fn,"\t<regulator>\n");
00739
00740
00741 if(obj->name != NULL){
00742 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
00743 } else {
00744 fprintf(fn,"\t\t<name>NA</name>\n");
00745 }
00746
00747
00748 fprintf(fn,"\t\t<id>regulator:%d</id>\n",obj->id);
00749
00750
00751 if(pRegulator[index]->from->name[0] != 0){
00752 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pRegulator[index]->from->oclass->name,pRegulator[index]->from->name);
00753 } else {
00754 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pRegulator[index]->from->oclass->name,pRegulator[index]->from->id);
00755 }
00756
00757
00758 if(pRegulator[index]->to->name[0] != 0){
00759 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pRegulator[index]->to->oclass->name,pRegulator[index]->to->name);
00760 } else {
00761 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pRegulator[index]->to->oclass->name,pRegulator[index]->to->id);
00762 }
00763
00764
00765 if(pRegulator[index]->has_phase(PHASE_A)){
00766 node_voltage = get_complex(pRegulator[index]->from,"voltage_A");
00767 } else if(pRegulator[index]->has_phase(PHASE_B)){
00768 node_voltage = get_complex(pRegulator[index]->from,"voltage_B");
00769 } else if(pRegulator[index]->has_phase(PHASE_C)){
00770 node_voltage = get_complex(pRegulator[index]->from,"voltage_C");
00771 }
00772
00773 if(node_voltage == NULL){
00774 gl_error("From node has no voltage.");
00775 return 0;
00776 }
00777
00778 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
00779
00780
00781 if(pRegulator[index]->has_phase(PHASE_A)){
00782 node_voltage = get_complex(pRegulator[index]->to,"voltage_A");
00783 } else if(pRegulator[index]->has_phase(PHASE_B)){
00784 node_voltage = get_complex(pRegulator[index]->to,"voltage_B");
00785 } else if(pRegulator[index]->has_phase(PHASE_C)){
00786 node_voltage = get_complex(pRegulator[index]->to,"voltage_C");
00787 }
00788
00789 if(node_voltage == NULL){
00790 gl_error("From node has no voltage.");
00791 return 0;
00792 }
00793
00794 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
00795
00796
00797 if(pRegulator[index]->phases == 0x0001){
00798 fprintf(fn,"\t\t<phases>A</phases>\n");
00799 }
00800 if(pRegulator[index]->phases == 0x0002){
00801 fprintf(fn,"\t\t<phases>B</phases>\n");
00802 }
00803 if(pRegulator[index]->phases == 0x0004){
00804 fprintf(fn,"\t\t<phases>C</phases>\n");
00805 }
00806 if(pRegulator[index]->phases == 0x0009){
00807 fprintf(fn,"\t\t<phases>AN</phases>\n");
00808 }
00809 if(pRegulator[index]->phases == 0x000a){
00810 fprintf(fn,"\t\t<phases>BN</phases>\n");
00811 }
00812 if(pRegulator[index]->phases == 0x000c){
00813 fprintf(fn,"\t\t<phases>CN</phases>\n");
00814 }
00815 if(pRegulator[index]->phases == 0x0071){
00816 fprintf(fn,"\t\t<phases>AS</phases>\n");
00817 }
00818 if(pRegulator[index]->phases == 0x0072){
00819 fprintf(fn,"\t\t<phases>BS</phases>\n");
00820 }
00821 if(pRegulator[index]->phases == 0x0074){
00822 fprintf(fn,"\t\t<phases>CS</phases>\n");
00823 }
00824 if(pRegulator[index]->phases == 0x0003){
00825 fprintf(fn,"\t\t<phases>AB</phases>\n");
00826 }
00827 if(pRegulator[index]->phases == 0x0006){
00828 fprintf(fn,"\t\t<phases>BC</phases>\n");
00829 }
00830 if(pRegulator[index]->phases == 0x0005){
00831 fprintf(fn,"\t\t<phases>AC</phases>\n");
00832 }
00833 if(pRegulator[index]->phases == 0x000b){
00834 fprintf(fn,"\t\t<phases>ABN</phases>\n");
00835 }
00836 if(pRegulator[index]->phases == 0x000e){
00837 fprintf(fn,"\t\t<phases>BCN</phases>\n");
00838 }
00839 if(pRegulator[index]->phases == 0x000d){
00840 fprintf(fn,"\t\t<phases>ACN</phases>\n");
00841 }
00842 if(pRegulator[index]->phases == 0x0007){
00843 fprintf(fn,"\t\t<phases>ABC</phases>\n");
00844 }
00845 if(pRegulator[index]->phases == 0x000f){
00846 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
00847 }
00848 if(pRegulator[index]->phases == 0x0107){
00849 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
00850 }
00851
00852
00853 fprintf(fn,"\t\t<tapA>%d</tapA>\n",pRegulator[index]->tap[0]);
00854 fprintf(fn,"\t\t<tapB>%d</tapB>\n",pRegulator[index]->tap[1]);
00855 fprintf(fn,"\t\t<tapC>%d</tapC>\n",pRegulator[index]->tap[2]);
00856
00857 fprintf(fn,"\t\t<a_matrix>\n");
00858 for(x = 0; x < 3; x++){
00859 for(y = 0; y < 3; y++){
00860 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pRegulator[index]->a_mat[x][y].Re(),pRegulator[index]->a_mat[x][y].Im(),x+1,y+1);
00861 }
00862 }
00863 fprintf(fn,"\t\t</a_matrix>\n");
00864
00865
00866 fprintf(fn,"\t\t<b_matrix>\n");
00867 for(x = 0; x < 3; x++){
00868 for(y = 0; y < 3; y++){
00869 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pRegulator[index]->b_mat[x][y].Re(),pRegulator[index]->b_mat[x][y].Im(),x+1,y+1);
00870 }
00871 }
00872 fprintf(fn,"\t\t</b_matrix>\n");
00873
00874
00875 fprintf(fn,"\t\t<c_matrix>\n");
00876 for(x = 0; x < 3; x++){
00877 for(y = 0; y < 3; y++){
00878 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pRegulator[index]->c_mat[x][y].Re(),pRegulator[index]->c_mat[x][y].Im(),x+1,y+1);
00879 }
00880 }
00881 fprintf(fn,"\t\t</c_matrix>\n");
00882
00883
00884 fprintf(fn,"\t\t<d_matrix>\n");
00885 for(x = 0; x < 3; x++){
00886 for(y = 0; y < 3; y++){
00887 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pRegulator[index]->d_mat[x][y].Re(),pRegulator[index]->d_mat[x][y].Im(),x+1,y+1);
00888 }
00889 }
00890 fprintf(fn,"\t\t</d_matrix>\n");
00891
00892
00893 fprintf(fn,"\t\t<A_matrix>\n");
00894 for(x = 0; x < 3; x++){
00895 for(y = 0; y < 3; y++){
00896 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pRegulator[index]->A_mat[x][y].Re(),pRegulator[index]->A_mat[x][y].Im(),x+1,y+1);
00897 }
00898 }
00899 fprintf(fn,"\t\t</A_matrix>\n");
00900
00901
00902 fprintf(fn,"\t\t<B_matrix>\n");
00903 for(x = 0; x < 3; x++){
00904 for(y = 0; y < 3; y++){
00905 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pRegulator[index]->B_mat[x][y].Re(),pRegulator[index]->B_mat[x][y].Im(),x+1,y+1);
00906 }
00907 }
00908 fprintf(fn,"\t\t</B_matrix>\n");
00909
00910 fprintf(fn,"\t</regulator>\n");
00911
00912 ++index;
00913 }
00914 }
00915
00916 index = 0;
00917
00918 if(relays != NULL){
00919 pRelay = (link_object **)gl_malloc(relays->hit_count*sizeof(link_object*));
00920 if(pRelay == NULL){
00921 gl_error("Failed to allocate fuse array.");
00922 return TS_NEVER;
00923 }
00924 while(obj = gl_find_next(relays,obj)){
00925 if(index >= relays->hit_count){
00926 break;
00927 }
00928 pRelay[index] = OBJECTDATA(obj,link_object);
00929 if(pRelay[index] == NULL){
00930 gl_error("Unable to map object as a link object.");
00931 return 0;
00932 }
00933
00934
00935 fprintf(fn,"\t<relay>\n");
00936
00937
00938 if(obj->name[0] != 0){
00939 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
00940 } else {
00941 fprintf(fn,"\t\t<name>NA</name>\n");
00942 }
00943
00944
00945 fprintf(fn,"\t\t<id>relay:%d</id>\n",obj->id);
00946
00947
00948 if(pRelay[index]->from->name[0] != 0){
00949 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pRelay[index]->from->oclass->name,pRelay[index]->from->name);
00950 } else {
00951 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pRelay[index]->from->oclass->name,pRelay[index]->from->id);
00952 }
00953
00954
00955 if(pRelay[index]->to->name[0] != 0){
00956 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pRelay[index]->to->oclass->name,pRelay[index]->to->name);
00957 } else {
00958 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pRelay[index]->to->oclass->name,pRelay[index]->to->id);
00959 }
00960
00961
00962 if(pRelay[index]->has_phase(PHASE_A)){
00963 node_voltage = get_complex(pRelay[index]->from,"voltage_A");
00964 } else if(pRelay[index]->has_phase(PHASE_B)){
00965 node_voltage = get_complex(pRelay[index]->from,"voltage_B");
00966 } else if(pRelay[index]->has_phase(PHASE_C)){
00967 node_voltage = get_complex(pRelay[index]->from,"voltage_C");
00968 }
00969
00970 if(node_voltage == NULL){
00971 gl_error("From node has no voltage.");
00972 return 0;
00973 }
00974
00975 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
00976
00977
00978 if(pRelay[index]->has_phase(PHASE_A)){
00979 node_voltage = get_complex(pRelay[index]->to,"voltage_A");
00980 } else if(pRelay[index]->has_phase(PHASE_B)){
00981 node_voltage = get_complex(pRelay[index]->to,"voltage_B");
00982 } else if(pRelay[index]->has_phase(PHASE_C)){
00983 node_voltage = get_complex(pRelay[index]->to,"voltage_C");
00984 }
00985
00986 if(node_voltage == NULL){
00987 gl_error("From node has no voltage.");
00988 return 0;
00989 }
00990
00991 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
00992
00993
00994 if(pRelay[index]->phases == 0x0001){
00995 fprintf(fn,"\t\t<phases>A</phases>\n");
00996 }
00997 if(pRelay[index]->phases == 0x0002){
00998 fprintf(fn,"\t\t<phases>B</phases>\n");
00999 }
01000 if(pRelay[index]->phases == 0x0004){
01001 fprintf(fn,"\t\t<phases>C</phases>\n");
01002 }
01003 if(pRelay[index]->phases == 0x0009){
01004 fprintf(fn,"\t\t<phases>AN</phases>\n");
01005 }
01006 if(pRelay[index]->phases == 0x000a){
01007 fprintf(fn,"\t\t<phases>BN</phases>\n");
01008 }
01009 if(pRelay[index]->phases == 0x000c){
01010 fprintf(fn,"\t\t<phases>CN</phases>\n");
01011 }
01012 if(pRelay[index]->phases == 0x0071){
01013 fprintf(fn,"\t\t<phases>AS</phases>\n");
01014 }
01015 if(pRelay[index]->phases == 0x0072){
01016 fprintf(fn,"\t\t<phases>BS</phases>\n");
01017 }
01018 if(pRelay[index]->phases == 0x0074){
01019 fprintf(fn,"\t\t<phases>CS</phases>\n");
01020 }
01021 if(pRelay[index]->phases == 0x0003){
01022 fprintf(fn,"\t\t<phases>AB</phases>\n");
01023 }
01024 if(pRelay[index]->phases == 0x0006){
01025 fprintf(fn,"\t\t<phases>BC</phases>\n");
01026 }
01027 if(pRelay[index]->phases == 0x0005){
01028 fprintf(fn,"\t\t<phases>AC</phases>\n");
01029 }
01030 if(pRelay[index]->phases == 0x000b){
01031 fprintf(fn,"\t\t<phases>ABN</phases>\n");
01032 }
01033 if(pRelay[index]->phases == 0x000e){
01034 fprintf(fn,"\t\t<phases>BCN</phases>\n");
01035 }
01036 if(pRelay[index]->phases == 0x000d){
01037 fprintf(fn,"\t\t<phases>ACN</phases>\n");
01038 }
01039 if(pRelay[index]->phases == 0x0007){
01040 fprintf(fn,"\t\t<phases>ABC</phases>\n");
01041 }
01042 if(pRelay[index]->phases == 0x000f){
01043 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
01044 }
01045 if(pRelay[index]->phases == 0x0107){
01046 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
01047 }
01048
01049
01050 fprintf(fn,"\t\t<a_matrix>\n");
01051 for(x = 0; x < 3; x++){
01052 for(y = 0; y < 3; y++){
01053 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pRelay[index]->a_mat[x][y].Re(),pRelay[index]->a_mat[x][y].Im(),x+1,y+1);
01054 }
01055 }
01056 fprintf(fn,"\t\t</a_matrix>\n");
01057
01058
01059 fprintf(fn,"\t\t<b_matrix>\n");
01060 for(x = 0; x < 3; x++){
01061 for(y = 0; y < 3; y++){
01062 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pRelay[index]->b_mat[x][y].Re(),pRelay[index]->b_mat[x][y].Im(),x+1,y+1);
01063 }
01064 }
01065 fprintf(fn,"\t\t</b_matrix>\n");
01066
01067
01068 fprintf(fn,"\t\t<c_matrix>\n");
01069 for(x = 0; x < 3; x++){
01070 for(y = 0; y < 3; y++){
01071 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pRelay[index]->c_mat[x][y].Re(),pRelay[index]->c_mat[x][y].Im(),x+1,y+1);
01072 }
01073 }
01074 fprintf(fn,"\t\t</c_matrix>\n");
01075
01076
01077 fprintf(fn,"\t\t<d_matrix>\n");
01078 for(x = 0; x < 3; x++){
01079 for(y = 0; y < 3; y++){
01080 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pRelay[index]->d_mat[x][y].Re(),pRelay[index]->d_mat[x][y].Im(),x+1,y+1);
01081 }
01082 }
01083 fprintf(fn,"\t\t</d_matrix>\n");
01084
01085
01086 fprintf(fn,"\t\t<A_matrix>\n");
01087 for(x = 0; x < 3; x++){
01088 for(y = 0; y < 3; y++){
01089 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pRelay[index]->A_mat[x][y].Re(),pRelay[index]->A_mat[x][y].Im(),x+1,y+1);
01090 }
01091 }
01092 fprintf(fn,"\t\t</A_matrix>\n");
01093
01094
01095 fprintf(fn,"\t\t<B_matrix>\n");
01096 for(x = 0; x < 3; x++){
01097 for(y = 0; y < 3; y++){
01098 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pRelay[index]->B_mat[x][y].Re(),pRelay[index]->B_mat[x][y].Im(),x+1,y+1);
01099 }
01100 }
01101 fprintf(fn,"\t\t</B_matrix>\n");
01102
01103 fprintf(fn,"\t</relay>\n");
01104
01105 ++index;
01106 }
01107 }
01108
01109 index = 0;
01110
01111 if(sectionalizers != NULL){
01112 pSectionalizer = (link_object **)gl_malloc(sectionalizers->hit_count*sizeof(link_object*));
01113 if(pSectionalizer == NULL){
01114 gl_error("Failed to allocate fuse array.");
01115 return TS_NEVER;
01116 }
01117 while(obj = gl_find_next(sectionalizers,obj)){
01118 if(index >= sectionalizers->hit_count){
01119 break;
01120 }
01121 pSectionalizer[index] = OBJECTDATA(obj,link_object);
01122 if(pSectionalizer[index] == NULL){
01123 gl_error("Unable to map object as a link object.");
01124 return 0;
01125 }
01126
01127
01128 fprintf(fn,"\t<sectionalizer>\n");
01129
01130
01131 if(obj->name[0] != 0){
01132 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
01133 } else {
01134 fprintf(fn,"\t\t<name>NA</name>\n");
01135 }
01136
01137
01138 fprintf(fn,"\t\t<id>sectionalizer:%d</id>\n",obj->id);
01139
01140
01141 if(pSectionalizer[index]->from->name[0] != 0){
01142 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pSectionalizer[index]->from->oclass->name,pSectionalizer[index]->from->name);
01143 } else {
01144 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pSectionalizer[index]->from->oclass->name,pSectionalizer[index]->from->id);
01145 }
01146
01147
01148 if(pSectionalizer[index]->to->name[0] != 0){
01149 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pSectionalizer[index]->to->oclass->name,pSectionalizer[index]->to->name);
01150 } else {
01151 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pSectionalizer[index]->to->oclass->name,pSectionalizer[index]->to->id);
01152 }
01153
01154
01155 if(pSectionalizer[index]->has_phase(PHASE_A)){
01156 node_voltage = get_complex(pSectionalizer[index]->from,"voltage_A");
01157 } else if(pSectionalizer[index]->has_phase(PHASE_B)){
01158 node_voltage = get_complex(pSectionalizer[index]->from,"voltage_B");
01159 } else if(pSectionalizer[index]->has_phase(PHASE_C)){
01160 node_voltage = get_complex(pSectionalizer[index]->from,"voltage_C");
01161 }
01162
01163 if(node_voltage == NULL){
01164 gl_error("From node has no voltage.");
01165 return 0;
01166 }
01167
01168 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
01169
01170
01171 if(pSectionalizer[index]->has_phase(PHASE_A)){
01172 node_voltage = get_complex(pSectionalizer[index]->to,"voltage_A");
01173 } else if(pSectionalizer[index]->has_phase(PHASE_B)){
01174 node_voltage = get_complex(pSectionalizer[index]->to,"voltage_B");
01175 } else if(pSectionalizer[index]->has_phase(PHASE_C)){
01176 node_voltage = get_complex(pSectionalizer[index]->to,"voltage_C");
01177 }
01178
01179 if(node_voltage == NULL){
01180 gl_error("From node has no voltage.");
01181 return 0;
01182 }
01183
01184 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
01185
01186
01187 if(pSectionalizer[index]->phases == 0x0001){
01188 fprintf(fn,"\t\t<phases>A</phases>\n");
01189 }
01190 if(pSectionalizer[index]->phases == 0x0002){
01191 fprintf(fn,"\t\t<phases>B</phases>\n");
01192 }
01193 if(pSectionalizer[index]->phases == 0x0004){
01194 fprintf(fn,"\t\t<phases>C</phases>\n");
01195 }
01196 if(pSectionalizer[index]->phases == 0x0009){
01197 fprintf(fn,"\t\t<phases>AN</phases>\n");
01198 }
01199 if(pSectionalizer[index]->phases == 0x000a){
01200 fprintf(fn,"\t\t<phases>BN</phases>\n");
01201 }
01202 if(pSectionalizer[index]->phases == 0x000c){
01203 fprintf(fn,"\t\t<phases>CN</phases>\n");
01204 }
01205 if(pSectionalizer[index]->phases == 0x0071){
01206 fprintf(fn,"\t\t<phases>AS</phases>\n");
01207 }
01208 if(pSectionalizer[index]->phases == 0x0072){
01209 fprintf(fn,"\t\t<phases>BS</phases>\n");
01210 }
01211 if(pSectionalizer[index]->phases == 0x0074){
01212 fprintf(fn,"\t\t<phases>CS</phases>\n");
01213 }
01214 if(pSectionalizer[index]->phases == 0x0003){
01215 fprintf(fn,"\t\t<phases>AB</phases>\n");
01216 }
01217 if(pSectionalizer[index]->phases == 0x0006){
01218 fprintf(fn,"\t\t<phases>BC</phases>\n");
01219 }
01220 if(pSectionalizer[index]->phases == 0x0005){
01221 fprintf(fn,"\t\t<phases>AC</phases>\n");
01222 }
01223 if(pSectionalizer[index]->phases == 0x000b){
01224 fprintf(fn,"\t\t<phases>ABN</phases>\n");
01225 }
01226 if(pSectionalizer[index]->phases == 0x000e){
01227 fprintf(fn,"\t\t<phases>BCN</phases>\n");
01228 }
01229 if(pSectionalizer[index]->phases == 0x000d){
01230 fprintf(fn,"\t\t<phases>ACN</phases>\n");
01231 }
01232 if(pSectionalizer[index]->phases == 0x0007){
01233 fprintf(fn,"\t\t<phases>ABC</phases>\n");
01234 }
01235 if(pSectionalizer[index]->phases == 0x000f){
01236 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
01237 }
01238 if(pSectionalizer[index]->phases == 0x0107){
01239 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
01240 }
01241
01242
01243 fprintf(fn,"\t\t<a_matrix>\n");
01244 for(x = 0; x < 3; x++){
01245 for(y = 0; y < 3; y++){
01246 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pSectionalizer[index]->a_mat[x][y].Re(),pSectionalizer[index]->a_mat[x][y].Im(),x+1,y+1);
01247 }
01248 }
01249 fprintf(fn,"\t\t</a_matrix>\n");
01250
01251
01252 fprintf(fn,"\t\t<b_matrix>\n");
01253 for(x = 0; x < 3; x++){
01254 for(y = 0; y < 3; y++){
01255 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pSectionalizer[index]->b_mat[x][y].Re(),pSectionalizer[index]->b_mat[x][y].Im(),x+1,y+1);
01256 }
01257 }
01258 fprintf(fn,"\t\t</b_matrix>\n");
01259
01260
01261 fprintf(fn,"\t\t<c_matrix>\n");
01262 for(x = 0; x < 3; x++){
01263 for(y = 0; y < 3; y++){
01264 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pSectionalizer[index]->c_mat[x][y].Re(),pSectionalizer[index]->c_mat[x][y].Im(),x+1,y+1);
01265 }
01266 }
01267 fprintf(fn,"\t\t</c_matrix>\n");
01268
01269
01270 fprintf(fn,"\t\t<d_matrix>\n");
01271 for(x = 0; x < 3; x++){
01272 for(y = 0; y < 3; y++){
01273 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pSectionalizer[index]->d_mat[x][y].Re(),pSectionalizer[index]->d_mat[x][y].Im(),x+1,y+1);
01274 }
01275 }
01276 fprintf(fn,"\t\t</d_matrix>\n");
01277
01278
01279 fprintf(fn,"\t\t<A_matrix>\n");
01280 for(x = 0; x < 3; x++){
01281 for(y = 0; y < 3; y++){
01282 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pSectionalizer[index]->A_mat[x][y].Re(),pSectionalizer[index]->A_mat[x][y].Im(),x+1,y+1);
01283 }
01284 }
01285 fprintf(fn,"\t\t</A_matrix>\n");
01286
01287
01288 fprintf(fn,"\t\t<B_matrix>\n");
01289 for(x = 0; x < 3; x++){
01290 for(y = 0; y < 3; y++){
01291 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pSectionalizer[index]->B_mat[x][y].Re(),pSectionalizer[index]->B_mat[x][y].Im(),x+1,y+1);
01292 }
01293 }
01294 fprintf(fn,"\t\t</B_matrix>\n");
01295
01296 fprintf(fn,"\t</sectionalizer>\n");
01297
01298 ++index;
01299 }
01300 }
01301
01302 index = 0;
01303
01304 if(series_reactors != NULL){
01305 pSeriesReactor = (link_object **)gl_malloc(series_reactors->hit_count*sizeof(link_object*));
01306 if(pSeriesReactor == NULL){
01307 gl_error("Failed to allocate fuse array.");
01308 return TS_NEVER;
01309 }
01310 while(obj = gl_find_next(series_reactors,obj)){
01311 if(index >= series_reactors->hit_count){
01312 break;
01313 }
01314 pSeriesReactor[index] = OBJECTDATA(obj,link_object);
01315 if(pSeriesReactor[index] == NULL){
01316 gl_error("Unable to map object as a link object.");
01317 return 0;
01318 }
01319
01320
01321 fprintf(fn,"\t<series reactor>\n");
01322
01323
01324 if(obj->name[0] != 0){
01325 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
01326 } else {
01327 fprintf(fn,"\t\t<name>NA</name>\n");
01328 }
01329
01330
01331 fprintf(fn,"\t\t<id>series_reactor:%d</id>\n",obj->id);
01332
01333
01334 if(pSeriesReactor[index]->from->name[0] != 0){
01335 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pSeriesReactor[index]->from->oclass->name,pSeriesReactor[index]->from->name);
01336 } else {
01337 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pSeriesReactor[index]->from->oclass->name,pSeriesReactor[index]->from->id);
01338 }
01339
01340
01341 if(pSeriesReactor[index]->to->name[0] != 0){
01342 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pSeriesReactor[index]->to->oclass->name,pSeriesReactor[index]->to->name);
01343 } else {
01344 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pSeriesReactor[index]->to->oclass->name,pSeriesReactor[index]->to->id);
01345 }
01346
01347
01348 if(pSeriesReactor[index]->has_phase(PHASE_A)){
01349 node_voltage = get_complex(pSeriesReactor[index]->from,"voltage_A");
01350 } else if(pSeriesReactor[index]->has_phase(PHASE_B)){
01351 node_voltage = get_complex(pSeriesReactor[index]->from,"voltage_B");
01352 } else if(pSeriesReactor[index]->has_phase(PHASE_C)){
01353 node_voltage = get_complex(pSeriesReactor[index]->from,"voltage_C");
01354 }
01355
01356 if(node_voltage == NULL){
01357 gl_error("From node has no voltage.");
01358 return 0;
01359 }
01360
01361 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
01362
01363
01364 if(pSeriesReactor[index]->has_phase(PHASE_A)){
01365 node_voltage = get_complex(pSeriesReactor[index]->to,"voltage_A");
01366 } else if(pSeriesReactor[index]->has_phase(PHASE_B)){
01367 node_voltage = get_complex(pSeriesReactor[index]->to,"voltage_B");
01368 } else if(pSeriesReactor[index]->has_phase(PHASE_C)){
01369 node_voltage = get_complex(pSeriesReactor[index]->to,"voltage_C");
01370 }
01371
01372 if(node_voltage == NULL){
01373 gl_error("From node has no voltage.");
01374 return 0;
01375 }
01376
01377 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
01378
01379
01380 if(pSeriesReactor[index]->phases == 0x0001){
01381 fprintf(fn,"\t\t<phases>A</phases>\n");
01382 }
01383 if(pSeriesReactor[index]->phases == 0x0002){
01384 fprintf(fn,"\t\t<phases>B</phases>\n");
01385 }
01386 if(pSeriesReactor[index]->phases == 0x0004){
01387 fprintf(fn,"\t\t<phases>C</phases>\n");
01388 }
01389 if(pSeriesReactor[index]->phases == 0x0009){
01390 fprintf(fn,"\t\t<phases>AN</phases>\n");
01391 }
01392 if(pSeriesReactor[index]->phases == 0x000a){
01393 fprintf(fn,"\t\t<phases>BN</phases>\n");
01394 }
01395 if(pSeriesReactor[index]->phases == 0x000c){
01396 fprintf(fn,"\t\t<phases>CN</phases>\n");
01397 }
01398 if(pSeriesReactor[index]->phases == 0x0071){
01399 fprintf(fn,"\t\t<phases>AS</phases>\n");
01400 }
01401 if(pSeriesReactor[index]->phases == 0x0072){
01402 fprintf(fn,"\t\t<phases>BS</phases>\n");
01403 }
01404 if(pSeriesReactor[index]->phases == 0x0074){
01405 fprintf(fn,"\t\t<phases>CS</phases>\n");
01406 }
01407 if(pSeriesReactor[index]->phases == 0x0003){
01408 fprintf(fn,"\t\t<phases>AB</phases>\n");
01409 }
01410 if(pSeriesReactor[index]->phases == 0x0006){
01411 fprintf(fn,"\t\t<phases>BC</phases>\n");
01412 }
01413 if(pSeriesReactor[index]->phases == 0x0005){
01414 fprintf(fn,"\t\t<phases>AC</phases>\n");
01415 }
01416 if(pSeriesReactor[index]->phases == 0x000b){
01417 fprintf(fn,"\t\t<phases>ABN</phases>\n");
01418 }
01419 if(pSeriesReactor[index]->phases == 0x000e){
01420 fprintf(fn,"\t\t<phases>BCN</phases>\n");
01421 }
01422 if(pSeriesReactor[index]->phases == 0x000d){
01423 fprintf(fn,"\t\t<phases>ACN</phases>\n");
01424 }
01425 if(pSeriesReactor[index]->phases == 0x0007){
01426 fprintf(fn,"\t\t<phases>ABC</phases>\n");
01427 }
01428 if(pSeriesReactor[index]->phases == 0x000f){
01429 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
01430 }
01431 if(pSeriesReactor[index]->phases == 0x0107){
01432 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
01433 }
01434
01435
01436 fprintf(fn,"\t\t<a_matrix>\n");
01437 for(x = 0; x < 3; x++){
01438 for(y = 0; y < 3; y++){
01439 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pSeriesReactor[index]->a_mat[x][y].Re(),pSeriesReactor[index]->a_mat[x][y].Im(),x+1,y+1);
01440 }
01441 }
01442 fprintf(fn,"\t\t</a_matrix>\n");
01443
01444
01445 fprintf(fn,"\t\t<b_matrix>\n");
01446 for(x = 0; x < 3; x++){
01447 for(y = 0; y < 3; y++){
01448 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pSeriesReactor[index]->b_mat[x][y].Re(),pSeriesReactor[index]->b_mat[x][y].Im(),x+1,y+1);
01449 }
01450 }
01451 fprintf(fn,"\t\t</b_matrix>\n");
01452
01453
01454 fprintf(fn,"\t\t<c_matrix>\n");
01455 for(x = 0; x < 3; x++){
01456 for(y = 0; y < 3; y++){
01457 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pSeriesReactor[index]->c_mat[x][y].Re(),pSeriesReactor[index]->c_mat[x][y].Im(),x+1,y+1);
01458 }
01459 }
01460 fprintf(fn,"\t\t</c_matrix>\n");
01461
01462
01463 fprintf(fn,"\t\t<d_matrix>\n");
01464 for(x = 0; x < 3; x++){
01465 for(y = 0; y < 3; y++){
01466 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pSeriesReactor[index]->d_mat[x][y].Re(),pSeriesReactor[index]->d_mat[x][y].Im(),x+1,y+1);
01467 }
01468 }
01469 fprintf(fn,"\t\t</d_matrix>\n");
01470
01471
01472 fprintf(fn,"\t\t<A_matrix>\n");
01473 for(x = 0; x < 3; x++){
01474 for(y = 0; y < 3; y++){
01475 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pSeriesReactor[index]->A_mat[x][y].Re(),pSeriesReactor[index]->A_mat[x][y].Im(),x+1,y+1);
01476 }
01477 }
01478 fprintf(fn,"\t\t</A_matrix>\n");
01479
01480
01481 fprintf(fn,"\t\t<B_matrix>\n");
01482 for(x = 0; x < 3; x++){
01483 for(y = 0; y < 3; y++){
01484 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pSeriesReactor[index]->B_mat[x][y].Re(),pSeriesReactor[index]->B_mat[x][y].Im(),x+1,y+1);
01485 }
01486 }
01487 fprintf(fn,"\t\t</B_matrix>\n");
01488
01489 fprintf(fn,"\t</sereis reactor>\n");
01490
01491 ++index;
01492 }
01493 }
01494
01495 index = 0;
01496
01497 if(switches != NULL){
01498 pSwitch = (switch_object **)gl_malloc(switches->hit_count*sizeof(switch_object*));
01499 if(pSwitch == NULL){
01500 gl_error("Failed to allocate fuse array.");
01501 return TS_NEVER;
01502 }
01503 while(obj = gl_find_next(switches,obj)){
01504 if(index >= switches->hit_count){
01505 break;
01506 }
01507 pSwitch[index] = OBJECTDATA(obj,switch_object);
01508 if(pSwitch[index] == NULL){
01509 gl_error("Unable to map object as a link object.");
01510 return 0;
01511 }
01512
01513
01514 if (pSwitch[index]->phase_A_state==1) {
01515 fprintf(fn,"\t<switch>\n");
01516
01517
01518 if(obj->name[0] != 0){
01519 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
01520 } else {
01521 fprintf(fn,"\t\t<name>NA</name>\n");
01522 }
01523
01524
01525 fprintf(fn,"\t\t<id>switch:%d</id>\n",obj->id);
01526
01527
01528 if(pSwitch[index]->from->name[0] != 0){
01529 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pSwitch[index]->from->oclass->name,pSwitch[index]->from->name);
01530 } else {
01531 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pSwitch[index]->from->oclass->name,pSwitch[index]->from->id);
01532 }
01533
01534
01535 if(pSwitch[index]->to->name[0] != 0){
01536 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pSwitch[index]->to->oclass->name,pSwitch[index]->to->name);
01537 } else {
01538 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pSwitch[index]->to->oclass->name,pSwitch[index]->to->id);
01539 }
01540
01541
01542 if(pSwitch[index]->has_phase(PHASE_A)){
01543 node_voltage = get_complex(pSwitch[index]->from,"voltage_A");
01544 } else if(pSwitch[index]->has_phase(PHASE_B)){
01545 node_voltage = get_complex(pSwitch[index]->from,"voltage_B");
01546 } else if(pSwitch[index]->has_phase(PHASE_C)){
01547 node_voltage = get_complex(pSwitch[index]->from,"voltage_C");
01548 }
01549
01550 if(node_voltage == NULL){
01551 gl_error("From node has no voltage.");
01552 return 0;
01553 }
01554
01555 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
01556
01557
01558 if(pSwitch[index]->has_phase(PHASE_A)){
01559 node_voltage = get_complex(pSwitch[index]->to,"voltage_A");
01560 } else if(pSwitch[index]->has_phase(PHASE_B)){
01561 node_voltage = get_complex(pSwitch[index]->to,"voltage_B");
01562 } else if(pSwitch[index]->has_phase(PHASE_C)){
01563 node_voltage = get_complex(pSwitch[index]->to,"voltage_C");
01564 }
01565
01566 if(node_voltage == NULL){
01567 gl_error("From node has no voltage.");
01568 return 0;
01569 }
01570
01571 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
01572
01573
01574 if(pSwitch[index]->phases == 0x0001){
01575 fprintf(fn,"\t\t<phases>A</phases>\n");
01576 }
01577 if(pSwitch[index]->phases == 0x0002){
01578 fprintf(fn,"\t\t<phases>B</phases>\n");
01579 }
01580 if(pSwitch[index]->phases == 0x0004){
01581 fprintf(fn,"\t\t<phases>C</phases>\n");
01582 }
01583 if(pSwitch[index]->phases == 0x0009){
01584 fprintf(fn,"\t\t<phases>AN</phases>\n");
01585 }
01586 if(pSwitch[index]->phases == 0x000a){
01587 fprintf(fn,"\t\t<phases>BN</phases>\n");
01588 }
01589 if(pSwitch[index]->phases == 0x000c){
01590 fprintf(fn,"\t\t<phases>CN</phases>\n");
01591 }
01592 if(pSwitch[index]->phases == 0x0071){
01593 fprintf(fn,"\t\t<phases>AS</phases>\n");
01594 }
01595 if(pSwitch[index]->phases == 0x0072){
01596 fprintf(fn,"\t\t<phases>BS</phases>\n");
01597 }
01598 if(pSwitch[index]->phases == 0x0074){
01599 fprintf(fn,"\t\t<phases>CS</phases>\n");
01600 }
01601 if(pSwitch[index]->phases == 0x0003){
01602 fprintf(fn,"\t\t<phases>AB</phases>\n");
01603 }
01604 if(pSwitch[index]->phases == 0x0006){
01605 fprintf(fn,"\t\t<phases>BC</phases>\n");
01606 }
01607 if(pSwitch[index]->phases == 0x0005){
01608 fprintf(fn,"\t\t<phases>AC</phases>\n");
01609 }
01610 if(pSwitch[index]->phases == 0x000b){
01611 fprintf(fn,"\t\t<phases>ABN</phases>\n");
01612 }
01613 if(pSwitch[index]->phases == 0x000e){
01614 fprintf(fn,"\t\t<phases>BCN</phases>\n");
01615 }
01616 if(pSwitch[index]->phases == 0x000d){
01617 fprintf(fn,"\t\t<phases>ACN</phases>\n");
01618 }
01619 if(pSwitch[index]->phases == 0x0007){
01620 fprintf(fn,"\t\t<phases>ABC</phases>\n");
01621 }
01622 if(pSwitch[index]->phases == 0x000f){
01623 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
01624 }
01625 if(pSwitch[index]->phases == 0x0107){
01626 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
01627 }
01628
01629
01630 fprintf(fn,"\t\t<a_matrix>\n");
01631 for(x = 0; x < 3; x++){
01632 for(y = 0; y < 3; y++){
01633 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pSwitch[index]->a_mat[x][y].Re(),pSwitch[index]->a_mat[x][y].Im(),x+1,y+1);
01634 }
01635 }
01636 fprintf(fn,"\t\t</a_matrix>\n");
01637
01638
01639 fprintf(fn,"\t\t<b_matrix>\n");
01640 for(x = 0; x < 3; x++){
01641 for(y = 0; y < 3; y++){
01642 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pSwitch[index]->b_mat[x][y].Re(),pSwitch[index]->b_mat[x][y].Im(),x+1,y+1);
01643 }
01644 }
01645 fprintf(fn,"\t\t</b_matrix>\n");
01646
01647
01648 fprintf(fn,"\t\t<c_matrix>\n");
01649 for(x = 0; x < 3; x++){
01650 for(y = 0; y < 3; y++){
01651 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pSwitch[index]->c_mat[x][y].Re(),pSwitch[index]->c_mat[x][y].Im(),x+1,y+1);
01652 }
01653 }
01654 fprintf(fn,"\t\t</c_matrix>\n");
01655
01656
01657 fprintf(fn,"\t\t<d_matrix>\n");
01658 for(x = 0; x < 3; x++){
01659 for(y = 0; y < 3; y++){
01660 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pSwitch[index]->d_mat[x][y].Re(),pSwitch[index]->d_mat[x][y].Im(),x+1,y+1);
01661 }
01662 }
01663 fprintf(fn,"\t\t</d_matrix>\n");
01664
01665
01666 fprintf(fn,"\t\t<A_matrix>\n");
01667 for(x = 0; x < 3; x++){
01668 for(y = 0; y < 3; y++){
01669 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pSwitch[index]->A_mat[x][y].Re(),pSwitch[index]->A_mat[x][y].Im(),x+1,y+1);
01670 }
01671 }
01672 fprintf(fn,"\t\t</A_matrix>\n");
01673
01674
01675 fprintf(fn,"\t\t<B_matrix>\n");
01676 for(x = 0; x < 3; x++){
01677 for(y = 0; y < 3; y++){
01678 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pSwitch[index]->B_mat[x][y].Re(),pSwitch[index]->B_mat[x][y].Im(),x+1,y+1);
01679 }
01680 }
01681 fprintf(fn,"\t\t</B_matrix>\n");
01682
01683 fprintf(fn,"\t</switch>\n");
01684
01685 ++index;
01686 }
01687 }
01688 }
01689
01690 index = 0;
01691
01692 if(transformers != NULL){
01693 pTransformer = (transformer **)gl_malloc(transformers->hit_count*sizeof(transformer*));
01694 if(pTransformer == NULL){
01695 gl_error("Failed to allocate fuse array.");
01696 return TS_NEVER;
01697 }
01698 while(obj = gl_find_next(transformers,obj)){
01699 if(index >= transformers->hit_count){
01700 break;
01701 }
01702 pTransformer[index] = OBJECTDATA(obj,transformer);
01703 if(pTransformer[index] == NULL){
01704 gl_error("Unable to map object as a link object.");
01705 return 0;
01706 }
01707
01708
01709 fprintf(fn,"\t<transformer>\n");
01710
01711
01712 if(obj->name[0] != 0){
01713 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
01714 } else {
01715 fprintf(fn,"\t\t<name>NA</name>\n");
01716 }
01717
01718
01719 fprintf(fn,"\t\t<id>transformer:%d</id>\n",obj->id);
01720
01721
01722 if(pTransformer[index]->from->name[0] != 0){
01723 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pTransformer[index]->from->oclass->name,pTransformer[index]->from->name);
01724 } else {
01725 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pTransformer[index]->from->oclass->name,pTransformer[index]->from->id);
01726 }
01727
01728
01729
01730 if(pTransformer[index]->to->name[0] != 0){
01731 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pTransformer[index]->to->oclass->name,pTransformer[index]->to->name);
01732 } else {
01733 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pTransformer[index]->to->oclass->name,pTransformer[index]->to->id);
01734 }
01735
01736
01737
01738 if(pTransformer[index]->has_phase(PHASE_A)){
01739 node_voltage = get_complex(pTransformer[index]->from,"voltage_A");
01740 } else if(pTransformer[index]->has_phase(PHASE_B)){
01741 node_voltage = get_complex(pTransformer[index]->from,"voltage_B");
01742 } else if(pTransformer[index]->has_phase(PHASE_C)){
01743 node_voltage = get_complex(pTransformer[index]->from,"voltage_C");
01744 }
01745
01746
01747 if(node_voltage == NULL){
01748 gl_error("From node %s has no voltage.",pTransformer[index]->from->name);
01749 return 0;
01750 }
01751
01752 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
01753
01754
01755 if(pTransformer[index]->SpecialLnk == SPLITPHASE) {
01756 node_voltage = get_complex(pTransformer[index]->to,"voltage_12");
01757 } else {
01758 if(pTransformer[index]->has_phase(PHASE_A)){
01759 node_voltage = get_complex(pTransformer[index]->to,"voltage_A");
01760 } else if(pTransformer[index]->has_phase(PHASE_B)){
01761 node_voltage = get_complex(pTransformer[index]->to,"voltage_B");
01762 } else if(pTransformer[index]->has_phase(PHASE_C)){
01763 node_voltage = get_complex(pTransformer[index]->to,"voltage_C");
01764 }
01765 }
01766
01767 if(node_voltage == NULL){
01768 gl_error("To node %s has no voltage.",pTransformer[index]->to->name);
01769 return 0;
01770 }
01771
01772 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
01773
01774
01775
01776 fprintf(fn,"\t\t<xfmr_config>%u</xfmr_config>\n",pTransformer[index]->config->connect_type);
01777
01778
01779 if(pTransformer[index]->phases == 0x0001){
01780 fprintf(fn,"\t\t<phases>A</phases>\n");
01781 }
01782 if(pTransformer[index]->phases == 0x0002){
01783 fprintf(fn,"\t\t<phases>B</phases>\n");
01784 }
01785 if(pTransformer[index]->phases == 0x0004){
01786 fprintf(fn,"\t\t<phases>C</phases>\n");
01787 }
01788 if(pTransformer[index]->phases == 0x0009){
01789 fprintf(fn,"\t\t<phases>AN</phases>\n");
01790 }
01791 if(pTransformer[index]->phases == 0x000a){
01792 fprintf(fn,"\t\t<phases>BN</phases>\n");
01793 }
01794 if(pTransformer[index]->phases == 0x000c){
01795 fprintf(fn,"\t\t<phases>CN</phases>\n");
01796 }
01797 if(pTransformer[index]->phases == 0x0071){
01798 fprintf(fn,"\t\t<phases>AS</phases>\n");
01799 }
01800 if(pTransformer[index]->phases == 0x0072){
01801 fprintf(fn,"\t\t<phases>BS</phases>\n");
01802 }
01803 if(pTransformer[index]->phases == 0x0074){
01804 fprintf(fn,"\t\t<phases>CS</phases>\n");
01805 }
01806 if(pTransformer[index]->phases == 0x0003){
01807 fprintf(fn,"\t\t<phases>AB</phases>\n");
01808 }
01809 if(pTransformer[index]->phases == 0x0006){
01810 fprintf(fn,"\t\t<phases>BC</phases>\n");
01811 }
01812 if(pTransformer[index]->phases == 0x0005){
01813 fprintf(fn,"\t\t<phases>AC</phases>\n");
01814 }
01815 if(pTransformer[index]->phases == 0x000b){
01816 fprintf(fn,"\t\t<phases>ABN</phases>\n");
01817 }
01818 if(pTransformer[index]->phases == 0x000e){
01819 fprintf(fn,"\t\t<phases>BCN</phases>\n");
01820 }
01821 if(pTransformer[index]->phases == 0x000d){
01822 fprintf(fn,"\t\t<phases>ACN</phases>\n");
01823 }
01824 if(pTransformer[index]->phases == 0x0007){
01825 fprintf(fn,"\t\t<phases>ABC</phases>\n");
01826 }
01827 if(pTransformer[index]->phases == 0x000f){
01828 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
01829 }
01830 if(pTransformer[index]->phases == 0x0107){
01831 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
01832 }
01833
01834
01835 if(pTransformer[index]->config->kVA_rating!=NULL){
01836 fprintf(fn,"\t\t<power_rating>%.6f</power_rating>\n",pTransformer[index]->config->kVA_rating);
01837 }
01838
01839
01840
01841 if(pTransformer[index]->config->impedance.Re()!=NULL){
01842 fprintf(fn,"\t\t<resistance>%.6f</resistance>\n",pTransformer[index]->config->impedance.Re());
01843 }
01844 if(pTransformer[index]->config->impedance.Im()!=NULL){
01845 fprintf(fn,"\t\t<reactance>%.6f</reactance>\n",pTransformer[index]->config->impedance.Im());
01846 }
01847
01848 fprintf(fn,"\t\t<a_matrix>\n");
01849 for(x = 0; x < 3; x++){
01850 for(y = 0; y < 3; y++){
01851 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pTransformer[index]->a_mat[x][y].Re(),pTransformer[index]->a_mat[x][y].Im(),x+1,y+1);
01852 }
01853 }
01854 fprintf(fn,"\t\t</a_matrix>\n");
01855
01856
01857 fprintf(fn,"\t\t<b_matrix>\n");
01858 for(x = 0; x < 3; x++){
01859 for(y = 0; y < 3; y++){
01860 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pTransformer[index]->b_mat[x][y].Re(),pTransformer[index]->b_mat[x][y].Im(),x+1,y+1);
01861 }
01862 }
01863 fprintf(fn,"\t\t</b_matrix>\n");
01864
01865
01866 fprintf(fn,"\t\t<c_matrix>\n");
01867 for(x = 0; x < 3; x++){
01868 for(y = 0; y < 3; y++){
01869 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pTransformer[index]->c_mat[x][y].Re(),pTransformer[index]->c_mat[x][y].Im(),x+1,y+1);
01870 }
01871 }
01872 fprintf(fn,"\t\t</c_matrix>\n");
01873
01874
01875 fprintf(fn,"\t\t<d_matrix>\n");
01876 for(x = 0; x < 3; x++){
01877 for(y = 0; y < 3; y++){
01878 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pTransformer[index]->d_mat[x][y].Re(),pTransformer[index]->d_mat[x][y].Im(),x+1,y+1);
01879 }
01880 }
01881 fprintf(fn,"\t\t</d_matrix>\n");
01882
01883
01884 fprintf(fn,"\t\t<A_matrix>\n");
01885 for(x = 0; x < 3; x++){
01886 for(y = 0; y < 3; y++){
01887 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pTransformer[index]->A_mat[x][y].Re(),pTransformer[index]->A_mat[x][y].Im(),x+1,y+1);
01888 }
01889 }
01890 fprintf(fn,"\t\t</A_matrix>\n");
01891
01892
01893 fprintf(fn,"\t\t<B_matrix>\n");
01894 for(x = 0; x < 3; x++){
01895 for(y = 0; y < 3; y++){
01896 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pTransformer[index]->B_mat[x][y].Re(),pTransformer[index]->B_mat[x][y].Im(),x+1,y+1);
01897 }
01898 }
01899 fprintf(fn,"\t\t</B_matrix>\n");
01900
01901 fprintf(fn,"\t</transformer>\n");
01902
01903 ++index;
01904 }
01905 }
01906
01907 index = 0;
01908
01909 if(tplines != NULL){
01910 pTpLine = (line **)gl_malloc(tplines->hit_count*sizeof(line*));
01911 if(pTpLine == NULL){
01912 gl_error("Failed to allocate fuse array.");
01913 return TS_NEVER;
01914 }
01915 while(obj = gl_find_next(tplines,obj)){
01916 if(index >= tplines->hit_count){
01917 break;
01918 }
01919 pTpLine[index] = OBJECTDATA(obj,line);
01920 if(pTpLine[index] == NULL){
01921 gl_error("Unable to map object as overhead_line object.");
01922 return 0;
01923 }
01924
01925
01926 fprintf(fn,"\t<triplex_line>\n");
01927
01928
01929 if(obj->name[0] != 0){
01930 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
01931 } else {
01932 fprintf(fn,"\t\t<name>NA</name>\n");
01933 }
01934
01935
01936 fprintf(fn,"\t\t<id>triplex_line:%d</id>\n",obj->id);
01937
01938
01939 if(pTpLine[index]->from->name[0] != 0){
01940 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pTpLine[index]->from->oclass->name,pTpLine[index]->from->name);
01941 } else {
01942 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pTpLine[index]->from->oclass->name,pTpLine[index]->from->id);
01943 }
01944
01945
01946 if(pTpLine[index]->to->name[0] != 0){
01947 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pTpLine[index]->to->oclass->name,pTpLine[index]->to->name);
01948 } else {
01949 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pTpLine[index]->to->oclass->name,pTpLine[index]->to->id);
01950 }
01951
01952
01953 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",120);
01954
01955
01956 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",120);
01957
01958
01959 if(pTpLine[index]->phases == 0x0001){
01960 fprintf(fn,"\t\t<phases>A</phases>\n");
01961 }
01962 if(pTpLine[index]->phases == 0x0002){
01963 fprintf(fn,"\t\t<phases>B</phases>\n");
01964 }
01965 if(pTpLine[index]->phases == 0x0004){
01966 fprintf(fn,"\t\t<phases>C</phases>\n");
01967 }
01968 if(pTpLine[index]->phases == 0x0009){
01969 fprintf(fn,"\t\t<phases>AN</phases>\n");
01970 }
01971 if(pTpLine[index]->phases == 0x000a){
01972 fprintf(fn,"\t\t<phases>BN</phases>\n");
01973 }
01974 if(pTpLine[index]->phases == 0x000c){
01975 fprintf(fn,"\t\t<phases>CN</phases>\n");
01976 }
01977 if(pTpLine[index]->phases == 0x0071){
01978 fprintf(fn,"\t\t<phases>AS</phases>\n");
01979 }
01980 if(pTpLine[index]->phases == 0x0072){
01981 fprintf(fn,"\t\t<phases>BS</phases>\n");
01982 }
01983 if(pTpLine[index]->phases == 0x0074){
01984 fprintf(fn,"\t\t<phases>CS</phases>\n");
01985 }
01986 if(pTpLine[index]->phases == 0x0003){
01987 fprintf(fn,"\t\t<phases>AB</phases>\n");
01988 }
01989 if(pTpLine[index]->phases == 0x0006){
01990 fprintf(fn,"\t\t<phases>BC</phases>\n");
01991 }
01992 if(pTpLine[index]->phases == 0x0005){
01993 fprintf(fn,"\t\t<phases>AC</phases>\n");
01994 }
01995 if(pTpLine[index]->phases == 0x000b){
01996 fprintf(fn,"\t\t<phases>ABN</phases>\n");
01997 }
01998 if(pTpLine[index]->phases == 0x000e){
01999 fprintf(fn,"\t\t<phases>BCN</phases>\n");
02000 }
02001 if(pTpLine[index]->phases == 0x000d){
02002 fprintf(fn,"\t\t<phases>ACN</phases>\n");
02003 }
02004 if(pTpLine[index]->phases == 0x0007){
02005 fprintf(fn,"\t\t<phases>ABC</phases>\n");
02006 }
02007 if(pTpLine[index]->phases == 0x000f){
02008 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
02009 }
02010 if(pTpLine[index]->phases == 0x0107){
02011 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
02012 }
02013
02014
02015 fprintf(fn,"\t\t<length>%f</length>\n",pTpLine[index]->length);
02016
02017
02018 fprintf(fn,"\t\t<a_matrix>\n");
02019 for(x = 0; x < 3; x++){
02020 for(y = 0; y < 3; y++){
02021 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pTpLine[index]->a_mat[x][y].Re(),pTpLine[index]->a_mat[x][y].Im(),x+1,y+1);
02022 }
02023 }
02024 fprintf(fn,"\t\t</a_matrix>\n");
02025
02026
02027 fprintf(fn,"\t\t<b_matrix>\n");
02028 for(x = 0; x < 3; x++){
02029 for(y = 0; y < 3; y++){
02030 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pTpLine[index]->b_mat[x][y].Re(),pTpLine[index]->b_mat[x][y].Im(),x+1,y+1);
02031 }
02032 }
02033 fprintf(fn,"\t\t</b_matrix>\n");
02034
02035
02036 fprintf(fn,"\t\t<c_matrix>\n");
02037 for(x = 0; x < 3; x++){
02038 for(y = 0; y < 3; y++){
02039 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pTpLine[index]->c_mat[x][y].Re(),pTpLine[index]->c_mat[x][y].Im(),x+1,y+1);
02040 }
02041 }
02042 fprintf(fn,"\t\t</c_matrix>\n");
02043
02044
02045 fprintf(fn,"\t\t<d_matrix>\n");
02046 for(x = 0; x < 3; x++){
02047 for(y = 0; y < 3; y++){
02048 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pTpLine[index]->d_mat[x][y].Re(),pTpLine[index]->d_mat[x][y].Im(),x+1,y+1);
02049 }
02050 }
02051 fprintf(fn,"\t\t</d_matrix>\n");
02052
02053
02054 fprintf(fn,"\t\t<A_matrix>\n");
02055 for(x = 0; x < 3; x++){
02056 for(y = 0; y < 3; y++){
02057 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pTpLine[index]->A_mat[x][y].Re(),pTpLine[index]->A_mat[x][y].Im(),x+1,y+1);
02058 }
02059 }
02060 fprintf(fn,"\t\t</A_matrix>\n");
02061
02062
02063 fprintf(fn,"\t\t<B_matrix>\n");
02064 for(x = 0; x < 3; x++){
02065 for(y = 0; y < 3; y++){
02066 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pTpLine[index]->B_mat[x][y].Re(),pTpLine[index]->B_mat[x][y].Im(),x+1,y+1);
02067 }
02068 }
02069 fprintf(fn,"\t\t</B_matrix>\n");
02070
02071 fprintf(fn,"\t</triplex_line>\n");
02072
02073 ++index;
02074 }
02075 }
02076
02077 index = 0;
02078
02079 if(uglines != NULL){
02080 pUgLine = (line **)gl_malloc(uglines->hit_count*sizeof(line*));
02081 if(pUgLine == NULL){
02082 gl_error("Failed to allocate fuse array.");
02083 return TS_NEVER;
02084 }
02085 while(obj = gl_find_next(uglines,obj)){
02086 if(index >= uglines->hit_count){
02087 break;
02088 }
02089 pUgLine[index] = OBJECTDATA(obj,line);
02090 if(pUgLine[index] == NULL){
02091 gl_error("Unable to map object as overhead_line object.");
02092 return 0;
02093 }
02094
02095
02096 fprintf(fn,"\t<underground_line>\n");
02097
02098
02099 if(obj->name[0] != 0){
02100 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
02101 } else {
02102 fprintf(fn,"\t\t<name>NA</name>\n");
02103 }
02104
02105
02106 fprintf(fn,"\t\t<id>underground_line:%d</id>\n",obj->id);
02107
02108
02109 if(pUgLine[index]->from->name[0] != 0){
02110 fprintf(fn,"\t\t<from_node>%s:%s</from_node>\n",pUgLine[index]->from->oclass->name,pUgLine[index]->from->name);
02111 } else {
02112 fprintf(fn,"\t\t<from_node>%s:%d</from_node>\n",pUgLine[index]->from->oclass->name,pUgLine[index]->from->id);
02113 }
02114
02115
02116 if(pUgLine[index]->to->name[0] != 0){
02117 fprintf(fn,"\t\t<to_node>%s:%s</to_node>\n",pUgLine[index]->to->oclass->name,pUgLine[index]->to->name);
02118 } else {
02119 fprintf(fn,"\t\t<to_node>%s:%d</to_node>\n",pUgLine[index]->to->oclass->name,pUgLine[index]->to->id);
02120 }
02121
02122
02123 if(pUgLine[index]->has_phase(PHASE_A)){
02124 node_voltage = get_complex(pUgLine[index]->from,"voltage_A");
02125 } else if(pUgLine[index]->has_phase(PHASE_B)){
02126 node_voltage = get_complex(pUgLine[index]->from,"voltage_B");
02127 } else if(pUgLine[index]->has_phase(PHASE_C)){
02128 node_voltage = get_complex(pUgLine[index]->from,"voltage_C");
02129 }
02130
02131 if(node_voltage == NULL){
02132 gl_error("From node has no voltage.");
02133 return 0;
02134 }
02135
02136 fprintf(fn,"\t\t<from_voltage>%f</from_voltage>\n",node_voltage->Mag());
02137
02138
02139 if(pUgLine[index]->has_phase(PHASE_A)){
02140 node_voltage = get_complex(pUgLine[index]->to,"voltage_A");
02141 } else if(pUgLine[index]->has_phase(PHASE_B)){
02142 node_voltage = get_complex(pUgLine[index]->to,"voltage_B");
02143 } else if(pUgLine[index]->has_phase(PHASE_C)){
02144 node_voltage = get_complex(pUgLine[index]->to,"voltage_C");
02145 }
02146
02147 if(node_voltage == NULL){
02148 gl_error("From node has no voltage.");
02149 return 0;
02150 }
02151
02152 fprintf(fn,"\t\t<to_voltage>%f</to_voltage>\n",node_voltage->Mag());
02153
02154
02155 if(pUgLine[index]->phases == 0x0001){
02156 fprintf(fn,"\t\t<phases>A</phases>\n");
02157 }
02158 if(pUgLine[index]->phases == 0x0002){
02159 fprintf(fn,"\t\t<phases>B</phases>\n");
02160 }
02161 if(pUgLine[index]->phases == 0x0004){
02162 fprintf(fn,"\t\t<phases>C</phases>\n");
02163 }
02164 if(pUgLine[index]->phases == 0x0009){
02165 fprintf(fn,"\t\t<phases>AN</phases>\n");
02166 }
02167 if(pUgLine[index]->phases == 0x000a){
02168 fprintf(fn,"\t\t<phases>BN</phases>\n");
02169 }
02170 if(pUgLine[index]->phases == 0x000c){
02171 fprintf(fn,"\t\t<phases>CN</phases>\n");
02172 }
02173 if(pUgLine[index]->phases == 0x0071){
02174 fprintf(fn,"\t\t<phases>AS</phases>\n");
02175 }
02176 if(pUgLine[index]->phases == 0x0072){
02177 fprintf(fn,"\t\t<phases>BS</phases>\n");
02178 }
02179 if(pUgLine[index]->phases == 0x0074){
02180 fprintf(fn,"\t\t<phases>CS</phases>\n");
02181 }
02182 if(pUgLine[index]->phases == 0x0003){
02183 fprintf(fn,"\t\t<phases>AB</phases>\n");
02184 }
02185 if(pUgLine[index]->phases == 0x0006){
02186 fprintf(fn,"\t\t<phases>BC</phases>\n");
02187 }
02188 if(pUgLine[index]->phases == 0x0005){
02189 fprintf(fn,"\t\t<phases>AC</phases>\n");
02190 }
02191 if(pUgLine[index]->phases == 0x000b){
02192 fprintf(fn,"\t\t<phases>ABN</phases>\n");
02193 }
02194 if(pUgLine[index]->phases == 0x000e){
02195 fprintf(fn,"\t\t<phases>BCN</phases>\n");
02196 }
02197 if(pUgLine[index]->phases == 0x000d){
02198 fprintf(fn,"\t\t<phases>ACN</phases>\n");
02199 }
02200 if(pUgLine[index]->phases == 0x0007){
02201 fprintf(fn,"\t\t<phases>ABC</phases>\n");
02202 }
02203 if(pUgLine[index]->phases == 0x000f){
02204 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
02205 }
02206 if(pUgLine[index]->phases == 0x0107){
02207 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
02208 }
02209
02210
02211 fprintf(fn,"\t\t<length>%f</length>\n",pUgLine[index]->length);
02212
02213
02214 fprintf(fn,"\t\t<a_matrix>\n");
02215 for(x = 0; x < 3; x++){
02216 for(y = 0; y < 3; y++){
02217 fprintf(fn,"\t\t\t<a%d%d>%+.15f%+.15fj</a%d%d>\n",x+1,y+1,pUgLine[index]->a_mat[x][y].Re(),pUgLine[index]->a_mat[x][y].Im(),x+1,y+1);
02218 }
02219 }
02220 fprintf(fn,"\t\t</a_matrix>\n");
02221
02222
02223 fprintf(fn,"\t\t<b_matrix>\n");
02224 for(x = 0; x < 3; x++){
02225 for(y = 0; y < 3; y++){
02226 fprintf(fn,"\t\t\t<b%d%d>%+.15f%+.15fj</b%d%d>\n",x+1,y+1,pUgLine[index]->b_mat[x][y].Re(),pUgLine[index]->b_mat[x][y].Im(),x+1,y+1);
02227 }
02228 }
02229 fprintf(fn,"\t\t</b_matrix>\n");
02230
02231
02232 fprintf(fn,"\t\t<c_matrix>\n");
02233 for(x = 0; x < 3; x++){
02234 for(y = 0; y < 3; y++){
02235 fprintf(fn,"\t\t\t<c%d%d>%+.15f%+.15fj</c%d%d>\n",x+1,y+1,pUgLine[index]->c_mat[x][y].Re(),pUgLine[index]->c_mat[x][y].Im(),x+1,y+1);
02236 }
02237 }
02238 fprintf(fn,"\t\t</c_matrix>\n");
02239
02240
02241 fprintf(fn,"\t\t<d_matrix>\n");
02242 for(x = 0; x < 3; x++){
02243 for(y = 0; y < 3; y++){
02244 fprintf(fn,"\t\t\t<d%d%d>%+.15f%+.15fj</d%d%d>\n",x+1,y+1,pUgLine[index]->d_mat[x][y].Re(),pUgLine[index]->d_mat[x][y].Im(),x+1,y+1);
02245 }
02246 }
02247 fprintf(fn,"\t\t</d_matrix>\n");
02248
02249
02250 fprintf(fn,"\t\t<A_matrix>\n");
02251 for(x = 0; x < 3; x++){
02252 for(y = 0; y < 3; y++){
02253 fprintf(fn,"\t\t\t<A%d%d>%+.15f%+.15fj</A%d%d>\n",x+1,y+1,pUgLine[index]->A_mat[x][y].Re(),pUgLine[index]->A_mat[x][y].Im(),x+1,y+1);
02254 }
02255 }
02256 fprintf(fn,"\t\t</A_matrix>\n");
02257
02258
02259 fprintf(fn,"\t\t<B_matrix>\n");
02260 for(x = 0; x < 3; x++){
02261 for(y = 0; y < 3; y++){
02262 fprintf(fn,"\t\t\t<B%d%d>%+.15f%+.15fj</B%d%d>\n",x+1,y+1,pUgLine[index]->B_mat[x][y].Re(),pUgLine[index]->B_mat[x][y].Im(),x+1,y+1);
02263 }
02264 }
02265 fprintf(fn,"\t\t</B_matrix>\n");
02266
02267 fprintf(fn,"\t</underground_line>\n");
02268
02269 ++index;
02270 }
02271 }
02272
02273 index=0;
02274
02275 if(capacitors != NULL){
02276 pCapacitor = (capacitor **)gl_malloc(capacitors->hit_count*sizeof(capacitor*));
02277 if(pCapacitor == NULL){
02278 gl_error("Failed to allocate fuse array.");
02279 return TS_NEVER;
02280 }
02281 while(obj = gl_find_next(capacitors,obj)){
02282 if(index >= capacitors->hit_count){
02283 break;
02284 }
02285 pCapacitor[index] = OBJECTDATA(obj,capacitor);
02286 if(pCapacitor[index] == NULL){
02287 gl_error("Unable to map object as a link object.");
02288 return 0;
02289 }
02290
02291
02292 fprintf(fn,"\t<capacitor>\n");
02293
02294
02295 if(obj->name[0] != 0){
02296 fprintf(fn,"\t\t<name>%s</name>\n",obj->name);
02297 } else {
02298 fprintf(fn,"\t\t<name>NA</name>\n");
02299 }
02300
02301
02302 fprintf(fn,"\t\t<id>cap:%d</id>\n",obj->id);
02303
02304
02305
02306 if(obj->parent->name[0] != 0){
02307 fprintf(fn,"\t\t<node>%s:%s</node>\n",pCapacitor[index]->pclass->name,obj->parent->name);
02308 } else {
02309 fprintf(fn,"\t\t<node>%s:%d</node>\n",pCapacitor[index]->pclass->name,obj->parent->id);
02310 }
02311
02312
02313
02314 if(pCapacitor[index]->phases == 0x0001){
02315 fprintf(fn,"\t\t<phases>A</phases>\n");
02316 }
02317 if(pCapacitor[index]->phases == 0x0002){
02318 fprintf(fn,"\t\t<phases>B</phases>\n");
02319 }
02320 if(pCapacitor[index]->phases == 0x0004){
02321 fprintf(fn,"\t\t<phases>C</phases>\n");
02322 }
02323 if(pCapacitor[index]->phases == 0x0009){
02324 fprintf(fn,"\t\t<phases>AN</phases>\n");
02325 }
02326 if(pCapacitor[index]->phases == 0x000a){
02327 fprintf(fn,"\t\t<phases>BN</phases>\n");
02328 }
02329 if(pCapacitor[index]->phases == 0x000c){
02330 fprintf(fn,"\t\t<phases>CN</phases>\n");
02331 }
02332 if(pCapacitor[index]->phases == 0x0071){
02333 fprintf(fn,"\t\t<phases>AS</phases>\n");
02334 }
02335 if(pCapacitor[index]->phases == 0x0072){
02336 fprintf(fn,"\t\t<phases>BS</phases>\n");
02337 }
02338 if(pCapacitor[index]->phases == 0x0074){
02339 fprintf(fn,"\t\t<phases>CS</phases>\n");
02340 }
02341 if(pCapacitor[index]->phases == 0x0003){
02342 fprintf(fn,"\t\t<phases>AB</phases>\n");
02343 }
02344 if(pCapacitor[index]->phases == 0x0006){
02345 fprintf(fn,"\t\t<phases>BC</phases>\n");
02346 }
02347 if(pCapacitor[index]->phases == 0x0005){
02348 fprintf(fn,"\t\t<phases>AC</phases>\n");
02349 }
02350 if(pCapacitor[index]->phases == 0x000b){
02351 fprintf(fn,"\t\t<phases>ABN</phases>\n");
02352 }
02353 if(pCapacitor[index]->phases == 0x000e){
02354 fprintf(fn,"\t\t<phases>BCN</phases>\n");
02355 }
02356 if(pCapacitor[index]->phases == 0x000d){
02357 fprintf(fn,"\t\t<phases>ACN</phases>\n");
02358 }
02359 if(pCapacitor[index]->phases == 0x0007){
02360 fprintf(fn,"\t\t<phases>ABC</phases>\n");
02361 }
02362 if(pCapacitor[index]->phases == 0x000f){
02363 fprintf(fn,"\t\t<phases>ABCN</phases>\n");
02364 }
02365 if(pCapacitor[index]->phases == 0x0107){
02366 fprintf(fn,"\t\t<phases>ABCD</phases>\n");
02367 }
02368
02369 fprintf(fn,"\t\t<QA>%f</QA>\n",pCapacitor[index]->capacitor_A);
02370 fprintf(fn,"\t\t<QB>%f</QB>\n",pCapacitor[index]->capacitor_B);
02371 fprintf(fn,"\t\t<QC>%f</QC>\n",pCapacitor[index]->capacitor_C);
02372
02373 fprintf(fn,"\t</capacitor>\n");
02374
02375 ++index;
02376 }
02377 }
02378
02379 fprintf(fn,"</gridlabd>");
02380
02381 fclose(fn);
02382 return 1;
02383 }
02384
02385 TIMESTAMP impedance_dump::commit(TIMESTAMP t){
02386 if(runtime == 0){
02387 runtime = t;
02388 }
02389 if((t == runtime || runtime == TS_NEVER) && (runcount < 1)){
02390
02391 int rv = dump(t);
02392 ++runcount;
02393 if(rv == 0){
02394 return TS_INVALID;
02395 }
02396 return TS_NEVER;
02397 } else {
02398 if(t < runtime){
02399 return runtime;
02400 } else {
02401 return TS_NEVER;
02402 }
02403 }
02404 }
02405
02407
02409
02417 EXPORT int create_impedance_dump(OBJECT **obj, OBJECT *parent)
02418 {
02419 try
02420 {
02421 *obj = gl_create_object(impedance_dump::oclass);
02422 if (*obj!=NULL)
02423 {
02424 impedance_dump *my = OBJECTDATA(*obj,impedance_dump);
02425 gl_set_parent(*obj,parent);
02426 return my->create();
02427 }
02428 }
02429 catch (const char *msg)
02430 {
02431 gl_error("create_impedance_dump: %s", msg);
02432 }
02433 return 0;
02434 }
02435
02436 EXPORT int init_impedance_dump(OBJECT *obj)
02437 {
02438 impedance_dump *my = OBJECTDATA(obj,impedance_dump);
02439 try {
02440 return my->init(obj->parent);
02441 }
02442 catch (const char *msg)
02443 {
02444 gl_error("%s (impedance_dump:%d): %s", obj->name, obj->id, msg);
02445 return 0;
02446 }
02447 }
02448
02449 EXPORT TIMESTAMP sync_impedance_dump(OBJECT *obj, TIMESTAMP t1, PASSCONFIG pass)
02450 {
02451 try
02452 {
02453 impedance_dump *my = OBJECTDATA(obj,impedance_dump);
02454 TIMESTAMP rv;
02455 obj->clock = t1;
02456 rv = my->runtime > t1 ? my->runtime : TS_NEVER;
02457 return rv;
02458 }
02459 SYNC_CATCHALL(impedance_dump);
02460 }
02461
02462 EXPORT TIMESTAMP commit_impedance_dump(OBJECT *obj, TIMESTAMP t1, TIMESTAMP t2){
02463 try {
02464 impedance_dump *my = OBJECTDATA(obj,impedance_dump);
02465 return my->commit(t1);
02466 }
02467 I_CATCHALL(commit,impedance_dump);
02468 }
02469
02470 EXPORT int isa_impedance_dump(OBJECT *obj, char *classname)
02471 {
02472 return OBJECTDATA(obj,impedance_dump)->isa(classname);
02473 }
02474