Текст ВКР (1218920), страница 11
Текст из файла (страница 11)
for(i=0;i<N;i++){
osnovanie=4+2*Chislo_setok-2*N_fields_from_end-1;
tika=4+2*Chislo_setok;
a[i][4+2*Chislo_setok-1]=-9999999;
for(j=5;j<tika;j+=2){
if(a[i][j-1]!=0 && j!=(4+2*Chislo_setok-1)){
if(a[i][j+1]==0){
a[i][j]=1.;
}
else{a[i][j]=(a[i][j+1]/a[i][j-1]-speed);}
}
else{if(j!=(4+2*Chislo_setok-1))a[i][j]=0;}
if(a[i][j]>a[i][4+2*Chislo_setok-1]&& j!=(4+2*Chislo_setok-1)&&(j>=osnovanie)) {a[i][4+2*Chislo_setok-1]=a[i][j];}
}
}
}
void choose_array(double** full,double **third,int Rows, int Chislo_setok,int No_rez){
int i,j,k=No_rez-1;
for(i=0;i<Rows;i++){
for(j=0;j<4+2*Chislo_setok;j++){
third[i][j]=full[k][j];
}
k+=3;
}
}
void zapoln(double **New_rez,double **rezult,int I,int Chislo_setok,int *setki){
int p,potoki,t,i=0,next=1;
for(p=0;p<I-1;++p){
New_rez[p][0]=rezult[p-i][0];
if((rezult[p+1-i][0]-rezult[p-i][0])>1){
potoki=rezult[p+1-i][0]-rezult[p-i][0];
while(potoki>1){
New_rez[p+1][0]=New_rez[p][0]+1;
for(t=1;t<6+2*Chislo_setok;++t){
New_rez[p][t]=rezult[p-i][t];
if(t<6 ){
New_rez[p+1][t]=rezult[p-1-i][t];
if(t==1){
next=(New_rez[p+1][0]);
next=next%Chislo_setok;
New_rez[p+1][t]=setki[next];}
}
else{
New_rez[p+1][t]=0.;
if(rezult[p-i][1]==setki[0]){
New_rez[p+1][t]=rezult[p+1-i][t];
}
}
if(t==(6+2*Chislo_setok-1)) {
p++;
i++;
potoki--;}
}
}
}
else{
for(t=1;t<6+2*Chislo_setok;++t){
New_rez[p][t]=rezult[p-i][t];
}
}
}
for(t=0;t<6+2*Chislo_setok;++t){
New_rez[p][t]=rezult[p-i][t];
}
}
int read_stage(){
FILE *fpa;
char s[50];
if((fpa=fopen("analyze.txt","r+"))!=NULL){
for(int i=0;i<11;++i){
fgets(s, 50, fpa);
}
if(fscanf(fpa,"%d\n",&stage)==0);
}
fclose(fpa);
return stage;
}
void print_gnu(int Strok,FILE *f){
int c,i,N=0;
FILE * dirs=fopen("dirs","w");
char buf[300];
N=string_count(f);
rewind(f);
FILE * dirs2=fopen("Directories_with_plots","a");
for(i=0;i<Strok;i++){fgets(buf,300,f);}
for(i=0;i<(N-Strok);i++){
while((c=fgetc(f))!='/'){}
char path[250];
fscanf(f,"%s\n",&path);
string full_path1="/";
string full_path2="/";
full_path1+=path;
full_path2+=path;
full_path1+="/";
full_path2+="/";
fprintf(dirs2,"%s\n",full_path1.c_str());
fprintf(dirs2,"%s\n",full_path2.c_str());
full_path1+="v";
full_path2+="u";
fprintf(dirs,"%s\n",full_path1.c_str());
fprintf(dirs,"%s\n",full_path2.c_str());
}
fclose(dirs);
fclose(dirs2);
}
void analyze(){
double left,right;
FILE *log=fopen("error.log","a");
FILE *temporary=fopen("rezult_sorted","w");
FILE *temporary2;
FILE *fpa;
if((fpa=fopen("analyze.txt","r+"))==NULL){
fprintf(log,"%s\n","Doesn’t exist analyze.txt.\n");
exit(1);}
int Chislo_setok,p,No_rez,chislo_stolbcov,shtraf_type,field_1,field_2,kolvo_2_shtraf,N_best;
double teor_velosity,e_bias;
int i=0,j=0;
if(fscanf(fpa,"%s\n",input)==0){}
if(fscanf(fpa,"%d\n",&chislo_stolbcov)==0){fprintf(log,"%s\n","Error in analyze file string 2");}
if(fscanf(fpa,"%d\n",&Chislo_setok)==0){fprintf(log,"%s\n","Error in analyze file string 3");}
int *setki=new int[Chislo_setok];
for(i=0;i<Chislo_setok-1;++i){
if(fscanf(fpa,"%d ",&setki[i])==0){fprintf(log,"%s\n","Error in analyze file string 4");};
}
if(fscanf(fpa,"%d\n",&setki[i])==0){fprintf(log,"%s\n","Error in analyze file string 4");};
if(fscanf(fpa,"%d\n",&No_rez)==0){fprintf(log,"%s\n","Error in analyze file string 5");};
if(fscanf(fpa,"%lf\n",&teor_velosity)==0){fprintf(log,"%s\n","Error in analyze file string 6");};
//if(fscanf(fpa,"%d\n",&shtraf_type)==0){fprintf(log,"%s\n","Error in analyze file string 7");}
if(fscanf(fpa,"%d\n",&kolvo_2_shtraf)==0){fprintf(log,"%s\n","Error in analyze file string 7");}
if(fscanf(fpa,"%d %d\n",&field_1,&field_2)==0){fprintf(log,"%s\n","Error in analyze file string 9");}
if(fscanf(fpa,"%d\n",&N_best)==0){fprintf(log,"%s\n","Error in analyze file string 10");}
if(fscanf(fpa,"%lf\n",&e_bias)==0){fprintf(log,"%s\n","Error in analyze file string 11");}
if(stage==0){if(fscanf(fpa,"%s\n",¤t_task)==0){fprintf(log,"%s\n","Error in analyze file string 12");}}
if(fscanf(fpa,"%d\n",&stage)==0){fprintf(log,"%s\n","Error in analyze file string 13");}
FILE *file=fopen(current_task,"r+" );
fclose(fpa);
string outp=input; //sozdanie imeni faila vivoda
outp+="_[";
outp+=intToChar(stage);
outp+="]_";
outp+="[";
outp+=intToChar(ochered+1);
outp+="]_";
outp+="_shtraf";
int chislo;
FILE *output_file=fopen(outp.c_str(),"w");
FILE *f=fopen(input,"r+");
string outp2=outp;
outp2+="_";
chislo=4+2*Chislo_setok-1;
outp2+=intToChar(chislo);
FILE *output_file_sorted=fopen(outp2.c_str(),"w");
outp2+="A";
FILE *temporary1=fopen(outp2.c_str(),"w");
outp2+="F";
temporary2=fopen(outp2.c_str(),"w");
if(f==NULL){cout<<"rezyltat is NULL\n";exit(0);}
char * s=new char[500];
string err;
i=string_count(f);//chislo strok v file f=fopen(input)
if((i/Chislo_setok<2) || (i/Chislo_setok<N_best)){
cout<<"\nError in data volume. See error.log\n";
if((i/Chislo_setok)<2)fprintf(log,"%s\n","Chislo naborov dlya analiza doljno bit' ne men'she 2");
if((i/Chislo_setok<N_best))fprintf(log,"%s\n","N_best - is too large.");
fclose(f);
fclose(log);
fclose(output_file);
fclose(output_file_sorted);
fclose(temporary2);
cin.get();
exit(0);}
double **rezult=new double*[i];
for(p=0;p<i;++p){
rezult[p]=new double[6+2*Chislo_setok];
}
rewind(f);
p=0;
int c;
bool bul;
for(p=0;p<i;++p){
bul=1;
for(j=0;j<chislo_stolbcov;++j){
if(fscanf(f,"%lf ",&rezult[p][j])==0){
while((c=fgetc(f))!='\n'){}
err="Fail to read row ";
chislo=rezult[p][0];
err+=intToChar(chislo);
fprintf(log,"%s\n",err.c_str());
for(j=5;j<6+2*Chislo_setok;++j){rezult[p][j]=0;}
break;
}
if(j==6 && bul){j--;bul=0;}
}
}
sort(rezult,i,6+2*Chislo_setok,0,1);
print_out_double_array(rezult,i,chislo_stolbcov,temporary);
int I=0;
for(j=0;j<i-1;++j){
if((rezult[j+1][0]-rezult[j][0])>1)I+=(rezult[j+1][0]-rezult[j][0])-1;
}
I+=i;
double ** New_rez=new double*[I];//stroki
for(p=0;p<I;++p){New_rez[p]=new double[6+2*Chislo_setok];
}
zapoln(New_rez,rezult,I,Chislo_setok,setki);
transpose(New_rez,I,Chislo_setok,No_rez,field_1,field_2);
get_shtraf(New_rez,I/Chislo_setok,Chislo_setok,teor_velosity,kolvo_2_shtraf); print_out_double_array(New_rez,I/Chislo_setok,6+2*Chislo_setok,output_file);
sort(New_rez,I/Chislo_setok,6+2*Chislo_setok,6+2*Chislo_setok-3,1); print_out_double_array(New_rez,I/Chislo_setok,6+2*Chislo_setok,output_file_sorted);
int chipolino=kolvo_neg_zero(New_rez,I/Chislo_setok,6+2*Chislo_setok-3);
sort2(New_rez,chipolino,6+2*Chislo_setok);
print_out_double_array(New_rez,I/Chislo_setok,6+2*Chislo_setok,temporary1);
string outp_final="Output";
FILE *outp_fin=fopen(outp_final.c_str(),"a");
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
fprintf(outp_fin,"%s %d %s\n","stage",stage,asctime(timeinfo));
print_out_double_array(New_rez,N_best,6+2*Chislo_setok,outp_fin);
FILE *pars=fopen("pars.inp","w");
for(p=0;p<N_best;p++){
fprintf(pars,"%.0f %d %d %f %f %f %d\n",New_rez[p][0],9,4,New_rez[p][1],New_rez[p][2],New_rez[p][3],1);
}
fclose(pars);
fclose(f);
fscanf( file, "%s", starter);
inp_file="inp.inp";
rewind(file);
string ts="./";
ts+=starter;
ts+=" ";
ts+=inp_file;
system(ts.c_str());// change to parametrical
system("sleep 180");
f=fopen(input,"r+");
print_gnu(I,f);
system("sleep 80");
double* diapazoni=new double[N_best*4];
for(p=0;p<N_best;p++){
for(j=p*4;j<(p+1)*4;j++){
diapazoni[j]=New_rez[p][j-(p*4)];
}
}
for(i=chipolino;i<I/Chislo_setok;i++){
if(New_rez[i][4+2*Chislo_setok-1]<e_bias)chipolino++;
}
FILE *data2;
int t=0;
string dat2;
for(i=0;i<N_best;++i){
dat2="data2D_[";
dat2+=intToChar(stage);
dat2+="]_[";
dat2+=intToChar(ochered+1);
dat2+="]_[";
dat2+=intToChar(i+1);
dat2+="]";
data2=fopen(dat2.c_str(), "w");
for(j=4;j<6+2*Chislo_setok-2;j+=2){
fprintf(data2,"%d %f\n",setki[t],New_rez[i][j]);
t++;
}
t=0;
fclose(data2);
}
if(chipolino==0){chipolino=N_best;}
right=left=New_rez[0][2];
sort(New_rez,chipolino,6+2*Chislo_setok,2,1);
print_out_double_array(New_rez,I/Chislo_setok,6+2*Chislo_setok,temporary2);
for(i=0;i<N_best-1;i++){
if(exist(diapazoni,N_best*4,i))search(New_rez,chipolino,diapazoni,file,i,outp_fin);
}
if(!exist(diapazoni,N_best*4,N_best-2))search(New_rez,chipolino,diapazoni,file,N_best-2,outp_fin);
percents(outp_fin);
system("./bash3d.sh");
fprintf(outp_fin,"\n\n");
fclose(outp_fin);
if(stage==0){
cout<<"\nStage="<<stage;
stage=1;
UpdateAnalyzeFile("analyze.txt");
cout<<"->"<<stage<<'\n';
}
fclose(f);
fclose(file);
fclose(log);
fclose(output_file);
fclose(output_file_sorted);
fclose(temporary2);
fclose(temporary1);
fclose(temporary);
cout<<"\nANALYZE stage["<<stage<<"] completed!";
}
void prepare(char* parametro){
int i=0, j=0;
int Chislo_setok;
double **massive=new double*[3];
for(i=0;i<3;++i){massive[i]=new double[3];}
inp_file="inp.inp";
FILE *log=fopen("error.log","a" );
FILE *f=fopen(parametro,"r+" );
FILE *pars=fopen("pars.inp","w");
if(f!=NULL){
fscanf( f, "%s", starter);
for(i=0;i<3;++i){
fscanf( f, "%lf %lf %lf\n", &massive[i][0], &massive[i][1],&massive[i][2]);
}
fscanf( f, "%d\n", &Chislo_setok);
int* setki=new int[Chislo_setok];
for(i=0;i<Chislo_setok;i++){
fscanf( f, "%d ", &setki[i]);
}
printf_pars(massive,setki,Chislo_setok,pars);
fclose(pars);
string ts="./";
ts+=starter;
ts+=" ";
ts+=inp_file;
system(ts.c_str());
cout<<"\nPREPARE stage["<<stage<<"] completed!\n";
system("sleep 350");
if(stage<=1)analyze();
}
else{
fprintf(log,"%s %s %s\n","File ",parametro," is not exist\n");
fclose(log);
cout<<"Error have been occured. See the error.log for details.";
}
fclose(log);
}
void rename_rez_file(){
FILE *ifp,*tfp, *ofp;
int c;
string forUpdateName="rezyltat";
forUpdateName+="_[";














