⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readdata.c

📁 电力系统分析计算 学习调试程序 UNIX / LINUX / CYGWIN 系统使用
💻 C
📖 第 1 页 / 共 2 页
字号:
          if (ELptrp==ELptr) Aptr->Elem=ELptr->Next;          else ELptrp->Next=ELptr->Next;#ifndef WINDOWS          free(ELptr);#else          delete ELptr;#endif        }      }      NacEl--;      if (Eptr->Prev==NULL) {        Eptrp=Eptr->Next;        dataPtr->Element=Eptrp;        Eptrp->Prev=NULL;      } else {        Eptrp=Eptr->Prev;        Eptrp->Next=Eptr->Next;        if (Eptr->Next!=NULL) Eptr->Next->Prev=Eptrp;      }#ifndef WINDOWS      free(Eptr);#else      delete Eptr;#endif      /* Remove DC bus from AC data base */      Aptr=ACptr->Area;      if (Aptr!=NULL) {        for (ptrp=Aptr->AC;ptrp!=NULL;ptrp=ptrp->Next) if (ACptrp==ptrp->AC) break;        if (ptrp!=NULL) {          if (ptrp->Prev==NULL) {            ptrs=ptrp->Next;            Aptr->AC=ptrs;            ptrs->Prev=NULL;          } else {            ptrs=ptrp->Prev;            ptrs->Next=ptrp->Next;            if (ptrp->Next!=NULL) ptrp->Next->Prev=ptrs;          }#ifndef WINDOWS          free(ptrp);#else          delete ptrp;#endif        }      }      Nac--;      for(ACptrs=ACptrp->Next;ACptrs!=NULL;ACptrs->N--,ACptrs=ACptrs->Next);      if (ACptrp->Prev==NULL) {        ACptrs=ACptrp->Next;        dataPtr->ACbus=ACptrs;        ACptrs->Prev=NULL;      } else {        ACptrs=ACptrp->Prev;        ACptrs->Next=ACptrp->Next;        if (ACptrp->Next!=NULL) ACptrp->Next->Prev=ACptrs;      }#ifndef WINDOWS      free(ACptrp);#else      delete ACptrp;#endif    }    if (DCptr->MVA>0) {      KVs=ACptr->KV*DCptr->Ntrf/DCptr->Nbr;      DCptr->Xc=DCptr->Xc/DCptr->Nbr;      DCptr->Xc=(DCptr->Xc*KVs*KVs/DCptr->MVA)*DCptr->Nbr;    }    if (DCptr->Xc<=0.1){      fCustomPrint(stderr,"ERROR: DC bus %8s has a negative or zero commutation reactance ->\n",DCptr->Name);      fCustomPrint(stderr,"       Xc=%6.3lf (Ohms)\n",DCptr->Xc);      fCustomPrint(stderr,"       Check the BD and/or BZ cards.\n");      InputError=TRUE;    }    if (DCptr->To==NULL){      fCustomPrint(stderr,"ERROR: DC bus %8s is isolated.\n",DCptr->Name);      fCustomPrint(stderr,"       Check the DC line input cards.\n");      InputError=TRUE;    }    DCptr->Area=ACptr->Area;    if(!strcmp(DCptr->Cont1,"AL")||!strcmp(DCptr->Cont2,"AL")) {      if (DCptr->Alfa>DCptr->AlfaMax || DCptr->Alfa<DCptr->AlfaMin) {         fCustomPrint(stderr,"ERROR: DC bus %8s has ALPHA outside its limits.\n",DCptr->Name);         fCustomPrint(stderr,"       Check the BD (limits) and/or BZ card.\n");         InputError=TRUE;      }      DCptr->Gamma=180-DCptr->Alfa;    }    else if(!strcmp(DCptr->Cont1,"GA")||!strcmp(DCptr->Cont2,"GA")) {      if (DCptr->Gamma<DCptr->GammaMin) {         fCustomPrint(stderr,"ERROR: DC bus %8s has GAMMA outside its limits.\n",DCptr->Name);         fCustomPrint(stderr,"       Check the BD (limits) and/or BZ card.\n");         InputError=TRUE;      }      DCptr->Alfa=180-DCptr->Gamma;    }    else if(!strcmp(DCptr->Type,"R")) {      DCptr->Alfa=DCptr->AlfaMin;      DCptr->Gamma=180-DCptr->Alfa;    }    else {      DCptr->Gamma=DCptr->GammaMin;      DCptr->Alfa=180-DCptr->Gamma;    }    if (DCptr->Alfa>DCptr->AlfaMax || DCptr->Alfa<DCptr->AlfaMin || DCptr->Gamma<DCptr->GammaMin)         fCustomPrint(stderr,"***Warning: DC bus %8s could have wrong ALPHA or GAMMA limits.\n",DCptr->Name);    if (DCptr->Tap<=0) DCptr->Tap=1;    if (DCptr->Tap<DCptr->TapMin) DCptr->Tap=DCptr->TapMin;    if (DCptr->Tap>DCptr->TapMax) DCptr->Tap=DCptr->TapMax;  } /* ------------------- DC elements ------------------------ */  if (Ndc!=(2*NdcEl)) {    fCustomPrint(stderr,"ERROR: There are inconsistencies between the DC bus and DC line input data.\n");    fCustomPrint(stderr,"       Check DC input data and remember that the program just allows for \n");    fCustomPrint(stderr,"       two-terminal HVDC links.\n");    InputError=TRUE;  }  for(DCptr=dataPtr->DCbus;DCptr!=NULL;DCptr=DCptr->Next){    DCptrp=DCptr->To;    if (DCptr->N!=0 && DCptrp->N!=0){      if ((strcmp(DCptr->Type,"R") || strcmp(DCptrp->Type,"I")) &&         (strcmp(DCptr->Type,"I") || strcmp(DCptrp->Type,"R"))){         fCustomPrint(stderr,"ERROR: Both converters for the DC link between %8s and %8s\n",                  DCptr->Name,DCptrp->Name);         fCustomPrint(stderr,"       are either rectifiers or inverters.\n");         InputError=TRUE;      }      if ((!strcmp(DCptr->Cont1,"ID") || !strcmp(DCptr->Cont2,"ID")) &&           (!strcmp(DCptrp->Cont1,"ID") || !strcmp(DCptrp->Cont2,"ID"))){         fCustomPrint(stderr,"ERROR: Both converters for the DC link between %8s and %8s\n",                  DCptr->Name,DCptrp->Name);         fCustomPrint(stderr,"       are controlling the current.\n");         InputError=TRUE;      }      if (DCptr->Area==DCptrp->Area||!strcmp(DCptr->Zone,DCptrp->Zone))   DCptr->Meter=DCptrp->Meter=NULL;      if (DCptr->Area!=DCptrp->Area) for(i=1;i<=2;i++) {         if (i==1) Aptr=DCptr->Area;         else Aptr=DCptrp->Area;         if (Aptr!=NULL) {           ptr=Aptr->DC;#ifdef WINDOWS           Aptr->DC= new DClist;#else           Aptr->DC=(DClist *) malloc(sizeof(DClist));           if (Aptr->DC==NULL) {ErrorHalt("Insufficient memory to allocate area data."); stopExecute(ERROREXIT);}#endif           if (i==1) Aptr->DC->DC=DCptr;           else Aptr->DC->DC=DCptrp;           Aptr->DC->Next=ptr;         }      }      if (DCptr->Id>0) DCptrp->Id=DCptr->Id;      else if (DCptrp->Id>0) DCptr->Id=DCptrp->Id;      DCptr->N=0;      DCptrp->N=0;    }  } /* -------------------------- Areas --------------------------- */  for (Aptr=dataPtr->Area; Aptr!=NULL; Aptr=Aptr->Next) {    flag=TRUE;    i=0; j=0;    for(ELptr=Aptr->Elem;ELptr!=NULL;ELptr=ELptr->Next){      Eptr=ELptr->Eptr; flag=FALSE; i++;      if(!strcmp(Eptr->Type,"RP")) j++;      if (Eptr->From->Area!=Aptr) Aptrp=Eptr->From->Area;      else Aptrp=Eptr->To->Area;      if (!Acont && strpbrk(Aptr->Slack->Type,"S") && !strpbrk(Aptrp->Slack->Type,"S")) ExpandSlack(Aptr->Slack,Aptrp);    }    if (!flag && i==j) {      fCustomPrint(stderr,"ERROR: All tie lines for area %d %s are P reg. transf.\n",Aptr->N,Aptr->Name);      fCustomPrint(stderr,"       Change at least one reg. transf. to a standard one.\n");      InputError=TRUE;    }    if (flag && !strpbrk(Aptr->Slack->Type,"S")) {      strcat(Aptr->Slack->Type,"S");      Nslack++;    }    ptrp=Aptr->AC;    while(ptrp!=NULL){      ptrs=ptrp->Next;      ptrp->Next=ptrp->Prev;      ptrp->Prev=ptrs;      if (ptrs==NULL) Aptr->AC=ptrp;      ptrp=ptrs;    }  } /* -------------------------- FACTS --------------------------- */  for(SVCptr=dataPtr->SVCbus;SVCptr!=NULL;SVCptr=SVCptr->Next){    ACptr=SVCptr->Ctrl;    if (ACptr->Cont==NULL) {      fCustomPrint(stderr,"ERROR: The SVC controlled bus %d %s is already controlled.\n",ACptr->N,ACptr->Name);      fCustomPrint(stderr,"       Check the AC bus cards.\n");      InputError=TRUE;    }    ACptr=SVCptr->From;    if (ACptr->Cont==NULL) {      fCustomPrint(stderr,"ERROR: The SVC bus %d %s is a voltage controlled bus.\n",ACptr->N,ACptr->Name);      fCustomPrint(stderr,"       Check the AC bus cards.\n");      InputError=TRUE;    }    for (ELptr=ACptr->Elem,i=0;ELptr!=NULL;ELptr=ELptr->Next,i++);    if (i>1) {      fCustomPrint(stderr,"ERROR: The SVC bus %d %s has more than one AC element connected to it.\n",ACptr->N,ACptr->Name);      fCustomPrint(stderr,"       Check the AC element cards.\n");      InputError=TRUE;    }  }  for(STATCOMptr=dataPtr->STATCOMbus;STATCOMptr!=NULL;STATCOMptr=STATCOMptr->Next){    ACptr=STATCOMptr->Ctrl;    if (ACptr->Cont==NULL) {      fCustomPrint(stderr,"ERROR: The STATCOM controlled bus %d %s is already controlled.\n",ACptr->N,ACptr->Name);      fCustomPrint(stderr,"       Check the AC bus cards.\n");      InputError=TRUE;    }    ACptr=STATCOMptr->From;    if (ACptr->Cont==NULL) {      fCustomPrint(stderr,"ERROR: The STATCOM bus %d %s is a voltage controlled bus.\n",ACptr->N,ACptr->Name);      fCustomPrint(stderr,"       Check the AC bus cards.\n");      InputError=TRUE;    }  }}/* --------- ExpandSlack --------- */#ifdef ANSIPROTOvoid ExpandSlack(ACbusData *BSptr,AreaData *Aptr)#elsevoid ExpandSlack(BSptr,Aptr)ACbusData *BSptr;AreaData *Aptr;#endif{  AreaData *Aptrp;  ElementList *ELptr;  ElementData *Eptr;  Aptr->Slack=BSptr;  for(ELptr=Aptr->Elem;ELptr!=NULL;ELptr=ELptr->Next) {    Eptr=ELptr->Eptr;    if (Eptr->From->Area!=Aptr) Aptrp=Eptr->From->Area;    else Aptrp=Eptr->To->Area;    if (!strpbrk(Aptrp->Slack->Type,"S")) ExpandSlack(Aptr->Slack,Aptrp);  }}/* --------- WriteSummary --------- */#ifdef ANSIPROTOvoid WriteSummary(void)#elsevoid WriteSummary()#endif{  ACbusData *ACptr;  int i;  fCustomPrint(stderr,"Summary of input data for case:\n");  i=0;  while(i<=2 && dataPtr->Title[0][0]!='\0'){    fCustomPrint(stderr,"%s",dataPtr->Title[i]);    i++;  }  fCustomPrint(stderr,"            AC buses -> %d\n",Nac);  fCustomPrint(stderr,"            PV buses -> %d\n",Nvolt);  fCustomPrint(stderr,"            X buses  -> %d\n",NXvolt);  fCustomPrint(stderr,"            Z buses  -> %d\n",NZvolt);  fCustomPrint(stderr,"            AC elem. -> %d\n",NacEl);  fCustomPrint(stderr,"         V Reg. Trf. -> %d\n",NregV);  fCustomPrint(stderr,"        PQ Reg. Trf. -> %d\n",NregPQ);  fCustomPrint(stderr,"            DC buses -> %d\n",Ndc);  fCustomPrint(stderr,"            DC lines -> %d\n",NdcEl);  fCustomPrint(stderr,"                SVCs -> %d\n",Nsvc);     /* FACTS */  fCustomPrint(stderr,"               TCSCs -> %d\n",Ntcsc);    /* FACTS */  fCustomPrint(stderr,"            STATCOMs -> %d\n",Nstatcom); /* FACTS */  fCustomPrint(stderr,"           No. Areas -> %d\n",Narea);  fCustomPrint(stderr,"   Reference Bus(es) -> ");  i=0;  for (ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next)    if(strpbrk(ACptr->Type,"S")){      if (i>0)   fCustomPrint(stderr,"                        ");      fCustomPrint(stderr,"%d %s (Angle=%6.2lf deg.)\n",ACptr->Num,ACptr->Name,ACptr->Ang*180/PI);      i++;    }  if (i==0) fCustomPrint(stderr,"\n");  return;}/* ------------------------- ReadData ------------------------------- */#ifdef ANSIPROTOvoid ReadData(char *Name)#elsevoid ReadData(Name)char *Name;#endif /* Main routine. */{	InputDataFile=(FILE *) OpenInput(Name);  #ifdef WINDOWS	dataPtr= new Data;#else  dataPtr=(Data *) malloc(sizeof(Data));  if (dataPtr==NULL) {    fclose(InputDataFile);    ErrorHalt("Insufficient memory to read input data.");    stopExecute(ERROREXIT);  }#endif  dataPtr->Title[0][0]='\0';  dataPtr->ACbus=NULL;  dataPtr->DCbus=NULL;  dataPtr->Element=NULL;  dataPtr->Area=NULL;  dataPtr->KGbus=NULL;  dataPtr->SVCbus=NULL;     /* FACTS */  dataPtr->TCSCbus=NULL;    /* FACTS */  dataPtr->STATCOMbus=NULL; /* FACTS */  Nac=0; Ndc=0; NacEl=0; NdcEl=0;  Nsvc=Nstatcom=0; Ntcsc=NtcscVar=0;  /* FACTS */  LineNum=0;  Nvolt=0; Nslack=0;  Narea=0; NregPQ=NregV=0;  NZvolt=NXvolt=0;  InputError=FALSE;  flag2Vcontrol=ExistParameter('#');  if(ExistParameter('I')) ReadIEEE();  else if(ExistParameter('6')) ReadITALY();  else ReadWSCC();  ErrorDetect();  WriteSummary();  if (InputError==TRUE) {      fCustomPrint(stderr,"*** The data has errors! Please review the input file. ***\n");      stopExecute(ERROREXIT);  }  else fCustomPrint(stderr,"*** The data has been read successfully ***\n");#ifdef WINDOWS  delete[] Name;#else  free(Name);#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -