/**
 * @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;
}
void
PlotGraph::PlotAugmentingPath(BipartiteGraph& _bg, vector<EID>& _path){

    //get assignment size, assume the sizes of agents and tasks are identical
    size_t as_size = _bg.GetNumAgents();
    double plx[as_size];
    double ply[as_size];
/*
    //gnuplot_resetplot(g);
    gnuplot_cmd(g, (char*)"unset label");
    gnuplot_cmd(g, (char*)"set xrange [-0.25:1.25]");
    gnuplot_cmd(g, (char*)"set yrange [-0.25:%f]", as_size-1+.25);
    gnuplot_cmd(g, (char*)"set xtics 0");
    gnuplot_cmd(g, (char*)"set ytics 0");
    gnuplot_cmd(g, (char*)"set nokey");
*/
    //gnuplot_cmd(g, (char*)"set style line 2 lt 2 lc rgb \"blue\" lw 3");
    // Plot matching
    //cout<<endl<<"Set M: "<<endl;
    //DisplayData(_M);    
    bool alter = true;
    for (unsigned int i = 0; i < _path.size(); i++){
        plx[0] = _path[i].first;
        ply[0] = 0.0;
        plx[1] = _path[i].second;
        ply[1] = 1.0;

        //gnuplot_setstyle(g, (char*)"linespoints lc rgb \"#55DD99\" lw 3");
        if(alter)
          gnuplot_setstyle(g, (char*)"lines lc rgb \"#458B74\" lw 3");
        else
          gnuplot_setstyle(g, (char*)"lines lc rgb \"#7CCD7C\" lw 3");

        alter = !alter;
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
    }

#ifdef SAVE_PLOTS
    stringstream ss;
    ss << setw(3) << setfill('0') << Cnt++;
    string postfix = ss.str();

    string name="save/plot"+postfix+".jpeg";
    gnuplot_cmd(g, (char*)"set terminal jpeg");
    //gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
    gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
    printf("saved jpeg: \"%s\"\n", name.c_str());
#endif

    gnuplot_cmd(g, (char*)"replot");

   sleep(period);
}
Exemple #3
0
gnuplot_ctrl * gnuplot_init(void)
{
    gnuplot_ctrl *  handle ;
    int i;

#ifndef WIN32
    if (getenv("DISPLAY") == NULL) {
        fprintf(stderr, "cannot find DISPLAY variable: is it set?\n") ;
    }
#endif // #ifndef WIN32


    /*
     * Structure initialization:
     */
    handle = (gnuplot_ctrl*)malloc(sizeof(gnuplot_ctrl)) ;
    handle->nplots = 0 ;
    gnuplot_setstyle(handle, "points") ;
    handle->ntmp = 0 ;

    handle->gnucmd = popen("gnuplot", "w") ;
    if (handle->gnucmd == NULL) {
        fprintf(stderr, "error starting gnuplot, is gnuplot or gnuplot.exe in your path?\n") ;
        free(handle) ;
        return NULL ;
    }

    for (i=0;i<GP_MAX_TMP_FILES; i++)
    {
        handle->tmp_filename_tbl[i] = NULL;
    }
    return handle;
}
Exemple #4
0
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);
}
Exemple #5
0
gnuplot_ctrl * gnuplot_init ( void )
{
    gnuplot_ctrl *  handle ;

    if (check_X_display(1)) return NULL ;

	if (gnuplot_get_program_path("gnuplot")==NULL) {
	  fprintf(stderr, "cannot find gnuplot in your PATH");
	  return NULL ;
	}

    /* 
     * Structure initialization:
     */
    handle = malloc(sizeof(gnuplot_ctrl)) ;
    handle->nplots = 0 ;
    gnuplot_setstyle(handle, "points") ;
    handle->ntmp = 0 ;

    handle->gnucmd = popen("gnuplot", "w") ;
    if (handle->gnucmd == NULL) {
        fprintf(stderr, "error starting gnuplot\n") ;
        free(handle) ;
        return NULL ;
    }
    return handle;
}
Exemple #6
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;
}
Exemple #7
0
gnuplot_ctrl * gnuplot_init(void)
{
    gnuplot_ctrl *  handle ;

    if (getenv("DISPLAY") == NULL) {
        fprintf(stderr, "cannot find DISPLAY variable: is it set?\n") ;
    }
	if (gnuplot_get_program_path("gnuplot")==NULL) {
		fprintf(stderr, "cannot find gnuplot in your PATH");
		return NULL ;
	}

    /*
     * Structure initialization:
     */
    handle = (gnuplot_ctrl*)malloc(sizeof(gnuplot_ctrl)) ;
    handle->nplots = 0 ;
    gnuplot_setstyle(handle, "points") ;
    handle->ntmp = 0 ;

    handle->gnucmd = popen("gnuplot", "w") ;
    if (handle->gnucmd == NULL) {
        fprintf(stderr, "error starting gnuplot\n") ;
        free(handle) ;
        return NULL ;
    }
    return handle;
}
Exemple #8
0
int main(int arg, char *argv[])
{
	int Npoint, dec, line, Nline, sector;
	double x0, xf;

	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);

	int Nset=5;
	char settings[Nset];
	receive_TCP_client(&sock, settings, Nset);
	x0=(double)int_converter(settings[0]);
	xf=(double)int_converter(settings[1]);
	dec=int_converter(settings[2]);
	line=int_converter(settings[3]);
	Nline=line/2;
	sector=int_converter(settings[4]);
	Npoint=(int)(2.0*(xf-x0)*125.0/1.48/((double)dec));
	char *buff=(char *)malloc((Npoint+1)*sizeof(char));

	//gnuplot variable
	gnuplot_ctrl * h;
	double *y= (double *)malloc(Npoint*sizeof(double));
	int i,j;

	//gnuplot object
	h=gnuplot_init();
	gnuplot_setstyle(h,"lines");
	gnuplot_set_xlabel(h,"time (us)");
	gnuplot_set_ylabel(h,"signal");
	gnuplot_cmd(h,"set yrange [1:%d]",Ymax);
	gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);

	while(1)
	{
		if (receive_TCP_client(&sock, buff, Npoint+1)==1)
		{
			break;
		}	
			
		if ((int)(buff[0])==Nline)
		{
			for (i=1; i<Npoint+1 ; i++)
			{
				y[i-1]=(double)(buff[i]);
			}
			gnuplot_resetplot(h);
			gnuplot_plot_x(h, y, Npoint, "RP");
		}
	}

	usleep(30);
	close(sock);
	free(y);
	return 0;
}
Exemple #9
0
void plotter_init(){
    handle = gnuplot_init();
    gnuplot_setstyle(handle, "lines") ;
    gnuplot_cmd(handle, "set yrange [-1.0:1.0]");
    gnuplot_cmd(handle, "set xrange [0:2205]");
    gnuplot_cmd(handle, "set title 'Microphone Input'");
    gnuplot_cmd(handle, "set xlabel 'Sample'");
    gnuplot_cmd(handle, "set ylabel 'Amplitude'");
}
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 ;
}
Exemple #11
0
int plot_doubles(gnuplot_ctrl *h, double *xdata, double *ydata, int len, char *plot_name)
{
	if( h == NULL || ydata == NULL || xdata == NULL|| len <= 0  || plot_name == NULL){
		fprintf(stderr, "plot_data: dodgy arguments\n");
		return -1;
	}

	gnuplot_setstyle(h, "lines");
	gnuplot_resetplot(h);
	gnuplot_plot_xy(h, xdata, ydata, len, plot_name);

	return 0;
}
Exemple #12
0
gnuplot_ctrl * gnuplot_init(void)
{
    gnuplot_ctrl *  handle ;
#ifndef _WIN32
#ifndef __APPLE__
        if (getenv("DISPLAY") == NULL) {
            fprintf(stderr, "cannot find DISPLAY variable: is it set?\n") ;
        }
#endif
#endif
#ifndef _WIN32
    if (gnuplot_get_program_path("gnuplot")==NULL) {
        fprintf(stderr, "cannot find gnuplot in your PATH");
        return NULL ;
    }
#endif
    if (gnuplot_get_program_path(GNUPLOT_EXEC)==NULL) {
        fprintf(stderr, "cannot find gnuplot in your PATH");
        return NULL ;
    }

    /*
     * Structure initialization:
     */
    handle = (gnuplot_ctrl*)malloc(sizeof(gnuplot_ctrl)) ;
    handle->nplots = 0 ;
    gnuplot_setstyle(handle, "points") ;
    gnuplot_setaxes(handle, "x1y1") ;
    handle->ntmp = 0 ;
    handle->gnucmd = popen(GNUPLOT_EXEC " -geometry \"640x480+0+0\"", "w") ;
    if (handle->gnucmd == NULL) {
        fprintf(stderr, "error starting gnuplot\n") ;

        free(handle) ;
        handle = NULL;

        return NULL ;
    }
#ifdef _WIN32
    gnuplot_setterm(handle,"windows");
#elif __APPLE__
    // Try to determine whether we should use aqua or x11 as our default
    if (getenv("DISPLAY") == NULL || (getenv("USE_AQUA")!=NULL && strcmp(getenv("USE_AQUA"),"1")>=0))
        gnuplot_setterm(handle,"aqua");
    else
        gnuplot_setterm(handle,"x11");
#else
    gnuplot_setterm(handle,"x11");
#endif
    return handle;
}
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);
}
Exemple #14
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Plotter::setPlottingStyle(PlottingStyle style)
{
	const char* styleString = NULL;
	switch (style)
	{
	case LINES:
		styleString = "lines";
		break;

	case POINTS:
		styleString = "points";
		break;

	case LINESPOINTS:
		styleString = "linespoints";
		break;

	case IMPULSES:
		styleString = "impulses";
		break;

	case DOTS:
		styleString = "dots";
		break;

	case STEPS:
		styleString = "steps";
		break;

	default:
		break;
	}

	if (_plotter && styleString)
		gnuplot_setstyle(_plotter, styleString);
}
void 
PlotGraph::PlotBipartiteGraph(BipartiteGraph& _bg,
			      vector<VID>& _S, 
			      vector<VID>& _T,
			      vector<VID>& _N,
			      vector<EID>& _EG,
			      vector<EID>& _M, 
			      int target_task){

    //get assignment size, assume the sizes of agents and tasks are identical
    size_t as_size = _bg.GetNumAgents();
    double plx[as_size];
    double ply[as_size];

    //g=gnuplot_init();
    gnuplot_resetplot(g);
    gnuplot_cmd(g, (char*)"unset label");
    gnuplot_cmd(g, (char*)"set xrange [-0.25:%f]", as_size-1+.25);
    gnuplot_cmd(g, (char*)"set yrange [-0.25:1.25]");
    gnuplot_cmd(g, (char*)"set xtics 0");
    gnuplot_cmd(g, (char*)"set ytics 0");
    gnuplot_cmd(g, (char*)"set nokey");

    // Plot matching
    //cout<<endl<<"Set M: "<<endl;
    //DisplayData(_M);    
    for (unsigned int i = 0; i < _M.size(); i++){
        plx[0] = _M[i].first;
        ply[0] = 0.0;
        plx[1] = _M[i].second;
        ply[1] = 1.0;

        gnuplot_setstyle(g, (char*)"lines lc rgb \"red\" lw 3");
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
    }

    // Plot admissible edges (EG)
    //cout<<"EG: "<<endl;
    //DisplayData(_EG);
    for(unsigned int i=0; i<_EG.size(); i++){
        plx[0] = _EG[i].first;
        ply[0] = 0.0;
        plx[1] = _EG[i].second;
        ply[1] = 1.0;

        gnuplot_setstyle(g, (char*)"lines lc rgb \"gray\"");
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
                
        plx[0] = (0.9*plx[0] + 0.1*plx[1]);
        ply[0] = 0.11;
        gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#FFFFFF\" pt 7");
        gnuplot_plot_xy(g, plx, ply, 1, NULL);

        //cout<<"EG "<<i<<": "<<_bg.GetMatrix(_EG[i])->GetWeight()<<endl;
        gnuplot_cmd(g, (char*)"set label \"%d\" at %f-0.04,0.1 front tc rgb \"#4682B4\" font \",8\"", int(_bg.GetMatrix(_EG[i])->GetWeight()), plx[0]);
    }


    // Plot membership of set S
    //cout<<"S: "<<endl;
    //DisplayData(_S);
    for(unsigned int i=0; i<_S.size(); i++){
        plx[0] = _S[i];
        ply[0] = 0.0;
        gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"green\" pt 7");
        gnuplot_plot_xy(g, plx, ply, 1, NULL);
    }

    // Plot membership of the set T
    //cout<<"T: "<<endl;
    //DisplayData(_T);
    for(unsigned int i=0; i<_T.size(); i++){
        plx[0] = _T[i];
        ply[0] = 1.0;
        gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"#00BFFF\" pt 7");
        gnuplot_plot_xy(g, plx, ply, 1, NULL);
    }

        if (target_task != -1) // not yet unioned, but the reversal point for the 
        {                         // alternating path
            plx[0] = target_task;
            ply[0] = 1.0;
            gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"grey\" pt 7");
            gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }


    // Plot nodes
    for(unsigned int i = 0; i < as_size; i++)
    {
        plx[i] = i;
        ply[i] = 0.0;
    }

    gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7");
    gnuplot_plot_xy(g, plx, ply, as_size, NULL);

    for(unsigned int i = 0; i < as_size; i++)
    {
        plx[i] = i;
        ply[i] = 1.0;
    }

    gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7");
    gnuplot_plot_xy(g, plx, ply, as_size, NULL);

    for (unsigned int i = 0; i < as_size; i++)
    {
        gnuplot_cmd(g, (char*)"set label \"x%d\" at %d-0.025,-0.08 tc rgb \"black\"", i, i);
        gnuplot_cmd(g, (char*)"set label \"y%d\" at %d-0.025,1.08 tc rgb \"black\"", i, i);
	//cout<<"Label "<<i<<": "<<_bg.GetAgent(i)->GetLabel()<<endl;
	//cout<<"Label "<<i<<": "<<_bg.GetTask(i)->GetLabel()<<endl;
        gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,-0.15 tc rgb \"#112244\"", int(_bg.GetAgent(i)->GetLabel()), i);
        gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,1.15 tc rgb \"#112244\"", int(_bg.GetTask(i)->GetLabel()), i);
    }

/*    //image setting
       set terminal png 
              {{no}transparent} {{no}interlace}
              {tiny | small | medium | large | giant}
              {font <face> {<pointsize>}}
              {size <x>,<y>} {{no}crop}
              {{no}enhanced}
              {<color0> <color1> <color2> ...}
*/

#ifdef SAVE_PLOTS
    stringstream ss;
    ss << setw(3) << setfill('0') << Cnt++;
    string postfix = ss.str();

    string name="save/plot"+postfix+".jpeg";
    gnuplot_cmd(g, (char*)"set terminal jpeg");
    //gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
    gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
    printf("saved jpeg: \"%s\"\n", name.c_str());
#endif

    gnuplot_cmd(g, (char*)"replot");

    sleep(period);
    //gnuplot_close(g);
}
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;
}
Exemple #17
0
int main(int arg, char *argv[])
{
	int Npoint;

	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);
	get_RP_settings(&sock);
	printf("r0=%f\n",r0);
        printf("rf=%f\n",rf);
        printf("dec=%i\n",dec);
        printf("Nline=%i\n",Nline);
        printf("sector=%f\n",sector);
	printf("mode_RP=%i\n",mode_RP);

	int l=0;

	Npoint=(int)(2.0*(rf-r0)*125.0/1.48/((double)dec));
        if (Npoint>16384) {Npoint=16384;}
	printf("Npoint = %i\n",Npoint);

	int powd, pad_len;
        if (power_two(Npoint,&powd)){powd++;}
        pad_len=int_pow(2,powd);
	init_table(pad_len);
	float fech=125000000.0/((float)dec);

	//gnuplot variable
	gnuplot_ctrl * h;
	double *y= (double *)malloc(Npoint*sizeof(double));
	int i;

	int Ymax=1.5;

	//gnuplot object
	h=gnuplot_init();
	gnuplot_setstyle(h,"lines");
	gnuplot_set_xlabel(h,"time (us)");
	gnuplot_set_ylabel(h,"signal");
	//gnuplot_cmd(h,"set yrange [0:%d]", 2*Ymax);
	gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);

	char name[30];

	if (mode_RP==0)
	{

		int powd, pad_len;
		if (power_two(Npoint,&powd)){powd++;}
        	pad_len=int_pow(2,powd);
		double *pad=NULL;
		pad=(double *)malloc(pad_len*sizeof(double));
		double *env=NULL;
		env=(double *)malloc(pad_len*sizeof(double));
	
		gnuplot_cmd(h,"set yrange [-0.01:1.5]");
		gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);
		int16_t *buff=(int16_t *)malloc((Npoint+1)*sizeof(int16_t));
		while(1)
		{
			if(receive_int16_TCP_client(&sock, buff, Npoint+1)==1){break;}
			for (i=1 ; i<Npoint+1 ; i++){y[i-1]=(double)(buff[i])/409.6;} //divide by 409.6 to have voltage value
			zero_padding(y, pad, Npoint, pad_len, 1);
			envelope(pad, env, pad_len, fech, fmin, fmax, 0);
			gnuplot_resetplot(h);
			//gnuplot_plot_x(h, y, Npoint, "Oscillo int16_t");
			gnuplot_plot_x(h, env, pad_len, "Oscillo int16_t");			
                        //sprintf(name, "int%i.txt", l);
                        //writefile(y, Npoint, name);
                        l++;

		}
		free(buff);
		free(pad);
		free(env);
	}

	else if (mode_RP==1)
	{
		char *buff=(char *)malloc((Npoint+1)*sizeof(char));
		while(1)
		{
			if(receive_TCP_client(&sock, buff, Npoint+1)==1){break;}
			for (i=1 ; i<Npoint+1 ; i++){y[i-1]=(double)(int_converter(buff[i]));} 
			gnuplot_resetplot(h);
			gnuplot_plot_x(h, y, Npoint, "Oscillo 256 gray");
			sprintf(name, "char%i.txt", l);
			//writefile(y, Npoint, name);
			l++;
		}
		free(buff);
	}

	else {printf("Problem of settings\n");}

	usleep(30);
	close(sock);
	free(y);

	return 0;
}
Exemple #18
0
void draw_graph(int new_member_of_T)
{
    double plx[N];
    double ply[N];
    int count = 0;

    if (!graph) return;

    reinit_graph(g);
    gnuplot_cmd(g, "unset label");
    gnuplot_cmd(g, "set xrange [-0.25:1.25]");
    gnuplot_cmd(g, "set yrange [-0.25:%f]", n-1+.25);
    gnuplot_cmd(g, "set xtics 0");
    gnuplot_cmd(g, "set ytics 0");
    gnuplot_cmd(g, "set nokey");

    // Plot matching
    for (int i = 0; i < n; i++)
    {
        if (xy[i] >= 0)
        {
            plx[0] = 0.0;
            ply[0] = n-i-1;
            plx[1] = 1.0;
            ply[1] = n-xy[i]-1;

            gnuplot_setstyle(g, "lines lc rgb \"#55DD99\" lw 3");
            gnuplot_plot_xy(g, plx, ply, 2, NULL);

        }

    }

    // Plot edges 
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (cost[i][j] == lx[i] + ly[j])
            {
                plx[0] = 0.0;
                ply[0] = n-i-1;
                plx[1] = 1.0;
                ply[1] = n-j-1;

                gnuplot_setstyle(g, "lines lc rgb \"gray\"");
                gnuplot_plot_xy(g, plx, ply, 2, NULL);

                
                plx[0] = 0.11;
                ply[0] = (0.9*ply[0] + 0.1*ply[1]);
                gnuplot_setstyle(g, "points pointsize 2 lc rgb \"#FFFFFF\" pt 7");
                gnuplot_plot_xy(g, plx, ply, 1, NULL);


                gnuplot_cmd(g, "set label \"%d\" at 0.1,%f front tc rgb \"magenta\"", cost[i][j], ply[0]);
            }
        }
    }

    // Plot membership of the S / T sets
    for (int i = 0; i < n; i++)
    {
        if (S[i])
        {
                plx[0] = 0.0;
                ply[0] = n-i-1;
                gnuplot_setstyle(g, "points pointsize 3 lc rgb \"#99AAFF\" pt 7");
                gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }

        if (T[i])
        {
                plx[0] = 1.0;
                ply[0] = n-i-1;
                gnuplot_setstyle(g, "points pointsize 3 lc rgb \"#FF99AA\" pt 7");
                gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }

        if (i == new_member_of_T) // not yet unioned, but the reversal point for the 
        {                         // laternating path
            plx[0] = 1.0;
            ply[0] = n-i-1;
            gnuplot_setstyle(g, "points pointsize 3 lc rgb \"#FF99FF\" pt 7");
            gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }

    }


    // Plot nodes
    count = 0;
    for (int i = 0; i < n; i++)
    {
        plx[count] = 0.0;
        ply[count] = i;
        count++;
    }

    for (int i = 0; i < n; i++)
    {
        plx[count] = 1.0;
        ply[count] = i;
        count++;
    }

    gnuplot_setstyle(g, "points pointsize 2 lc rgb \"#102063\" pt 7");
    gnuplot_plot_xy(g, plx, ply, count, NULL);

    for (int i = 0; i < n; i++)
    {
        gnuplot_cmd(g, "set label \"x%d\" at -0.075,%d tc rgb \"black\"", i, n-i-1);
        gnuplot_cmd(g, "set label \"y%d\" at  1.02,%d tc rgb \"black\"", i, n-i-1);

        gnuplot_cmd(g, "set label \"%d\" at -0.175,%d tc rgb \"#112244\"", lx[i], n-i-1);
        gnuplot_cmd(g, "set label \"%d\" at 1.12,%d tc rgb \"#112244\"", ly[i], n-i-1);
    }

    gnuplot_cmd(g, "replot");

}
Exemple #19
0
void draw_bfs_tree(int root, int addx, bool high_light_root)
{
    bool myS[N], myT[N];         //sets S and T in algorithm
    bool leaf[N];
    double edgex[2];
    double edgey[2];
    int i, j;
    int q[N], wr = 0, rd = 0;          //q - queue for bfs, wr,rd - write and read

    int level[N];

    memset(myS, false, sizeof(S));      
    memset(myT, false, sizeof(T));       
    memset(leaf, false, sizeof(leaf));       
    memset(level, -1, sizeof(level));       

    level[root] = 0;
    S[root] = true;

    q[wr++] = root;
    while (rd < wr)                                                 
    {
        i = q[rd++];         

        if ((root == i) && (high_light_root))
            gnuplot_cmd(h, "set label \"x%d\" at %f,%f front tc rgb \"red\"", i, (float)i+addx, (float)-level[i]);
        else
            gnuplot_cmd(h, "set label \"x%d\" at %f,%f front tc rgb \"black\"", i, (float)i+addx, (float)-level[i]);
        

        for (j = 0; j < n; j++)                                     
        {
                if (cost[i][j] == lx[i] + ly[j] &&  !myT[j])
                {
                    // plot edge between i and j
                    edgex[0] = i+addx;
                    edgey[0] = -level[i];
                    edgex[1] = j+addx;
                    edgey[1] = -(level[i]+0.5);

                    gnuplot_setstyle(h, "lines lc rgb \"#FF2222\" lw 2");
                    gnuplot_plot_xy(h, edgex, edgey, 2, NULL);

                    gnuplot_cmd(h, "set label \"y%d\" at %f,%f front tc rgb \"black\"", j, edgex[1], edgey[1]);

                    leaf[j] = (yx[j] == -1);
                    
                    myT[j] = true;

                    if (!leaf[j])
                    {
                        q[wr++] = yx[j];
                        myS[yx[j]] = true;
                        level[yx[j]] = level[i] + 1;

                        edgex[0] = yx[j]+addx;
                        edgey[0] = -level[yx[j]];
                        edgex[1] = j+addx;
                        edgey[1] = -(level[i]+0.5);

                        gnuplot_setstyle(h, "lines lc rgb \"#FFFF22\" lw 2");
                        gnuplot_plot_xy(h, edgex, edgey, 2, NULL);


                    }
                    else
                    {

                    }

                    
                }
        }
    }
    

}
Exemple #20
0
/**
 * Testsuite:
 * Generates random symbols and calls the module ....
 * @param ...
 * @param ...
 * @param ... */
int main(int argc, char **argv)
{
	struct timespec tdata[3];
	gnuplot_ctrl *plot;
	char tmp[64];
	int ret, i, j;
	float *tmp_f;
	_Complex float *tmp_c;
	double *plot_buff_r;
	double *plot_buff_c;

	allocate_memory();

	parameters = NULL;

	parse_paramters(argc, argv);

	if (generate_input_signal(input_data, input_lengths)) {
		printf("Error generating input signal\n");
		exit(1);
	}

	for (i=0;i<nof_input_itf;i++) {
		if (!input_lengths[i]) {
			printf("Warning, input interface %d has zero length\n",i);
		}
	}

	if (initialize()) {
		printf("Error initializing\n");
		exit(1); /* the reason for exiting should be printed out beforehand */
	}

#ifndef _ALOE_OLD_SKELETON
	for (i=0;i<nof_input_itf;i++) {
		input_ptr[i] = &input_data[i*input_max_samples*input_sample_sz];
	}
	for (i=0;i<nof_output_itf;i++) {
		output_ptr[i] = &output_data[i*output_max_samples*output_sample_sz];
	}
	clock_gettime(CLOCK_MONOTONIC,&tdata[1]);
	ret = work(input_ptr, output_ptr);
	clock_gettime(CLOCK_MONOTONIC,&tdata[2]);

#else

	clock_gettime(CLOCK_MONOTONIC,&tdata[1]);
	ret = work(input_data, output_data);
	clock_gettime(CLOCK_MONOTONIC,&tdata[2]);
#endif

	stop();
	if (ret == -1) {
		printf("Error running\n");
		exit(-1);
	}
	get_time_interval(tdata);

	for (i=0;i<nof_output_itf;i++) {
		if (!output_lengths[i]) {
			output_lengths[i] = ret;
		}
		if (!output_lengths[i]) {
			printf("Warning output interface %d has zero length\n",i);
		}
	}


	printf("\nExecution time: %d ns.\n", (int) tdata[0].tv_nsec);
	printf("FINISHED\n");

	if (use_gnuplot) {
		for (i=0;i<nof_input_itf;i++) {
			plot_buff_r = malloc(sizeof(double)*input_lengths[i]);
			plot_buff_c = malloc(sizeof(double)*input_lengths[i]);
			if (input_sample_sz == sizeof(float)) {
				tmp_f = (float*) &input_data[i*input_max_samples];
				for (j=0;j<input_lengths[i];j++) {
					plot_buff_r[j] = (double) tmp_f[j];
				}
				plot = gnuplot_init() ;
			    gnuplot_setstyle(plot,"lines");
			    snprintf(tmp,64,"input_%d",i);
		        gnuplot_plot_x(plot, plot_buff_r,
		        		get_input_samples(i), tmp);
		        free(plot_buff_r);
			} else if (input_sample_sz == sizeof(_Complex float)) {
				tmp_c = (_Complex float*) &input_data[i*input_max_samples];
				for (j=0;j<input_lengths[i];j++) {
					plot_buff_r[j] = (double) __real__ tmp_c[j];
					plot_buff_c[j] = (double) __imag__ tmp_c[j];
				}
				plot = gnuplot_init() ;
			    gnuplot_setstyle(plot,"lines");
			    snprintf(tmp,64,"input_real_%d",i);
		        gnuplot_plot_x(plot, plot_buff_r,
		        		get_input_samples(i), tmp);
		        plot = gnuplot_init() ;
			    gnuplot_setstyle(plot,"lines");
			    snprintf(tmp,64,"input_imag_%d",i);
		        gnuplot_plot_x(plot, plot_buff_c,
		        		get_input_samples(i), tmp);
		        free(plot_buff_r);
		        free(plot_buff_c);
			}
		}
		for (i=0;i<nof_output_itf;i++) {
			plot_buff_r = malloc(sizeof(double)*output_lengths[i]);
			plot_buff_c = malloc(sizeof(double)*output_lengths[i]);
			if (output_sample_sz == sizeof(float)) {
				tmp_f = (float*) &output_data[i*output_max_samples];
				for (j=0;j<output_lengths[i];j++) {
					plot_buff_r[j] = (double) __real__ tmp_f[j];
				}
				plot = gnuplot_init() ;
				gnuplot_setstyle(plot,"lines");
				snprintf(tmp,64,"output_%d",i);
				gnuplot_plot_x(plot, plot_buff_r,
						output_lengths[i], tmp);
				free(plot_buff_r);
			} else if (output_sample_sz == sizeof(_Complex float)) {
				tmp_c = (_Complex float*) &output_data[i*output_max_samples];
				for (j=0;j<output_lengths[i];j++) {
					plot_buff_r[j] = (double) __real__ tmp_c[j];
					plot_buff_c[j] = (double) __imag__ tmp_c[j];
				}
				plot = gnuplot_init() ;
				gnuplot_setstyle(plot,"lines");
				snprintf(tmp,64,"output_real_%d",i);
				gnuplot_plot_x(plot, plot_buff_r,
						output_lengths[i], tmp);
				plot = gnuplot_init() ;
				gnuplot_setstyle(plot,"lines");
				snprintf(tmp,64,"output_imag_%d",i);
				gnuplot_plot_x(plot, plot_buff_c,
						output_lengths[i], tmp);
				free(plot_buff_r);
				free(plot_buff_c);
	        }
		}

		printf("Type ctrl+c to exit\n");fflush(stdout);
		free_memory();
		pause();
		/* make sure we exit here */
		exit(1);
	}

	free_memory();

	return 0;
}
Exemple #21
0
void plotData(const parameters * p, fit_results * fr, plot_data * pd)
{
  int i;
  char * str=(char*)calloc(256,sizeof(char));
  plotOpen=1; 
  handle=gnuplot_init();
    
  printf("\nDATA PLOTS\n----------\n");
  
  if(strcmp(p->plotMode,"1d")==0)
    {
      for(i=0;i<p->numVar;i++)
        {
          gnuplot_setstyle(handle,"points"); //set style for grid points
          if(strcmp(p->dataType,"chisq")==0)
            gnuplot_cmd(handle,"set ylabel 'Chisq'");
          else  
            gnuplot_cmd(handle,"set ylabel 'Value'");
          sprintf(str,"set xlabel 'Parameter %i'",i+1);
          gnuplot_cmd(handle,str);
          gnuplot_plot_xy(handle, pd->data[i][i], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
          if(pd->axisLabelStyle[i][i]==1)
            gnuplot_cmd(handle,"set format x '%%12.2E'");
          if(pd->axisLabelStyle[i][p->numVar]==1)
            gnuplot_cmd(handle,"set format y '%%12.2E'");
          gnuplot_setstyle(handle,"lines");//set style for fit data
          if(p->numVar==1)
            {
              gnuplot_plot_xy(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPlotPts, "Fit");
            }  
          else
            {
              if(i==0)
                gnuplot_plot_xy(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPtsPerVar, "Fit");
              else if(i==1)
                gnuplot_plot_xygrid(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, "Fit");
              else if(i==2)
                gnuplot_plot_xygrid(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, pd->numFitPtsPerVar*pd->numFitPtsPerVar, 0, "Fit");
            }
          //strcpy(str,fr->fitForm[i]);//retrieve fit data functional form
          //gnuplot_plot_equation(handle, str, "Fit (function)");
          //plot confidence intervals
          if(p->plotCI==1)
          	{
          		gnuplot_plot_xy(handle,fr->ciXVal[i],fr->ciUVal[i],CI_DIM,"Upper 1-sigma confidence band");
          		gnuplot_plot_xy(handle,fr->ciXVal[i],fr->ciLVal[i],CI_DIM,"Lower 1-sigma confidence band");
          		/*strcpy(str,fr->ciUForm[0]);
          		gnuplot_plot_equation(handle, str, "Upper 95% confidence band");
          		strcpy(str,fr->ciLForm[0]);
          		gnuplot_plot_equation(handle, str, "Lower 95% confidence band");
          		strcpy(str,fr->piUForm[0]);
          		gnuplot_plot_equation(handle, str, "Upper 95% prediction band");
          		strcpy(str,fr->piLForm[0]);
          		gnuplot_plot_equation(handle, str, "Lower 95% prediction band");*/
          	}
          printf("Showing plot for parameter %i.\n",i+1);
          if(p->numVar==3)
            {
              if(i==0)
                printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",2,pd->fixedParVal[1],3,pd->fixedParVal[2]);
              if(i==1)
                printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",1,pd->fixedParVal[0],3,pd->fixedParVal[2]);
              if(i==2)
                printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",1,pd->fixedParVal[0],2,pd->fixedParVal[1]);
            }
          else if(p->numVar==2)
            {
              if(i==0)
                printf("Parameter %i fixed to %Lf\n",2,pd->fixedParVal[1]);
              if(i==1)
                printf("Parameter %i fixed to %Lf\n",1,pd->fixedParVal[0]);
            }
          printf("%i data points available for plot.\n",pd->plotDataSize[i]);
          if(i<(p->numVar-1))
            plotPrompt(1);
          else
            plotPrompt(0);
          gnuplot_resetplot(handle);
        }
    }
  else if(strcmp(p->plotMode,"2d")==0)
    {
      if(p->numVar==3)
        {
          for(i=0;i<p->numVar;i++)
            {
              gnuplot_setstyle(handle,"points"); //set style for grid points
              if(i==0)
                {
                  gnuplot_plot_xyz(handle, pd->data[i][1], pd->data[i][2], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
                  if(pd->axisLabelStyle[i][1]==1)
                    gnuplot_cmd(handle,"set format x '%%12.2E'");
                  if(pd->axisLabelStyle[i][2]==1)
                    gnuplot_cmd(handle,"set format y '%%12.2E'");
                  if(pd->axisLabelStyle[i][p->numVar]==1)
                    gnuplot_cmd(handle,"set format z '%%12.2E'");
                  sprintf(str,"set xlabel 'Parameter 2'; set ylabel 'Parameter 3'");
                }
              else if(i==1)
                {
                  gnuplot_plot_xyz(handle, pd->data[i][0], pd->data[i][2], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
                  if(pd->axisLabelStyle[i][0]==1)
                    gnuplot_cmd(handle,"set format x '%%12.2E'");
                  if(pd->axisLabelStyle[i][2]==1)
                    gnuplot_cmd(handle,"set format y '%%12.2E'");
                  if(pd->axisLabelStyle[i][p->numVar]==1)
                    gnuplot_cmd(handle,"set format z '%%12.2E'");
                  sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 3'");
                }
              else if(i==2)
                {
                  gnuplot_plot_xyz(handle, pd->data[i][0], pd->data[i][1], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
                  if(pd->axisLabelStyle[i][0]==1)
                    gnuplot_cmd(handle,"set format x '%%12.2E'");
                  if(pd->axisLabelStyle[i][1]==1)
                    gnuplot_cmd(handle,"set format y '%%12.2E'");
                  if(pd->axisLabelStyle[i][p->numVar]==1)
                    gnuplot_cmd(handle,"set format z '%%12.2E'");
                  sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'");
                }
              if(strcmp(p->dataType,"chisq")==0)
                gnuplot_cmd(handle,"set zlabel 'Chisq'");
              else  
                gnuplot_cmd(handle,"set zlabel 'Value'");
              gnuplot_cmd(handle,str);
              gnuplot_setstyle(handle,"lines");
              gnuplot_cmd(handle,"set grid");//set style for fit data
              if(i==0)
                gnuplot_plot_xyzgrid(handle, pd->fit[i][1], pd->fit[i][2], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, "Fit");
              else if(i==1)
                gnuplot_plot_xyzgrid(handle, pd->fit[i][0], pd->fit[i][2], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, 0, pd->numFitPtsPerVar, "Fit");
              else if(i==2)
                gnuplot_plot_xyzgrid(handle, pd->fit[i][0], pd->fit[i][1], pd->fit[i][p->numVar], pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, 0, "Fit");
              //strcpy(str,fr->fitForm[i]);//retrieve fit data functional form
              //gnuplot_plot_equation(handle, str, "Fit (function)");
              printf("Showing surface plot with parameter %i fixed to %Lf\n",i+1,pd->fixedParVal[i]);
              printf("%i data points available for plot.\n",pd->plotDataSize[i]);
              if(i<(p->numVar-1))
                plotPrompt(1);
              else
                plotPrompt(0);
              gnuplot_resetplot(handle);
            }
        }
      else if(p->numVar==2)
        {
          gnuplot_setstyle(handle,"points"); //set style for grid points
          gnuplot_plot_xyz(handle, pd->data[0][0], pd->data[0][1], pd->data[0][p->numVar], pd->plotDataSize[0], "Data");
          if(pd->axisLabelStyle[0][0]==1)
            gnuplot_cmd(handle,"set format x '%%12.2E'");
          if(pd->axisLabelStyle[0][1]==1)
            gnuplot_cmd(handle,"set format y '%%12.2E'");
          if(pd->axisLabelStyle[0][p->numVar]==1)
            gnuplot_cmd(handle,"set format z '%%12.2E'"); 
          if(strcmp(p->dataType,"chisq")==0)
            gnuplot_cmd(handle,"set zlabel 'Chisq'");
          else  
            gnuplot_cmd(handle,"set zlabel 'Value'");
          sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'");
          gnuplot_cmd(handle,str);
          gnuplot_setstyle(handle,"lines");
          gnuplot_cmd(handle,"set grid");//set style for fit data
          //gnuplot_cmd(handle,"set dgrid3d 30,30 qnorm 2");//set style for fit data
          gnuplot_plot_xyzgrid(handle, pd->fit[0][0], pd->fit[0][1], pd->fit[0][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, 0, 0, "Fit");
          //strcpy(str,fr->fitForm[0]);//retrieve fit data functional form
          //gnuplot_plot_equation(handle, str, "Fit (function)");
          printf("Showing surface plot.\n");
          printf("%i data points available for plot.\n",pd->plotDataSize[0]);
          plotPrompt(0);
          gnuplot_resetplot(handle);
        }
    }
  else if(strcmp(p->plotMode,"3d")==0)
    {
      if(p->numVar==3)
        {
          gnuplot_setstyle(handle,"points"); //set style for grid points
          gnuplot_plot_xyza(handle, pd->data[0][0], pd->data[0][1], pd->data[0][2], pd->data[0][p->numVar], pd->plotDataSize[0], "Data");
          if(pd->axisLabelStyle[0][0]==1)
            gnuplot_cmd(handle,"set format x '%%12.2E'");
          if(pd->axisLabelStyle[0][1]==1)
            gnuplot_cmd(handle,"set format y '%%12.2E'");
          if(pd->axisLabelStyle[0][2]==1)
            gnuplot_cmd(handle,"set format z '%%12.2E'");
          sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'; set zlabel 'Parameter 3'");
          gnuplot_cmd(handle,str);
          sprintf(str,"set cbrange [%f:%f]",pd->min_m,pd->max_m); //set the color bar range
          gnuplot_cmd(handle,str);
          if(strcmp(p->fitType,"par3")==0)
            {
              gnuplot_setcolor(handle,"black");
              gnuplot_cmd(handle,"set pointsize 1.5");
              double xVert=(double)fr->fitVert[0];
              double yVert=(double)fr->fitVert[1];
              double zVert=(double)fr->fitVert[2];
              gnuplot_plot_xyz(handle, &xVert, &yVert, &zVert, 1, "Fit Vertex");
            }
          printf("Showing heatmap plot.\n");
          printf("%i data points available for plot.\n",pd->plotDataSize[0]);
          plotPrompt(0);
          gnuplot_resetplot(handle);
        }
    }
  else
    {
      printf("ERROR: The plot mode '%s' defined in the data file '%s' is not supported!\n",p->plotMode,p->filename);
      exit(-1);
    }

}
Exemple #22
0
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;
}
void
consensus (void *space, Uint *consensus, Uint len, IntSequence *query,
		Uint seedlen, void* info) {

    Uint i,j;	
	char *constr;	
	double sum, norm;
	double *consensus_double;
	double *seedprobability;
	
	imbissinfo *imbiss;	
	IntSequence *consensusSequence;
	gnuplot_ctrl *h;

	imbiss = (imbissinfo*) info;
    

	seedprobability = ALLOCMEMORY(space, NULL, double, len);
	for (i=0; i < len; i++) {
		for (sum=0.0, j=0; j < seedlen; j++) {
			sum += imbiss->score[(Uint) query->sequence[i+j]];
		}
		seedprobability[i] = log10(imbiss->K*2500000*seedlen*
			exp(-(double)imbiss->lambda*sum));
	}
	
	consensusSequence = initSequence(space);
	consensusSequence->sequence = consensus;
	consensusSequence->length = len;
	
	constr = printSequence(space, consensusSequence, 60);
	printf("%s\n", constr);
	FREEMEMORY(space, constr);
	
    consensus_double = ALLOCMEMORY(space, NULL, double, len);
	
	h = gnuplot_init();
	gnuplot_setstyle(h, "lines");
	sum = 0;
	for(i=0; i < len; i++) {
		sum += consensus[i];
	}
	
	for(i=0; i < len; i++) {
	  norm = consensus[i];
	  norm = (norm > 0) ? norm : 1;
	  consensus_double[i] = log10(norm);
	
		/*	log10(imbiss->K*3000000*len*exp(-(double)consensus[i]));
		  if (consensus_double[i] < -400) consensus_double[i]=-400;*/
	}

	gnuplot_cmd(h, "set title 'IMBISS - seed statistics' -28,0 font'Helvetica,15'");	
	gnuplot_cmd(h, "set label '%s' at screen 0.12,0.92 font 'Helvetica,12'", imbiss->query->strings[0].str);
	gnuplot_cmd(h, "set label 'seed length: %d' at graph 0.05,0.95 font 'Helvetica, 12'", seedlen);
	gnuplot_set_xlabel(h, "query sequence residue");
	gnuplot_set_ylabel(h, "log");	
	gnuplot_plot_x(h, consensus_double, len, "log(number of matches)");
	gnuplot_plot_x(h, seedprobability, len,  "log(Kmn*e^{lambda*score(seed)})");
	
	FREEMEMORY(space, seedprobability);
	FREEMEMORY(space, consensus_double);
	FREEMEMORY(space, consensusSequence);
}
Exemple #24
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 ;
}
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();
}
Exemple #26
0
/**
 * Parses a command.
 *
 * @param ctok Command string in strtok.
 * @param csv_file CSV file location.
 * @param gp gnuplot object.
 * @return True if the program should continue running.
 */
bool parse_cmd_line(char *ctok, char **csv_file, gnuplot_ctrl *gp, char *prompt, bool quiet) {
	// Command.
	if (!strcmp(ctok, "quit") || !strcmp(ctok, "exit")) {
		return false;
	} else if (!strcmp(ctok, "legend")) {
		// Toogle legend.
		if (!strcmp(strtok(NULL, " "), "off")) {
			gnuplot_cmd(gp, "set key off");
			if (!quiet) {
				printf("Legend turned off.\n");
			}
		} else {
			gnuplot_cmd(gp, "set key on");
			if (!quiet) {
				printf("Legend turned on.\n");
			}
		}
	} else if (!strcmp(ctok, "xlabel") || !strcmp(ctok, "ylabel")) {
		// Set xy label.
		char arg[64] = "";
		char xy = ctok[0];

		parse_spaced_arg(arg, ctok);
		if (!quiet) {
			printf("%clabel set to \"%s\"\n", xy, arg);
		}

		switch (xy) {
			case 'x':
				gnuplot_set_xlabel(gp, arg);
				break;
			case 'y':
				gnuplot_set_ylabel(gp, arg);
		}
	} else if (!strcmp(ctok, "plot")) {
		// Plot data.
		char lg_title[64] = "";
		uint8_t col = atoi(strtok(NULL, " "));
		double *items = NULL;
		unsigned int n = 0;

		parse_spaced_arg(lg_title, ctok);
		n = read_csv_col(&items, *csv_file, col);
		gnuplot_setstyle(gp, "lines");
		gnuplot_plot_x(gp, items, n, lg_title);
	} else if (!strcmp(ctok, "gp")) {
		// Execute raw gnuplot command.
		char gp_cmd[1024] = "";

		parse_spaced_arg(gp_cmd, ctok);
		gnuplot_cmd(gp, gp_cmd);
	} else if (!strcmp(ctok, "load")) {
		// Load CSV.
		char filename[2048] = "";
		parse_spaced_arg(filename, ctok);

		*csv_file = malloc(strlen(filename) + 1);
		strcpy(*csv_file, filename);
		generate_prompt(prompt, *csv_file);
	} else {
		printf("Invalid command: %s\n", ctok);
	}

	return true;
}
Exemple #27
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;
}
Exemple #28
0
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;
}
Exemple #29
0
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);

}