📄 readieee.c
字号:
/* Read AC data in IEEE common fotmat. */#include "readdata.h"/* --------- Global Input File --------- */extern FILE *InputDataFile;/* ---------------- ReadIEEE ----------------------------- */#ifdef ANSIPROTOvoid ReadIEEE()#elsevoid ReadIEEE()#endif/* Read Bus and Element data in WSCC format. */{ ACbusData *ACptr,*ACptrp,*ACptrs; ElementData *Eptr; ElementList *ELptr; AreaData *Aptr; char Line[75+BUFLEN],Linep[BUFLEN]; char Name[31],str[6]; VALUETYPE KV,R,X,Sb; BOOLEAN flag=FALSE,card=FALSE,empty=FALSE,flagp=FALSE; INDEX i,j,k,NumBusDigits=4,NumAreaDigits=2,CircData=21; Line[0]='\0'; for(i=0;i<=2;strcpy(dataPtr->Title[i],"\n"),i++); Sn=100.0; RealParameter('$',&Sn,1.0,100000000.0); if (!strcmp(NameParameter('I'),"p")) { NumBusDigits=5; NumAreaDigits=3; CircData=23; } for(;;){ /* Reading Loop */ if(LineNum && Line[0]!='%') strcpy(Linep,Line); if (fgets(Line,BUFLEN,InputDataFile)==NULL) { fCustomPrint(stderr,"***Warning: END OF DATA card missing in IEEE input data file."); break; } LineNum++; if(!strncmp(Line,"CARD",4)) card=TRUE; /* --------- Comment cards (Electrocon), Sn and Title ----------------- */ else if(!strncmp(Line,"COMMENT DATA",7)) for(;;){ if(!flagp) { flagp=TRUE; GetStr(Linep,39,35,35,dataPtr->Title[0]); Sb=GetValue(Linep,32,6,0); if(Sb>0) Sn=Sb; } if (fgets(Line,BUFLEN,InputDataFile)==NULL) { ErrorHalt("Missing $$$ card in COMMENT DATA."); break; } LineNum++; if(!strncmp(Line,"$$$",3)) break; } /* -------------------- AC bus data, Sn and Title --------------------- */ else if(!strncmp(Line,"BUS DATA",3)) for(;;){ if(!flagp) { flagp=TRUE; GetStr(Linep,46,28,28,dataPtr->Title[0]); Sb=GetValue(Linep,32,6,0); if(Sb>0) Sn=Sb; } BusData: if (fgets(Line,BUFLEN,InputDataFile)==NULL) { ErrorHalt("Missing -999 card in BUS DATA."); break; } LineNum++; if(Line[0]=='%') goto BusData; if(!strncmp(Line,"-999",4)) break; if (card) { if (fgets(Linep,BUFLEN,InputDataFile)==NULL){ ErrorHalt("Missing -999 card in BUS DATA."); break; } LineNum++; for(i=strlen(Line)-1;i<=74;Line[i]=' ',i++); Line[75]='\0'; strcat(Line,Linep); } i=GetInt(Line,25,2); if (i!=4) { i=GetInt(Line,1,NumBusDigits); GetStr(Line,6,12,12,Name); KV=GetValue(Line,77,7,2); for (j=0;j<=11;j++) { if (Name[j]!=' ') break; if (j==11) empty=TRUE; } if (empty||(strpbrk(Name,"0")&&strlen(Name)==1)) { empty=FALSE; strcpy(Name,"BUS_"); GetStr(Line,1,5,5,str); for(j=0;j<=3;j++) if(str[j]!=' ') break; strcat(Name,&str[j]); for(j=strlen(Name);j<=11;Name[j]=' ',j++); Name[12]='\0'; } ACptr=(ACbusData *) ACbusInList(i,Name,KV,Nac,0); if (ACptr->N==0) { Nac++; ACptr->Num=i; ACptr->N=Nac;} i=GetInt(Line,19,2); if (i) { ACptr->Area=(AreaData *) AreaInList(i,"",Narea); if (ACptr->Area->N==0) {Narea++; ACptr->Area->N=i;} } GetStr(Line,21,3,3,ACptr->Zone); i=GetInt(Line,25,2); ACptr->V=GetValue(Line,28,6,4); if (ACptr->V<=0) ACptr->V=1; ACptr->Ang=GetValue(Line,34,7,2)*K3; ACptr->Pl=GetValue(Line,41,9,2)/Sn; ACptr->Ql=GetValue(Line,50,9,2)/Sn; ACptr->Pg=GetValue(Line,59,9,2)/Sn; ACptr->Qg=GetValue(Line,68,8,2)/Sn; KV=GetValue(Line,85,6,4); ACptr->G=GetValue(Line,107,8,4); ACptr->B=GetValue(Line,115,8,4); if (i==0 && strcmp(ACptr->Type,"BC")) ACptr->Cont=ACptr; else if (i==1) { strcpy(ACptr->Type,"BV"); strcpy(ACptr->cont,"Q"); ACptr->VCont=ACptr->Qg; ACptr->Vmax=GetValue(Line,91,8,2); if (ACptr->Vmax<=0) ACptr->Vmax=10.; ACptr->Vmin=GetValue(Line,99,8,2); if (ACptr->Vmin<=0) ACptr->Vmin=0.001; if (ACptr->Vmax<=ACptr->Vmin) { fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("AC bus V limits are wrong: Vmin >= Vmax."); } ACptr->Cont=ACptr; ACptr->Qmax=99999999.; ACptr->Qmin= -99999999.; } else if (i==2 || i==3) { if (ExistParameter('g')) ACptr->Qg=0; ACptr->Qmax=GetValue(Line,91,8,2)/Sn; ACptr->Qmin=GetValue(Line,99,8,2)/Sn; if (ACptr->Qmax<ACptr->Qmin) { fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("AC bus Q limits are wrong: Qmin > Qmax."); } /*if (ACptr->Qmax==ACptr->Qmin && ACptr->Qmax==0.) { ACptr->Qmax=9999999.; ACptr->Qmin= -999999.; }*/ if (ACptr->Qmax==ACptr->Qmin) ACptr->Cont=ACptr; else { Nvolt++; ACptr->val=GetValue(Line,85,6,4); if (ACptr->val<=0) ACptr->val=1; j=GetInt(Line,124,NumBusDigits); if (j>0 && j!=ACptr->Num) { ACptr->Nc=j; strcpy(ACptr->Type,"BG"); strcpy(ACptr->cont,"V"); ACptr->Kbg=1; ACptr->VCont=ACptr->val; } else { strcpy(ACptr->Type,"BQ"); strcpy(ACptr->cont,"V"); ACptr->VCont=ACptr->V=ACptr->val; } } if (i==3) { Nslack++; strcat(ACptr->Type,"S"); if(ACptr->Area!=NULL) { ACptr->Area->i++; if (ACptr->Area->i>1) { if (card) LineNum--; fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("The Area has more than one slack bus."); } } } } } } /* -------------------- AC elemet data ------------------------- */ else if(!strncmp(Line,"BRANCH DATA",6)) for(;;){ BranchData: if (fgets(Line,BUFLEN,InputDataFile)==NULL) { ErrorHalt("Missing -999 card in BRANCH DATA."); break; } LineNum++; if(Line[0]=='%') goto BranchData; if(!strcmp(NameParameter('I'),"p") && Line[strlen(Line)-2]=='0') goto BranchData; if(!strncmp(Line,"-999",4)) break; k=GetInt(Line,19,1); if (card && k) { if (fgets(Linep,BUFLEN,InputDataFile)==NULL){ ErrorHalt("Missing -999 card in BRANCH DATA."); break; } LineNum++; for(i=strlen(Line)-1;i<=74;Line[i]=' ',i++); Line[75]='\0'; strcat(Line,Linep); } i=GetInt(Line,1,NumBusDigits); ACptr=(ACbusData *) ACbusInList(i,"",0.,Nac,1); if (ACptr->N==0) { if (card) LineNum--; fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("The tap bus has not been defined (check BUS DATA cards)."); } j=GetInt(Line,6,NumBusDigits); ACptrp=(ACbusData *) ACbusInList(j,"",0.,Nac,1); if (ACptrp->N==0) { if (card) LineNum--; fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("The Z bus has not been defined (check BUS DATA cards)."); } Eptr=(ElementData *) ElemInList(ACptr,ACptrp,NacEl++,0,"",""); R=GetValue(Line,20,10,6); X=GetValue(Line,30,10,6); if (fabs(R)<0.0000001 && fabs(X)<0.0000001) { fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("AC element is a short circuit. Try eliminating it."); } else { Eptr->G= R/(R*R+X*X); Eptr->B= -X/(R*R+X*X); } Eptr->B1=Eptr->B2=GetValue(Line,41,9,5)/2; Eptr->Imax=GetInt(Line,51,5)/Sn; i=GetInt(Line,11,2); if (i) { Eptr->Area=(AreaData *) AreaInList(i,"",Narea); if (Eptr->Area->N==0) { if (card) LineNum--; fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("The Area has not been defined (check BUS DATA cards)."); } } GetStr(Line,13,3,3,Eptr->Zone); GetStr(Line,17,1,1,Eptr->Ckt); if (k==0) strcpy(Eptr->Type,"L"); else if (k>=1) { Eptr->Tap=1/GetValue(Line,77,6,4); Eptr->Ang=GetValue(Line,84,7,2)*K3; j=GetInt(Line,69,NumBusDigits); if (j>0) { ACptrs=(ACbusData *) ACbusInList(j,"",0.,Nac,1); if (ACptrs->N==0) { fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("The controlled bus has not been defined (check BUS DATA cards)."); } } else ACptrs=ACptr; if(k==1) strcpy(Eptr->Type,"T"); else if(k==2) { Eptr->Tmin=GetValue(Line,91,7,2); Eptr->Tmax=GetValue(Line,98,7,2); if(Eptr->Tmax<0) Eptr->Tmax=1.1; if(Eptr->Tmin<0) Eptr->Tmin=0.9; if(Eptr->Tmax<Eptr->Tmin) { fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line); ErrorHalt("LTC limits are wrong: Tmin > Tmax.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -