📄 writeiee.c
字号:
/* Write output in IEEE format. */#include "write.h"#include <time.h>#include <string.h> /* FACTS *//* --------------- Print ----------------- */#ifdef ANSIPROTOvoid Print(FILE *File,int spaces,int width,int decimals,VALUETYPE val)#elsevoid Print(File,spaces,width,decimals,val)FILE *File;int spaces,width,decimals;VALUETYPE val;#endif{ int i,j; double cons; BOOLEAN flagNegative=FALSE; char str[50],*ptr; if (spaces>0) fCustomPrint(File,"%*s",spaces,""); width=abs(width); decimals=abs(decimals); if(val<0) { width--; val=fabs(val); flagNegative=TRUE; } if(width<=decimals) decimals=width-1; if(decimals) width--; if(!width) {width=1; decimals=0;} if(decimals) cons=5*pow(10.,(double)-width-1); else cons=5*pow(10.,(double)-width); if (val<cons) { if(flagNegative && width>1) width++; if(decimals) width++; if (width==1) strcpy(str,"0"); else { strcpy(str,"0."); for(i=2;i<=width-1;i++) strcat(str,"0"); } fCustomPrint(File,"%*s",width,str); return; } if(width==1 && flagNegative) { fCustomPrint(File,"*"); return; } if(val<(pow(10.,(double)width)-0.5)){ if(flagNegative) fCustomPrint(File,"-"); j=0; for(i=width-1;i>=0;i--) { if(val>(pow(10.,(double)i)-0.5*pow(10.,(double)-j))) break; j++; } if(decimals) width++; else if(i<width-1) j--; sprintf(str,"%-*.*lf",width,j,val); if(!strncmp(str,"0.",2)) ptr=strpbrk(str,"."); else if(strlen(str)==width && strpbrk(str," ")) { str[width-1]='.'; str[width]='\0'; ptr=str; } else ptr=str; fCustomPrint(File,"%*s",width,ptr); return; } else { if(flagNegative) width++; if(decimals) width++; for(i=0;i<=width-2;i++) { if (flagNegative && i==0) str[i]='-'; else str[i]='9'; } if(decimals) str[width-1]='.'; else str[width-1]='9'; str[width]='\0'; fCustomPrint(File,"%s",str); return; }}/* --------------- IEEE ----------------- */#ifdef ANSIPROTOvoid IEEE(void)#elsevoid IEEE()#endif{ ACbusData *ACptr; DCbusData *DCptrR,*DCptrI,*DCptr; SVCbusData *SVCptr; /* FACTS */ TCSCbusData *TCSCptr; /* FACTS */ STATCOMbusData *STATCOMptr; /* FACTS */ ElementData *Eptr; ElementList *ELptr; AreaData *Aptr; char str[32],Num[5],Nump[5],Area[3],Zone[4]; int Type,Nties,i,j; VALUETYPE R,X,Vn,In,Pl,Ql,Imax,delta,vals; VALUETYPE Ssvc,Stcsc,Sstatcom,G,B,Max,Xc; /* FACTS */ BOOLEAN card=FALSE,flag=FALSE; FILE *OutFile; time_t t; struct tm *localt; int month,year,yearp; Type = 0; if (ExistParameter('W')) { if (NullName(NameParameter('W'))) return; OutFile=OpenOutput(NameParameter('W')); } else { if (NullName(NameParameter('w'))) return; OutFile=OpenOutput(NameParameter('w')); card=TRUE; } if(card) fCustomPrint(OutFile,"CARD\n"); else fCustomPrint(OutFile,"TAPE\n"); t = time(NULL); localt=localtime(&t); if (localt->tm_mday<10) fCustomPrint(OutFile," 0%1d/",localt->tm_mday); else fCustomPrint(OutFile," %2d/",localt->tm_mday); month=localt->tm_mon+1; if (month<10) fCustomPrint(OutFile,"0%1d/",month); else fCustomPrint(OutFile,"%2d/",month); year=localt->tm_year; yearp=year+1900; if (year>=100) year=year-100; if (year<10) fCustomPrint(OutFile,"0%1d",year); else fCustomPrint(OutFile,"%2d",year); fCustomPrint(OutFile," Generated with PFLOW"); Print(OutFile,1,6,0,Sn); fCustomPrint(OutFile," %4d",yearp); if (month>3 && month<10) fCustomPrint(OutFile," S "); else fCustomPrint(OutFile," W "); strncpy(str,dataPtr->Title[0],29); for(i=0;i<=28;i++){ if (str[i]=='\n') str[i]='\0'; } str[28]='\0'; fCustomPrint(OutFile,"%s\n",str); /* --------------------- AC bus results -----------------------------*/ fCustomPrint(OutFile,"BUS DATA FOLLOWS %5d ITEMS\n",Nac); for (ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next){ if (ACptr->Num<=9999) sprintf(Num,"%4d",ACptr->Num); else strcpy(Num,"****"); if (Narea<2 || ACptr->Area==NULL) strcpy(Area,"0"); else if (ACptr->Area->N<=99) sprintf(Area,"%2d",ACptr->Area->N); else strcpy(Area,"99"); if ((isdigit(ACptr->Zone[0])||ACptr->Zone[0]==' ') && (isdigit(ACptr->Zone[1])||ACptr->Zone[1]==' ')) sprintf(Zone,"%3d",atoi(ACptr->Zone)); else sprintf(Zone,"%3d",toascii(ACptr->Zone[0])+toascii(ACptr->Zone[1])); if(!strcmp(ACptr->Type,"B")||!strcmp(ACptr->Type,"BA")||strpbrk(ACptr->Type,"L,T,C,R")) Type=0; else if(strpbrk(ACptr->Type,"V,X")) Type=1; else { if(strpbrk(ACptr->Type,"G,Q,Z")) Type=2; if(strpbrk(ACptr->Type,"S")) Type=3; } fCustomPrint(OutFile,"%4s %12s %2s%3s %2d",Num,ACptr->Name,Area,Zone,Type); Print(OutFile,1,6,4,ACptr->V); delta=ACptr->Ang; if (delta>=0) vals=1.00; else vals=-1.00; if (fabs(delta)>2*PI) delta=delta-vals*floor(fabs(delta)/(2*PI))*2*PI; if (fabs(delta)>PI) delta=delta-vals*2*PI; ACptr->Ang=delta; Print(OutFile,1,6,2,ACptr->Ang/K3); Pl=(ACptr->Pn+lambda*ACptr->Pnl)*pow(ACptr->V,ACptr->a)+ (ACptr->Pz+lambda*ACptr->Pzl)*ACptr->V*ACptr->V; Print(OutFile,1,8,2,Pl*Sn); Ql=(ACptr->Qn+lambda*ACptr->Qnl)*pow(ACptr->V,ACptr->b)+ (ACptr->Qz+lambda*ACptr->Qzl)*ACptr->V*ACptr->V; Print(OutFile,1,8,2,Ql*Sn); Print(OutFile,1,8,2,ACptr->PG*Sn); Print(OutFile,1,7,2,ACptr->Qg*Sn); if(card) fCustomPrint(OutFile,"\n"); Print(OutFile,1,7,2,ACptr->KV); if(strpbrk(ACptr->Type,"G") && ACptr->Cont!=NULL) Print(OutFile,1,6,4,ACptr->Cont->VCont); else if(strpbrk(ACptr->Type,"Q,S")) Print(OutFile,1,6,4,ACptr->VCont); else Print(OutFile,1,6,4,ACptr->V); if(strpbrk(ACptr->Type,"V,X")) { Print(OutFile,1,7,2,ACptr->Vmax); Print(OutFile,1,7,2,ACptr->Vmin); } else { Print(OutFile,1,7,2,ACptr->Qmax*Sn); Print(OutFile,1,7,2,ACptr->Qmin*Sn); } for(ELptr=ACptr->Elem;ELptr!=NULL;ELptr=ELptr->Next){ Eptr=ELptr->Eptr; if(Eptr->From==ACptr){ ACptr->G=ACptr->G+Eptr->G1*Eptr->Tap*Eptr->Tap; if(Eptr->B1!=Eptr->B2) ACptr->B=ACptr->B+Eptr->B1*Eptr->Tap*Eptr->Tap; } else { ACptr->G=ACptr->G+Eptr->G2; if(Eptr->B1!=Eptr->B2) ACptr->B=ACptr->B+Eptr->B2; } } Print(OutFile,1,7,4,ACptr->G); Print(OutFile,1,7,4,ACptr->B); if(strpbrk(ACptr->Type,"G") && ACptr->Cont!=NULL) { if (ACptr->Cont->Num<=9999) sprintf(Num,"%4d",ACptr->Cont->Num); else strcpy(Num,"****"); } else strcpy(Num," 0"); fCustomPrint(OutFile," %4s\n",Num); } fCustomPrint(OutFile,"-999\n"); /* --------------------- AC element results ---------------------------*/ Nties=0; fCustomPrint(OutFile,"BRANCH DATA FOLLOWS %5d ITEMS\n",NacEl); for(Eptr=dataPtr->Element;Eptr!=NULL;Eptr=Eptr->Next){ if(Narea>1 && Eptr->From->Area!=Eptr->To->Area) Nties++; if (Eptr->From->Num<=9999) sprintf(Num,"%4d",Eptr->From->Num); else strcpy(Num,"****"); if (Eptr->To->Num<=9999) sprintf(Nump,"%4d",Eptr->To->Num); else strcpy(Nump,"****"); if (Eptr->Area==NULL) { if (Eptr->From->Area==Eptr->To->Area) Eptr->Area=Eptr->From->Area; else Eptr->Area=Eptr->Meter->Area; } if (Narea<2 || Eptr->Area==NULL) strcpy(Area,"0"); else if (Eptr->Area->N<=99) sprintf(Area,"%2d",Eptr->Area->N); else strcpy(Area,"**"); if ((isdigit(Eptr->Zone[0])||Eptr->Zone[0]==' ') && (isdigit(Eptr->Zone[1])||Eptr->Zone[1]==' ')) sprintf(Zone,"%3d",atoi(Eptr->Zone)); else sprintf(Zone,"%3d",toascii(Eptr->Zone[0])+toascii(Eptr->Zone[1])); if(strpbrk(Eptr->Type,"LE")) Type=0; else if(strpbrk(Eptr->Type,"T")) Type=1; else if(!strcmp(Eptr->Type,"R")||strpbrk(Eptr->Type,"V")) Type=2; else if(strpbrk(Eptr->Type,"QN")) Type=3; else Type=4; if(!strcmp(Eptr->Ckt," ")) strcpy(Eptr->Ckt,"1"); fCustomPrint(OutFile,"%4s %4s %2s%3s %1s %1d",Num,Nump,Area,Zone,Eptr->Ckt,Type); R=Eptr->G/(Eptr->G*Eptr->G+Eptr->B*Eptr->B); X= -Eptr->B/(Eptr->G*Eptr->G+Eptr->B*Eptr->B); Print(OutFile,1,9,6,R);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -