int plotit(){ char temp[50]; gnuplot_ctrl * h ; h = gnuplot_init() ; // gnuplot_set_ylabel(h, "Temp") ; // gnuplot_set_xlabel(h, "Time") ; gnuplot_cmd(h, "set terminal png size 900,900"); gnuplot_cmd(h, "set output \"/tmp/Temp1.png\""); gnuplot_cmd(h, "set xdata time"); gnuplot_cmd(h,"set timefmt \"%%m-%%d-%%H:%%M:%%S\""); // gnuplot_cmd(h,"set xrange [\"08-10-00:00\":\"08-11-23:59\"]"); //gnuplot_cmd(h, "set grid"); gnuplot_cmd(h, "plot \"/tmp/log1\" using 1:2 index 0 with linespoint"); gnuplot_close(h); h = gnuplot_init() ; // gnuplot_set_ylabel(h, "Temp") ; // gnuplot_set_xlabel(h, "Time") ; gnuplot_cmd(h, "set terminal png size 900,900"); gnuplot_cmd(h, "set output \"/tmp/Temp2.png\""); gnuplot_cmd(h, "set xdata time"); gnuplot_cmd(h,"set timefmt \"%%m-%%d-%%H:%%M:%%S\""); // gnuplot_cmd(h,"set xrange [\"08-10-00:00\":\"08-11-23:59\"]"); //gnuplot_cmd(h, "set grid"); gnuplot_cmd(h, "plot \"/tmp/log2\" using 1:2 index 0 with linespoint"); gnuplot_close(h); return 0; ; }
void Gnuplot_Init(t_data d, char *day, char *hour) { /* Gnuplot Plotting (Experimental) */ gnuplot_ctrl *g1, *g2, *g3, *g4; g1 = gnuplot_init(); g2 = gnuplot_init(); g3 = gnuplot_init(); g4 = gnuplot_init(); gnuplot_close(g1); gnuplot_close(g2); gnuplot_close(g3); gnuplot_close(g4); }
void plot_line(struct Fis * fis) { int i; double dx = 0.01; int max = (int) (1.0 / dx); double x[1]; double out[1]; double y[max], x_i[max]; gnuplot_ctrl * h1; h1 = gnuplot_init(); gnuplot_setstyle(h1,"lines"); for (i = 0; i < max; i++) { x[0] = (double)i * dx; // x[1] = (double)i * dx; x_i[i] = x[0]; evalfis(out,x,fis); y[i] = out[0]; } gnuplot_plot_xy(h1, x_i, y, max, "Fuzzy Output"); gnuplot_plot_xy(h1, x_i, x_i, max, "Expected Output"); printf("Press any key to close window\n"); getchar(); gnuplot_close(h1); }
int main () { char buf[256]; #ifdef SIGPIPE signal (SIGPIPE, SIG_IGN); #endif if (-1 == gnuplot_open (0, NULL)) { fprintf (stderr, "Unable to start 0\n"); return -1; } while (NULL != fgets (buf, sizeof(buf), stdin)) { if (-1 == gnuplot_cmd (0, buf)) { fprintf (stderr, "Unable to write cmd\n"); return -1; } } if (-1 == gnuplot_close (0)) { fprintf (stderr, "Unable to close 0\n"); return -1; } return 0; }
int main(void) { unsigned sampRate = 16000; unsigned nsamps = sampRate * 5; int16_t* buffer = (int16_t*) calloc(nsamps, sizeof(int16_t)); /* Record into the buffer */ LA_record(buffer, nsamps, sampRate, LA_REC_ONCE); printf("Recording...\n");fflush(stdout); while(LA_is_recording() == 1) sleep(1); /* Terminate the audio recording session */ LA_terminate(); /* Convert 16-bit ints to doubles for plotting */ double* dbuf = calloc(nsamps, sizeof(double)); for (unsigned i=0;i<nsamps;i++) dbuf[i] = (double) buffer[i]; /* Plot with gnuplot */ gnuplot_ctrl* h = gnuplot_init(); gnuplot_setstyle(h,"lines"); gnuplot_plot_x(h,dbuf,nsamps,"Live Audio"); gnuplot_close(h); /* Clean up */ free(dbuf); free(buffer); return 0; }
int main (int argc, char *argv[]) { gnuplot_ctrl * h; //handler of gnuplot session int i, j; double *x = (double *)malloc(Nx*sizeof(double)); double *y = (double *)malloc(Ny*sizeof(double)); double **z = (double **)malloc(Nx*sizeof(double *)); for (i=0 ; i<Ny ; i++) { z[i]=malloc(Ny*sizeof(double)); } h=gnuplot_init(); for (i=0 ; i<Nx ; i++) { for (j=0 ; j<Ny ; j++) { x[i]=(double)(i-Nx/2); y[j]=(double)(j-Ny/2); z[i][j]=x[i]*y[j]; //printf("z[i][j]=%e\n",z[i][j]); } } gnuplot_surf_gray_IMP(h, x, y, z, Nx, Ny, "try surface plot"); sleep(10); gnuplot_close(h); return 0; }
/** * @brief Open a new session, plot a signal, close the session. * @param title Plot title * @param style Plot style * @param label_x Label for X * @param label_y Label for Y * @param x Array of X coordinates * @param y Array of Y coordinates (can be NULL) * @param n Number of values in x and y. * @return * * This function opens a new gnuplot session, plots the provided * signal as an X or XY signal depending on a provided y, waits for * a carriage return on stdin and closes the session. * * It is Ok to provide an empty title, empty style, or empty labels for * X and Y. Defaults are provided in this case. */ void gnuplot_plot_once(char* title, char* style, char* label_x, char* label_y, float* x, float* y, int n) { gnuplot_ctrl* handle; if (x==NULL || n<1) return; if ((handle = gnuplot_init()) == NULL) return; if (style!=NULL) gnuplot_setstyle(handle, style); else gnuplot_setstyle(handle, (char*)"lines"); if (label_x!=NULL) gnuplot_set_xlabel(handle, label_x); else gnuplot_set_xlabel(handle, (char*)"X"); if (label_y!=NULL) gnuplot_set_ylabel(handle, label_y); else gnuplot_set_ylabel(handle, (char*)"Y"); if (y==NULL) gnuplot_plot_x(handle, x, n, title); else gnuplot_plot_xy(handle, x, y, n, title); printf("press ENTER to continue\n"); while (getchar()!='\n') {} gnuplot_close(handle); return; }
int clean(gnuplot_ctrl *bsln_disp[4]) { int count; for( count = 0; count < 4; count++) { if(bsln_disp[count] != NULL){ gnuplot_close(bsln_disp[count]); } } return 0; }
int main(int argc, char * argv[]) { gnuplot_ctrl * g = gnuplot_init(); char out_cmd[1024]; gnuplot_cmd(g, "set terminal png"); gnuplot_cmd(g, "set output \"sine.png\""); gnuplot_plot_equation(g, "sin(x)", "Sine wave"); gnuplot_close(g); return 0 ; }
int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s <training-csv-file>\n", argv[0]); return 1; } plotter = gnuplot_init(); csv_file* csv = csv_parse(argv[1]); linear_regression* lr = linreg_run(csv); printf("h(x) = %f + %fx\n", lr->theta0, lr->theta1); plot_data_and_model(argv[1], lr); linreg_free(lr); csv_free(csv); gnuplot_close(plotter); return 0; }
void BatchBinSet::plotBatchMu(const char* filename, const char* xlabel, const char* ylabel) { if (_num_batches == 0) log_printf(ERROR, "Cannot plot batch mu since the binners" " for this BatchBinSet have not yet been generated"); else if (!_statistics_compute) log_printf(ERROR, "Cannot plot batch mu since is has not yet" " not yet been computed for this BatchBinSet"); /* Plot the neutron flux */ gnuplot_ctrl* handle = gnuplot_init(); gnuplot_set_xlabel(handle, (char*)xlabel); gnuplot_set_ylabel(handle, (char*)ylabel); gnuplot_setstyle(handle, (char*)"dots"); gnuplot_saveplot(handle, (char*)filename); gnuplot_plot_xy(handle, getBinner(0)->getBinCenters(), _batch_mu, _num_bins, (char*)"Batch Mu"); gnuplot_close(handle); }
void gnuplot_plot_once( char * title, char * style, char * label_x, char * label_y, double * x, double * y, int n ) { gnuplot_ctrl * handle ; if (x==NULL || n<1) return ; handle = gnuplot_init(); if (style!=NULL) { gnuplot_setstyle(handle, style); } else { gnuplot_setstyle(handle, "lines"); } if (label_x!=NULL) { gnuplot_set_xlabel(handle, label_x); } else { gnuplot_set_xlabel(handle, "X"); } if (label_y!=NULL) { gnuplot_set_ylabel(handle, label_y); } else { gnuplot_set_ylabel(handle, "Y"); } if (y==NULL) { gnuplot_plot_x(handle, x, n, title); } else { gnuplot_plot_xy(handle, x, y, n, title); } printf("press ENTER to continue\n"); while (getchar()!='\n') {} gnuplot_close(handle); return ; }
/** * No need to explain this. * * @param argc Number of arguments. * @param argv Arguments array. * @return Return code. */ int main(int argc, char **argv) { bool running = true; char *script_file = NULL; char *csv_file = NULL; char *ctok = NULL; gnuplot_ctrl *gp = gnuplot_init(); char prompt[64] = "> "; if (argc == 2) { if (argv[1][strlen(argv[1]) - 3] == '.' && argv[1][strlen(argv[1]) - 2] == 'p' && argv[1][strlen(argv[1]) - 1] == 'c') { // Script file. script_file = argv[1]; running = parse_script(script_file, ctok, &csv_file, gp, prompt); } else { // CSV file. csv_file = argv[1]; generate_prompt(prompt, csv_file); } } while (running) { char *buffer = NULL; buffer = readline(prompt); if (buffer && *buffer) { add_history(buffer); ctok = strtok(buffer, " "); } else { continue; } running = parse_cmd_line(ctok, &csv_file, gp, prompt, false); } gnuplot_close(gp); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { unsigned int free_cs_size=0; h=0; unsigned int numPointsAdjTable; double start,stop, stop1,start1; MPI_Init(&argc,&argv); int myrank, nprocs; MPI_Comm_rank(MPI_COMM_WORLD,&myrank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); if(myrank==0) start = MPI_Wtime(); // ------------- polygons- ----------- // struct polygon obstacle1, obstacle2, link1, link2,link3; struct point base1, base2, base3; generate_obstacles_and_links(&obstacle1, &obstacle2, &link1, &link2, &link3 , &base1 , &base2 , &base3); int number_of_obstacles=2; struct polygon *obstacle_list; obstacle_list=(struct polygon*)malloc(number_of_obstacles*sizeof(struct polygon)); obstacle_list[0]=obstacle1; obstacle_list[1]=obstacle2; // ------------ sample list ------------------// int i,j, size_per_proc, n,n_cube; n = 5; n_cube=n*n*n; size_per_proc = floor(n_cube/nprocs); if(myrank==0){ size_per_proc+=n_cube % nprocs; } double ** sampleList; double ** free_configSpace; sampleList = (double **)malloc(sizeof(double*)* size_per_proc); free_configSpace = (double **)malloc(sizeof(double*)* size_per_proc); for(i=0;i<size_per_proc ; i++){ sampleList[i] = (double*)malloc(sizeof(double) * 3); free_configSpace[i] = (double*)malloc(sizeof(double) * 3); for(j=0;j<3;j++){ sampleList[i][j] = 0; free_configSpace[i][j] = 0; } } if(myrank==1) start1 = MPI_Wtime(); createSampeList(sampleList,n,size_per_proc); if(myrank==1){ stop1 = MPI_Wtime(); printf("create sampleList took %2.5f seconds \n", stop1-start1); } // -------- compute free config space --------- // if(myrank==0) start1 = MPI_Wtime(); compute3LinkFreeConfigSpace(size_per_proc,sampleList,&free_cs_size,free_configSpace,base1,base2,base3,link1,link2,link3,obstacle_list, number_of_obstacles); if(myrank==0){ stop1 = MPI_Wtime(); printf("compute3link took %2.5f seconds \n", stop1-start1); } // free memory for sampleList free(obstacle_list); for(i=0;i<size_per_proc;i++){ free(sampleList[i]); } free(sampleList); // allocate memory for total config space on proc 0 unsigned int free_cs_size_total; double** free_configSpace_total; MPI_Reduce(&free_cs_size,&free_cs_size_total,1,MPI_INT,MPI_SUM ,0,MPI_COMM_WORLD); if(myrank==0){ free_configSpace_total=(double **)malloc(free_cs_size_total*sizeof(double *)); for(i=0;i<free_cs_size_total;i++){ free_configSpace_total[i]=(double *)malloc(3*sizeof(double)); for(j=0;j<3;j++){ free_configSpace_total[i][j]=0; } } } if(myrank==0) start1 = MPI_Wtime(); gather_free_cs(&free_cs_size_total, free_configSpace_total,&free_cs_size, free_configSpace); if(myrank==0){ stop1 = MPI_Wtime(); printf(" gather free cs took %2.5f seconds \n", stop1-start1); // print_free_configSpace(free_cs_size_total,free_configSpace_total); } // adjacency table if(myrank==0){ double connectRadius=2.2*PI/(n-1); int ** adjTable = (int **)malloc(sizeof(int*)* free_cs_size); int * adjTableElementSize = (int*)malloc(sizeof(int)* free_cs_size); numPointsAdjTable = computeAdjTableForFreeCSpacePoints(free_cs_size, sampleList, adjTable, adjTableElementSize, connectRadius); //print_adjTable(free_cs_size,adjTable, adjTableElementSize); //printf("numPoints: %d\n", numPointsAdjTable); //draw_adjTable(free_cs_size_total,free_configSpace_total,adjTableElementSize,adjTable,1000000000); s.front = 0; s.rear = 0; int numInSPath = computeBFSPath(3, 60, adjTable, free_cs_size, adjTableElementSize, numPointsAdjTable); } // new ******************************************** // example: /* s.front = 0; s.rear = 0; int free_cs_size3 = 5; int free_cs_size2 = 3; int ** adjTable = (int **)malloc(sizeof(int*)* free_cs_size3); for (i=0;i<free_cs_size3;i++){ adjTable[i] = (int *)malloc(sizeof(int)* free_cs_size2); } int * adjTableElementSize = (int*)malloc(sizeof(int)* free_cs_size3); adjTable[0][0] = 1; adjTable[1][0] = 0; adjTable[1][1] = 2; adjTable[1][2] = 3; adjTable[2][0] = 1; adjTable[2][1] = 4; adjTable[2][2] = 3; adjTable[3][0] = 1; adjTable[3][1] = 2; adjTable[4][0] = 2; adjTableElementSize[0] = 1; adjTableElementSize[1] = 3; adjTableElementSize[2] = 3; adjTableElementSize[3] = 2; adjTableElementSize[4] = 1; int numInSPath = computeBFSPath(0, 4, adjTable, free_cs_size3, adjTableElementSize, 20); */ // **************************************************************** if(h!=NULL) gnuplot_close(h); /* if(myrank==0){ stop = MPI_Wtime(); printf("run time: %2.5f \n ", stop-start); } */ MPI_Finalize(); return 0; }
void plotter_close(){ gnuplot_close(handle); }
int main(int argc,char* argv[]) { PlasmaData pdata(argc,argv); gnuplot_ctrl* plot; gnuplot_ctrl* plot_anim; plot = gnuplot_init(); plot_anim = gnuplot_init(); gnuplot_setstyle(plot,"lines"); gnuplot_setstyle(plot_anim,"points"); gnuplot_cmd(plot_anim,"set term gif animate nooptimize size 1280,1280 xffffffff"); gnuplot_cmd(plot_anim,"set output \"particles.gif\""); gnuplot_cmd(plot_anim,"set xrange [-1:1]"); gnuplot_cmd(plot_anim,"set yrange [-1:1]"); float xmin = 0; float ymin = 0; float zmin = 0; float Lx = 5.0; float Ly = 5.0; float Lz = 5.0; int nx = 64; int ny = 64; int nz = 64; int nspecies = 1; const float dt = 0.01; const float dtau0 = 0.1; const int nptcls = 500; const int steps = 200; int iptcl[nptcls]; float Ey = 5.0; float Bz = 100.0; pdata.nx = nx; pdata.ny = ny; pdata.nz = nz; pdata.Lx = Lx; pdata.Ly = Ly; pdata.Lz = Lz; pdata.xmin = xmin; pdata.ymin = ymin; pdata.zmin = zmin; pdata.epsilon_a = 1.0e-4; pdata.epsilon_r = 1.0e-10; pdata.dt = dt; pdata.niter_max = 20; pdata.nSubcycle_max = 1000; pdata.Bmag_avg = 1.0; pdata.ndimensions = 3; pdata.setup(); FieldDataCPU fields; ParticleListCPU particles; HOMoments* moments; int numprocs = omp_get_num_procs(); moments = (HOMoments*)malloc(numprocs*sizeof(HOMoments)); for(int i=0;i<numprocs;i++) { moments[i] = *new HOMoments(&pdata); } float x_plot[nptcls][steps]; float y_plot[nptcls][steps]; float gx_plot[nptcls][steps]; float gy_plot[nptcls][steps]; float error_array[nptcls]; //float x_plot_a[nptcls]; //float y_plot_a[nptcls]; fields.allocate(&pdata); particles.allocate(nptcls); fields.dx = pdata.dxdi; fields.dy = pdata.dydi; fields.dz = pdata.dzdi; particles.ispecies = 0; for(int i=0;i<nptcls;i++) { iptcl[i] = i; particles.px[i] = rand()%10000/10000.0; particles.py[i] = rand()%10000/10000.0; particles.pz[i] = 0.5; particles.ix[i] = nx/2; particles.iy[i] = ny/2; particles.iz[i] = nz/2; particles.vx[i] = 0.5*(2*(rand()%10000))/10000.0 + 0.5; particles.vy[i] = 0.5*(2*(rand()%10000))/10000.0 + 0.5; particles.vz[i] = 0.0* (rand()%50000 / 50000.0f - 0.5); error_array[i] = 0; } // Setup E-field for(int i=0;i<nx;i++) { for(int j=0;j<ny;j++) { for(int k=0;k<nz;k++) { float x = i*pdata.dxdi+xmin; float y = j*pdata.dydi+ymin; float z = k*pdata.dzdi+zmin; float Ex = -1.0*x; fields.getE(i,j,k,0) = 0; fields.getE(i,j,k,1) = Ey; fields.getE(i,j,k,2) = 0; fields.getB(i,j,k,0) = 0; fields.getB(i,j,k,1) = 0; fields.getB(i,j,k,2) = Bz; // printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k, // fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2)); } } } fields.q2m[0] = 1.0; printf("Efield setup complete\n"); float time; double avg_error = 0.0; int n_error = 0; CPUTimer timer; moments->init_plot(); timer.start(); for(int i=0;i<steps;i++) { //time = dtau0*(i); //moments.set_vals(0); particles.push(&pdata,&fields,moments); printf("finished step %i\n",i); for(int j=0;j<nptcls;j++) { float px,py,gx,gy; float rl; float vx,vy,vxy,vz,vxyz; float vgx,vgy; float verror; px = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin; py = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin; vx = particles.vx[j]; vy = particles.vy[j]; vz = particles.vz[j]; vxy = sqrt(vx*vx+vy*vy); vxyz = sqrt(vxy*vxy + vz*vz); rl = vxy/Bz; gx = vy*Bz/sqrt(vx*Bz*vx*Bz + vy*Bz*vy*Bz)*rl + px; gy = -vx*Bz/sqrt(vx*Bz*vx*Bz + vy*Bz*vy*Bz)*rl + py; x_plot[j][i] = px; y_plot[j][i] = py; gx_plot[j][i] = gx; gy_plot[j][i] = gy; if(i >= 1) { vgx = (gx_plot[j][i] - gx_plot[j][0])/(dt*(i)); vgy = (gy_plot[j][i] - gy_plot[j][0])/(dt*(i)); verror = fabs(Ey/Bz - vgx)/(Ey/Bz); error_array[j] = fmax(error_array[j],verror); avg_error += verror; n_error ++; // printf("true[%i] v = %e, %e actual v = %e, %e, error = %e\n", // j,Ey/Bz,0.0f,vgx,vgy,verror); } } //if((i+1)%64 == 0) //gnuplot_resetplot(plot_anim); /* float diff_avg = 0.0; for(int j=0;j<nptcls;j++) { x_plot[j][i] = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin; y_plot[j][i] = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin; //printf("particle %i with position %f, %f\n",j,x_plot[j][i],y_plot[j][i]); // x_plot_a[j] = x_plot[j][i]; // y_plot_a[j] = y_plot[j][i]; } */ //avg_error += diff_avg / steps; //gnuplot_plot_xy(plot_anim,x_plot_a,y_plot_a,nptcls,NULL); } timer.stop(); printf("average error = %e \n",avg_error/((float)n_error)); printf("Run did %f particles per second\n",nptcls*steps/(timer.diff()*1.0e-3)); for(int j=0;j<nptcls;j++) { if(error_array[j] >= 1.0e-2) gnuplot_plot_xy(plot,x_plot[j],y_plot[j],steps,NULL); } //moments->plot(nz/2,0,HOMoments_currentx); printf("Press 'Enter' to continue\n"); getchar(); moments->close_plot(); gnuplot_close(plot); gnuplot_close(plot_anim); }
int main() { if (graph) { g = gnuplot_init(); h = gnuplot_init(); } /* n = 3; cost[0][0] = 2; cost[0][1] = 1; cost[0][2] = 3; cost[1][0] = 7; cost[1][1] = 4; cost[1][2] = 3; cost[2][0] = 3; cost[2][1] = 0; cost[2][2] = 0; */ // Worst case: n = 3; cost[0][0] = 11; // x = 11, e = 1, k = 2, l = 2 cost[0][1] = 10; cost[1][0] = 9; cost[1][1] = 7; cost[0][2] = 2; cost[1][2] = 3; cost[2][0] = 30; cost[2][1] = 40; cost[2][2] = 39; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d\t", cost[i][j]); } printf("\n"); } printf("\n"); hungarian(); for (int i = 0; i < n; i++) printf("%d\t", lx[i]); printf("\n\n"); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (xy[i] == j) printf("%d\t", 1); else printf("%d\t", 0); } printf("| %d\n", ly[i]); } printf("\n"); printf("Slack: "); for (int i = 0; i < n; i++) printf("%d\t", slack[i]); printf("\n"); printf("Slackx: "); for (int i = 0; i < n; i++) printf("%d\t", slackx[i]); printf("\n"); if (g != NULL) gnuplot_close(g); if (h != NULL) gnuplot_close(h); return 0; }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Plotter::~Plotter() { if (_plotter) gnuplot_close(_plotter); }
//function run after CTRL-C, used to clean up temporary files generated //by the plotting library void sigint_cleanup() { if(plotOpen==1) gnuplot_close(handle); //cleans up temporary files exit(1); }
int main(int argc, const char **argv) { Options options(argc, argv); Timer timer; log_setlevel(options.getVerbosity()); /* Get the number of neutrons, bins and batches */ int num_neutrons = options.getNumNeutrons(); int num_bins = options.getNumBins(); int num_batches = options.getNumBatches(); int num_threads = options.getNumThreads(); int num_gen; int num_alive; log_printf(NORMAL, "Beginning two region problem with %d neutrons, " "%d bins, %d batches, %d threads...", num_neutrons, num_bins, num_batches, num_threads); /* Create a handle for plotting with gnuplot */ gnuplot_ctrl* handle; /* Create a set of plotting flux bins for each batch */ BatchBinSet* total_flux = new BatchBinSet(); BatchBinSet* fuel_flux = new BatchBinSet(); BatchBinSet* moderator_flux = new BatchBinSet(); total_flux->createBinners(1E-6, 1E7, num_bins, num_batches, LOGARITHMIC, FLUX_ENERGY, (char*)"all"); fuel_flux->createBinners(1E-6, 1E7, num_bins, num_batches, LOGARITHMIC, FLUX_ENERGY, (char*)"all"); moderator_flux->createBinners(1E-6, 1E7, num_bins, num_batches, LOGARITHMIC, FLUX_ENERGY, (char*)"all"); /* Create bins to compute total fission and absorption rates */ BatchBinSet* tot_fiss_rate = new BatchBinSet(); BatchBinSet* tot_abs_rate = new BatchBinSet(); tot_fiss_rate->createBinners(1E-7, 1E7, 1, num_batches, EQUAL, FISSION_RATE_ENERGY, (char*)"all"); tot_abs_rate->createBinners(1E-7, 1E7, 1, num_batches, EQUAL, ABSORPTION_RATE_ENERGY, (char*)"all"); float nu_bar = 2.455; /* CASMO edit for average # neutrons per fission */ /* Create bins to compute two group cell-averaged cross-sections */ BatchBinSet* capture_2G = new BatchBinSet(); BatchBinSet* absorb_2G = new BatchBinSet(); BatchBinSet* fission_2G = new BatchBinSet(); BatchBinSet* elastic_2G = new BatchBinSet(); BatchBinSet* total_2G = new BatchBinSet(); BatchBinSet* two_group_flux = new BatchBinSet(); float two_group_E_ranges[3] = {0.0, 0.625, 1E7}; capture_2G->createBinners(two_group_E_ranges, 2, num_batches, CAPTURE_RATE_ENERGY, (char*)"all"); absorb_2G->createBinners(two_group_E_ranges, 2, num_batches, ABSORPTION_RATE_ENERGY, (char*)"all"); fission_2G->createBinners(two_group_E_ranges, 2, num_batches, FISSION_RATE_ENERGY, (char*)"all"); elastic_2G->createBinners(two_group_E_ranges, 2, num_batches, ELASTIC_RATE_ENERGY, (char*)"all"); total_2G->createBinners(two_group_E_ranges, 2, num_batches, COLLISION_RATE_ENERGY, (char*)"all"); two_group_flux->createBinners(two_group_E_ranges, 2, num_batches, FLUX_ENERGY, (char*)"all"); /* Create bins to compute two group isotopic cross-sections */ BatchBinSet* H1_capture_rate_2G = new BatchBinSet(); BatchBinSet* H1_elastic_rate_2G = new BatchBinSet(); BatchBinSet* O16_elastic_rate_2G = new BatchBinSet(); BatchBinSet* ZR90_elastic_rate_2G = new BatchBinSet(); BatchBinSet* U235_capture_rate_2G = new BatchBinSet(); BatchBinSet* U235_elastic_rate_2G = new BatchBinSet(); BatchBinSet* U235_fission_rate_2G = new BatchBinSet(); BatchBinSet* U238_capture_rate_2G = new BatchBinSet(); BatchBinSet* U238_elastic_rate_2G = new BatchBinSet(); BatchBinSet* U238_fission_rate_2G = new BatchBinSet(); H1_capture_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, CAPTURE_RATE_ENERGY, (char*)"H1"); H1_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, ELASTIC_RATE_ENERGY, (char*)"H1"); O16_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, ELASTIC_RATE_ENERGY, (char*)"O16"); ZR90_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, ELASTIC_RATE_ENERGY, (char*)"ZR90"); U235_capture_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, CAPTURE_RATE_ENERGY, (char*)"U235"); U235_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, ELASTIC_RATE_ENERGY, (char*)"U235"); U235_fission_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, FISSION_RATE_ENERGY, (char*)"U235"); U238_capture_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, CAPTURE_RATE_ENERGY, (char*)"U238"); U238_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, ELASTIC_RATE_ENERGY, (char*)"U238"); U238_fission_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, FISSION_RATE_ENERGY, (char*)"U238"); /* Create bins to compute moderator to fuel flux ratios */ int num_ratios = 13; BatchBinSet* fuel_flux_ratio = new BatchBinSet(); BatchBinSet* moderator_flux_ratio = new BatchBinSet(); float flux_ratio_E_ranges[14] = {0.0, 0.1, 0.5, 1.0, 6.0, 10.0, 25.0, 50.0, 100.0, 1000.0, 10000.0, 100000.0, 500000.0, 10000000.0}; fuel_flux_ratio->createBinners(flux_ratio_E_ranges, num_ratios, num_batches, FLUX_ENERGY, (char*)"all"); moderator_flux_ratio->createBinners(flux_ratio_E_ranges, num_ratios, num_batches, FLUX_ENERGY, (char*)"all"); /* Create bins to compute the diffusion coefficient for three methods */ BatchBinSet* coll_rate_2G = new BatchBinSet(); BatchBinSet* transport_rate_2G = new BatchBinSet(); BatchBinSet* diffusion_rate_2G = new BatchBinSet(); coll_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, COLLISION_RATE_ENERGY, (char*)"all"); transport_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, TRANSPORT_RATE_ENERGY, (char*)"all"); diffusion_rate_2G->createBinners(two_group_E_ranges, 2, num_batches, DIFFUSION_RATE_ENERGY, (char*)"all"); /* 2-region pin cell geometric parameters (units in cm) */ float r_fuel = 0.4096; float r_gap = 0.4178; float r_cladding = 0.4750; float pitch = 1.26; float p2 = pitch * pitch; /* 2-region homogenized densities (g/cm^3) and enrichment */ float rho_fuel = 10.2; float rho_cladding = 6.549; float rho_coolant = 0.9966; float enrichment = 0.03035; /* Isotope number densities */ float N_A = 6.023E23; /* Avogadro's number (at / mol) */ float N_U238 = rho_fuel*N_A*(1.0 - enrichment) / ((238.0 * (1.0 - enrichment)) + (235.0*enrichment) + (16.0*2.0)); float N_U235 = rho_fuel*N_A*enrichment / ((238.0 * (1.0 - enrichment)) + (235.0*enrichment) + (16.0*2.0)); float N_O16 = rho_fuel*N_A*2.0 / ((238.0 * (1.0 - enrichment)) + (235.0*enrichment) + (16.0*2.0)); float N_ZR90 = rho_cladding*N_A / 90.0; float N_H2O = rho_coolant*N_A / 18.0; float N_H1 = rho_coolant*N_A*2.0 / 18.0; /* 2-region pin cell volumes (cm^3) */ float v_fuel = M_PI*r_fuel*r_fuel; float v_gap = M_PI*(r_gap*r_gap - r_fuel*r_fuel); float v_cladding = M_PI*(r_cladding*r_cladding - r_gap*r_gap); float v_coolant = p2 - M_PI*r_cladding*r_cladding; float v_moderator = v_gap + v_cladding + v_coolant; float v_total = v_fuel + v_moderator; /* Compute homogenized moderator number densities using volume weighting */ N_H2O *= (v_coolant / v_moderator); N_H1 *= (v_coolant / v_moderator); N_ZR90 *= (v_cladding / v_moderator); /* Dancoff factor from CASMO-5 */ float dancoff = 0.277; /* Escape cross-section */ float sigma_e = 1.0 / (2.0*r_fuel); /* Carlvik's two-term rational model */ float A = (1.0 - dancoff) / dancoff; float alpha1 = ((5.0*A + 6.0) - sqrt(A*A + 36.0*A + 36.0)) / (2.0*(A+1.0)); float alpha2 = ((5.0*A + 6.0) + sqrt(A*A + 36.0*A + 36.0)) / (2.0*(A+1.0)); float beta = (((4.0*A + 6.0) / (A + 1.0)) - alpha1) / (alpha2 - alpha1); /* Print out the geometry parameters */ log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, "\t\t\t\tGeometry Parameters (cm)"); log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, ""); log_printf(NORMAL, "r_fuel = %f", r_fuel); log_printf(NORMAL, "r_gap = %f", r_gap); log_printf(NORMAL, "r_cladding = %f", r_cladding); log_printf(NORMAL, "pitch = %f", pitch); log_printf(NORMAL, "total cell area = %f", p2); log_printf(NORMAL, "v_fuel = %f", v_fuel); log_printf(NORMAL, "v_gap = %f", v_gap); log_printf(NORMAL, "v_cladding = %f", v_cladding); log_printf(NORMAL, "v_coolant = %f", v_coolant); log_printf(NORMAL, "v_moderator = %f", v_moderator); log_printf(NORMAL, "v_total = %f", v_total); log_printf(NORMAL, ""); /* Print to the console the number densities */ log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, "\t\t\t\tNumber Densities (at/cm^3)"); log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, ""); log_printf(NORMAL, "H1:\t%1.5e", N_H1); log_printf(NORMAL, "H2O:\t%1.5e", N_H2O); log_printf(NORMAL, "ZR90:\t%1.5e", N_ZR90); log_printf(NORMAL, "U235:\t%1.5e", N_U235); log_printf(NORMAL, "U238:\t%1.5e", N_U238); log_printf(NORMAL, "O16:\t%1.5e", N_O16); log_printf(NORMAL, ""); /* Print to the console the collision probability parameters */ log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, "\t\t\tTwo Region Collision Probability Parameters"); log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, ""); log_printf(NORMAL, "dancoff = %f", dancoff); log_printf(NORMAL, "sigma_e = %f", sigma_e); log_printf(NORMAL, "A = %f", A); log_printf(NORMAL, "alpha1 = %f", alpha1); log_printf(NORMAL, "alpha2 = %f", alpha2); log_printf(NORMAL, "beta = %f", beta); log_printf(NORMAL, ""); /* Create isotopes*/ char* delim = (char*)"\t"; Isotope* H1 = new Isotope(); H1->setA(1); H1->setIsotopeType((char*)"H1"); H1->loadXS((char*)"pendf/h-1_capture.txt", CAPTURE, delim); H1->loadXS((char*)"pendf/h-1_elastic.txt", ELASTIC, delim); H1->setElasticAngleType(ISOTROPIC_LAB); H1->initializeThermalScattering(1E-6, 15, 1000, 15); Isotope* O16 = new Isotope(); O16->setA(16); O16->setIsotopeType((char*)"O16"); O16->loadXS((char*)"pendf/o-16_elastic.txt", ELASTIC, delim); O16->setElasticAngleType(ISOTROPIC_LAB); Isotope* ZR90 = new Isotope(); ZR90->setA(90); ZR90->setIsotopeType((char*)"ZR90"); ZR90->loadXS((char*)"pendf/zr-90_elastic.txt", ELASTIC, delim); ZR90->setElasticAngleType(ISOTROPIC_LAB); Isotope* U235 = new Isotope(); U235->setA(235); U235->setIsotopeType((char*)"U235"); U235->loadXS((char*)"pendf/u-235_capture.txt", CAPTURE, delim); U235->setOneGroupElasticXS(11.4, ISOTROPIC_LAB); U235->loadXS((char*)"pendf/u-235_fission.txt", FISSION, delim); Isotope* U238 = new Isotope(); U238->setA(238); U238->setIsotopeType((char*)"U238"); U238->loadXS((char*)"pendf/u-238_capture.txt", CAPTURE, delim); U238->setOneGroupElasticXS(11.3, ISOTROPIC_LAB); U238->loadXS((char*)"pendf/u-238_fission.txt", FISSION, delim); /* Create Materials */ Material* moderator = new Material[num_threads]; Material* fuel = new Material[num_threads]; /* Create Regions for each thread */ Region1D* pellet = new Region1D[num_threads]; Region1D* coolant = new Region1D[num_threads]; /* Create Fissioners for each thread */ Fissioner* fissioners = new Fissioner[num_threads]; /* Create Region class objects for each thread */ for (int i=0; i < num_threads; i++) { /* Initialize Materials for each thread with isotope clones */ moderator[i].setMaterialName((char*)"moderator"); fuel[i].setMaterialName((char*)"fuel"); moderator[i].addIsotope(ZR90->clone(), N_ZR90); moderator[i].addIsotope(H1->clone(), N_H1); moderator[i].addIsotope(O16->clone(), N_H2O); moderator[i].rescaleCrossSections(1E-7, 1E7, 50000, LOGARITHMIC); fuel[i].addIsotope(U235->clone(), N_U235); fuel[i].addIsotope(U238->clone(), N_U238); fuel[i].addIsotope(O16->clone(), N_O16); fuel[i].rescaleCrossSections(1E-7, 1E7, 50000, LOGARITHMIC); /* Set the two region collision probability parameters */ pellet[i].setRegionName((char*)"pellet"); pellet[i].setMaterial(&fuel[i]); pellet[i].setAsFuel(); pellet[i].setOtherPinCellRegion(&coolant[i]); pellet[i].setVolume(v_fuel); pellet[i].setTwoRegionPinCellParams(sigma_e, beta, alpha1, alpha2); coolant[i].setRegionName((char*)"coolant"); coolant[i].setMaterial(&moderator[i]); coolant[i].setAsModerator(); coolant[i].setOtherPinCellRegion(&pellet[i]); coolant[i].setVolume(v_moderator); coolant[i].setTwoRegionPinCellParams(sigma_e, beta, alpha1, alpha2); /* Set the fissioner class for this thread to have 10MeV maximum and * 5000 sample bins */ fissioners[i].setEMax(10.0); fissioners[i].setNumBins(200); fissioners[i].buildCDF(); } /* Run the simulation */ log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, "\t\t\t\tBeginning Simulation..."); log_printf(NORMAL, "*******************************************************" "*************************"); log_printf(NORMAL, ""); timer.start(); omp_set_num_threads(num_threads); #pragma omp parallel shared(total_flux, fuel_flux, moderator_flux,\ fuel_flux_ratio, moderator_flux_ratio,\ tot_fiss_rate, tot_abs_rate, U235_capture_rate_2G,\ U235_elastic_rate_2G, U235_fission_rate_2G,\ U238_capture_rate_2G, U238_elastic_rate_2G,\ U238_fission_rate_2G, H1_capture_rate_2G,\ H1_elastic_rate_2G, O16_elastic_rate_2G,\ ZR90_elastic_rate_2G, fuel, moderator, \ pellet, coolant, fissioners) { /* Loop over batches */ #pragma omp for private(num_gen, num_alive) for (int b=0; b < num_batches; b++) { int thread_num = omp_get_thread_num(); log_printf(NORMAL, "Batch: %d\tThread: %d", b, thread_num); /* Set the binns for this batch */ pellet[thread_num].clearBinners(); pellet[thread_num].addBinner(total_flux->getBinner(b)); pellet[thread_num].addBinner(fuel_flux->getBinner(b)); pellet[thread_num].addBinner(fuel_flux_ratio->getBinner(b)); pellet[thread_num].addBinner(tot_fiss_rate->getBinner(b)); pellet[thread_num].addBinner(tot_abs_rate->getBinner(b)); pellet[thread_num].addBinner(U235_capture_rate_2G->getBinner(b)); pellet[thread_num].addBinner(U235_elastic_rate_2G->getBinner(b)); pellet[thread_num].addBinner(U235_fission_rate_2G->getBinner(b)); pellet[thread_num].addBinner(U238_capture_rate_2G->getBinner(b)); pellet[thread_num].addBinner(U238_elastic_rate_2G->getBinner(b)); pellet[thread_num].addBinner(U238_fission_rate_2G->getBinner(b)); pellet[thread_num].addBinner(O16_elastic_rate_2G->getBinner(b)); pellet[thread_num].addBinner(two_group_flux->getBinner(b)); pellet[thread_num].addBinner(coll_rate_2G->getBinner(b)); pellet[thread_num].addBinner(transport_rate_2G->getBinner(b)); pellet[thread_num].addBinner(diffusion_rate_2G->getBinner(b)); pellet[thread_num].addBinner(capture_2G->getBinner(b)); pellet[thread_num].addBinner(fission_2G->getBinner(b)); pellet[thread_num].addBinner(absorb_2G->getBinner(b)); pellet[thread_num].addBinner(elastic_2G->getBinner(b)); pellet[thread_num].addBinner(total_2G->getBinner(b)); coolant[thread_num].clearBinners(); coolant[thread_num].addBinner(total_flux->getBinner(b)); coolant[thread_num].addBinner(moderator_flux->getBinner(b)); coolant[thread_num].addBinner(moderator_flux_ratio->getBinner(b)); coolant[thread_num].addBinner(tot_fiss_rate->getBinner(b)); coolant[thread_num].addBinner(tot_abs_rate->getBinner(b)); coolant[thread_num].addBinner(H1_capture_rate_2G->getBinner(b)); coolant[thread_num].addBinner(H1_elastic_rate_2G->getBinner(b)); coolant[thread_num].addBinner(O16_elastic_rate_2G->getBinner(b)); coolant[thread_num].addBinner(ZR90_elastic_rate_2G->getBinner(b)); coolant[thread_num].addBinner(two_group_flux->getBinner(b)); coolant[thread_num].addBinner(coll_rate_2G->getBinner(b)); coolant[thread_num].addBinner(transport_rate_2G->getBinner(b)); coolant[thread_num].addBinner(diffusion_rate_2G->getBinner(b)); coolant[thread_num].addBinner(capture_2G->getBinner(b)); coolant[thread_num].addBinner(fission_2G->getBinner(b)); coolant[thread_num].addBinner(absorb_2G->getBinner(b)); coolant[thread_num].addBinner(elastic_2G->getBinner(b)); coolant[thread_num].addBinner(total_2G->getBinner(b)); /* Initialize all neutrons for this batch and add them to slab 1 */ for (int n=0; n < num_neutrons; n++) { neutron* new_neutron = initializeNewNeutron(); new_neutron->_x = 0.0; new_neutron->_mu = (float(rand()) / RAND_MAX) * 2.0 - 1.0; new_neutron->_energy = fissioners[thread_num].emitNeutroneV(); pellet[thread_num].addNeutron(new_neutron); } /* Loop over all neutrons until they are all dead */ num_gen = 1; num_alive = num_neutrons; while (num_alive > 0) { log_printf(DEBUG, "batch = %d, thread = %d, gen = %d, " "num_alive = %d", b, thread_num, num_gen, num_alive); num_gen++; num_alive = 0; /* Transfer neutrons between regions based on * two region collision probabilities */ pellet[thread_num].twoRegionNeutronTransferral(); coolant[thread_num].twoRegionNeutronTransferral(); /* Update each region's vector of neutrons with those * neutrons which were just transferred */ pellet[thread_num].initializeTransferredNeutrons(); coolant[thread_num].initializeTransferredNeutrons(); /* Move neutrons within each region */ pellet[thread_num].moveNeutrons(); coolant[thread_num].moveNeutrons(); num_alive = pellet[thread_num].getNumNeutrons() + coolant[thread_num].getNumNeutrons(); } } } log_printf(NORMAL, ""); /* Stop the timer record the timing split for this simulation */ timer.stop(); timer.recordSplit("Pset 4 time (sec)"); /* Compute batch statistics for total flux and flux in fuel, moderator */ total_flux->computeScaledBatchStatistics(num_neutrons*v_total); fuel_flux->computeScaledBatchStatistics(num_neutrons*v_fuel); moderator_flux->computeScaledBatchStatistics(num_neutrons*v_moderator); /* Compute batch statistics for total fission and absorption rates */ tot_fiss_rate->computeScaledBatchStatistics(num_neutrons*v_total); tot_abs_rate->computeScaledBatchStatistics(num_neutrons*v_total); /* Compute batch statistics for cell-averaged macro cross-sections */ capture_2G->computeScaledBatchStatistics(num_neutrons*v_total); fission_2G->computeScaledBatchStatistics(num_neutrons*v_total); absorb_2G->computeScaledBatchStatistics(num_neutrons*v_total); elastic_2G->computeScaledBatchStatistics(num_neutrons*v_total); total_2G->computeScaledBatchStatistics(num_neutrons*v_total); /* Compute batch statistics for one group cross-sections */ H1_capture_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); H1_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); O16_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); ZR90_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); U235_capture_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); U235_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); U235_fission_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); U238_capture_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); U238_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); U238_fission_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); two_group_flux->computeScaledBatchStatistics(num_neutrons*v_total); coll_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); transport_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); diffusion_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total); /* Compute k-infinity */ float fiss_rate_mu = tot_fiss_rate->getBatchMu()[0]; float fiss_rate_var = tot_fiss_rate->getBatchVariance()[0]; float abs_rate_mu = tot_abs_rate->getBatchMu()[0]; float abs_rate_var = tot_abs_rate->getBatchVariance()[0]; float k_inf = fiss_rate_mu * nu_bar / abs_rate_mu; float k_inf_var = (fiss_rate_mu*fiss_rate_mu)*abs_rate_var + (abs_rate_mu*abs_rate_mu)*fiss_rate_var + fiss_rate_var*abs_rate_var; float k_inf_std_dev = sqrt(k_inf_var); /* Compute moderator to fuel flux ratios */ fuel_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_fuel); moderator_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_moderator); fuel_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_fuel); moderator_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_moderator); /* Print to the console the total fission rate */ log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\t\t\tTotal Fission Rate (Batch Statistics)"); log_printf(RESULT, "*******************************************************" "*************************"); log_printf(NORMAL, ""); log_printf(RESULT, "Tot fission rate = %1.8f\t\tVariance = %1.8f", tot_fiss_rate->getBatchMu()[0], tot_fiss_rate->getBatchVariance()[0]); log_printf(RESULT, "Tot absorption rate = %f\t\tVariance = %f", tot_abs_rate->getBatchMu()[0], tot_abs_rate->getBatchVariance()[0]); log_printf(RESULT, "k_inf = %f\t\tvariance = %1.8f \t\t 2 sigma = %1.8f", k_inf, k_inf_var, k_inf_std_dev); log_printf(RESULT, ""); /* Print to the console the moderator/fuel flux ratios */ log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\t\t\t\tModerator/Fuel Flux Ratios"); log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, ""); float ratio; for (int i=1; i < num_ratios+1; i++) { ratio = moderator_flux_ratio->getBatchMu()[i-1] / fuel_flux_ratio->getBatchMu()[i-1]; log_printf(RESULT, "[%2.e eV - %2.e eV]:\t%f", flux_ratio_E_ranges[i-1], flux_ratio_E_ranges[i], ratio); } log_printf(RESULT, ""); /* Print to the console the cell-averaged fast to thermal flux ratio */ log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\t\t\tCell-Averaged Fast-to-Thermal Flux Ratio"); log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, ""); double* two_group_flux_mu = two_group_flux->getBatchMu(); double flux1 = two_group_flux_mu[0]; double flux2 = two_group_flux_mu[1]; log_printf(RESULT, "Ratio = %f", flux2 / flux1); log_printf(RESULT, ""); /* Print to the console the two group macroscopic cross-sections */ log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\t\tTwo Group Macroscopic Cross-Sections (cm^-1)"); log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, ""); float xs1, xs2; log_printf(RESULT, "\t\t\t[%1.1f eV - %1.3f eV]\t[%1.3f eV - %1.1e eV]", two_group_flux->getBinner(0)->getBinEdges()[0], two_group_flux->getBinner(0)->getBinEdges()[1], two_group_flux->getBinner(0)->getBinEdges()[1], two_group_flux->getBinner(0)->getBinEdges()[2]); /* H1 capture */ xs1 = H1_capture_rate_2G->getBatchMu()[0] / flux1; xs2 = H1_capture_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "H1 Capture: \t\t%f\t\t%f", xs1, xs2); /* H1 elastic */ xs1 = H1_elastic_rate_2G->getBatchMu()[0] / flux1; xs2 = H1_elastic_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "H1 Elastic: \t\t%f\t\t%f", xs1, xs2); /* O16 elastic */ xs1 = O16_elastic_rate_2G->getBatchMu()[0] / flux1; xs2 = O16_elastic_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "O16 Elastic: \t\t%f\t\t%f", xs1, xs2); /* ZR90 elastic */ xs1 = ZR90_elastic_rate_2G->getBatchMu()[0] / flux1; xs2 = ZR90_elastic_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "ZR90 Elastic: \t\t%f\t\t%f", xs1, xs2); /* U235 capture */ xs1 = U235_capture_rate_2G->getBatchMu()[0] / flux1; xs2 = U235_capture_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "U235 Capture: \t\t%f\t\t%f", xs1, xs2); /* U235 elastic */ xs1 = U235_elastic_rate_2G->getBatchMu()[0] / flux1; xs2 = U235_elastic_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "U235 Elastic: \t\t%f\t\t%f", xs1, xs2); /* U235 fission */ xs1 = U235_fission_rate_2G->getBatchMu()[0] / flux1; xs2 = U235_fission_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "U235 Fission: \t\t%f\t\t%f", xs1, xs2); /* U238 capture */ xs1 = U238_capture_rate_2G->getBatchMu()[0] / flux1; xs2 = U238_capture_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "U238 Capture: \t\t%f\t\t%f", xs1, xs2); /* U238 elastic */ xs1 = U238_elastic_rate_2G->getBatchMu()[0] / flux1; xs2 = U238_elastic_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "U238 Elastic: \t\t%f\t\t%f", xs1, xs2); /* U238 fission */ xs1 = U238_fission_rate_2G->getBatchMu()[0] / flux1; xs2 = U238_fission_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "U238 Fission: \t\t%f\t\t%f", xs1, xs2); log_printf(RESULT, ""); /* Print to the console the two group macroscopic cross-sections */ log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\tTwo Group Cell-Averaged Macroscopic " "Cross-Sections (cm^-1)"); log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, ""); log_printf(RESULT, "\t\t\t[%1.1f eV - %1.3f eV]\t[%1.3f eV - %1.1e eV]", two_group_flux->getBinner(0)->getBinEdges()[0], two_group_flux->getBinner(0)->getBinEdges()[1], two_group_flux->getBinner(0)->getBinEdges()[1], two_group_flux->getBinner(0)->getBinEdges()[2]); /* Flux */ log_printf(RESULT, "Flux: \t\t\t%f\t\t%f", flux1, flux2); /* Capture */ xs1 = capture_2G->getBatchMu()[0] / flux1; xs2 = capture_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "Capture: \t\t\t%f\t\t%f", xs1, xs2); /* Fission */ xs1 = fission_2G->getBatchMu()[0] / flux1; xs2 = fission_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "Fission: \t\t\t%f\t\t%f", xs1, xs2); /* Absorption */ xs1 = absorb_2G->getBatchMu()[0] / flux1; xs2 = absorb_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "Absorb: \t\t\t%f\t\t%f", xs1, xs2); /* Elastic */ xs1 = elastic_2G->getBatchMu()[0] / flux1; xs2 = elastic_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "Elastic: \t\t\t%f\t\t%f", xs1, xs2); /* Total */ xs1 = total_2G->getBatchMu()[0] / flux1; xs2 = total_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "Total: \t\t\t%f\t\t%f", xs1, xs2); log_printf(RESULT, ""); /* Print to the console the two group macroscopic cross-sections */ log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\t\t\tTwo Group Diffusion Coefficients"); log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, ""); log_printf(RESULT, "\t\t\t[%1.1f eV - %1.3f eV]\t[%1.3f eV - %1.1e eV]", two_group_flux->getBinner(0)->getBinEdges()[0], two_group_flux->getBinner(0)->getBinEdges()[1], two_group_flux->getBinner(0)->getBinEdges()[1], two_group_flux->getBinner(0)->getBinEdges()[2]); float sigma_t1, sigma_t2; float sigma_tr1, sigma_tr2; float D1, D2; sigma_t1 = coll_rate_2G->getBatchMu()[0] / flux1; sigma_t2 = coll_rate_2G->getBatchMu()[1] / flux2; D1 = 1.0 / (3.0 * sigma_t1); D2 = 1.0 / (3.0 * sigma_t2); log_printf(RESULT, "1/(3*sigma_t):\t\t%f\t\t%f", D1, D2); sigma_tr1 = transport_rate_2G->getBatchMu()[0] / flux1; sigma_tr2 = transport_rate_2G->getBatchMu()[1] / flux2; D1 = 1.0 / (3.0 * sigma_tr1); D2 = 1.0 / (3.0 * sigma_tr2); log_printf(RESULT, "1/(3*sigma_tr):\t\t%f\t\t%f", D1, D2); D1 = diffusion_rate_2G->getBatchMu()[0] / flux1; D2 = diffusion_rate_2G->getBatchMu()[1] / flux2; log_printf(RESULT, "Diff coeff:\t\t%f\t\t%f", D1, D2); log_printf(RESULT, ""); /* Plot the total neutron flux */ handle = gnuplot_init(); gnuplot_set_xlabel(handle, (char*)"Energy (eV)"); gnuplot_set_ylabel(handle, (char*)"flux"); gnuplot_set_xrange(handle, 0.005, 1E7); gnuplot_cmd(handle, (char*)"set logscale xy"); gnuplot_cmd(handle, (char*)"set title \"Normalized Flux\""); gnuplot_setstyle(handle, (char*)"lines"); gnuplot_plot_xy(handle, total_flux->getBinner(0)->getBinCenters(), total_flux->getBatchMu(), num_bins, (char*)"Total Flux"); gnuplot_plot_xy(handle, fuel_flux->getBinner(0)->getBinCenters(), fuel_flux->getBatchMu(), num_bins, (char*)"Fuel Flux"); gnuplot_saveplot(handle, (char*)"flux"); gnuplot_plot_xy(handle, moderator_flux->getBinner(0)->getBinCenters(), moderator_flux->getBatchMu(), num_bins, (char*)"Moderator Flux"); gnuplot_close(handle); /* Free all allocated memory */ delete [] pellet; delete [] coolant; delete [] fissioners; delete [] moderator; delete [] fuel; delete total_flux; delete fuel_flux; delete moderator_flux; delete tot_fiss_rate; delete tot_abs_rate; delete fuel_flux_ratio; delete moderator_flux_ratio; delete H1_capture_rate_2G; delete H1_elastic_rate_2G; delete O16_elastic_rate_2G; delete U235_capture_rate_2G; delete U235_elastic_rate_2G; delete U235_fission_rate_2G; delete U238_capture_rate_2G; delete U238_elastic_rate_2G; delete U238_fission_rate_2G; delete ZR90_elastic_rate_2G; delete two_group_flux; delete coll_rate_2G; delete transport_rate_2G; delete diffusion_rate_2G; delete H1; delete O16; delete ZR90; delete U235; delete U238; log_printf(RESULT, "*******************************************************" "*************************"); log_printf(RESULT, "\t\t\t\tTiming Results"); log_printf(RESULT, "*******************************************************" "*************************"); timer.printSplits(); }
int main(int argc, char **argv) { ros::init(argc, argv, "wander"); ros::NodeHandle node; VFH vfh; ros::Subscriber laser = node.subscribe("base_scan/scan", 100, &VFH::laser_cb, &vfh); ros::Publisher way_point = node.advertise<visualization_msgs::MarkerArray>("cmd_pnt", 1); ros::Publisher dir = node.advertise<geometry_msgs::Twist>("cmd_vel", 10); ros::Rate rate(20); dynamic_reconfigure::Server<wanderer::wanderConfig> server; dynamic_reconfigure::Server<wanderer::wanderConfig>::CallbackType update_fields; update_fields = boost::bind(&VFH::update_cb, &vfh, _1, _2); server.setCallback(update_fields); ros::Subscriber ekf_sub; ros::Subscriber odometry_sub; bool real_flag = 1; node.getParamCached("/wander/real_flag", real_flag); //vfh.hdl = gnuplot_init(); if (real_flag) { ekf_sub = node.subscribe("robot_pose_ekf/odom", 100, &VFH::ekf_cb, &vfh); } else { odometry_sub = node.subscribe("odom", 100, &VFH::odometry_cb, &vfh); } tf::StampedTransform rel_frame; tf::TransformListener listen; tf::Quaternion rotation; //Waits for tf from laser scan try { ros::Time now = ros::Time::now(); listen.waitForTransform(vfh.sensor_frame_id, "/base_link", now, ros::Duration(5.0)); listen.lookupTransform(vfh.sensor_frame_id, "/base_link", ros::Time(0), rel_frame); rotation = rel_frame.getRotation(); vfh.trans_angle = rotation.getAngle(); } catch (tf::TransformException ex) { ROS_ERROR("%s",ex.what()); } while (ros::ok()) { geometry_msgs::Twist heading; heading.linear.x = vfh.linear_vel; heading.angular.z = vfh.angular_vel; dir.publish(heading); way_point.publish(vfh.m_array); vfh.m_array.markers.clear(); //vfh.previous = vfh.current; rate.sleep(); ros::spinOnce(); } gnuplot_close(vfh.hdl); return 0; }
int main(int argc, char *argv[]) { FILE *inputfiles,*posting_file; int i=0; char *fileinput,*stemming_file,*posting_filename; if(argc < 2) { printf("\nIncorrect Usage. ./keywordengine <filelist.txt>\n"); return 0; } if((inputfiles=fopen(argv[1],"r+"))==NULL) { printf("\nCould not open %s. Exiting\n",argv[1]); exit(0); } if((posting_file=fopen("../output/posting_list_file_input.txt","w"))==NULL) { printf("\nFatal Error! Could not open/create posting_list_file_input.txt. Check output directory.\nErrorcode : %d\n",errno); exit(0); } int after_stemming=0; int before_stemming=0; double ratio=0.0; double array[20]; for(i=0; i<20; i++) { array[i]=0; } while(!feof(inputfiles)) { fileinput=(char *)malloc(sizeof(char)*FILENAME); fscanf(inputfiles,"%s\n",fileinput); stemming_file=(char *)malloc(sizeof(char)*(strlen(fileinput)+8)); strcpy(stemming_file,"output_"); strcat(stemming_file,fileinput); posting_filename=(char *)malloc(sizeof(char)*(strlen(stemming_file)+6)); strcpy(posting_filename,"stem_"); strcat(posting_filename,stemming_file); fprintf(posting_file,"%s\n",posting_filename); /* Tokenise and remove stopwords */ getwords(fileinput); /* Add to postings list */ initialize(); before_stemming=add_document_to_postingslist(stemming_file); /* Apply Porter's Stemmer */ stemmer(stemming_file); /* Add to postings list */ initialize(); after_stemming=add_document_to_postingslist(posting_filename); ratio=(double)after_stemming/before_stemming; //printf("\nbefore=%d and after=%d Ratio= %lf\n",before_stemming,after_stemming,ratio); if(0 <= ratio && 0.05 > ratio ) array[0]++; else if(0.75 <= ratio && 0.765 > ratio ) array[1]++; else if(0.765 <= ratio && 0.780 > ratio ) array[2]++; else if(0.780 <= ratio && 0.795 > ratio ) array[3]++; else if(0.795 <= ratio && 0.810 > ratio ) array[4]++; else if(0.810 <= ratio && 0.825 > ratio ) array[5]++; else if(0.825 <= ratio && 0.840 > ratio ) array[6]++; else if(0.840 <= ratio && 0.855 > ratio ) array[7]++; else if(0.855 <= ratio && 0.870 > ratio ) array[8]++; else if(0.870 <= ratio && 0.885 > ratio ) array[9]++; else if(0.885 <= ratio && 0.9 > ratio ) array[10]++; else if(0.9 <= ratio && 0.915 > ratio ) array[11]++; else if(0.915 <= ratio && 0.930 > ratio ) array[12]++; else if(0.930 <= ratio && 0.945 > ratio ) array[13]++; else if(0.945 <= ratio && 0.960 > ratio ) array[14]++; else if(0.960 <= ratio && 0.975 > ratio ) array[15]++; else if(0.975 <= ratio && 0.990 > ratio ) array[16]++; else if(0.990 <= ratio && 1.05 > ratio ) array[17]++; else if(1.05 <= ratio && 1.20 > ratio ) array[18]++; else if(1.20 <= ratio && 1.35 >= ratio ) array[19]++; i++; free(fileinput); fileinput=NULL; } fclose(posting_file); fclose(inputfiles); gnuplot_ctrl *h1; h1 = gnuplot_init() ; gnuplot_setstyle(h1, "lines"); gnuplot_set_xlabel(h1, "Compression"); gnuplot_set_ylabel(h1, "Frequency"); gnuplot_plot_x(h1, array ,20, "Ratio Graph") ; getchar(); /*Closing the files*/ gnuplot_close(h1); return 0; }
void destroy_plot() { gnuplot_close(plot_handle); }
int main(int argc, char **argv) { gnuplot_ctrl *gam; char kcode; int exit_flag = 1; gam = gnuplot_init(); gnuplot_setstyle(gam, "lines"); plot_bezier(gam); // gnuplot_plot_slope(gam, 2.0, 0.0, "y=2x"); while(1){ switch(getkey()){ case 'x': exit_flag = 0; break; case 'a': gnuplot_resetplot(gam); gnuplot_plot_equation(gam, "log(x)", "logarithm") ; break; case '=': gnuplot_resetplot(gam); bez_adj(gam, target, COARSE, PLUS); plot_bezier(gam); break; case '-': gnuplot_resetplot(gam); bez_adj(gam, target, COARSE, MINUS); plot_bezier(gam); break; case '+': gnuplot_resetplot(gam); bez_adj(gam, target, FINE, PLUS); plot_bezier(gam); break; case '_': gnuplot_resetplot(gam); bez_adj(gam, target, FINE, MINUS); plot_bezier(gam); break; case '1': target = YONE; printf("\nset YONE as adjust target: %f\n", yone); break; case '2': target = YTWO; printf("\nset YTWO as adjust target: %f\n", ytwo); break; case '3': target = XONE; printf("\nset XONE as adjust target: %f\n", xone); break; case '4': target = XTWO; printf("\nset XTWO as adjust target: %f\n", xtwo); break; default: break; } if (!exit_flag) break; usleep(500*1000); } print_curve(); gnuplot_close(gam); return 0; }
int main(int arg, char *argv[]) { //socket variable int sock; struct sockaddr_in sin; char buff[BuffLength]={0}; const char *IP="192.168.128.3"; //gnuplot variable gnuplot_ctrl * h; //handler of gnuplot session printf("gnuctrl done\n"); int i, j, line; int **z = (int **)malloc(Nline*sizeof(int *)); for (i=0 ; i<Nline ; i++) { z[i]=(int *)malloc((BuffLength-1)*sizeof(int)); } printf("z init finish\n"); //Create socket sock=socket(AF_INET, SOCK_STREAM, 0); if (sock==-1) { perror("socket()"); exit(errno); } sin.sin_addr.s_addr=inet_addr(IP); sin.sin_family=AF_INET; sin.sin_port=htons(Port); printf("define socket\n"); if (connect(sock, (struct sockaddr *) &sin, sizeof(sin))==-1) { perror("connect()"); exit(errno); } printf("Connected\n"); //gnuplot object h=gnuplot_init(); gnuplot_cmd(h,"set pm3d map"); gnuplot_cmd(h,"set palette gray"); int k=0, l=1;; while(l) { for (i=0 ; i<Nline ; i++) { if(recv(sock, buff, BuffLength, MSG_WAITALL)==0) { printf("Server closed\n"); i=Nline+1; l=0; break; } if (i<Nline+2) { line=(int)(buff[0])-1; printf("line number %d\n",line); for (j=0 ; j<BuffLength-1 ; j++) { z[line][j]=(int)(buff[j+1]); } } } printf("image number %d\n",k); k++; gnuplot_matrix(h, z, BuffLength-1, Nline); } close(sock); gnuplot_close(h); free(z); return 0; }
int main(int argc, char *argv[]) { gnuplot_ctrl * h1, * h2, * h3, * h4 ; double x[NPOINTS] ; double y[NPOINTS] ; int i ; /* * Initialize the gnuplot handle */ printf("*** example of gnuplot control through C ***\n") ; h1 = gnuplot_init() ; /* * Slopes */ gnuplot_setstyle(h1, "lines") ; printf("*** plotting slopes\n") ; printf("y = x\n") ; gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope") ; sleep(SLEEP_LGTH) ; printf("y = 2*x\n") ; gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x") ; sleep(SLEEP_LGTH) ; printf("y = -x\n") ; gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x") ; sleep(SLEEP_LGTH) ; /* * Equations */ gnuplot_resetplot(h1) ; printf("\n\n") ; printf("*** various equations\n") ; printf("y = sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("y = log(x)\n") ; gnuplot_plot_equation(h1, "log(x)", "logarithm") ; sleep(SLEEP_LGTH) ; printf("y = sin(x)*cos(2*x)\n") ; gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product") ; sleep(SLEEP_LGTH) ; /* * Styles */ gnuplot_resetplot(h1) ; printf("\n\n") ; printf("*** showing styles\n") ; printf("sine in points\n") ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("sine in impulses\n") ; gnuplot_setstyle(h1, "impulses") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("sine in steps\n") ; gnuplot_setstyle(h1, "steps") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; /* * User defined 1d and 2d point sets */ gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "impulses") ; printf("\n\n") ; printf("*** user-defined lists of doubles\n") ; for (i=0 ; i<NPOINTS ; i++) { x[i] = (double)i*i ; } gnuplot_plot_x(h1, x, NPOINTS, "user-defined doubles") ; sleep(SLEEP_LGTH) ; printf("*** user-defined lists of points\n"); for (i=0 ; i<NPOINTS ; i++) { x[i] = (double)i ; y[i] = (double)i * (double)i ; } gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_xy(h1, x, y, NPOINTS, "user-defined points") ; sleep(SLEEP_LGTH) ; /* * Multiple output screens */ printf("\n\n") ; printf("*** multiple output windows\n") ; gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "lines") ; h2 = gnuplot_init() ; gnuplot_setstyle(h2, "lines") ; h3 = gnuplot_init() ; gnuplot_setstyle(h3, "lines") ; h4 = gnuplot_init() ; gnuplot_setstyle(h4, "lines") ; printf("window 1: sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sin(x)") ; sleep(SLEEP_LGTH) ; printf("window 2: x*sin(x)\n") ; gnuplot_plot_equation(h2, "x*sin(x)", "x*sin(x)") ; sleep(SLEEP_LGTH) ; printf("window 3: log(x)/x\n") ; gnuplot_plot_equation(h3, "log(x)/x", "log(x)/x"); sleep(SLEEP_LGTH) ; printf("window 4: sin(x)/x\n") ; gnuplot_plot_equation(h4, "sin(x)/x", "sin(x)/x") ; sleep(SLEEP_LGTH) ; /* * close gnuplot handles */ printf("\n\n") ; printf("*** end of gnuplot example\n") ; gnuplot_close(h1) ; gnuplot_close(h2) ; gnuplot_close(h3) ; gnuplot_close(h4) ; return 0 ; }
void din_close() {/* The function closes everything that needs to be closed */ int i,j; free(init_name); free(data_name); free(conf_name); free(input_name); free(out_name); for(j=0;j<MAX_N_HIST_ENT;j++){ for(i=0;i<MAX_N_ARG;i++) free(buf_hist[j][i]); free(buf_hist[j]); } free(buf_hist); for(i=0;i<MAX_N_ARG;i++) free(cmd[i]); free(cmd); /* The following is deprecated */ for(i=0;i<BUFFER;i++) free(xs[i]); free(xs); free(ts); /* *************************** */ //free(ampl); //free(max_x); //free(min_x); free(x_cross); free(x); free(y); free(xin); free(xin_par); free(yin); free(f); free(ksi); free(pr); free(a); for(i=0;i<DIM;i++) free(var_name[i]); free(var_name); for(i=0;i<AUXNUM;i++) free(aux_name[i]); free(aux_name); gnuplot_close(plot_handle); if(!perDet) free(perDet); if(!perStoch) free(perStoch); /* Free Random */ random_free(); /*Free Lyapunov*/ lyap_free(); /* Free periods histogram */ thist_free(); /* Deleting unnecessary files after finishing the program */ printf("Deleting unnecessary files...\n"); if((fopen("slopeAmpl.dat","r")) != NULL){ if(remove("slopeAmpl.dat") != 0) printf("Error deleting file slopeAmpl.dat\n"); } if((fopen("slopeAmpl1.dat","r")) != NULL){ if(remove("slopeAmpl1.dat") != 0) printf("Error deleting file slopeAmpl.dat\n"); } if((fopen("hist.dat","r")) != NULL){ if(remove("hist.dat") != 0) printf("Error deleting file hist.dat\n"); } if((fopen("acorr.dat","r")) != NULL){ if(remove("acorr.dat") != 0) printf("Error deleting file acorr.dat\n"); } if((fopen("tmap.dat","r")) != NULL){ if(remove("tmap.dat") != 0) printf("Error deleting file tmap.dat\n"); } if((fopen("rand.throw","r")) != NULL){ if(remove("rand.throw") != 0) printf("Error deleting file rand.throw\n"); } printf("Done.\n"); }
int main(void) { int i,j,k,m,seed,idx,fcluster[S+1+1],bond[N+1][NB+1],cluster_size[S+1+1][B+1]; double X[S+1+1],temperature[S+1]; char filename[20]; gnuplot_ctrl*a; gnuplot_ctrl*b; FILE *fp1=fopen("Iris01.dat","r"),//Αρχικό αρχείο δεδομένων-Συμπληρώνεται και στη συνάρτηση output, εάν θέλουμε να κάνουμε διστδιάστατες προβολές *fp2=fopen("data_iris.dat","w"),//Αρχείο που δημιουργείται, με τα παραγόμενα δεδομένα (χ,Τ,cluster size κλπ) *fp3=fopen("cluster_iris","w"),//αρχείο με πληροφορίες για τα clusters *fp4=fopen("G.dat","w"),//αρχείο με πληροφορίες για τη συνάρτηση G *fp5=fopen("nbors_iris.dat","r");//αρχείο γειτόνων, που παρήχθησαν από το πρόγραμμα nbors.c /*Parameters(Παράμετροι)*/ T0=EPS; //Starting Temperature(αρχική θερμοκρασία) Tmax=0.09; //Highest Temperature(τελική θερμοκρασία) Tinc=(Tmax-T0)/S; //Temperature Increment(βήμα θερμοκρασίας) th=0.5; //Threshold Value for condition [G(i,j)>th] (κατώφλι για τη συνθήκη [G(i,j)>th]) /*Read data from file(διάβασμα αρχείου)*/ /* ============= ============= */ //Initialise data(Αρχικοποίηση δεδομένων) for(i=0;i<=N;i++)for(j=0;j<=DM;j++)data[i][j]=0.0;T=0.0; for(i=0;i<=N;i++)for(j=0;j<=NB;j++){dist[i][j]=0.0;nbors[i][j]=0;} for(i=0;i<=N;i++)for(j=0;j<=NB;j++){J[i][j]=0.0;G[i][j]=0.0;} for(i=0;i<=S+1;i++){X[i]=0.0;fcluster[i]=0;} for(i=0;i<=S+1;i++)for(j=0;j<=B;j++)cluster_size[i][j]=0; for(i=0;i<=N;i++)for(j=0;j<=NB;j++)bond[i][j]=0; for(i=0;i<=N;i++)G_max[i]=0.0;for(i=0;i<=S;i++)temperature[i]=0; for(i=0;i<=N;i++)cluster[i]=0; for(i=0;i<S+1;i++)a1[i]=0.0; //Open file(Άνοιγμα αρχείου) //File 1--------------------------------------------- if(fp1==NULL) { printf("Unable to open file for reading\n"); exit(1); } rewind(fp1);//rewinding file(τοποθέτηση δείκτη αρχείου στην αρχή) i=1;j=1; while(fscanf(fp1,"%lf",&data[i][j])!=EOF) { j++; if(j==DM+1) { i++; j=1; }//Read data from file(Ανάγνωση δεδομένων από το αρχείο) } fclose(fp1); //File 1--------------------------------------------- printf("\nReading Data Complete\n"); //open file (άνοιγμα αρχείου γειτόνων) //File 5--------------------------------------------- if(fp5==NULL) { printf("\nUnable to open file for reading\n"); exit(1); } i=1;j=1; while (fscanf(fp5,"%d ",&nbors[i][j])!=EOF) { j++; if(j==NB+1) { i++; j=1; } } fclose(fp5); printf("Reading Neighbor List File Complete\n"); //File 5--------------------------------------------- /*Calculate Interaction Matrix*/ /*============================*/ /*-----CALL interaction_matrix function to calculate the interactions between the points (Καλούμε τη συνάρτηση interaction_matrix για τον υπολογισμό των αλληλεπιδράσεων μεταξύ των σημείων )------*/ interaction_matrix(nbors,J,dist,data); /*------ */ printf("Calculate Interaction matrix complete\n"); //Create random numbers(Δημιουργούμε τυχαίους αριθμούς) srand48((unsigned int)time(NULL)); printf("seed =%d\n",(unsigned int) time(NULL)); seed=1083354197; srand48(seed); /*--------------------------------------------------------*/ for(k=1;k<=S+1;k++)//Temperature steps (Βήματα θερμοκρασίας) { /* Clustering Algorithm(Αλγόριθμος Ομαδοποίησης) */ T=T0+Tinc*(k-1); X[k]=SW(q,T,nbors,bond,cluster,J,G);//χ[T] Calculation printf("T= %f X[%d] = %f\n",T,k,X[k]); temperature[k]=T; /* Final Data Clusters */ fcluster[k]=final_cluster(k,q,th,nbors,bond,cluster,cluster_data,G); printf("# of clusters[%d]=%d\n",k,fcluster[k]); if(plot_pixelmap==1) { sprintf(filename,"%f",temperature[k]); strncat(filename,".ppm",4); output(lattice,filename); } /* Find Biggest Clusters */ find_ClusterSize(k,cluster,fcluster,cluster_size); } /*--------------------------------------------------------*/ /*Write result to file (εγγραφή αποτελεσμάτων σε αρχείο)*/ //File 2--------------------------------------------- X[2]=0.0309; for(i=1;i<=S+1;i++) { fprintf(fp2,"%f %f %d ",T0+Tinc*(i-1),X[i],fcluster[i]); for(j=1;j<=B;j++) { fprintf(fp2," %d ",cluster_size[i][j]); } fprintf(fp2,"\n"); } fclose(fp2); //File 2--------------------------------------------- //File 3--------------------------------------------- for(i=1;i<=N;i++) { for(j=1;j<=S+1;j++) { fprintf(fp3,"%d ",cluster_data[i][j]); } fprintf(fp3,"\n"); } fclose(fp3); //File 3--------------------------------------------- //File 4--------------------------------------------- for(i=1;i<=N;i++) { for(j=1;j<=NB;j++) { fprintf(fp4,"%f ",G[i][j]); } fprintf(fp4,"\n"); } fclose(fp4); //File 4--------------------------------------------- /*Gnuplot Graphics session - Συνεδρία γραφικών Gnuplot*/ a=gnuplot_init(); gnuplot_setstyle(a,"lines"); gnuplot_set_xlabel(a,"Boltzmann constant*temperature"); gnuplot_set_ylabel(a,"Susceptibility density"); gnuplot_cmd(a,"set terminal svg"); gnuplot_cmd(a,"set output \"Susceptibility.svg\""); for(k=0;k<=S;k++) {//Correction for Gnuplot, nothing important temperature[k]=temperature[k+1]; X[k]=X[k+1]; } gnuplot_plot_xy(a,temperature,X,(S+1),"X");//plotting X for all temperatures. (σχεδιάζουμε την χ για όλες τις θερμοκρασίες.) gnuplot_close(a); //---------------------------------------------------------// b=gnuplot_init(); gnuplot_setstyle(b,"lines"); gnuplot_set_xlabel(b,"Boltzmann constant*temperature"); gnuplot_set_ylabel(b,"Cluster Size"); gnuplot_cmd(b,"set terminal svg"); gnuplot_cmd(b,"set output \"Clustersize.svg\""); //gnuplot_cmd(b,"set xrange [0:0.08]");//optional. sets the x-axis range. for (i=1;i<=B;i++)//For all the biggest clusters(για όλα τα μεγαλύτερα clusters) { for (j=1;j<=(S+1);j++)//For all temperatures (για όλες τις θερμοκρασίες) { a1[j]=(double)cluster_size[j][i];//keep current cluster array depending on T, to plot(κρατάμε τον τρέχοντα πίνακα για ένα συγκεκριμένο cluster για όλες τις Τ) } gnuplot_plot_xy(b,temperature,a1,(S+1),"cluster");//plotting current cluster curve (σχεδιάζουμε την καμπύλη του τρέχοντος cluster) }//now we have all cluster curves in a single diagram.(έχουμε όλες τις καμπύλες cluster σε μία γραφική παράσταση) gnuplot_close(b); //---------------------------------------------------------// return 0; }
int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for ANIM. Modified: 24 June 2011 */ { double d[NPOINTS]; dpoint dp[NPOINTS]; gnuplot_ctrl *h1; gnuplot_ctrl *h2; gnuplot_ctrl *h3; gnuplot_ctrl *h4; int i; int j; double x[NPOINTS]; double y[NPOINTS]; printf ( "\n" ); printf ( "EXAMPLE:\n" ); printf ( " C++ version.\n" ); printf ( " Demonstrate how a running C++ program can produce plots\n" ); printf ( " through GNUPLOT, by invoking the GNUPLOT_I interface library.\n" ); /* Initialize the gnuplot handle */ h1 = gnuplot_init(); if ( h1 == NULL ) { printf ( "\n" ); printf ( "EXAMPLE - Fatal error!\n" ); printf ( " GNUPLOT is not available in your path.\n" ); exit ( 1 ); } /* Slopes */ gnuplot_setstyle(h1, "lines"); slow_print("*** plotting slopes\n"); slow_print("y = x\n"); gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope"); sleep(SLEEP_LGTH); slow_print("y = 2*x\n"); gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x"); sleep(SLEEP_LGTH); slow_print("y = -x\n"); gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x"); sleep(SLEEP_LGTH); /* Equations */ gnuplot_resetplot(h1); printf("\n\n"); slow_print("*** various equations\n"); slow_print("y = sin(x)\n"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); slow_print("y = log(x)\n"); gnuplot_plot_equation(h1, "log(x)", "logarithm"); sleep(SLEEP_LGTH); slow_print("y = sin(x)*cos(2*x)\n"); gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product"); sleep(SLEEP_LGTH); /* Styles */ gnuplot_resetplot(h1); printf("\n\n"); slow_print("*** Showing plot style options:\n"); slow_print("sine(x) in points\n"); gnuplot_setstyle(h1, "points"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); slow_print("sine(x) in impulses\n"); gnuplot_setstyle(h1, "impulses"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); slow_print("sine(x) in steps\n"); gnuplot_setstyle(h1, "steps"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); /* User defined 1d and 2d point sets */ gnuplot_resetplot(h1); gnuplot_setstyle(h1, "impulses"); printf("\n\n"); slow_print("*** user defined lists of points\n"); slow_print("random doubles\n"); srand48 ( getpid ( ) ); for ( i = 0; i < NPOINTS; i++ ) { d[i] = drand48(); } gnuplot_plot1d_var1(h1, d, NPOINTS, "random doubles"); sleep(SLEEP_LGTH); gnuplot_resetplot(h1); gnuplot_setstyle(h1, "points"); slow_print("random points\n"); for ( i = 0; i < NPOINTS; i++ ) { dp[i].x = drand48(); dp[i].y = drand48(); } gnuplot_plot1d_var2(h1, dp, NPOINTS, "random points"); sleep(SLEEP_LGTH); gnuplot_resetplot(h1); gnuplot_setstyle(h1, "points"); slow_print("cosine points with var2v\n"); for ( j = 0; j < NPOINTS; j++ ) { x[j] = ( double ) j / 10.0; y[j] = cos ( x[j] ); } gnuplot_plot1d_var2v(h1, x, y, NPOINTS, "cosine points"); sleep(SLEEP_LGTH); /* Multiple output screens */ printf("\n\n"); slow_print("*** multiple output windows\n"); gnuplot_resetplot(h1); gnuplot_setstyle(h1, "lines"); h2 = gnuplot_init(); gnuplot_setstyle(h2, "lines"); h3 = gnuplot_init(); gnuplot_setstyle(h3, "lines"); h4 = gnuplot_init(); gnuplot_setstyle(h4, "lines"); slow_print("window 1: sin(x)\n"); gnuplot_plot_equation(h1, "sin(x)", "sin(x)"); sleep(SLEEP_LGTH); slow_print("window 2: cos(x)\n"); gnuplot_plot_equation(h2, "cos(x)", "cos(x)"); sleep(SLEEP_LGTH); slow_print("window 3: asin(x)\n"); gnuplot_plot_equation(h3, "asin(x)", "arcsin(x)"); sleep(SLEEP_LGTH); slow_print("window 4: acos(x)\n"); gnuplot_plot_equation(h4, "acos(x)", "arccos(x)"); sleep(SLEEP_LGTH); /* Close gnuplot handles. */ printf ( "\n\n" ); slow_print ( "*** end of gnuplot example\n" ); gnuplot_close ( h1 ); gnuplot_close ( h2 ); gnuplot_close ( h3 ); gnuplot_close ( h4 ); /* Terminate. */ printf ( "\n" ); printf ( "EXAMPLE:\n" ); printf ( " Normal end of execution.\n" ); return 0; }
int main(int arg, char *argv[]) { //socket variable int sock; struct sockaddr_in sin; char buff[BuffLength]; const char *IP="192.168.128.3"; //gnuplot variable gnuplot_ctrl * h; //handler of gnuplot session int i, j, line; double *x = NULL; double *y = NULL; double **z = (double **)malloc(Nline*sizeof(double *)); for (i=0 ; i<Nline ; i++) { x=malloc((BuffLength-1)*sizeof(double)); y=malloc(Nline*sizeof(double)); z[i]=malloc((BuffLength-1)*sizeof(double)); } init_xy(x,y); //Create socket sock=socket(AF_INET, SOCK_STREAM, 0); if (sock==-1) { perror("socket()"); exit(errno); } sin.sin_addr.s_addr=inet_addr(IP); sin.sin_family=AF_INET; sin.sin_port=htons(Port); if (connect(sock, (struct sockaddr *) &sin, sizeof(sin))==-1) { perror("connect()"); exit(errno); } printf("Connected\n"); //gnuplot object h=gnuplot_init(); gnuplot_surf_gray(h, x, y, z, BuffLength-1, Nline, "test"); while(1) { if(recv(sock, buff, BuffLength, MSG_WAITALL)==0) { printf("Server closed\n"); break; } for (i=0 ; i<Nline ; i++) { line=(int)(buff[0]); for (j=0 ; j<BuffLength-1 ; j++) { z[line][j]=(double)(buff[j+1]); } } gnuplot_surf_gray(h, x, y, z, BuffLength-1, Nline,"test"); } writefile(x,y,z,Nline,BuffLength-1); close(sock); gnuplot_close(h); free(x); free(y); free(z); return 0; }