void GraphMlLoader::getEdge() { QString comment = ""; QPointF pos(0,0), compos(0,0); QColor col; int target_id = 0; int source_id = 0; if(reader.name() == "edge") { QXmlStreamAttributes attributes = reader.attributes(); source_id = attributes.value("source").toString().toInt(); target_id = attributes.value("target").toString().toInt(); } while(!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == "edge")) { if(reader.tokenType() == QXmlStreamReader::StartElement && reader.name() == "data") { QXmlStreamAttributes attributes = reader.attributes(); reader.readNext(); if(attributes.value("id").toString() == "comment") { comment = reader.text().toString(); pos.setX(attributes.value("x").toString().toDouble()); pos.setY(attributes.value("y").toString().toDouble()); } if(attributes.value("color").toString() == "color") { col.setNamedColor(reader.text().toString()); } } reader.readNext(); } qDebug() << source_id << target_id; GraphVisNode *source_node = Gmodel->getNodes().at(source_id)->mdata; GraphVisNode *target_node = Gmodel->getNodes().at(target_id)->mdata; if(source_node!= NULL && target_node!=NULL) { qDebug() << "edge added"; GraphVisEdge *edge = graph->addEdge(source_node, target_node); edge->setPos(pos); if(comment != "") { graph->addComment(edge, comment, compos); } } }
int main( int argc, char *argv[] ) { int ncolumns = 0; int autolabel = 0; int curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0; int xsgn, ysgn; char *thislabel; int an; SET_DEFAULT_BINARY(); SET_FILE_BINARY(stdin); SET_FILE_BINARY(stdout); progname = argv[0]; for (an = 1; an < argc && argv[an][0] == '-'; an++) switch (argv[an][1]) { case 'h': echoheader = !echoheader; break; case 'x': xsiz = atoi(argv[++an]); break; case 'y': ysiz = atoi(argv[++an]); break; case 'b': setcolr(bgcolr, atof(argv[an+1]), atof(argv[an+2]), atof(argv[an+3])); an += 3; break; case 'a': ncolumns = atoi(argv[++an]); break; case 's': spacing = atoi(argv[++an]); break; case 'o': curx = x0 = atoi(argv[++an]); cury = atoi(argv[++an]); break; case 'l': switch (argv[an][2]) { case 'a': autolabel++; break; case 'h': labelht = atoi(argv[++an]); break; case '\0': goto dofiles; default: goto userr; } break; case '\0': case 't': goto dofiles; default: goto userr; } dofiles: newheader("RADIANCE", stdout); fputnow(stdout); for (nfile = 0; an < argc; nfile++) { if (nfile >= MAXFILE) goto toomany; thislabel = NULL; input[nfile].flags = 0; xsgn = ysgn = '-'; while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+' || argv[an][0] == '=')) { switch (argv[an][1]) { case 't': checkthresh = 1; if (argv[an][0] == '-') { input[nfile].flags |= HASMIN; input[nfile].thmin = atof(argv[an+1]); } else if (argv[an][0] == '+') { input[nfile].flags |= HASMAX; input[nfile].thmax = atof(argv[an+1]); } else goto userr; an++; break; case 'l': if (strcmp(argv[an], "-l")) goto userr; thislabel = argv[++an]; break; case '+': case '-': case '0': if (argv[an][0] != '=') goto userr; xsgn = argv[an][1]; ysgn = argv[an][2]; if (ysgn != '+' && ysgn != '-' && ysgn != '0') goto userr; break; case '\0': if (argv[an][0] == '-') goto getfile; goto userr; default: goto userr; } an++; } getfile: if (argc-an < (ncolumns ? 1 : 3)) goto userr; if (autolabel && thislabel == NULL) thislabel = argv[an]; if (!strcmp(argv[an], "-")) { input[nfile].name = StandardInput; input[nfile].fp = stdin; } else { if (argv[an][0] == '!') { input[nfile].name = Command; input[nfile].fp = popen(argv[an]+1, "r"); } else { input[nfile].name = argv[an]; input[nfile].fp = fopen(argv[an], "r"); } if (input[nfile].fp == NULL) { perror(argv[an]); quit(1); } } an++; /* get header */ if (echoheader) printf("%s:\n", input[nfile].name); getheader(input[nfile].fp, headline, NULL); if (wrongformat) { fprintf(stderr, "%s: incompatible input format\n", input[nfile].name); quit(1); } /* get picture size */ if (fgetresolu(&input[nfile].xres, &input[nfile].yres, input[nfile].fp) < 0) { fprintf(stderr, "%s: bad picture size\n", input[nfile].name); quit(1); } if (ncolumns > 0) { if (curcol >= ncolumns) { cury = ymax + spacing; curx = x0; curcol = 0; } input[nfile].xloc = curx; input[nfile].yloc = cury; curx += input[nfile].xres + spacing; curcol++; } else { input[nfile].xloc = atoi(argv[an++]); if (xsgn == '+') input[nfile].xloc -= input[nfile].xres; else if (xsgn == '0') input[nfile].xloc -= input[nfile].xres/2; input[nfile].yloc = atoi(argv[an++]); if (ysgn == '+') input[nfile].yloc -= input[nfile].yres; else if (ysgn == '0') input[nfile].yloc -= input[nfile].yres/2; } if (input[nfile].xloc < xmin) xmin = input[nfile].xloc; if (input[nfile].yloc < ymin) ymin = input[nfile].yloc; if (input[nfile].xloc+input[nfile].xres > xmax) xmax = input[nfile].xloc+input[nfile].xres; if (input[nfile].yloc+input[nfile].yres > ymax) ymax = input[nfile].yloc+input[nfile].yres; if (thislabel != NULL) { if (++nfile >= MAXFILE) goto toomany; input[nfile].name = Label; input[nfile].flags = 0; input[nfile].xres = input[nfile-1].xres; input[nfile].yres = labelht; if ((input[nfile].fp = lblopen(thislabel, &input[nfile].xres, &input[nfile].yres)) == NULL) goto labelerr; input[nfile].xloc = input[nfile-1].xloc; input[nfile].yloc = input[nfile-1].yloc + input[nfile-1].yres-input[nfile].yres; } } if (xsiz <= 0) xsiz = xmax; else if (xsiz > xmax) xmax = xsiz; if (ysiz <= 0) ysiz = ymax; else if (ysiz > ymax) ymax = ysiz; /* add new header info. */ printargs(argc, argv, stdout); if (strcmp(ourfmt, PICFMT)) fputformat(ourfmt, stdout); /* print format if known */ putchar('\n'); fprtresolu(xsiz, ysiz, stdout); compos(); quit(0); userr: fprintf(stderr, "Usage: %s [-h][-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", progname); fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n"); quit(1); toomany: fprintf(stderr, "%s: only %d files and labels allowed\n", progname, MAXFILE); quit(1); labelerr: fprintf(stderr, "%s: error opening label\n", progname); quit(1); return 1; /* pro forma return */ }
void GraphMlLoader::getNode() { QString path = "", comment = "", name = ""; QPointF pos(0,0), compos(0,0); QColor col; while(!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == "node")) { if(reader.tokenType() == QXmlStreamReader::StartElement && reader.name() == "data") //We found "data" { //Read data's attributes QXmlStreamAttributes attributes = reader.attributes(); reader.readNext();//Read data's attributes data if(attributes.value("id").toString() == "path") { path = reader.text().toString(); } if(attributes.value("id").toString() == "x") { pos.setX(reader.text().toString().toDouble()); } if(attributes.value("id").toString() == "y") { pos.setY(reader.text().toString().toDouble()); } if(attributes.value("id").toString() == "comment") { comment = reader.text().toString(); compos.setX(attributes.value("x").toString().toDouble()); compos.setY(attributes.value("y").toString().toDouble()); } if(attributes.value("id").toString() == "color") { col.setNamedColor(reader.text().toString()); } if(attributes.value("id").toString() == "name") { name = reader.text().toString(); } } reader.readNext(); } if(path == "") { QMessageBox::warning(0, "Wrong path", "Wrong path was given in " + QString::number(reader.lineNumber()) + " line. \nNode will not be loaded.", QMessageBox::Ok, QMessageBox::NoButton); return; } QFileInfo *fileInfo = new QFileInfo(path); GraphVisNode* node = graph->addNode(fileInfo); node->setPos(pos); node->setColor(col); node->setNameText(name); if(comment != "") { graph->addComment(node, comment, compos); } }
int main(int argc, char *argv[]) { #ifdef __linux feenableexcept(2); feenableexcept(3); #endif FILE * matrici_iniziali=fopen("Matrici_Iniziali.txt","w"); FILE * posizionePart=fopen("Posizione_Particelle.txt","w"); FILE * ellissi=fopen("Parametri_Ellissi_Funz_Ottiche.txt","w"); FILE * funzioni_ottiche=fopen("Funzioni_Ottiche.txt","w"); FILE * confronti=fopen("Math_rilevati.txt","w"); #ifdef TEST_OPTICAL_FUNCTIONS FILE * funzioni_ottiche_t=fopen("Funzioni_Ottiche_T.txt","w"); FILE * ellissi_t=fopen("Parametri_Ellissi_Funz_Ottiche_T.txt","w"); FILE * confronti_t=fopen("Math_rilevati_T.txt","w"); #endif #ifdef DEBUG FILE * outputDEBUG=fopen("DEBUG.txt","w"); #endif bool fallita_lettura_parametri = true; bool fallita_lettura_inputdistr = true; bool do_transport = false; bool do_optics = false; bool posso_fare_funzioni_ottiche = false; ifstream parametri; ifstream inputdistr; int nstep = 1; double gnuplot_ymax_opt=0.; bool calcola_ymax_opt = true; #ifdef TEST_OPTICAL_FUNCTIONS double gnuplot_ymax_opt_T=0.; bool calcola_ymax_opt_T = true; #endif double gnuplot_ymax_pos=0.; bool calcola_ymax_pos = true; double gnuplot_xmax_opt=0.; double gnuplot_xmax_pos=0.; bool calcola_ymax_ell = true; double gnuplot_ymax_ell=0.; double percentuale=0.03; int conto_per_confronto=0; double *compare_x=new double[2]; double *compare_y=new double[2]; bool confronto_pos_x=false; bool confronto_pos_y=false; double *paramIniz_X=new double[2]; double *paramIniz_Y=new double[2]; #ifdef TEST_OPTICAL_FUNCTIONS int conto_per_confronto_t_x=0; int conto_per_confronto_t_y=0; bool confronto_pos_t_y=false; bool confronto_pos_t_x=false; bool fai_da_te_x=false; bool fai_da_te_y=false; #endif for (int i = 1; i < argc; i++) { if (string(argv[i]) == "-p") { parametri.open(argv[i+1]); fallita_lettura_parametri=parametri.fail(); i++; } else if (string(argv[i]) == "-i") { inputdistr.open(argv[i+1]); fallita_lettura_inputdistr=inputdistr.fail(); i++; } else if (string(argv[i]) == "-transport") { do_transport=true; } else if (string(argv[i]) == "-xmax_opt") { gnuplot_xmax_opt=atof(argv[i+1]); i++; } else if (string(argv[i]) == "-xmax_pos") { gnuplot_xmax_pos=atof(argv[i+1]); i++; } else if (string(argv[i]) == "-ymax_opt") { gnuplot_ymax_opt=atof(argv[i+1]); calcola_ymax_opt = false; i++; } #ifdef TEST_OPTICAL_FUNCTIONS else if (string(argv[i]) == "-ymax_opt_T") { gnuplot_ymax_opt_T=atof(argv[i+1]); calcola_ymax_opt_T = false; i++; } #endif else if (string(argv[i]) == "-ymax_pos") { gnuplot_ymax_pos=atof(argv[i+1]); calcola_ymax_pos = false; i++; } else if (string(argv[i]) == "-ymax_ell") { gnuplot_ymax_ell=atof(argv[i+1]); calcola_ymax_ell = false; i++; } else if (string(argv[i]) == "-compare_X") { compare_x[0]=atof(argv[i+1]); compare_x[1]=atof(argv[i+2]); i+=2; } else if (string(argv[i]) == "-compare_Y") { compare_y[0]=atof(argv[i+1]); compare_y[1]=atof(argv[i+2]); i+=2; } else if (string(argv[i]) == "-perc") { percentuale=atof(argv[i+1]); fprintf(matrici_iniziali,"\n%f\n",percentuale); i++; } else if (string(argv[i]) == "-optics") { do_optics=true; } else if (string(argv[i]) == "-nstep") { nstep = atoi(argv[i+1]); i++; } #ifdef TEST_OPTICAL_FUNCTIONS else if (string(argv[i]) == "-paramIniz_X") { paramIniz_X[0] = atoi(argv[i+1]); paramIniz_X[1] = atoi(argv[i+2]); fai_da_te_x=true; i+=2; } else if (string(argv[i]) == "-paramIniz_Y") { paramIniz_Y[0] = atoi(argv[i+1]); paramIniz_Y[1] = atoi(argv[i+2]); fai_da_te_y=true; i+=2; } #endif else { printf("Impossibile riconoscere il parametro %s\n",argv[i]); } } string utile_per_contare; int conta_righe_parametri = 0; if (fallita_lettura_parametri || fallita_lettura_inputdistr) { printf("Impossibile aprire (o non definito) il file contenente i parametri\no il file contenente la distribuzione/particella iniziale\n"); exit(204); } double * dati_iniziali = new double[6]; // emittanza, energia, x, y, px, py for (int i = 0; i < 6; i++) { if(inputdistr.eof()) { printf("Mancano dei dati iniziali!\n"); exit(123); } inputdistr >> dati_iniziali[i]; } inputdistr.clear(); inputdistr.seekg(0,std::ios::beg); double emittanza = dati_iniziali[0]; double energia = dati_iniziali[1]; double *vett_i=new double[4]; vett_i[0]=dati_iniziali[2]; vett_i[1]=dati_iniziali[4]; vett_i[2]=dati_iniziali[3]; vett_i[3]=dati_iniziali[5]; do { parametri >> utile_per_contare; if(parametri.eof()) break; parametri.ignore(1000, '\n'); conta_righe_parametri++; } while(!parametri.eof()); parametri.clear(); parametri.seekg(0,std::ios::beg); // qui di leggono tutti i dati // char *elemento=new char[conta_righe_parametri]; string *elemento=new string[conta_righe_parametri]; double * lunghezza= new double[conta_righe_parametri]; double * gradiente= new double[conta_righe_parametri]; int contatore=0; for (int i = 0; i < conta_righe_parametri; i++) { parametri >> elemento[i]; parametri >> gradiente[i]; parametri >> lunghezza[i]; #ifdef DEBUG cout << "Tipo elemento: " << elemento[i] << ", gradiente: " << gradiente[i] << ", lunghezza: " << lunghezza[i] << endl; #endif contatore++; } #ifdef DEBUG printf("contatore: %d",contatore); #endif vector <vector <double> > I(4,vector<double>(4,0.0)); vector <vector <double> > K(4,vector<double>(4,0.0)); vector <vector <double> > F(4,vector<double>(4,0.0)); vector <vector <vector <double> > > Fx(contatore,vector <vector <double> > (4, vector <double> (4,0.0))); vector <vector <vector <double> > > Dx(contatore,vector <vector <double> > (4, vector <double> (4,0.0))); vector <vector <vector <double> > > OI(contatore,vector <vector <double> > (4, vector <double> (4,0.0))); vector <vector <vector <double> > > FxI(contatore,vector <vector <double> > (4, vector <double> (4,0.0))); vector <vector <vector <double> > > DxI(contatore,vector <vector <double> > (4, vector <double> (4,0.0))); vector <vector <vector <double> > > O(contatore,vector <vector <double> > (4, vector <double> (4,0.0))); double *alpha = new double[2]; double *beta = new double[2]; double *aminmax = new double[2]; double *bminmax = new double[2]; bool alpha_calcolato_con_successo=false; bool beta_calcolato_con_successo=false; #ifdef TEST_OPTICAL_FUNCTIONS double *ottiche_x_t = new double[2]; double *ottiche_y_t = new double[2]; double *aminmax_x_t = new double[2]; double *bminmax_y_t = new double[2]; for (int i = 0; i < 2; i++) ottiche_x_t[i] = ottiche_y_t[i] = aminmax_x_t[i] = bminmax_y_t[i] = 0.; #endif double gamma_beta=sqrt(2.0*energia/MP_MEV); double gamma_v=gamma_beta*SPEED_OF_LIGHT; double *f1 =new double [contatore]; double *d1 =new double [contatore]; for (int i=0;i<contatore;i++) { if (elemento[i]=="F") f1[i]=sqrt(gradiente[i]*CHARGE/(MP_KG*gamma_v)); if (elemento[i]=="D") d1[i]=sqrt(gradiente[i]*CHARGE/(MP_KG*gamma_v)); } #ifdef DEBUG for (int i=0;i<contatore;i++) { fprintf(outputDEBUG,"\ngrad. foc. %+20.10f ", f1[i]*f1[i]); fprintf(outputDEBUG,"\ngrad. defoc. %+20.10f ", d1[i]*d1[i]); } #endif for (int i=0;i<contatore;i++) { #ifdef DEBUG if (elemento[i]=="F") Fx[i]=focusing(Fx[i],f1[i],lunghezza[i],matrici_iniziali,i); else if (elemento[i]=="D") Dx[i]=defocusing(Dx[i],d1[i],lunghezza[i],matrici_iniziali,i); else if (elemento[i]=="O") O[i]=drift(O[i],lunghezza[i],matrici_iniziali,i); else fprintf(outputDEBUG,"Elemento[%d] non riconosciuto\n", i); #else if (elemento[i]=="F") Fx[i]=focusing(Fx[i],f1[i],lunghezza[i]); else if (elemento[i]=="D") Dx[i]=defocusing(Dx[i],d1[i],lunghezza[i]); else if (elemento[i]=="O") O[i]=drift(O[i],lunghezza[i]); #endif } #ifdef DEBUG for (int i=0;i<contatore;i++) { if (elemento[i]=="O") { // if (O[i][0][0] == 0.0) continue; fprintf(matrici_iniziali,"\nMATRICE DRIFT"); scrivimatr2D(O[i],matrici_iniziali); fprintf(matrici_iniziali,"\n"); } else if (elemento[i]=="F") { // if (Fx[i][0][0] == 0.0) continue; fprintf(matrici_iniziali,"\nMATRICE FOC."); scrivimatr2D(Fx[i],matrici_iniziali); fprintf(matrici_iniziali,"\n"); } else if (elemento[i]=="D") { // if (Dx[i][0][0] == 0.0) continue; fprintf(matrici_iniziali,"\nMATRICE DEFOC."); scrivimatr2D(Dx[i],matrici_iniziali); fprintf(matrici_iniziali,"\n"); } } #endif /************************************************************************/ if (do_optics) { vector <vector <double> > compos(4,vector<double>(4,0)); if (elemento[0]=="O") { for (int k=0; k<4; k++) for (int j=0; j<4; j++) compos[k][j]=O[0][k][j]; } else if (elemento[0]=="F") { for (int k=0; k<4; k++) for (int j=0; j<4; j++) compos[k][j]=Fx[0][k][j]; } else if (elemento[0]=="D") { for (int k=0; k<4; k++) for (int j=0; j<4; j++) compos[k][j]=Dx[0][k][j]; } for (int i=1;i<contatore;i++) { if (elemento[i]=="O") compos=prodo(O[i],compos,4); else if (elemento[i]=="F") compos=prodo(Fx[i],compos,4); else if (elemento[i]=="D") compos=prodo(Dx[i],compos,4); } for (int i=0;i<4;i++) for(int a=0;a<4;a++) F[i][a]=compos[i][a]; // Calcolo Funzioni OTTICHE for (int i = 0; i < 2; i++) alpha[i] = beta[i] = aminmax[i] = bminmax[i] = 0.; if ( (fabs((F[FOC][FOC]+F[FOC+1][FOC+1])*0.5) <= 1.) && (fabs((F[DEFOC][DEFOC]+F[DEFOC+1][DEFOC+1])*0.5) <= 1.)) posso_fare_funzioni_ottiche = true; else cout << "Impossibile calcolare le funzioni ottiche!" << endl; //cout << "posso_fare_funzioni_ottiche="<<posso_fare_funzioni_ottiche<<endl; //if ((((F[FOC][FOC]+F[FOC+1][FOC+1])*(F[FOC][FOC]+F[FOC+1][FOC+1])-4)<=0) && (((F[DEFOC][DEFOC]+F[DEFOC+1][DEFOC+1])*(F[DEFOC][DEFOC]+F[DEFOC+1][DEFOC+1])-4)<=0) ) // posso_fare_funzioni_ottiche = true; //else cout << "Impossibile calcolare le funzioni ottiche!" << endl; if (posso_fare_funzioni_ottiche) { alpha=optics(F,FOC,&alpha_calcolato_con_successo); beta=optics(F,DEFOC,&beta_calcolato_con_successo); aminmax = assi_ellissi(alpha, emittanza); bminmax = assi_ellissi(beta, emittanza); if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt); if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos); if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell); fprintf(funzioni_ottiche,"# alpha_successo %d beta_successo %d\n",(int)(alpha_calcolato_con_successo),(int)(beta_calcolato_con_successo)); if (alpha_calcolato_con_successo&&beta_calcolato_con_successo) { fprintf(funzioni_ottiche,"\n#%7c",'S'); fprintf(funzioni_ottiche,"%10.8s","Alpha x"); fprintf(funzioni_ottiche,"%10.7s","Beta x"); fprintf(funzioni_ottiche,"%12.8s","Alpha y"); fprintf(funzioni_ottiche,"%10.7s","Beta y"); fprintf(ellissi,"%10s","x"); fprintf(ellissi,"%11s","p_x"); fprintf(ellissi,"%11s","y"); fprintf(ellissi,"%11s","p_y"); } scrividati(0.0,alpha,beta,funzioni_ottiche); scrividati_ellissi(0.0,aminmax,bminmax,ellissi); #ifdef TEST_OPTICAL_FUNCTIONS for (int i=0;i<2;i++) { if (fai_da_te_x&&fai_da_te_y) { ottiche_x_t[i]=paramIniz_X[i]; ottiche_y_t[i]=paramIniz_Y[i]; } else if (fai_da_te_x) { ottiche_x_t[i]=paramIniz_X[i]; ottiche_y_t[i]=paramIniz_X[i]; } else if (fai_da_te_y) { ottiche_x_t[i]=paramIniz_Y[i]; ottiche_y_t[i]=paramIniz_Y[i]; } else { ottiche_x_t[i]=alpha[i]; ottiche_y_t[i]=beta[i]; } } aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza); bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza); scrividati(0.0,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t); scrividati_ellissi(0.0,aminmax_x_t,bminmax_y_t,ellissi_t); if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T); #endif } } if(do_transport) { fprintf(posizionePart," %+10.5f",0.0); fprintf(posizionePart," %+10.5f",vett_i[0]); fprintf(posizionePart," %+10.5f",vett_i[1]); fprintf(posizionePart," %+10.5f",vett_i[2]); fprintf(posizionePart," %+10.5f\n",vett_i[3]); } #ifdef DEBUG fprintf(outputDEBUG, "\nFODO:"); scrivimatr2D(F,outputDEBUG); #endif /************************************************************************/ //ora primi dell'iterazione mi calcolo le micromappe Li di lunghezza S=L/n double lunghezzatotale=0.; for (int i = 0 ;i < contatore;i++) lunghezzatotale+=lunghezza[i]; #ifdef DEBUG for (int i=0; i < contatore; i++) { fprintf(outputDEBUG,"\n#step in elemento %d = %d",i, dsMap(lunghezza[i],lunghezzatotale,nstep)); } fprintf(outputDEBUG,"\n"); #endif double S = 0.; //Calcolo MICROMAPPE per il Drift for (int i=0; i < contatore; i++) { S=lunghezza[i]/dsMap(lunghezza[i],lunghezzatotale,nstep); #ifdef DEBUG if (elemento[i] == "O") { O[i]=drift(O[i],S,matrici_iniziali,i); OI[i]=drift(OI[i],-S,matrici_iniziali,i); } else if (elemento[i] == "F") { Fx[i]=focusing(Fx[i],f1[i],S,matrici_iniziali,i); FxI[i]=focusing(FxI[i],f1[i],-S,matrici_iniziali,i); } else if (elemento[i] == "D") { Dx[i]=defocusing(Dx[i],d1[i],S,matrici_iniziali,i); DxI[i]=defocusing(DxI[i],d1[i],-S,matrici_iniziali,i); } #else if (elemento[i] == "O") { O[i]=drift(O[i],S); OI[i]=drift(OI[i],-S); } else if (elemento[i] == "F") { Fx[i]=focusing(Fx[i],f1[i],S); FxI[i]=focusing(FxI[i],f1[i],-S); } else if (elemento[i] == "D") { Dx[i]=defocusing(Dx[i],d1[i],S); DxI[i]=defocusing(DxI[i],d1[i],-S); } #endif } /***********************************************************************/ double dl=0.; double lunghezza_accumulata=0.0; for (int i=0;i<contatore;i++) { dl=lunghezza[i]/dsMap(lunghezza[i],lunghezzatotale,nstep); if (elemento[i]=="O") { fprintf(matrici_iniziali,"\n#Drift #%d, dl = %f",i,dl); fprintf(funzioni_ottiche,"\n#Drift #%d, dl = %f",i,dl); while(S<=(lunghezza_accumulata+lunghezza[i])) { fprintf(matrici_iniziali,"\n\n Num_Step %f", S); scrivimatr2D(F,matrici_iniziali); if (do_transport) { #ifdef DEBUG prod(vett_i,O[i],S); #else prod(vett_i,O[i]); #endif if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos); scrivi_pos_part(posizionePart,vett_i,S); } if (do_optics) { F=simil(F,OI[i],O[i]); if (posso_fare_funzioni_ottiche) { alpha=optics(F,FOC,&alpha_calcolato_con_successo); beta=optics(F,DEFOC,&beta_calcolato_con_successo); aminmax = assi_ellissi(alpha, emittanza); bminmax = assi_ellissi(beta, emittanza); confronto(compare_x,aminmax,S,percentuale,confronti,&confronto_pos_x,&conto_per_confronto); confronto(compare_y,bminmax,S,percentuale,confronti,&confronto_pos_y,&conto_per_confronto); scrividati(S,alpha,beta,funzioni_ottiche); scrividati_ellissi(S,aminmax,bminmax,ellissi); if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell); if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt); #ifdef TEST_OPTICAL_FUNCTIONS ottiche_x_t=optics_T(ottiche_x_t,FOC,O[i]); ottiche_y_t=optics_T(ottiche_y_t,DEFOC,O[i]); aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza); bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza); confronto(paramIniz_X,aminmax_x_t,S,percentuale,confronti_t,&confronto_pos_t_x,&conto_per_confronto_t_x); confronto(paramIniz_Y,bminmax_y_t,S,percentuale,confronti_t,&confronto_pos_t_y,&conto_per_confronto_t_y); scrividati(S,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t); scrividati_ellissi(S,aminmax_x_t,bminmax_y_t,ellissi_t); if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T); #endif } } S+=dl; } lunghezza_accumulata+=lunghezza[i]; } else if (elemento[i]=="F") { fprintf(matrici_iniziali,"\n#Foc. #%d, dl = %f",i,dl); fprintf(funzioni_ottiche,"\n#Foc. #%d, dl = %f",i,dl); while(S<=(lunghezza_accumulata+lunghezza[i])) { fprintf(matrici_iniziali,"\n\n Num_Step %f", S); scrivimatr2D(F,matrici_iniziali); if (do_transport) { #ifdef DEBUG prod(vett_i,Fx[i],S); #else prod(vett_i,Fx[i]); #endif if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos); scrivi_pos_part(posizionePart,vett_i,S); } if (do_optics) { if (posso_fare_funzioni_ottiche) { F=simil(F,FxI[i],Fx[i]); alpha=optics(F,FOC,&alpha_calcolato_con_successo); beta=optics(F,DEFOC,&beta_calcolato_con_successo); aminmax = assi_ellissi(alpha, emittanza); bminmax = assi_ellissi(beta, emittanza); confronto(compare_x,aminmax,S,percentuale,confronti,&confronto_pos_x,&conto_per_confronto); confronto(compare_y,bminmax,S,percentuale,confronti,&confronto_pos_y,&conto_per_confronto); scrividati(S,alpha,beta,funzioni_ottiche); scrividati_ellissi(S,aminmax,bminmax,ellissi); if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell); if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt); #ifdef TEST_OPTICAL_FUNCTIONS ottiche_x_t=optics_T(ottiche_x_t,FOC,Fx[i]); ottiche_y_t=optics_T(ottiche_y_t,DEFOC,Fx[i]); aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza); bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza); confronto(paramIniz_X,aminmax_x_t,S,percentuale,confronti_t,&confronto_pos_t_x,&conto_per_confronto_t_x); confronto(paramIniz_Y,bminmax_y_t,S,percentuale,confronti_t,&confronto_pos_t_y,&conto_per_confronto_t_y); scrividati(S,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t); scrividati_ellissi(S,aminmax_x_t,bminmax_y_t,ellissi_t); if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T); #endif } } S+=dl; } lunghezza_accumulata+=lunghezza[i]; } else if (elemento[i]=="D") { fprintf(matrici_iniziali,"\n#Defoc. #%d, dl = %f",i,dl); fprintf(funzioni_ottiche,"\n#Defoc. #%d, dl = %f",i,dl); while (S<=(lunghezza_accumulata+lunghezza[i])) { fprintf(matrici_iniziali,"\n\n Num_Step %f", S); scrivimatr2D(F,matrici_iniziali); if (do_transport) { #ifdef DEBUG prod(vett_i,Dx[i],S); #else prod(vett_i,Dx[i]); #endif if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos); scrivi_pos_part(posizionePart,vett_i,S); } if (do_optics) { if (posso_fare_funzioni_ottiche) { F=simil(F,DxI[i],Dx[i]); alpha=optics(F,FOC,&alpha_calcolato_con_successo); beta=optics(F,DEFOC,&beta_calcolato_con_successo); aminmax = assi_ellissi(alpha, emittanza); bminmax = assi_ellissi(beta, emittanza); confronto(compare_x,aminmax,S,percentuale,confronti,&confronto_pos_x,&conto_per_confronto); confronto(compare_y,bminmax,S,percentuale,confronti,&confronto_pos_y,&conto_per_confronto); scrividati(S,alpha,beta,funzioni_ottiche); scrividati_ellissi(S,aminmax,bminmax,ellissi); if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell); if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt); #ifdef TEST_OPTICAL_FUNCTIONS ottiche_x_t=optics_T(ottiche_x_t,FOC,Dx[i]); ottiche_y_t=optics_T(ottiche_y_t,DEFOC,Dx[i]); aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza); bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza); confronto(paramIniz_X,aminmax_x_t,S,percentuale,confronti_t,&confronto_pos_t_x,&conto_per_confronto_t_x); confronto(paramIniz_Y,bminmax_y_t,S,percentuale,confronti_t,&confronto_pos_t_y,&conto_per_confronto_t_y); scrividati(S,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t); scrividati_ellissi(S,aminmax_x_t,bminmax_y_t,ellissi_t); if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T); #endif } } S+=dl; } lunghezza_accumulata+=lunghezza[i]; } } fclose(funzioni_ottiche); fclose(matrici_iniziali); fclose(posizionePart); fclose(ellissi); fclose(confronti); parametri.close(); inputdistr.close(); #ifdef TEST_OPTICAL_FUNCTIONS fclose(funzioni_ottiche_t); fclose(ellissi_t); #endif string *etichette_posizione = new string[8]; string *etichette_ottiche = new string[8]; string *etichette_ellissi = new string[8]; #ifdef TEST_OPTICAL_FUNCTIONS string *etichette_ottiche_T = new string[8]; string *etichette_ellissi_T = new string[8]; #endif etichette_posizione[0] = "Posizione_Particelle"; etichette_posizione[1] = "Posizione Particelle"; etichette_posizione[2] = "z (m)"; etichette_posizione[3] = "x/y (m), p_x/p_y"; etichette_posizione[4] = "x"; etichette_posizione[5] = "y"; etichette_posizione[6] = "p_x"; etichette_posizione[7] = "p_y"; etichette_ottiche[0] = "Funzioni_Ottiche"; etichette_ottiche[1] = "Funzioni Ottiche"; etichette_ottiche[2] = "z (m)"; #if defined (CREATE_EPS) etichette_ottiche[3] = "{/Symbol a}, {/Symbol b}"; etichette_ottiche[4] = "{/Symbol a}_x"; etichette_ottiche[5] = "{/Symbol a}_y"; etichette_ottiche[6] = "{/Symbol b}_x"; etichette_ottiche[7] = "{/Symbol b}_y"; #else etichette_ottiche[3] = "Alpha, Beta"; etichette_ottiche[4] = "Alpha_x"; etichette_ottiche[5] = "Alpha_y"; etichette_ottiche[6] = "Beta_x"; etichette_ottiche[7] = "Beta_y"; #endif etichette_ellissi[0] = "Parametri_Ellissi_Funz_Ottiche"; etichette_ellissi[1] = "Parametri Ellissi Funz Ottiche"; etichette_ellissi[2] = "z (m)"; etichette_ellissi[3] = "X , P"; etichette_ellissi[4] = "Xmax"; etichette_ellissi[5] = "Pmax_x"; etichette_ellissi[6] = "Ymax"; etichette_ellissi[7] = "Pmax_y"; #ifdef TEST_OPTICAL_FUNCTIONS etichette_ottiche_T[0] = "Funzioni_Ottiche_T"; etichette_ottiche_T[1] = "Funzioni ottiche test"; etichette_ottiche_T[2] = "z (m)"; #if defined (CREATE_EPS) etichette_ottiche_T[3] = "{/Symbol a}, {/Symbol b}"; etichette_ottiche_T[4] = "{/Symbol a}_x"; etichette_ottiche_T[5] = "{/Symbol a}_y"; etichette_ottiche_T[6] = "{/Symbol b}_x"; etichette_ottiche_T[7] = "{/Symbol b}_y"; #else etichette_ottiche_T[3] = "Alpha, Beta"; etichette_ottiche_T[4] = "Alpha_x"; etichette_ottiche_T[5] = "Alpha_y"; etichette_ottiche_T[6] = "Beta_x"; etichette_ottiche_T[7] = "Beta_y"; #endif etichette_ellissi_T[0] = "Parametri_Ellissi_Funz_Ottiche_T"; etichette_ellissi_T[1] = "Parametri Ellissi Funz Ottiche_T"; etichette_ellissi_T[2] = "z (m)"; etichette_ellissi_T[3] = "X , P"; etichette_ellissi_T[4] = "Xmax"; etichette_ellissi_T[5] = "Pmax_x"; etichette_ellissi_T[6] = "Ymax"; etichette_ellissi_T[7] = "Pmax_y"; #endif /***********************************************************/ //cout << "conto_per_confronto= "<<conto_per_confronto; double *dati_rilevati=new double [conto_per_confronto]; for (int a=0;a<conto_per_confronto;a++) dati_rilevati[a]=0.; if (confronto_pos_x||confronto_pos_y) { ifstream confro; confro.open("Math_rilevati.txt"); for (int i=0;i<conto_per_confronto;i++) { confro >> dati_rilevati[i]; } }