int main(int argc, char *argv[]) { /*---Arguments-------------------------*/ double boxsize; char *file=NULL,*fileformat=NULL; char *binfile=NULL; DOUBLE pimax ; /*---Data-variables--------------------*/ int64_t ND1=0; DOUBLE *x1=NULL,*y1=NULL,*z1=NULL; /*---Corrfunc-variables----------------*/ #if !(defined(USE_OMP) && defined(_OPENMP)) const char argnames[][30]={"boxsize","file","format","binfile","pimax"}; #else int nthreads=2; const char argnames[][30]={"boxsize","file","format","binfile","pimax","Nthreads"}; #endif int nargs=sizeof(argnames)/(sizeof(char)*30); struct timeval t_end,t_start,t0,t1; double read_time=0.0; gettimeofday(&t_start,NULL); /*---Read-arguments-----------------------------------*/ if(argc< (nargs+1)) { Printhelp() ; fprintf(stderr,"\nFound: %d parameters\n ",argc-1); int i; for(i=1;i<argc;i++) { if(i <= nargs) fprintf(stderr,"\t\t %s = `%s' \n",argnames[i-1],argv[i]); else fprintf(stderr,"\t\t <> = `%s' \n",argv[i]); } if(i <= nargs) { fprintf(stderr,"\nMissing required parameters \n"); for(i=argc;i<=nargs;i++) fprintf(stderr,"\t\t %s = `?'\n",argnames[i-1]); } return EXIT_FAILURE; } boxsize=atof(argv[1]); file=argv[2]; fileformat=argv[3]; binfile=argv[4]; pimax=40.0; #ifdef DOUBLE_PREC sscanf(argv[5],"%lf",&pimax) ; #else sscanf(argv[5],"%f",&pimax) ; #endif #if defined(USE_OMP) && defined(_OPENMP) nthreads=atoi(argv[6]); assert(nthreads >= 1 && "Number of threads must be at least 1"); #endif fprintf(stderr,"Running `%s' with the parameters \n",argv[0]); fprintf(stderr,"\n\t\t -------------------------------------\n"); for(int i=1;i<argc;i++) { if(i <= nargs) { fprintf(stderr,"\t\t %-10s = %s \n",argnames[i-1],argv[i]); } else { fprintf(stderr,"\t\t <> = `%s' \n",argv[i]); } } fprintf(stderr,"\t\t -------------------------------------\n"); gettimeofday(&t0,NULL); /*---Read-data1-file----------------------------------*/ ND1=read_positions(file,fileformat,sizeof(DOUBLE), 3, &x1, &y1, &z1); gettimeofday(&t1,NULL); read_time += ADD_DIFF_TIME(t0,t1); //check that theee positions are within limits for(int i=0;i<ND1;i++) { assert(x1[i] >= 0.0 && x1[i] <= boxsize && "xpos is within limits [0, boxsize]"); assert(y1[i] >= 0.0 && y1[i] <= boxsize && "ypos is within limits [0, boxsize]"); assert(z1[i] >= 0.0 && z1[i] <= boxsize && "zpos is within limits [0, boxsize]"); } /*---Count-pairs--------------------------------------*/ gettimeofday(&t0,NULL); results_countpairs_wp *results = countpairs_wp(ND1, x1, y1, z1, boxsize, #if defined(USE_OMP) && defined(_OPENMP) nthreads, #endif binfile, pimax); gettimeofday(&t1,NULL); double pair_time = ADD_DIFF_TIME(t0,t1); free(x1);free(y1);free(z1); //Output the results /* Note: we discard the first bin, to mimic the fact that close pairs * are disregarded in SDSS data. */ DOUBLE rlow=results->rupp[0]; for(int i=1;i<results->nbin;++i) { fprintf(stdout,"%e\t%e\t%e\t%e\t%12"PRIu64" \n",results->wp[i],results->rpavg[i],rlow,results->rupp[i],results->npairs[i]); rlow=results->rupp[i]; } //free the memory in the results struct free_results_wp(&results); gettimeofday(&t_end,NULL); fprintf(stderr,"wp> Done - ND1=%12"PRId64". Time taken = %6.2lf seconds. read-in time = %6.2lf seconds pair-counting time = %6.2lf sec\n", ND1,ADD_DIFF_TIME(t_start,t_end),read_time,pair_time); return EXIT_SUCCESS; }
int main(int argc,char *argv[]) { char *listfile,*inputfile; char choose= ' '; string operate=" "; double temperature=300; string output=" "; string segment="all"; int segment_b=0; int segment_e=0; // 读取当前的时间 time_t t = time( 0 ); char TIME[64]; strftime( TIME, sizeof(TIME), "%Y/%m/%d %X ",localtime(&t) ); // switch(argc) { case 1: cout<<"Usage:CurAnalysis -f listfile.txt -i inputfile.txt"<<endl; exit(0); case 2: if(string(argv[1])=="-a") { Printversion(); exit(0); } if(string(argv[1])=="-h") { Printhelp(); exit(0); } case 5: if(string(argv[1])=="-f"&&string(argv[3])=="-i") { listfile=argv[2]; inputfile=argv[4]; } break; default: cout<<"Usage:CurAnalysis -f listfile.txt -i inputfile.txt"<<endl; exit(0); } ReadInput(inputfile,operate,choose,output,temperature,segment,segment_b,segment_e); /* average部分已经完成,经测试可以使用,主要的问题是读文件的异常 比如说文件残缺,文件丢失等的情况的处理的过程没有完成。 */ if(operate=="average") { if(choose=='E'||choose=='F'||choose=='G'||choose=='H') { double ***totaldata; struct Filelist *fl; struct Paramater *spt; int N=0; ofstream outfile(output.c_str(),ios::app); fl=Readlist(listfile); switch(choose) { case 'E': spt=E_part(fl->file); break; case 'F': spt=F_part(fl->file); break; case 'G': spt=G_part(fl->file); break; case 'H': spt=H_part(fl->file); break; } int filesize=Getfilelen(fl); int size=GetParamaterlen(spt); if(segment!="all") { size=segment_e - segment_b+1; } if(segment=="all") { segment_b=1; segment_e=size; } totaldata=f3tensor(0,5,0,size-1,0,filesize-1); outfile<<"******************************************************************"<<endl; //output the input file! ifstream infile(inputfile); string s; getline(infile,s); while(!infile.fail()) { outfile<<"#"<<s<<endl; getline(infile,s); } outfile<<TIME<<endl; //输出当前时间 infile.close(); // while(fl!=NULL) { struct Paramater *sp; switch(choose) { case 'E': sp=E_part(fl->file); break; case 'F': sp=F_part(fl->file); break; case 'G': sp=G_part(fl->file); break; case 'H': sp=H_part(fl->file); break; } // int size=GetParamaterlen(sp); double **data; data=dmatrix(0,5,0,size-1); struct Namelist *name; name=(struct Namelist *)malloc(sizeof(struct Namelist)); Paramater2double(sp,data,name,segment_b,segment_e); for(int i=0;i<6;i++) { for(int j=0;j<size;j++) { totaldata[i][j][N]=data[i][j]; } } free_dmatrix(data,0,5,0,size-1); cout<<"Read file "<<fl->file<<" finished!"<<endl;//输出提示 fl=fl->next; N++; } double **aveg; aveg=dmatrix(0,5,0,size-1); for(int i=0;i<6;i++) { for(int j=0;j<size;j++) { aveg[i][j]=0; } } outfile<<endl; outfile<<"******************************************************************"<<endl; outfile<<"\t"<<"rise"<<"\t"<<"roll"<<"\t"<<"shift"<<"\t"<<"slide"<<"\t"<<"tilt"<<"\t"<<"twist"<<endl; outfile<<endl; for(int i=0;i<size;i++) { outfile<<i+segment_b<<"\t"; for(int j=0;j<6;j++) { for(int k=0;k<filesize;k++) { aveg[j][i]+=totaldata[j][i][k]; } aveg[j][i]=aveg[j][i]/filesize; outfile<<fixed<<showpoint; outfile<<setprecision(2)<<aveg[j][i]<<"\t"; } outfile<<endl; } outfile<<endl; outfile<<"******************************************************************"<<endl; cout<<"finished the calculation of average !"<<endl; cout<<"the output write in the file "<<output<<" !"<<endl; outfile.close(); free_f3tensor(totaldata,0,5,0,size-1,0,filesize-1); } //average for J if(choose=='J') { double ***totaldata; struct Filelist *fl; struct Backbone *spt; int N=0; fl=Readlist(listfile); spt=J_part(fl->file); int filesize=Getfilelen(fl); int size=GetBackbonelen(spt); if(segment!="all") { size=segment_e - segment_b+1; } if(segment=="all") { segment_b=1; segment_e=size; } totaldata=f3tensor(0,13,0,size-1,0,filesize-1); ofstream outfile(output.c_str(),ios::app); outfile<<"******************************************************************"<<endl; //output the input file! ifstream infile(inputfile); string s; getline(infile,s); while(!infile.fail()) { outfile<<"#"<<s<<endl; getline(infile,s); } outfile<<TIME<<endl; //输出当前时间 infile.close(); // while(fl!=NULL) { struct Backbone *sp; sp=J_part(fl->file); // int size=GetBackbonelen(sp); double **data; data=dmatrix(0,13,0,size-1); struct Namelist *name; name=(struct Namelist *)malloc(sizeof(struct Namelist)); Backbone2double(sp,data,name,segment_b,segment_e); for(int i=0;i<14;i++) { for(int j=0;j<size;j++) { totaldata[i][j][N]=data[i][j]; } } free_dmatrix(data,0,13,0,size-1); cout<<"Read file "<<fl->file<<" finished!"<<endl;//输出提示 fl=fl->next; N++; } double **aveg; aveg=dmatrix(0,13,0,size-1); for(int i=0;i<14;i++) { for(int j=0;j<size;j++) { aveg[i][j]=0; } } outfile<<endl; outfile<<"******************************************************************"<<endl; outfile<<"\t"<<"alpha"<<"\t"<<"ampli"<<"\t"<<"beta"<<"\t"<<"c1"<<"\t"<<"c1c2"<<"\t"<<"c2"<<"\t"<<"c2c3"<<"\t"<<"c3"<<"\t"<<"chi"<<"\t"<<"delta"<<"\t"<<"epsil"<<"\t"<<"gamma"<<"\t"<<"phase"<<"\t"<<"zeta"<<endl; outfile<<endl; for(int i=0;i<size;i++) { outfile<<i+segment_b<<"\t"; for(int j=0;j<14;j++) { for(int k=0;k<filesize;k++) { aveg[j][i]+=totaldata[j][i][k]; } aveg[j][i]=aveg[j][i]/filesize; outfile<<fixed<<showpoint; outfile<<setprecision(2)<<aveg[j][i]<<"\t"; } outfile<<endl; } outfile<<endl; outfile<<"******************************************************************"<<endl; cout<<"finished the calculation of average !"<<endl; cout<<"the output write in the file "<<output<<" !"<<endl; outfile.close(); free_f3tensor(totaldata,0,13,0,size-1,0,filesize-1); } } //计算某一数据的分布 if(operate=="distribution") { //part 1: get the data if(choose=='E'||choose=='F'||choose=='G'||choose=='H') { double ***totaldata; struct Filelist *fl; struct Paramater *spt; int N=0; ofstream outfile(output.c_str(),ios::app); fl=Readlist(listfile); switch(choose) { case 'E': spt=E_part(fl->file); break; case 'F': spt=F_part(fl->file); break; case 'G': spt=G_part(fl->file); break; case 'H': spt=H_part(fl->file); break; } int filesize=Getfilelen(fl); int size=GetParamaterlen(spt); if(segment!="all") { size=segment_e - segment_b+1; } if(segment=="all") { segment_b=1; segment_e=size; } totaldata=f3tensor(0,5,0,size-1,0,filesize-1); outfile<<"******************************************************************"<<endl; //output the input file! ifstream infile(inputfile); string s; getline(infile,s); while(!infile.fail()) { outfile<<"#"<<s<<endl; getline(infile,s); } outfile<<TIME<<endl; //输出当前时间 infile.close(); // while(fl!=NULL) { struct Paramater *sp; switch(choose) { case 'E': sp=E_part(fl->file); break; case 'F': sp=F_part(fl->file); break; case 'G': sp=G_part(fl->file); break; case 'H': sp=H_part(fl->file); break; } // int size=GetParamaterlen(sp); double **data; data=dmatrix(0,5,0,size-1); struct Namelist *name; name=(struct Namelist *)malloc(sizeof(struct Namelist)); Paramater2double(sp,data,name,segment_b,segment_e); for(int i=0;i<6;i++) { for(int j=0;j<size;j++) { totaldata[i][j][N]=data[i][j]; } } free_dmatrix(data,0,5,0,size-1); cout<<"Read file "<<fl->file<<" finished!"<<endl;//输出提示 fl=fl->next; N++; } // finished the input data //calculate the distribution! double *vect; vect=dvector(0, size*filesize-1) ; for(int i=0;i<6;i++) { outfile<<"******************************************************************"<<endl; switch(i) { case 0: outfile<<"the distribution of RISE"<<endl; break; case 1: outfile<<"the distribution of ROLL"<<endl; break; case 2: outfile<<"the distribution of SHIFT"<<endl; break; case 3: outfile<<"the distribution of SLIDE"<<endl; break; case 4: outfile<<"the distribution of TILT"<<endl; break; case 5: outfile<<"the distribution of TWIST"<<endl; break; } outfile<<"******************************************************************"<<endl; // for(int m=0;m<size;m++) { for(int n=0;n<filesize;n++) { vect[m*filesize+n]=totaldata[i][m][n]; } } //把二维的数据转化为一维的数据! Distribution(vect,size*filesize,output); outfile<<"******************************************************************"<<endl; } cout<<"finished the calculation of distribution !"<<endl; cout<<"the output write in the file "<<output<<" !"<<endl; outfile.close(); free_f3tensor(totaldata,0,5,0,size-1,0,filesize-1); // finished the calculation ! } if(choose=='J') { double ***totaldata; struct Filelist *fl; struct Backbone *spt; int N=0; fl=Readlist(listfile); spt=J_part(fl->file); int filesize=Getfilelen(fl); int size=GetBackbonelen(spt); if(segment!="all") { size=segment_e - segment_b+1; } if(segment=="all") { segment_b=1; segment_e=size; } totaldata=f3tensor(0,13,0,size-1,0,filesize-1); ofstream outfile(output.c_str(),ios::app); outfile<<"******************************************************************"<<endl; //output the input file! ifstream infile(inputfile); string s; getline(infile,s); while(!infile.fail()) { outfile<<"#"<<s<<endl; getline(infile,s); } outfile<<TIME<<endl; //输出当前时间 infile.close(); // while(fl!=NULL) { struct Backbone *sp; sp=J_part(fl->file); // int size=GetBackbonelen(sp); double **data; data=dmatrix(0,13,0,size-1); struct Namelist *name; name=(struct Namelist *)malloc(sizeof(struct Namelist)); Backbone2double(sp,data,name,segment_b,segment_e); for(int i=0;i<14;i++) { for(int j=0;j<size;j++) { totaldata[i][j][N]=data[i][j]; } } free_dmatrix(data,0,13,0,size-1); cout<<"Read file "<<fl->file<<" finished!"<<endl;//输出提示 fl=fl->next; N++; } double *vect; vect=dvector(0, size*filesize-1) ; for(int i=0;i<14;i++) { outfile<<"******************************************************************"<<endl; switch(i) { case 0: outfile<<"the distribution of ALPHA"<<endl; break; case 1: outfile<<"the distribution of AMPLI"<<endl; break; case 2: outfile<<"the distribution of BETA"<<endl; break; case 3: outfile<<"the distribution of C1'"<<endl; break; case 4: outfile<<"the distribution of C1'-C2'"<<endl; break; case 5: outfile<<"the distribution of C2'"<<endl; break; case 6: outfile<<"the distribution of C2'-C3'"<<endl; break; case 7: outfile<<"the distribution of C3'"<<endl; break; case 8: outfile<<"the distribution of CHI"<<endl; break; case 9: outfile<<"the distribution of DELTA"<<endl; break; case 10: outfile<<"the distribution of ESPIL"<<endl; break; case 11: outfile<<"the distribution of GAMMA"<<endl; break; case 12: outfile<<"the distribution of PHASE"<<endl; break; case 13: outfile<<"the distribution of ZETA"<<endl; break; } outfile<<"******************************************************************"<<endl; // for(int m=0;m<size;m++) { for(int n=0;n<filesize;n++) { vect[m*filesize+n]=totaldata[i][m][n]; } } //把二维的数据转化为一维的数据! Distribution(vect,size*filesize,output); outfile<<"******************************************************************"<<endl; } cout<<"finished the calculation of distribution !"<<endl; cout<<"the output write in the file "<<output<<" !"<<endl; outfile.close(); free_f3tensor(totaldata,0,13,0,size-1,0,filesize-1); // finished the calculation ! } } /*计算刚性*/ if(operate=="stiffness") { /*get the data*/ if(choose=='E'||choose=='F'||choose=='G'||choose=='H') { double ***totaldata; struct Filelist *fl; struct Paramater *spt; int N=0; ofstream outfile(output.c_str(),ios::app); fl=Readlist(listfile); switch(choose) { case 'E': spt=E_part(fl->file); break; case 'F': spt=F_part(fl->file); break; case 'G': spt=G_part(fl->file); break; case 'H': spt=H_part(fl->file); break; } int filesize=Getfilelen(fl); int size=GetParamaterlen(spt); if(segment!="all") { size=segment_e - segment_b+1; } if(segment=="all") { segment_b=1; segment_e=size; } totaldata=f3tensor(0,5,0,size-1,0,filesize-1); outfile<<"******************************************************************"<<endl; //output the input file! ifstream infile(inputfile); string s; getline(infile,s); while(!infile.fail()) { outfile<<"#"<<s<<endl; getline(infile,s); } outfile<<TIME<<endl; //输出当前时间 infile.close(); // while(fl!=NULL) { struct Paramater *sp; switch(choose) { case 'E': sp=E_part(fl->file); break; case 'F': sp=F_part(fl->file); break; case 'G': sp=G_part(fl->file); break; case 'H': sp=H_part(fl->file); break; } // int size=GetParamaterlen(sp); double **data; data=dmatrix(0,5,0,size-1); struct Namelist *name; name=(struct Namelist *)malloc(sizeof(struct Namelist)); Paramater2double(sp,data,name,segment_b,segment_e); for(int i=0;i<6;i++) { for(int j=0;j<size;j++) { totaldata[i][j][N]=data[i][j]; } } free_dmatrix(data,0,5,0,size-1); cout<<"Read file "<<fl->file<<" finished!"<<endl;//输出提示 fl=fl->next; N++; } // finished the input data /*calculate the stiffness! */ double **stiff; double **matrix; double **inve_matrix; /*output the title */ outfile<<"******************************************************************"<<endl; outfile<<"calculate the stiffness of part "<<choose<<endl; outfile<<"******************************************************************"<<endl; for(int x=segment_b-1;x<segment_e;x++) /* the loop for segment */ { stiff=dmatrix(0,5,0, filesize-1) ; /* hold the space!*/ matrix=dmatrix(0,5,0,5); inve_matrix=dmatrix(0,5,0,5); for(int i=0;i<6;i++) { for(int n=0;n<filesize;n++) { stiff[i][n]=totaldata[i][x][n]; } } Getmatrix(stiff,matrix,filesize); /*cteate the helical matrix!*/ free_dmatrix(stiff,0,5,0,filesize-1); inverse_matrix(matrix, inve_matrix,6); free_dmatrix(matrix,0,5,0,5); outfile<<"the stiffness of segment "<<x+1<<endl; outfile<<"******************************************************************"<<endl; outfile<<"\t"<<"rise"<<"\t"<<"roll"<<"\t"<<"shift"<<"\t"<<"slide"<<"\t"<<"tilt"<<"\t"<<"twist"<<endl; outfile<<fixed<<showpoint; for(int i=0;i<6;i++) { switch(i) { case 0: outfile<<"rise"<<"\t"; break; case 1: outfile<<"roll"<<"\t"; break; case 2: outfile<<"shift"<<"\t"; break; case 3: outfile<<"slide"<<"\t"; break; case 4: outfile<<"tilt"<<"\t"; break; case 5: outfile<<"twist"<<"\t"; break; } for(int j=0;j<6;j++) { outfile<<setprecision(2)<<R*temperature*inve_matrix[i][j]<<"\t"; } outfile<<endl; } outfile<<"******************************************************************"<<endl; } cout<<"finished the calculation of stiffness !"<<endl; cout<<"the output write in the file "<<"\""<<output<<"\" !"<<endl; outfile.close(); free_f3tensor(totaldata,0,5,0,size-1,0,filesize-1); // finished the calculation ! } else { cout<<"wrong input, please check!"<<endl; exit(0); } } if(operate!="stiffness"&&operate!="average"&&operate!="distribution") { cout<<"Input a wrong operate. the correct oprtate is 'average/distribution/stiffness'"<<endl; exit(0); } return 0; }