Allink  v0.1
VarDataRead.cpp
00001 /***********************************************************************
00002 VarData: This  Program reads and writes a specific file format 
00003 storing all the information relative to a set of equal structure
00004 polymers to the CHAIN, PART and GENERAL structures. It provides 
00005 two different ways to backfold the coordinates, a fanction that 
00006 creates an initial system with different option and some function
00007 for the data analisys. The first calculate the distribution of the
00008 monomer in the box, the second the distribution of the bonds.
00009 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it>
00010 
00011 
00012 This program is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU General Public License as published by
00014 the Free Software Foundation; either version 2 of the License, or
00015 (at your option) any later version.
00016 
00017 This program is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 GNU General Public License for more details.
00021 
00022 You should have received a copy of the GNU General Public License
00023 along with this program; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 ***********************************************************************/
00026 #include "../include/VarData.h"
00027 ;
00028 bool VarData::ReadConf(char *InFile){
00029   FILE *FileToRead;
00030   VarMessage("ReadConf");
00031   if((FileToRead = fopen(InFile,"r"))==0){
00032     printf("The file %s is missing\n",InFile);
00033     return 1;
00034   }
00035   //double *buff = (double *)malloc(sizeof(double));
00036   double buff[1];
00037   char cLine[STRSIZE];
00038   char Topology[20];
00039   int NCircle = 0;
00040   int NHeight = 0;
00041   int DiblockLim = 0;
00042   SysFormat = 0;
00043   //  fgets(cLine,256,FileToRead);
00044   for(int k=0;!(fgets(cLine,STRSIZE,FileToRead)==NULL);k++){
00045     if(cLine[0] == '#') continue;
00046     if(ReadString("NSoft",cLine,buff)==1){
00047       NSoft = (int)*buff;
00048       if(NSoft != 0) 
00049    Soft = (SOFT *)realloc(Soft,NSoft*sizeof(SOFT));
00050     }
00051     //sytem type
00052     if(ReadString("IfSystem",cLine,buff)==1){
00053       if( (int)*buff == 1 ){
00054    SysFormat = VAR_SYS_TXVL;
00055       }
00056       else{
00057    SysFormat = VAR_SYS_XVT;
00058       }
00059     }
00060     //
00061     if(ReadString("CNorm",cLine,buff)==1){
00062       CNorm = (int)*buff;
00063       CLat1 = (CNorm+1)%3;
00064       CLat2 = (CNorm+2)%3;
00065     }
00066     if(ReadString("NAddChain",cLine,buff)==1)
00067       NAddChain = (int)*buff;
00068     if(ReadString("NAddChol",cLine,buff)==1)
00069       NAddChol = (int)*buff;
00070     if(ReadString("NSolvent",cLine,buff)==1)
00071       NSolvent = (int)*buff;
00072     if(ReadString("NStuffing",cLine,buff)==1)
00073       NStuffing = (int)*buff;
00074     if(ReadString("DiblockLim",cLine,buff)==1)
00075       DiblockLim = (int)*buff;
00076     if(ReadString("IfTwoTails",cLine,buff)==1)
00077       if( (int)*buff == 1 ){
00078    VAR_ADD_TYPE(SysType,VAR_TWOTAILS);
00079       }      
00080     if(ReadString("NPartPChain",cLine,buff)==1)
00081       SetNPCh((int)*buff);
00082     if(ReadString("NNano",cLine,buff)==1){
00083       Gen->NNano = (int)*buff;
00084       if(Gen->NNano != 0) 
00085    Nano = (NANO *)realloc(Nano,Gen->NNano*sizeof(NANO));
00086     }
00087     if(ReadString("NCircle",cLine,buff)==1){
00088       NCircle = (int)*buff;
00089     }
00090     if(ReadString("NHeight",cLine,buff)==1){
00091       NHeight = (int)*buff;
00092     }
00093     if(ReadString("rho",cLine,buff)==1)
00094       Gen->rho = *buff;
00095     if(ReadString("chiN",cLine,buff)==1)
00096       Gen->chiN = *buff;
00097     if(ReadString("kappaN",cLine,buff)==1)
00098       Gen->kappaN = *buff;
00099     if(ReadString("kappaBend",cLine,buff)==1)
00100       Gen->kappaBend = *buff;
00101     if(ReadString("kappaSpring",cLine,buff)==1)
00102       Gen->kappaSpring = *buff;
00103     if(ReadString("ReOverCutOff",cLine,buff)==1)
00104       Gen->ReOverCutOff = *buff;
00105     if(ReadString("WFuncStraight2",cLine,buff)==1)
00106       Gen->WFuncStraight2 = *buff;
00107     if(ReadString("WFuncStraight3",cLine,buff)==1)
00108       Gen->WFuncStraight3 = *buff;
00109     if(ReadString("vBB",cLine,buff)==1)
00110       Gen->vBB = *buff;
00111     if(ReadString("Lx",cLine,buff)==1)
00112       Gen->Edge[0] = *buff;
00113     if(ReadString("Ly",cLine,buff)==1)
00114       Gen->Edge[1] = *buff;
00115     if(ReadString("Lz",cLine,buff)==1)
00116       Gen->Edge[2] = *buff;
00117   }
00118   ReadSoft(FileToRead);
00119   ReadNano(FileToRead,NCircle,NHeight);
00120   SetNBlock(1);
00121   Block[0].Asym = DiblockLim;
00122   fclose(FileToRead);
00123   // char cSystem[512];
00124   // SysDef(cSystem);
00125   // printf("%s\n",cSystem);
00126   // HeaderNano(cSystem);
00127   // printf("%s",cSystem);
00128   // HeaderSoft(cSystem);
00129   // printf("%s",cSystem);
00130   return 0;
00131 }
00132 int VarData::NanoString(char *cLine,int n){
00133   double Pos[3];
00134   double Vel[3];
00135   double Axis[3];
00136   double Char[5];
00137   char Shape[20];
00138   char Name[20];
00139   if( !Fetch(cLine,"x","%lf %lf %lf",Pos,Pos+1,Pos+2)){
00140     for(int d=0;d<3;d++)
00141       Nano[n].Pos[d] = pEdge(d)*.5;
00142   }
00143   else{
00144     for(int d=0;d<3;d++){
00145       if(isnan(Pos[d])) Pos[d] = .5*pEdge(d);
00146       Nano[n].Pos[d] = Pos[d]*ScaleF[d];
00147       Nano[n].Bkf[d] = - floor(Nano[n].Pos[d]/pEdge(d))*pEdge(d);
00148     }
00149   }    
00150   if( !Fetch(cLine,"a","%lf %lf %lf",Axis,Axis+1,Axis+2)){
00151     Nano[n].Axis[CLat1] = 0.;
00152     Nano[n].Axis[CLat2] = 0.;
00153     Nano[n].Axis[CNorm] = 1.;
00154   }
00155   else{
00156     if(isnan(Axis[0])) Axis[0] = 0.;
00157     if(isnan(Axis[1])) Axis[1] = 0.;
00158     if(isnan(Axis[2])) Axis[2] = 1.;
00159     Nano[n].Axis[0] = Axis[0];
00160     Nano[n].Axis[1] = Axis[1];
00161     Nano[n].Axis[2] = Axis[2];
00162   }
00163   if( Fetch(cLine,"c","%lf %lf %lf %lf",Char,Char+1,Char+2,Char+3)){
00164     double r = sqrt(.5*SQR(ScaleF[0])+.5*SQR(ScaleF[1]));
00165     Nano[n].Rad = Char[0]*r;
00166     Nano[n].Viscosity = 0.1;
00167     Nano[n].Hamaker = Char[1];
00168     Nano[n].Height = Char[2]*ScaleF[2];
00169     Nano[n].OffSet = Char[3];
00170     Nano[n].Coating = Char[3];
00171     Nano[n].Gamma = 3.*3.14*Nano[n].Rad*Nano[n].Viscosity;
00172     //Nano[n].Zeta = sqrt(12. * 2. * 1. * Nano[n].Gamma/Nano[n].Mass/dt);
00173   }
00174   // if( ret == 8){
00175   if( Fetch(cLine,"s","%s",Shape)){
00176     Nano[n].Shape = ShapeId(Shape);
00177   }
00178   Nano[n].Mass = 100.;
00179   return 0;
00180 }
00181 int VarData::ShapeId(char *Shape){
00182   int iShape=0;
00183   if(!strcmp(Shape,"no"))
00184     VAR_ADD_TYPE(iShape,SHAPE_NONE);
00185   else if(!strcmp(Shape,"sph")) 
00186     VAR_ADD_TYPE(iShape,SHAPE_SPH);
00187   else if(!strcmp(Shape,"tip")) 
00188     VAR_ADD_TYPE(iShape,SHAPE_TIP);
00189   else if(!strcmp(Shape,"dip")) 
00190     VAR_ADD_TYPE(iShape,SHAPE_SPH);
00191   else if(!strcmp(Shape,"cyl")){
00192     VAR_ADD_TYPE(iShape,SHAPE_CYL);
00193     VAR_ADD_TYPE(iShape,SHAPE_HEI);
00194   }
00195   else if(!strcmp(Shape,"tilt")){ 
00196     VAR_ADD_TYPE(iShape,SHAPE_TILT);
00197     VAR_ADD_TYPE(iShape,SHAPE_HEI);
00198   }
00199   else if(!strcmp(Shape,"pill")){
00200     VAR_ADD_TYPE(iShape,SHAPE_PILL);
00201     VAR_ADD_TYPE(iShape,SHAPE_HEI);
00202   }
00203   else if(!strcmp(Shape,"wall")) 
00204     VAR_ADD_TYPE(iShape,SHAPE_WALL);
00205   else if(!strcmp(Shape,"cluster")) 
00206     VAR_ADD_TYPE(iShape,SHAPE_CLUSTER);
00207   else if(!strcmp(Shape,"harm")) 
00208     VAR_ADD_TYPE(iShape,SHAPE_HARM);
00209   else if(!strcmp(Shape,"clinks")) 
00210     VAR_ADD_TYPE(iShape,SHAPE_CLINKS);
00211   else if(!strcmp(Shape,"pore")) 
00212     VAR_ADD_TYPE(iShape,SHAPE_PORE);
00213   else if(!strcmp(Shape,"ext")) 
00214     VAR_ADD_TYPE(iShape,SHAPE_EXT);
00215   else if(!strcmp(Shape,"janus")) 
00216     VAR_ADD_TYPE(iShape,SHAPE_JANUS);
00217   else if(!strcmp(Shape,"stalk")) 
00218     VAR_ADD_TYPE(iShape,SHAPE_STALK);
00219   else if(!strcmp(Shape,"torus"))
00220     VAR_ADD_TYPE(iShape,SHAPE_TORUS);
00221   else if(!strcmp(Shape,"umbr"))
00222     VAR_ADD_TYPE(iShape,SHAPE_UMBR);
00223   else if(!strcmp(Shape,"bound"))
00224     VAR_ADD_TYPE(iShape,SHAPE_BOUND);
00225   else 
00226     printf("Nano type %s not recognized\n",Shape);
00227   return iShape;
00228 }
00229 void VarData::ReadNano(FILE *ConfFile,int NCircle,int NHeight){
00230   char cLine[STRSIZE];
00231   rewind(ConfFile);
00232   for(int k=0,n=0;!(fgets(cLine,STRSIZE,ConfFile)==NULL);k++){
00233     if(n == Gen->NNano) break;
00234     if(cLine[0] == '#') continue;
00235     if(strstr(cLine, "Rigid") == cLine) {
00236       NanoString(cLine,n);
00237       for(int d=0;d<3;d++){
00238    Nano[n].Pos[d] *= pEdge(d);
00239    Nano[n].Vel[d] = 0.;
00240    Nano[n].AVel[d] = 0.;
00241       }
00242       Nano[n].NCircle = (int)(NCircle*Nano[n].Rad);
00243       if( (Nano[n].NCircle%2) != 0)
00244    Nano[n].NCircle++;
00245       Nano[n].NHeight = (int)(NHeight*Nano[n].Height);
00246       if( (Nano->NHeight%2) != 0)
00247    Nano->NHeight++;
00248       n++;
00249     }
00250   }
00251 }
00252 void VarData::SubNanoHeader(char *cFile){
00253   FILE *FRead = fopen(cFile,"r+");
00254   char cLine[STRSIZE];
00255   fpos_t fPosNano;
00256   do {
00257     fgetpos(FRead,&fPosNano);
00258     fgets(cLine, sizeof(cLine),FRead);
00259     if(strstr(cLine, "# Rigid") == cLine){
00260       break;
00261     }
00262     else if(strstr(cLine, "#") != cLine){
00263       printf("No # Rigid present!\n");
00264       break;
00265     }
00266   } while (1==1);
00267   fgets(cLine, sizeof(cLine),FRead);
00268   fsetpos(FRead,&fPosNano);
00269   HeaderNano(FRead);
00270   fprintf(FRead,"%s",cLine);
00271   fclose(FRead);
00272 }
00273 int VarData::ReadSoft(FILE *ConfFile){
00274   double Pos[3];
00275   double Vel[3];
00276   double Char[5];
00277   int iShape=0;
00278   char Shape[20];
00279   char Name[20];
00280   char cLine[STRSIZE];
00281   rewind(ConfFile);
00282   for(int k=0,n=0;!(fgets(cLine,STRSIZE,ConfFile)==NULL);k++){
00283     if(cLine[0] == '#') continue;
00284     if(n == NSoft) break;
00285     if (strstr(cLine, "Soft") == cLine) {
00286       if( !Fetch(cLine,"x","%lf %lf %lf",Pos,Pos+1,Pos+2)){
00287    Soft[n].Pos[0] = 0.;
00288    Soft[n].Pos[1] = 0.;
00289    Soft[n].Pos[2] = 0.;
00290       }
00291       else{
00292    Soft[n].Pos[0] = Pos[0]*pEdge(0);
00293    Soft[n].Pos[1] = Pos[1]*pEdge(1);
00294    Soft[n].Pos[2] = Pos[2]*pEdge(2);
00295       }    
00296       if( !Fetch(cLine,"v","%lf %lf %lf",Vel,Vel+1,Vel+2)){
00297    Soft[n].Vel[0] = 0.;
00298    Soft[n].Vel[1] = 0.;
00299    Soft[n].Vel[2] = 0.;
00300       }
00301       else{
00302    Soft[n].Vel[0] = Vel[0];
00303    Soft[n].Vel[1] = Vel[1];
00304    Soft[n].Vel[2] = Vel[2];
00305       }    
00306       if( !Fetch(cLine,"c","%lf %lf %lf",Char,Char+1,Char+2)){
00307    printf("Rigid characteristic are not specified\n");
00308    return 1;
00309       }
00310       Soft[n].Size[0] = Char[0];
00311       Soft[n].Size[1] = Char[1];
00312       Soft[n].Size[2] = Char[2];
00313       if( !Fetch(cLine,"s","%s",Shape)){
00314    printf("Soft shape is not specified\n");
00315    return 1;
00316       }
00317       if(!strcmp(Shape,"planar")){
00318    VAR_ADD_TYPE(Soft[n].Topology,VAR_PLANAR);
00319       }
00320       else if(!strcmp(Shape,"planarPE")){
00321    VAR_ADD_TYPE(Soft[n].Topology,VAR_PLANAR_PE);
00322       }
00323       else if(!strcmp(Shape,"tube"))
00324    VAR_ADD_TYPE(Soft[n].Topology,VAR_TUBE);
00325       else if(!strcmp(Shape,"obstacle"))
00326    VAR_ADD_TYPE(Soft[n].Topology,VAR_OBSTACLE);
00327       else if(!strcmp(Shape,"coating"))
00328    VAR_ADD_TYPE(Soft[n].Topology,VAR_COATING);
00329       else if(!strcmp(Shape,"distributed"))
00330    VAR_ADD_TYPE(Soft[n].Topology,VAR_DISTRIBUTED);
00331       else if(!strcmp(Shape,"vesicle"))
00332    VAR_ADD_TYPE(Soft[n].Topology,VAR_VESICLE);
00333       else{
00334    printf("Soft type not recognized %s\n",Shape);
00335    return 1;
00336       }
00337       sprintf(Soft[n].Name,"LIPID");
00338       // if( !Fetch(cLine,"n","%s",Name)){
00339       //    printf("Soft name not specified\n");
00340       //    return 1;
00341       // }
00342       //      sprintf(Soft[n].Name,"%s",Name);
00343       n++;
00344     }
00345   }
00346   return 0;
00347 }
00348 //#################SYS#INFO##################################
00349 void VarData::ReadHeader(FILE *FileToRead){
00350   VarMessage("ReadSysInfo");
00351   SysFormat = 0;
00352   VAR_REM_TYPE(SysType,VAR_CHAIN_DEF);
00353   char cLine[STRSIZE];
00354   double Val[6];
00355   for(int d=0;d<3;d++){
00356     Gen->Cm[d] = 0.;
00357   }
00358   fgets(cLine,STRSIZE,FileToRead);
00359   if(Fetch(cLine,"l",3,Val)){
00360     SysFormat = VAR_SYS_TXVL;
00361     VAR_ADD_TYPE(SysType,VAR_EDGE);
00362     SetEdge(Val[0]*ScaleF[0],0);
00363     SetEdge(Val[1]*ScaleF[1],1);
00364     SetEdge(Val[2]*ScaleF[2],2);
00365   }
00366   //else if(!strcspn(cLine,"# L=\n")){
00367   else if(!strncmp(cLine,"# L=",4)){
00368     SysFormat = VAR_SYS_XVT;
00369   }
00370   else{
00371     do{
00372       fgets(cLine,STRSIZE,FileToRead);
00373       char *pLine = strchr(cLine,'#');
00374       if(pLine == NULL){
00375    int NPar = sscanf(cLine,"%lf %lf %lf %lf\n",Val,Val+1,Val+2,Val+3);
00376    if(NPar == 3){
00377      SysFormat = VAR_SYS_XYZ;
00378      SetNChain(1);
00379      SetNBlock(1);
00380    }
00381    else if(NPar == 4){
00382      SysFormat = VAR_SYS_XYZT;
00383      SetNChain(1);
00384      SetNBlock(1);
00385    }
00386    break;
00387       }
00388     } while(1==1);
00389   }
00390   rewind(FileToRead);
00391   if( SysFormat == VAR_SYS_TXVL ){
00392     ReadHeaderTxvl(FileToRead);
00393   }
00394   else if ( SysFormat == VAR_SYS_XVT ){
00395     ReadHeaderXvt(FileToRead);
00396   }
00397   rewind(FileToRead);
00398 }
00399 void VarData::ReadHeaderTxvl(FILE *FileToRead){
00400   double Val[6];
00401   char cLine[STRSIZE];
00402   fgets(cLine,STRSIZE,FileToRead);
00403   Gen->Time += 1.;
00404   Gen->NNano = 0;
00405   //Energy
00406   //#Chain
00407   if(Fetch(cLine,"c",1,Val)){
00408     SetNChain((int)Val[0]);
00409   }
00410   //What to draw
00411   if(Fetch(cLine,"d","%s",cWhat2Draw)); 
00412   //Delta t
00413   if(Fetch(cLine,"D",1,Val)) SetDeltat(Val[0]);
00414   if(Fetch(cLine,"e",3,Val)){
00415     Gen->Energy[0] = Val[0];
00416     Gen->Energy[1] = Val[1];
00417     Gen->Energy[2] = Val[2];
00418   }
00419   //inputs
00420   if(Fetch(cLine,"i",3,Val)){
00421     Gen->rho    = Val[0];
00422     Gen->chiN   = Val[1];
00423     Gen->kappaN = Val[2];
00424   }
00425   //#link
00426   if(Fetch(cLine,"L",1,Val)){
00427     SetNLink((int)Val[0]);
00428   }
00429   //#Part
00430   if(Fetch(cLine,"n",1,Val)){
00431     //SetNLink(2);
00432     SetNPart((int)Val[0]);
00433     VAR_ADD_TYPE(SysType,VAR_OPEN_TRUST);
00434   }
00435   //Nano
00436   if(Fetch(cLine,"N",4,Val)){
00437     Gen->NNano = 1;
00438     //    Nano = (NANO *) realloc(Nano,Gen->NNano*sizeof(NANO));
00439     Nano->Rad = Val[0];
00440     Nano->Hamaker = Val[1];
00441     Nano->Viscosity = Val[2];
00442     Nano->Height = Val[3];
00443     if(Nano->Hamaker > 0.1){
00444       Nano->Shape = SHAPE_SPH;
00445       if(Nano->Height > 0.1){
00446    Nano->Shape = SHAPE_CYL;
00447       }
00448     }
00449   }
00450   if(Fetch(cLine,"P",1,Val)){
00451     if( *Val < 0. || *Val > 3.);
00452     else{
00453       CNorm = (int)*Val;
00454       CLat1 = (CNorm+1)%3;
00455       CLat2 = (CNorm+2)%3;
00456     }
00457   }
00458   if(Fetch(cLine,"r",4,Val)){
00459     Gen->NNano = 1;
00460     //    Nano = (NANO *) realloc(Nano,Gen->NNano*sizeof(NANO));
00461     Nano->Pos[0] = Val[0];
00462     Nano->Pos[1] = Val[1];
00463     Nano->Pos[2] = Val[2];
00464     Nano->Axis[0] = 0.;
00465     Nano->Axis[1] = 0.;
00466     Nano->Axis[2] = 1.;
00467     Nano->Shape = SHAPE_NONE;
00468   }
00469   //step
00470   if(Fetch(cLine,"s",1,Val)) SetStep((int) Val[0]);
00471   //Temperature
00472   if(Fetch(cLine,"T",1,Val)) SetTemp(Val[0]);
00473   //# Values
00474   if(Fetch(cLine,"v",1,Val)){
00475     NEdge = (int)Val[0];
00476     if(!strcmp(cWhat2Draw,"color")){
00477       SetNLink(0);
00478       SetNPart(NEdge*NEdge*NEdge);
00479       SetNChain(1);
00480       SetNPCh(pNPart());
00481       VAR_ADD_TYPE(SysType,VAR_OPEN_TRUST);
00482     }
00483   }
00484   SetNBlock(1);
00485   //----------inclusion------------------------
00486   // how many Nano
00487   //Gen->NNano = 0;
00488   fpos_t PosTemp;
00489   fgetpos(FileToRead,&PosTemp);
00490   do {
00491     fgets(cLine, sizeof(cLine),FileToRead);
00492     if(strstr(cLine, "# Rigid") == cLine)
00493       Gen->NNano++;
00494     else if(strstr(cLine, "# Pep") == cLine)
00495       Gen->NNano++;
00496     else 
00497       break;
00498   } while (1==1);
00499   fsetpos(FileToRead,&PosTemp);
00500   if(Gen->NNano != 0)
00501     Nano = (NANO *) realloc(Nano,Gen->NNano*sizeof(NANO));
00502   for(int n=0;n<Gen->NNano;n++){
00503     fgetpos(FileToRead,&PosTemp);
00504     fgets(cLine,STRSIZE,FileToRead);
00505     if( strncmp(cLine,"# Rigid",7)){// + strncmp(cLine,"# Pep",5)){
00506       fsetpos(FileToRead,&PosTemp);
00507       break;
00508     }
00509     NanoString(cLine,n);
00510   }
00511 }
00512 void VarData::ReadHeaderXvt(FILE *FileToRead){
00513   double Val[6];
00514   char cLine[STRSIZE];
00515   fgets(cLine,STRSIZE,FileToRead);
00516   fpos_t PosTemp;
00517   //-----------edge-nblock------------
00518   fgetpos(FileToRead,&PosTemp);
00519   double Time = 0.;
00520   int NBlock = 0;
00521   if( sscanf(cLine,"# L=%lf %lf %lf t=%lf blocks=%d",&Val[0],&Val[1],&Val[2],&Time,&NBlock) == 5 ){
00522     for(int d=0;d<3;d++) SetEdge(Val[d]*ScaleF[d],d);
00523     SetTime(Time);
00524     SetStep((int)(Time/0.05));
00525     SetNBlock(NBlock);
00526     VAR_ADD_TYPE(SysType,VAR_EDGE);
00527     for(int d=0;d<3;d++)
00528       Nano->Pos[d] = (.5 - ShiftPos[d])*pEdge(d);
00529     SetNanoBkf(0);
00530     Nano->Axis[0] = 0.;Nano->Axis[1] = 0.;Nano->Axis[2] = 1.;
00531   }
00532   //---------------virial-coefficients---------------
00533   //fgets(cLine,STRSIZE,FileToRead);
00534   double v[6];
00535   double w[10];
00536   int IfTwoType = 1;
00537   int IfThreeType = 1;
00538   fscanf(FileToRead,"# v=");
00539   for(int i=0;i<6;i++){
00540     if(fscanf(FileToRead,"%lf ",v+i) != 1){
00541       //fsetpos(FileToRead,&PosTemp);
00542       if(i == 2) IfThreeType = 0;
00543       break;
00544     }
00545     if(i >  2) IfTwoType = 0;
00546   }
00547   int NThird = 10;
00548   Gen->vBB = v[3];
00549   if(IfTwoType) NThird = 4;
00550   fscanf(FileToRead,"w=");
00551   for(int i=0;i<NThird;i++){
00552     if(fscanf(FileToRead,"%lf ",w+i) != 1){
00553       break;
00554     }
00555   }
00556   Gen->rho = 3.*(- .5*v[0] + sqrt(QUAD(v[0])*.25-8.*w[0]/3.))/(4.*w[0]);
00557   Gen->kappaN = - v[0] * Gen->rho*.5-3.;
00558   if(IfTwoType)
00559     Gen->chiN = (v[1] - .5*(v[0]+v[2]))*Gen->rho;
00560   else if(IfThreeType)
00561     Gen->chiN = (v[1] - .5*(v[0]+v[3]))*Gen->rho;
00562   //---------------intra-forces-------------------
00563   fgets(cLine,STRSIZE,FileToRead);
00564   double Nigot1,Nigot2,Nigot3;
00565   fgetpos(FileToRead,&PosTemp);
00566   int ret = sscanf(cLine,"# a2=%lf a3=%lf Re=%lf N=%lf ks=%lf kb=%lf l0=%lf",&Gen->WFuncStraight2,&Gen->WFuncStraight3,&Gen->ReOverCutOff,&Nigot3,&Gen->kappaSpring,&Gen->kappaBend,&Gen->SpringRest);
00567   if(ret == 7);
00568   else fsetpos(FileToRead,&PosTemp);
00569   SetCoeff(v,w);
00570   //----------inclusion------------------------
00571   double Pos[3];
00572   double Char[5];
00573   int NSide[2];
00574   double Axis[3];
00575   char Shape[10];
00576   char FileName[60];
00577   int NNanoTemp = 0;
00578   // how many Nano
00579   fgetpos(FileToRead,&PosTemp);
00580   Gen->NNano = 0;
00581   for(int t=0;t<50;t++){
00582     if(NULL == fgets(cLine,sizeof(cLine),FileToRead)) break;
00583     if(strstr(cLine, "# Rigid") == cLine)
00584       Gen->NNano++;
00585     else if(strstr(cLine, "# Pep") == cLine)
00586       Gen->NNano++;
00587     else 
00588       break;
00589   }
00590   fsetpos(FileToRead,&PosTemp);
00591   if(Gen->NNano != 0)
00592     Nano = (NANO *) realloc(Nano,Gen->NNano*sizeof(NANO));
00593   for(int n=0;n<Gen->NNano;n++){
00594     fgetpos(FileToRead,&PosTemp);
00595     fgets(cLine,STRSIZE,FileToRead);
00596     if( strncmp(cLine,"# Rigid",7)){
00597       fsetpos(FileToRead,&PosTemp);
00598       continue;
00599     }
00600     NanoString(cLine,n);
00601     NNanoTemp++;
00602   }
00603   //printf("%lf %lf %lf %s\n",Pos[0],Axis[0],Char[0],Shape);
00604   // Soft
00605   for(int n=NNanoTemp;n<Gen->NNano;n++){
00606     fgetpos(FileToRead,&PosTemp);
00607     fgets(cLine,STRSIZE,FileToRead);
00608     if( strncmp(cLine,"# Pep",4) ){
00609       fsetpos(FileToRead,&PosTemp);
00610       break;
00611     }
00612     if( Fetch(cLine,"g","%lf %lf %lf",Char,Char+1,Char+2)){
00613       Nano[n].Rad = Char[0];
00614       Nano[n].Height = Char[1];
00615       Nano[n].Hamaker = Char[2];
00616     }
00617     if( Fetch(cLine,"d","%d %d",NSide,NSide+1)){
00618       Nano[n].NCircle = NSide[0];
00619       Nano[n].NHeight = NSide[1];
00620     }
00621     if( Fetch(cLine,"fn","%s",FileName)){
00622       sprintf(Nano[n].ArchFile,"%s",FileName);
00623     }
00624     Nano[n].Shape = SHAPE_CLUSTER;
00625   }
00626 }
00627 //###############################PASS#THRU########################
00628 //If the information for the allocation are missing
00629 int VarData::ReadPassThru(FILE *FileToRead){
00630   VarMessage("PassThru");
00631   int Val[3];
00632   char cLine[STRSIZE];
00633   char cVar[STRSIZE];
00634   char cVal[STRSIZE];
00635   int Paren[2];
00636   int NChain = 0;
00637   int NPart = 0;
00638   int NPCh = 0;
00639   int NType = 0;
00640   int NLink = 0;
00641   if( SysFormat == VAR_SYS_TXVL ){
00642     for(int k=0;!(fgets(cLine,STRSIZE,FileToRead)==NULL);k++){
00643       if(cLine[0] == '#') continue;
00644       int iLen = (int) (strlen(cLine));
00645       if( Fetch(cLine,"t","%d %d %d",Val,Val+1,Val+2)){
00646    int p = Val[0];
00647    int c = Val[1];
00648    int t = Val[2];
00649    if(c >= NChain) NChain++;
00650    if(t >= NType) NType++;
00651       }
00652       if(cLine[0] == '{') NPart++;
00653       if(NChain==0) NPCh++;
00654       for(int i=0,link=0,part=0;i<iLen;i++){
00655    if(cLine[i] == 'l' && cLine[i+1] == '['){
00656      link++;
00657      if(link >= NLink) NLink++;
00658    }
00659       }
00660     }
00661     if(NChain==0) NChain = 1;
00662     Block[0].InitIdx = 0;
00663     Block[0].NChain = NChain;
00664     Block[0].NPCh = NPCh;
00665     Block[0].NPart = NPart;
00666     Block[0].EndIdx = NPart;
00667   }
00668   else if ( SysFormat == VAR_SYS_XVT ){
00669     for(int k=0,b=0;!(fgets(cLine,STRSIZE,FileToRead)==NULL);k++){
00670       if(3 == sscanf(cLine,"# n=%d N=%d name=%s",&Val[0],&Val[1],&Block[b].Name)){
00671    Block[b].InitIdx = NPart;
00672    Block[b].NChain = Val[0];
00673    Block[b].NPCh = Val[1];
00674    Block[b].NPart = Block[b].NChain*Block[b].NPCh;
00675    NChain += Block[b].NChain;
00676    NPart  += Block[b].NPart;
00677    Block[b].EndIdx = NPart;
00678    Block[b].Arch = ARCH_LINES;
00679    NLink = 1;
00680    if(strcasestr(Block[b].Name, "TT") == Block[b].Name){
00681      Block[b].Arch = ARCH_TWOTAILS;
00682      NLink = 2;
00683    }
00684    if(strcasestr(Block[b].Name, "PEP") == Block[b].Name){
00685      Block[b].Arch = ARCH_CLUSTER;
00686    }
00687    //printf("Found block # %d name %s #chain %d #part %d #partPchain%d from %d to %d\n",b,Block[b].NChain,Block[b].Name,Block[b].NPart,Block[b].NPCh,Block[b].InitIdx,Block[b].EndIdx);
00688    b++;
00689    if(Gen->NBlock == b) break;
00690       }
00691     }
00692     for(int b=0,nNano=0;b<pNBlock();b++){
00693       if(VAR_IF_TYPE(Block[b].Arch,ARCH_CLUSTER)){
00694    for(int n=0;n<pNNano();n++,nNano=n){
00695      if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CLUSTER)){
00696        Nano[n].nBlock = b;
00697      }
00698    }
00699       }
00700     }
00701     NPCh = Block[0].NPCh;
00702   }
00703   else{
00704     for(int k=0,b=0;!(fgets(cLine,STRSIZE,FileToRead)==NULL);k++){
00705       if(cLine[0] == '#' || cLine[0] == '$'){continue;}
00706       NPart++;
00707     }
00708     if(SysFormat == VAR_SYS_XYZ) NPCh = NPart;
00709   }
00710   SetNLink(NLink);
00711   SetNPart(NPart);
00712   SetNChain(NChain);
00713   SetNPCh(NPCh);
00714   SetNType(NType);
00715   rewind(FileToRead);
00716  return 0;
00717 }
00718 //####################READ#PART#################################3
00719 int VarData::ReadPart(FILE *FileToRead){
00720   for(int d=0;d<3;d++) Gen->Cm[d] = 0.;  
00721   if( SysFormat == VAR_SYS_TXVL ){
00722     if(ReadPartTxvl(FileToRead)) return 1;
00723     Block[0].NPart = Gen->NPart;
00724     Block[0].NChain = Gen->NChain;
00725     Block[0].NPCh = Gen->NPCh;
00726     Block[0].InitIdx = 0;
00727     Block[0].EndIdx = Gen->NPart;
00728   }
00729   else if( SysFormat == VAR_SYS_XVT ){
00730     if(ReadPartXvt(FileToRead)) return 1;
00731   }
00732   else if( SysFormat == VAR_SYS_XYZT ){
00733     if(ReadPartXyzt(FileToRead)) return 1;
00734   }
00735   else {
00736     if(ReadPartXyz(FileToRead)) return 1;
00737   }
00738   for(int d=0;d<3;d++) Gen->Cm[d] /= (double)pNPart();
00739   if(pNNano() == 0){
00740     for(int d=0;d<3;d++){
00741       Nano->Pos[d] = .5*pEdge(d);
00742     }
00743     SetNanoBkf(0);
00744     Nano->Axis[0] = 0.;Nano->Axis[1] = 0.;Nano->Axis[2] = 1.;
00745   }
00746   return 0;
00747 }
00748 int VarData::ReadPartTxvl(FILE *FileToRead){
00749   VarMessage("ReadPartSys");
00750   int NChain = 0;
00751   int NPart = 0;
00752   Gen->NPCh = 0;
00753   int NType = 0;
00754   int NLink = 0;
00755   double Val[6];
00756   int Char[6];
00757   char cLine[STRSIZE];
00758   for(int d=0;d<4;d++) Gen->Vel[d] = 0.000001;
00759   for(int c=0;c<Gen->NChain;c++){
00760     for(int d=0;d<3;d++)
00761       Ch[c].Pos[d] = 0.;
00762   }
00763   Block[0].InitIdx = 0;
00764   Block[0].EndIdx = Gen->NPart;
00765   int NPCh = 0;
00766   for(int p=0,c=0;!(fgets(cLine,STRSIZE,FileToRead)==NULL);p++){
00767     //if(p >= Gen->NPart) break;
00768     int IfContinue = 1;
00769     int iLen = strlen(cLine);
00770     for(int k=0;k<iLen;k++){
00771       if(cLine[k] == '#'){
00772    p--;
00773    IfContinue = 0;
00774    break;
00775       }
00776     }
00777     if(!IfContinue) continue;
00778     if(p >= Gen->NPart){
00779       //printf("More particles than expected %d > %d\n",p,Gen->NPart);
00780       //return 1;
00781     }
00782     Pm[p].Idx=p;Pm[p].Typ=0;Pm[p].CId=0;
00783     int sPos = Fetch(cLine,"t","%d %d %d",Char,Char+1,Char+2);
00784     if(sPos){
00785       Pm[p].Idx = Char[0];
00786       Pm[p].CId = Char[1];
00787       Pm[p].Typ = Char[2];
00788     }
00789     if(p>0 && Pm[p].CId != Pm[p-1].CId){
00790       Ch[c].NPCh = NPCh;
00791       Ch[c].InitBead = p-NPCh;
00792       Ch[c].EndBead = p;
00793       NPCh = 0;
00794     }
00795     sPos += Fetch(cLine+sPos,"x","%lf %lf %lf",Pm[p].Pos,Pm[p].Pos+1,Pm[p].Pos+2);
00796     sPos += Fetch(cLine+sPos,"v","%lf %lf %lf",Pm[p].Vel,Pm[p].Vel+1,Pm[p].Vel+2);
00797     for(int d=0;d<3;d++){
00798       Pm[p].Pos[d] *= ScaleF[d];
00799       Ch[c].Pos[d] += Pm[p].Pos[d];
00800       Gen->Cm[d] += Pm[p].Pos[d];
00801       //Ch[c].Vel[d] += Pm[p].Vel[d];
00802       if(Gen->Vel[d] < Pm[p].Vel[d])
00803    Gen->Vel[d] = Pm[p].Vel[d];
00804     }
00805     if(Pm[p].CId > c){
00806       c++;
00807       if(c >= Gen->NChain){
00808    printf("More chains than expected %d > %d\n",c,Gen->NChain);
00809       }
00810     }
00811     if(Pm[p].CId == 0){Gen->NPCh++;}
00812     if(Gen->NType < Pm[p].Typ ){
00813       NType++;
00814       if(Pm[p].CId == 0)
00815    Block[0].Asym = p;
00816     }
00817     //Ch[c].NPart++;
00818     Pm[p].Vel[3] = sqrt( QUAD((Pm[p].Vel[0])) + QUAD((Pm[p].Vel[1])) +  QUAD((Pm[p].Vel[2])) );
00819     Gen->Vel[3] += sqrt( QUAD((Pm[p].Vel[0])) + QUAD((Pm[p].Vel[1])) +  QUAD((Pm[p].Vel[2])) );
00820     for(int l=0;l<Gen->NLink;l++){
00821       Ln[p].Link[l] = 0;
00822       int sPosOld = Fetch(cLine+sPos,"l",1,Val);
00823       //int sPosOld = Fetch(cLine+sPos,"l","%d",Val);
00824       if(sPosOld){
00825    Ln[p].Link[l] = (int)Val[0];
00826    Ln[p].NLink = l+1;
00827    sPos += sPosOld;
00828       }
00829     }
00830     //printf("%s{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf) l[%d] l[%d]}\n\n",p,cLine,Pm[p].Idx,Pm[p].CId,Pm[p].Typ,Pm[p].Pos[0],Pm[p].Pos[1],Pm[p].Pos[2],Pm[p].Vel[0],Pm[p].Vel[1],Pm[p].Vel[2],Pm[p].Link[0],Pm[p].Link[1]);
00831   }
00832   for(int c=0;c<Gen->NChain;c++)
00833     for(int d=0;d<3;d++)
00834       Ch[c].Pos[d] /= Gen->NPCh;
00835   Gen->Vel[3] /= (double)NPart;
00836   NType++;
00837   //  Gen->NChain++;
00838   if(Gen->NPCh == 0) Gen->NPCh = Gen->NPart;
00839   return 0;
00840 }
00841 int VarData::ReadPartXvt(FILE *FileToRead){
00842   VarMessage("ReadPartNoSys");
00843   double *buff = (double *) malloc(sizeof(double));
00844   char cLine[STRSIZE];
00845   sprintf(cLine,"               ");
00846   int NChain = 0;
00847   int NPart = 0;
00848   int NPCh = 0;
00849   int NType = 0;
00850   int Asym = 0;
00851   int Val[3];
00852   int NLink=0;
00853   fpos_t PosTemp;
00854   for(int b=0,NCh=0;b<pNBlock();NCh+=Block[b++].NChain){
00855     for(int t=0;t<50;t++){
00856       fgets(cLine,STRSIZE,FileToRead);
00857       if(3 == sscanf(cLine,"# n=%d N=%d name=%s",&Val[0],&Val[1],&Block[b].Name)){
00858    Block[b].InitIdx = NPart;
00859    Block[b].NChain = Val[0];
00860    Block[b].NPCh = Val[1];
00861    Block[b].NPart = Block[b].NChain*Block[b].NPCh;
00862    NChain += Block[b].NChain;
00863    NPart  += Block[b].NPart;
00864    Block[b].EndIdx = NPart;
00865    Block[b].Arch = ARCH_LINES;
00866    NLink = 1;
00867    if(strcasestr(Block[b].Name, "TT") == Block[b].Name){
00868      Block[b].Arch = ARCH_TWOTAILS;
00869      NLink = 2;
00870    }
00871    if(strcasestr(Block[b].Name, "PEP") == Block[b].Name){
00872      Block[b].Arch = ARCH_CLUSTER;
00873    }
00874    break;
00875       }
00876     }
00877     // // while(strncmp(cLine,"# n=",3)){fgets(cLine,STRSIZE,FileToRead);printf("%s\n",cLine);}
00878     // printf("%s\n",cLine);
00879     for(int c=NCh;c<NCh+Block[b].NChain;c++){
00880       int pCurr = Block[b].InitIdx + (c-NCh)*Block[b].NPCh;
00881       Ch[c].NPCh = Block[b].NPCh;
00882       Ch[c].InitBead = pCurr;
00883       Ch[c].EndBead = pCurr + Block[b].NPCh;
00884       for(int ppc=0;ppc<Block[b].NPCh;ppc++){
00885    if(NULL == fgets(cLine,STRSIZE,FileToRead)) break;
00886    if(cLine[0] == '#'){ppc--;continue;}
00887    int p =  pCurr + ppc;
00888    if(p >= pNPart()){
00889      printf("Reading more particles than the ones allocated\n");
00890      exit(1);
00891    }
00892    Pm[p].Idx = p;
00893    Pm[p].CId = c;
00894    //sscanf(cLine,"%lf %lf %lf %lf %lf %lf %d",&Pm[p].Pos[0],&Pm[p].Pos[1],&Pm[p].Pos[2],&Pm[p].Vel[0],&Pm[p].Vel[1],&Pm[p].Vel[2],&Pm[p].Typ);
00895    int Incr = ReadVal(cLine  ,buff);Pm[p].Pos[0] = *buff*ScaleF[0];
00896    Incr += ReadVal(cLine+Incr,buff);Pm[p].Pos[1] = *buff*ScaleF[1];
00897    Incr += ReadVal(cLine+Incr,buff);Pm[p].Pos[2] = *buff*ScaleF[2];
00898    Incr += ReadVal(cLine+Incr,buff);Pm[p].Vel[0] = *buff;
00899    Incr += ReadVal(cLine+Incr,buff);Pm[p].Vel[1] = *buff;
00900    Incr += ReadVal(cLine+Incr,buff);Pm[p].Vel[2] = *buff;
00901    Incr += ReadVal(cLine+Incr,buff);Pm[p].Typ    = (int)*buff;
00902    for(int d=0;d<3;d++) Gen->Cm[d] += Pm[p].Pos[d];
00903    if(NType < Pm[p].Typ ) NType++;
00904       }
00905     }
00906   }
00907   for(int b=0;b<pNBlock();b++){
00908     int p1 = Block[b].InitIdx;
00909     for(int ppc=1;ppc<Block[b].NPCh;ppc++){
00910       //if(Pm[p1+ppc].Typ == 1 && Pm[p1+ppc-1].Typ == 0)
00911       if(Pm[p1+ppc].Typ != Pm[p1+ppc-1].Typ)
00912    Block[b].Asym = ppc;
00913     }
00914     if(Block[b].Asym == 0) Block[b].Asym = pNPCh();
00915   }
00916   // links
00917   if(pNLink() > 0){
00918     for(int b=0;b<pNBlock();b++){
00919       int NLink = 1;
00920       if(Block[b].Arch == ARCH_CLUSTER) NLink = 0;
00921       for(int c=0;c<Block[b].NChain;c++){ 
00922    int pCurr = Block[b].InitIdx + c*Block[b].NPCh;
00923    for(int ppc = 0;ppc<Block[b].NPCh-1;ppc++){
00924      Ln[pCurr+ppc].NLink = NLink;
00925      Ln[pCurr+ppc].Link[0] = pCurr+ppc+1;
00926      if(Block[b].Arch == ARCH_TWOTAILS){
00927        if(ppc == Block[b].Asym/2 - 1){
00928          Ln[pCurr+ppc].NLink = 1;
00929          Ln[pCurr+ppc].Link[0] = pCurr + Block[b].Asym - 1;
00930        }
00931        // if(ppc == Block[b].Asym){
00932        //   Ln[pCurr+ppc].NLink = 1;
00933        //   Ln[pCurr+ppc].Link[1] = pCurr + Block[b].Asym + 2;
00934        // }
00935      }
00936    }
00937       }
00938     }
00939   }
00940   //  for(int c=0;c<Gen->NChain;c++)printf("%d %d\n",c,Ch[c].NPart);
00941   double Norm2 = CUBE(pReOverCutOff()) / SQR(pNPCh());
00942   double Norm3 = CUBE(SQR(pReOverCutOff()) / pNPCh());
00943   MInt->Rescale(Norm2,2);
00944   MInt->Rescale(Norm3,3);
00945   free(buff);
00946   NType++;
00947   if(NPCh == 0) NPCh = Gen->NPart;
00948   SetNType(NType);
00949   if(0 == pNPart()){
00950     Block[0].InitIdx = 0;
00951     Block[0].NChain = 0;
00952     Block[0].NPCh = 0;
00953     Block[0].NPart = 0;
00954     Block[0].EndIdx = 0;
00955   }
00956   return 0;
00957 }
00958 int VarData::ReadLineXvt(char *cLine,double *Pos,int *Type){
00959   double Temp = 0.;
00960   int Incr = ReadVal(cLine  ,&Temp);Pos[0] = Temp*ScaleF[0];
00961   Incr += ReadVal(cLine+Incr,&Temp);Pos[1] = Temp*ScaleF[1];
00962   Incr += ReadVal(cLine+Incr,&Temp);Pos[2] = Temp*ScaleF[2];
00963   Incr += ReadVal(cLine+Incr,&Temp);
00964   Incr += ReadVal(cLine+Incr,&Temp);
00965   Incr += ReadVal(cLine+Incr,&Temp);
00966   Incr += ReadVal(cLine+Incr,&Temp);*Type   = (int)Temp;
00967   return 0;
00968 }
00969 int VarData::ReadPartXyz(FILE *FileToRead){
00970   double *buff = (double *) malloc(sizeof(double));
00971   char cLine[STRSIZE];
00972   double Pos[3];
00973   for(int p=0,c=-1;!(fgets(cLine,STRSIZE,FileToRead)==NULL);p++){
00974     if(p >= pNPart()-1) continue;
00975     Pm[p].Idx=p;Pm[p].Typ=0;Pm[p].CId=0;
00976     if(cLine[0] == '#' || cLine[0] == '$'){p--;continue;}
00977     sscanf(cLine,"%lf %lf %lf",Pos,Pos+1,Pos+2);
00978     for(int d=0;d<3;d++)
00979       Pm[p].Pos[d] = Pos[d];
00980     // int Incr = ReadVal(cLine,buff)  ;Pm[p].Pos[0] = *buff;
00981     // Incr += ReadVal(cLine+Incr,buff);Pm[p].Pos[1] = *buff;
00982     // Incr += ReadVal(cLine+Incr,buff);Pm[p].Pos[2] = *buff;
00983   }
00984   BfEdge();
00985   if(IfNormalize){
00986     for(int d=0;d<3;d++){
00987       ScaleF[d] = pInvEdge(d);
00988       SetEdge(1.,d);
00989     }
00990   }
00991   for(int p=0;p<pNPart();p++){
00992     for(int d=0;d<3;d++){
00993       Pm[p].Pos[d] *= ScaleF[d];
00994     }
00995   }
00996   SetNNano(0);
00997   Block[0].InitIdx = 0;
00998   Block[0].EndIdx = pNPart();
00999   Block[0].NChain = 1;
01000   Block[0].NPCh = pNPart();
01001   free(buff);
01002   return 0;
01003 }
01004 int VarData::ReadPartXyzt(FILE *FileToRead){
01005   double *buff = (double *) malloc(sizeof(double));
01006   char cLine[STRSIZE];
01007   double Pos[4];
01008   int NChain = 0;
01009   int NPCh = 0;
01010   int OldTyp = 0;
01011   for(int p=0,c=-1;!(fgets(cLine,STRSIZE,FileToRead)==NULL);p++){
01012     if(p >= pNPart()-1) continue;
01013     Pm[p].Idx=p;Pm[p].Typ=0;Pm[p].CId=0;
01014     if(cLine[0] == '#' || cLine[0] == '$'){p--;continue;}
01015     sscanf(cLine,"%lf %lf %lf %lf",Pos,Pos+1,Pos+2,Pos+3);
01016     for(int d=0;d<3;d++)
01017       Pm[p].Pos[d] = Pos[d];
01018     Pm[p].Typ = (int)Pos[3];
01019     if(OldTyp > Pm[p].Typ){
01020       NChain++;
01021     }
01022     Pm[p].CId = NChain;
01023     if(NChain == 0) NPCh++;
01024     OldTyp = Pm[p].Typ;
01025   }
01026   BfEdge();
01027   if(IfNormalize){
01028     for(int d=0;d<3;d++){
01029       ScaleF[d] = pInvEdge(d);
01030       SetEdge(1.,d);
01031     }
01032   }
01033   for(int p=0;p<pNPart();p++){
01034     for(int d=0;d<3;d++){
01035       Pm[p].Pos[d] *= ScaleF[d];
01036     }
01037   }
01038   if(NChain == 0) NChain = 1;
01039   SetNChain(NChain);
01040   SetNPCh(NPCh);
01041   Block[0].InitIdx= 0;
01042   Block[0].EndIdx = pNPart();
01043   Block[0].NChain = pNChain();
01044   Block[0].NPCh   = pNPCh();
01045   free(buff);
01046   return 0;
01047 }