Пример #1
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);
    }

}
Пример #2
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Plotter::Plotter() : _plotter(NULL)
{
	_plotter = gnuplot_init();
}
Пример #3
0
int main(int argc,char* argv[])
{
	PlasmaData pdata(argc,argv);


	FieldDataCPU fields;

	pdata.Lx = 1.0;
	pdata.Ly = 1.0;
	pdata.Lz = 1.0;

	pdata.setup();
	fields.allocate(&pdata);

	int nx = pdata.nx;
	int ny = pdata.ny;
	int nz = pdata.nz;
	int nshape = 100;

	float shape1[nshape];
	float shape2[nshape];
	float shapex[nshape];

	for(int i=0;i<nshape;i++)
	{
		float x = i*4.0/nshape - 2.0;

		shape1[i] = S1_shape(x);
		shape2[i] = S2_shape(x);
		shapex[i] = x;
	}


	gnuplot_ctrl* shape_plot = gnuplot_init();

	gnuplot_plot_xy(shape_plot,shapex,shape1,nshape,"Shape 1");
	gnuplot_plot_xy(shape_plot,shapex,shape2,nshape,"Shape 2");



	// Setup E-field
	for(int i=0;i<pdata.nx;i++)
	{
		for(int j=0;j<pdata.ny;j++)
		{
			for(int k=0;k<pdata.nz;k++)
			{
				float x = i*pdata.dxdi+pdata.xmin;
				float y = j*pdata.dydi+pdata.ymin;
				float z = k*pdata.dzdi+pdata.zmin;


				fields.getE(i,j,k,0) = Ex_function(x,y+0.5*pdata.dydi,z+0.5*pdata.dzdi);
				fields.getE(i,j,k,1) = Ey_function(x+0.5*pdata.dxdi,y,z+0.5*pdata.dzdi);
				fields.getE(i,j,k,2) = Ez_function(x+0.5*pdata.dxdi,y+0.5*pdata.dydi,z);

				fields.getB(i,j,k,0) = Ex_function(x,y,z);
				fields.getB(i,j,k,1) = Ey_function(x,y,z);
				fields.getB(i,j,k,2) = Ez_function(x,y,z);

				//fields.getB(i,j,k,0) = 0.0;
				//fields.getB(i,j,k,1) = 0.0f;
				//fields.getB(i,j,k,2) = 0.0f;

			//	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.init_plot();

	fields.plot(&pdata,pdata.nz/2,0,0,0);

	getchar();


	double Ex_total = 0;
	double Ey_total = 0;
	double Ez_total = 0;

	double Bx_total = 0;
	double By_total = 0;
	double Bz_total = 0;


	// Setup E-field
	for(int i=0;i<pdata.nx;i++)
	{
		for(int j=0;j<pdata.ny;j++)
		{
			for(int k=0;k<pdata.nz;k++)
			{
				float xfrac = 0.5;
				float yfrac = 0.5;
				float zfrac = 0.5;

				float x = (xfrac + i)*pdata.dxdi+pdata.xmin;
				float y = (yfrac + j)*pdata.dydi+pdata.ymin;
				float z = (zfrac + k)*pdata.dzdi+pdata.zmin;


				float Ex_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,0,FieldData_deriv_f);
				float Ey_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,1,FieldData_deriv_f);
				float Ez_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,2,FieldData_deriv_f);

				float Ex_real = Ex_function(x,y,z);
				float Ey_real = Ey_function(x,y,z);
				float Ez_real = Ez_function(x,y,z);


				float Ex_err = fabs(Ex_real - Ex_intrp)/fabs(Ex_real);
				float Ey_err = fabs(Ey_real - Ey_intrp)/fabs(Ey_real);
				float Ez_err = fabs(Ez_real - Ez_intrp)/fabs(Ez_real);

				float Bx_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,0,FieldData_deriv_f);
				float By_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,1,FieldData_deriv_f);
				float Bz_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,2,FieldData_deriv_f);

				float Bx_real = Ex_function(x,y,z);
				float By_real = Ey_function(x,y,z);
				float Bz_real = Ez_function(x,y,z);


				float Bx_err = fabs(Bx_real - Bx_intrp)/fabs(Bx_real);
				float By_err = fabs(By_real - By_intrp)/fabs(By_real);
				float Bz_err = fabs(Bz_real - Bz_intrp)/fabs(Bz_real);

				Ex_total += Ex_err;
				Ey_total += Ey_err;
				Ez_total += Ez_err;

				Bx_total += Bx_err;
				By_total += By_err;
				Bz_total += Bz_err;
				//printf("values: x: %f / %f, y: %f / %f, z: %f / %f \n",Ex_real,Ex_intrp,Ey_intrp,Ey_real,Ez_intrp,Ez_real);
				//printf("Errors: x = %e, y = %e, z = %e\n",Ex_err,Ey_err,Ez_err);

			}
		}
	}



	printf("Errors_avg: x = %e, y = %e, z = %e\n",Ex_total/(nx*ny*nz*1.0),Ey_total/(nx*ny*nz*1.0),Ez_total/(nx*ny*nz*1.0));
	printf("Errors_avg: x = %e, y = %e, z = %e\n",Bx_total/(nx*ny*nz*1.0),By_total/(nx*ny*nz*1.0),Bz_total/(nx*ny*nz*1.0));

	printf("Efield setup complete\n");


}
Пример #4
0
void init_plot()
{
    plot_handle = gnuplot_init();
}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
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();
}
Пример #8
0
int main(int arg, char *argv[])
{
	//socket variable
	int sock;
	struct sockaddr_in sin;
	char buff[BuffLength];
	const char *IP="192.168.128.3";

	//gnuplot variable
	gnuplot_ctrl * h; //handler of gnuplot session

	int i, j, line;

	double *x = NULL;
	double *y = NULL;
	double **z = (double **)malloc(Nline*sizeof(double *));

	for (i=0 ; i<Nline ; i++)
	{
		x=malloc((BuffLength-1)*sizeof(double));
		y=malloc(Nline*sizeof(double));
		z[i]=malloc((BuffLength-1)*sizeof(double));
	}

	init_xy(x,y);

	//Create socket
	sock=socket(AF_INET, SOCK_STREAM, 0);
	if (sock==-1)
	{
		perror("socket()");
		exit(errno);
	}

	sin.sin_addr.s_addr=inet_addr(IP);
	sin.sin_family=AF_INET;
	sin.sin_port=htons(Port);

	if (connect(sock, (struct sockaddr *) &sin, sizeof(sin))==-1)

	{
		perror("connect()");
		exit(errno);
	}

	printf("Connected\n");

	//gnuplot object
	h=gnuplot_init();
	gnuplot_surf_gray(h, x, y, z, BuffLength-1, Nline, "test");
	while(1)
	{	
		if(recv(sock, buff, BuffLength, MSG_WAITALL)==0)
			{
				printf("Server closed\n");
				break;
			}

		for (i=0 ; i<Nline ; i++)
		{
			line=(int)(buff[0]);
			for (j=0 ; j<BuffLength-1 ; j++)
			{
				z[line][j]=(double)(buff[j+1]);
			}
		}

		gnuplot_surf_gray(h, x, y, z, BuffLength-1, Nline,"test");
	}
	writefile(x,y,z,Nline,BuffLength-1);

	close(sock);
	gnuplot_close(h);
	free(x);
	free(y);
	free(z);
	return 0;
}
Пример #9
0
int main(int arg, char *argv[])
{
	//socket variable
	int sock;
	struct sockaddr_in sin;
	char buff[BuffLength]={0};
	const char *IP="192.168.128.3";

	//gnuplot variable
	gnuplot_ctrl * h; //handler of gnuplot session
	printf("gnuctrl done\n");
	int i, j, line;

	int **z = (int **)malloc(Nline*sizeof(int *));

	for (i=0 ; i<Nline ; i++)
	{
		z[i]=(int *)malloc((BuffLength-1)*sizeof(int));
	}
	printf("z init finish\n");

	//Create socket
	sock=socket(AF_INET, SOCK_STREAM, 0);
	if (sock==-1)
	{
		perror("socket()");
		exit(errno);
	}

	sin.sin_addr.s_addr=inet_addr(IP);
	sin.sin_family=AF_INET;
	sin.sin_port=htons(Port);

	printf("define socket\n");

	if (connect(sock, (struct sockaddr *) &sin, sizeof(sin))==-1)
	{
		perror("connect()");
		exit(errno);
	}

	printf("Connected\n");

	//gnuplot object
	h=gnuplot_init();
	gnuplot_cmd(h,"set pm3d map");
	gnuplot_cmd(h,"set palette gray");
	int k=0, l=1;;
	while(l)
	{	
		for (i=0 ; i<Nline ; i++)
		{
			if(recv(sock, buff, BuffLength, MSG_WAITALL)==0)
			{
				printf("Server closed\n");
				i=Nline+1;
				l=0;
				break;
			}

			if (i<Nline+2)
			{
				line=(int)(buff[0])-1;
				printf("line number %d\n",line);
				for (j=0 ; j<BuffLength-1 ; j++)
				{
					z[line][j]=(int)(buff[j+1]);
				}
			}
		}
		printf("image number %d\n",k);
		k++;
		gnuplot_matrix(h, z, BuffLength-1, Nline);
	}
	
	close(sock);
	gnuplot_close(h);
	free(z);

	return 0;
}
Пример #10
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;
}
Пример #11
0
int main(int arg, char *argv[])
{
	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);
        get_RP_settings(&sock);
        printf("x0=%f\n",x0);
        printf("xf=%f\n",xf);
        printf("dec=%i\n",dec);
        printf("Nline=%i\n",Nline);
        printf("sector=%f\n",sector);
	printf("mode_RP=%i\n",mode_RP);

	char name[50];

	Npoint=(int)(2.0*(xf-x0)*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);

	//gnuplot variable
	gnuplot_ctrl * h;
	int i, j;

	double **x = NULL;
        double **y = NULL;
        int **z = (int **)malloc(Nline*sizeof(int *));
	double *tmp = (double *)malloc(Npoint*sizeof(int));
	double *tmp2 = (double *)malloc(pad_len*sizeof(double));
	double **env = (double **)malloc(Nline*sizeof(double *));
	double *pad = (double *)malloc(pad_len*sizeof(double));
        x = malloc(Nline*sizeof(double *));
        y = malloc(Nline*sizeof(double *));

        for (i=0 ; i<Nline ; i++)
        {
                x[i]=malloc((Npoint)*sizeof(double));
                y[i]=malloc((Npoint)*sizeof(double));
                z[i]=malloc((Npoint)*sizeof(int));
		env[i]=(double *)malloc(pad_len*sizeof(double));
		if (env[i]==NULL) {printf("boulet!");}
		for (j=0 ; j<pad_len ; j++) {env[i][j]=0.0;}
        }

        init_xy(x,y);

	//gnuplot object
	h=gnuplot_init();
	gnuplot_cmd(h, "set pm3d map");
	gnuplot_cmd(h, "set palette gray");

	int k=1, line=0, l=0, temp;

	if (mode_RP==0)
	{
		int16_t *buff=(int16_t *)malloc((Npoint+1)*sizeof(int16_t));
		float fech, f0, fm;
		fech=125000000.0/dec;
		f0=3500000.0;
		fm=6500000.0;

	        i=0;
	        j=0;
	        while (1)
	        {
	                receive_int16_TCP_client(&sock, buff, Npoint+1);
	                j=i;
	                i=(int)buff[0];
	                if (j==63 && i==64) {break;}
	                if (j==2 && i==1) {break;}
	        }


		while(k)
		{
			temp=l/10;
			for (i=0 ; i<Nline ; i++)
			{
				if (receive_int16_TCP_client(&sock, buff, Npoint+1)==1)
				{
					i=Nline+2;
					k=0;
					break;
				}
	
				if(i<Nline+2)
				{
					line=(int)buff[0]-1;
					for (j=0 ; j<Npoint ; j++) {tmp[j]=(double)buff[j+1];}
					zero_padding(tmp, pad, Npoint, pad_len, 1); 
					tmp2=env[line];
                        		envelope(pad, tmp2, pad_len, fech, f0, fm, 0);
					if (temp*10==l) {z[line]=tmp[j];}
					//for (j=0 ; j<Npoint ; j++) {z[line][j]=(int)env[j];}
				}
			}
			gnuplot_matrix_double(h, env, Npoint, Nline);
			if (temp*10==l)
			{
				sprintf(name, "int%i.txt", l);
				writefile_double(env, Nline, Npoint, name);
			}
			l++;
		}
		free(buff);
	}

	else if (mode_RP==1)
	{
		char *buff=(char *)malloc((Npoint+1)*sizeof(char));
		while(k)
		{
			for (i=0 ; i<Nline ; i++)
			{
				if (receive_TCP_client(&sock, buff, Npoint+1)==1)
				{
					i=Nline+2;
					k=0;
					break;
				}
	
				if(i<Nline+2)
				{
					line=int_converter(buff[0])-1;
					for (j=0 ; j<Npoint ; j++) {z[line][j]=int_converter(buff[j+1]);}
				}
			}
			gnuplot_matrix(h, z, Npoint, Nline);
			temp=l/10;
			if (temp*10==l)
			{
				sprintf(name, "char%i.txt", l);
				writefile(z, Nline, Npoint, name);
			}
			l++;
		}
		free(buff);
	}

	else {printf("problem with RP settings\n");}


	/*int k=1, line=0, l=0;
	while(k)
	{
		for (i=0 ; i<Nline ; i++)
		{
			if (receive_TCP_client(&sock, buff, Npoint+1)==1)
			{
				i=Nline+2;
				k=0;
				break;
			}
			
			if (i<Nline+2)
			{
				line=int_converter(buff[0])-1;
				for (j=0 ; j<Npoint-1 ; j++)
				{
					//z[line][j]=(int)buff[j+1];
					z[line][j]=int_converter(buff[j+1]);
				}
			}
		}
		gnuplot_matrix(h, z, Npoint, Nline);	
		//sprintf(name, "main%i.txt",l);
		//writefile(z, Nline, Npoint, name);
		l++;
	}*/

	usleep(30);
	close(sock);
	free(x);
	free(y);
	free(z);
	free(env);
	free(pad);
	return 0;
}
Пример #12
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 ;
}
Пример #13
0
void TwoStream_Initializer::initialize_fields(FieldData** fields,
										HOMoments** moments,
										ParallelInfo* myinfo)
{

	int tid = myinfo->tid;

	// Setup E-field
	for(int k=0;k<pdata->nz;k++)
	{
		for(int j=0;j<pdata->ny;j++)
		{
			for(int i=0;i<pdata->nx;i++)
			{
				realkind x = i*pdata->dxdi+pdata->xmin;
				//realkind y = j*pdata->dydi+pdata->ymin;
				//realkind z = k*pdata->dzdi+pdata->zmin;

				realkind Ex = -alpha*sin(x/kt)*(kt);



				fields[tid+1] -> getE(i,j,k,0) = Ex/epsilon_naught;
				fields[tid+1] -> getE(i,j,k,1) = 0;
				fields[tid+1] -> getE(i,j,k,2) = 0;

				fields[tid+1] -> getB(i,j,k,0) = 0;
				fields[tid+1] -> getB(i,j,k,1) = 0;
				fields[tid+1] -> getB(i,j,k,2) = 0;

				fields[0] -> getE(i,j,k,0) = Ex/epsilon_naught;
				fields[0] -> getE(i,j,k,1) = 0;
				fields[0] -> getE(i,j,k,2) = 0;

				fields[0] -> getB(i,j,k,0) = 0;
				fields[0] -> getB(i,j,k,1) = 0;
				fields[0] -> getB(i,j,k,2) = 0;


			//	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));
			}
		}
	}

	if(myinfo->myid_mpi == 0)
	{
		realkind gamma;

		gamma = pi_const * powf(pdata->omega_pe,3.0f);

		if(pdata->plot_flag)
		{
			plot = gnuplot_init();
			kenergy_plot = gnuplot_init();
			Tenergy_plot = gnuplot_init();
			charge_cons_plot = gnuplot_init();
		}
		Energy_array = (float*)malloc(2*pdata->nsteps*sizeof(float));
		kEnergy_array = (float*)malloc(2*pdata->nsteps*sizeof(float));
		TEnergy_array = (float*)malloc(2*pdata->nsteps*sizeof(float));
		charge_cons_array = (float*)malloc(2*pdata->nsteps*sizeof(float));

		max_array = (float*)malloc(2*pdata->nsteps*sizeof(float));
		max_t_array = (float*)malloc(2*pdata->nsteps*sizeof(float));
		nplot = 0;
		nmax_array = 0;


		kE0 = moments[0] -> evaluate_energy();
		kEnergy_array[0] = kE0;
		E0 = fields[0] -> evaluate_energy();
		Energy_array[0] = (E0);

		TEnergy_array[0] =0;
		max_t_array[0] = 0;

		charge_cons_array[0] = 0;

		nplot++;

		if(pdata->plot_flag) gnuplot_cmd(plot,"set log y");
		//gnuplot_cmd(kenergy_plot,"set log y");


	}

}
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;
}
Пример #15
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);

}
Пример #16
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;
}
Пример #17
0
int main() 
{
    if (graph)
    {
        g = gnuplot_init();
        h = gnuplot_init();
    }

    /*
    n = 3;
    cost[0][0] = 2;
    cost[0][1] = 1;
    cost[0][2] = 3;
    cost[1][0] = 7;
    cost[1][1] = 4;
    cost[1][2] = 3;
    cost[2][0] = 3;
    cost[2][1] = 0;
    cost[2][2] = 0;
    */
    

    // Worst case:
    n = 3;
    cost[0][0] = 11;  // x = 11, e = 1, k = 2, l = 2
    cost[0][1] = 10;
    cost[1][0] = 9;
    cost[1][1] = 7;
    cost[0][2] = 2;
    cost[1][2] = 3;
    cost[2][0] = 30;
    cost[2][1] = 40;
    cost[2][2] = 39;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            printf("%d\t", cost[i][j]);
        }
        printf("\n");
    }
    printf("\n");

    hungarian();

    for (int i = 0; i < n; i++)
        printf("%d\t", lx[i]);
    printf("\n\n");

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (xy[i] == j)
                printf("%d\t", 1);
            else
                printf("%d\t", 0);
                
        }
        printf("| %d\n", ly[i]);
    }
    printf("\n");

    printf("Slack: ");
    for (int i = 0; i < n; i++)
        printf("%d\t", slack[i]);
    printf("\n");
    printf("Slackx: ");
    for (int i = 0; i < n; i++)
        printf("%d\t", slackx[i]);
    printf("\n");

    if (g != NULL)
        gnuplot_close(g);
    if (h != NULL)
        gnuplot_close(h);

    return 0;
}
Пример #18
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);
}
Пример #19
0
int main(int argc,char **argv)
{
	MYSQL mysql;
	FILE *file;
	MYSQL_RES *Gene_Result,*NFI_Result,*ZDR_Result;
	MYSQL_ROW *Gene_Row,*NFI_Row,*ZDR_Row;
	MYSQL_ROW_OFFSET *NFI_Rollback,*ZDR_Rollback;
	gnuplot_ctrl *g;
	char Order[32],query[4000],NFI_Table1[100],NFI_Table2[100],ZDR_Table1[100],ZDR_Table2[100],Gene_Table1[100],Gene_Table2[100];
	int GenOrd,NfiOrd,ZdrOrd;
	long int i,MinDist,MaxDist,GeneCount1,GeneCount2,NfiZdrGenes1,NfiZdrGenes2,GenePos,NfiStart,NfiStop,NfiBst,ZdrStart,ZdrStop,ZdrBst,NFIPos,ZDRPos;
	double NfiMin,NfiMax,NfiStp,NfiCut,ZdrMin,ZdrMax,ZdrStp,ZdrCut,GenePerc1,GenePerc2,MinDiff,MaxDiff;
	double *NfiScores1,*NfiScores2,*ZdrScores1,*ZdrScores2;

	if(argc!=16)
		return printf("usage:  %s Fasta_File1 Gene_File1 Fasta_File2 Gene_File2 Order MinDist MaxDist NfiMin NfiMax NfiStep ZdrMax ZdrMin ZdrStep OutFile Plot\n",argv[0]);

	sprintf(query,argv[1]);
	for(i=0;i<100;i++)
		switch(query[i])
		{
			case '.':       query[i]='_';       break;
			case '/':       sprintf(query,&query[i+1],100);
					i=0;
		}
	sprintf(NFI_Table1,"NFI_DNA.%s_nfihunt_classeq",query);
	sprintf(ZDR_Table1,"Z_DNA.%s_zhunt_classeq",query);
	sprintf(query,argv[2]);
	for(i=0;i<100;i++)
		switch(query[i])
		{
			case '.':       query[i]='_';   break;
			case '/':       sprintf(query,&query[i+1]);
					i=0;
		}
	sprintf(Gene_Table1,"Genomes.%s",query);
	sprintf(query,argv[3]);
	for(i=0;i<100;i++)
		switch(query[i])
		{
			case '.':       query[i]='_';       break;
			case '/':       sprintf(query,&query[i+1],100);
					i=0;
		}
	sprintf(NFI_Table2,"NFI_DNA.%s_nfihunt_classeq",query);
	sprintf(ZDR_Table2,"Z_DNA.%s_zhunt_classeq",query);
	sprintf(query,argv[4]);
	for(i=0;i<100;i++)
		switch(query[i])
		{
			case '.':       query[i]='_';       break;
			case '/':       sprintf(query,&query[i+1],100);
					i=0;
		}
	sprintf(Gene_Table2,"Genomes.%s",query);

	sprintf(Order,argv[5]);
	MinDist=atoi(argv[6]);
	MaxDist=atoi(argv[7]);
	NfiMin=atof(argv[8]);
	NfiMax=atof(argv[9]);
	NfiStp=atof(argv[10]);
	ZdrMax=atof(argv[11]);
	ZdrMin=atof(argv[12]);
	ZdrStp=atof(argv[13]);

	if(argc==15||strcmp(argv[15],"-r"))
	{
		if(!(strstr(Order,"T")&&strstr(Order,"N")&&strstr(Order,"Z")&&strlen(Order)==3))
			return printf("Improper Order format '%s'\n",Order);

		GenOrd=strstr(Order,"T")-Order;
		NfiOrd=strstr(Order,"N")-Order;
		ZdrOrd=strstr(Order,"Z")-Order;

		mysql_apps_logon(&mysql);

		fprintf(stderr,"Populating internal table 1\n");

		sprintf(query,"select start_site,strand,gene_num,gene_name from %s order by start_site",Gene_Table1);
		printf(mysql_query(&mysql,query)?strcat(strcat(query,"\n"),strcat(mysql_error(&mysql),"\n\n")):"");
		Gene_Result=mysql_store_result(&mysql);
		GeneCount1=mysql_num_rows(Gene_Result);

		sprintf(query,"select position,nfiscore from %s where nfiscore>=%f order by position",NFI_Table1,NfiMin);
		printf(mysql_query(&mysql,query)?strcat(strcat(query,"\n"),strcat(mysql_error(&mysql),"\n\n")):"");
		NFI_Result=mysql_store_result(&mysql);

		sprintf(query,"select position,deltalinking from %s where deltalinking<=%f order by position",ZDR_Table1,ZdrMax);
		printf(mysql_query(&mysql,query)?strcat(strcat(query,"\n"),strcat(mysql_error(&mysql),"\n\n")):"");
		ZDR_Result=mysql_store_result(&mysql);

		NfiScores1=(double*)malloc(GeneCount1*sizeof(double));
		ZdrScores1=(double*)malloc(GeneCount1*sizeof(double));

		NFI_Rollback=mysql_row_tell(NFI_Result);
		ZDR_Rollback=mysql_row_tell(ZDR_Result);

		for(i=0;i<GeneCount1;i++)
		{
			Gene_Row=mysql_fetch_row(Gene_Result);
			if(atoi(Gene_Row[0])-GenePos<=2000)
			{
				mysql_row_seek(NFI_Result,NFI_Rollback);
				mysql_row_seek(ZDR_Result,ZDR_Rollback);
			}
			GenePos=atoi(Gene_Row[0]);
			sprintf(query,Gene_Row[1]);
			switch(query[0])
			{
				case '+':       GenOrd=abs(GenOrd);
						NfiOrd=abs(NfiOrd);
						ZdrOrd=abs(ZdrOrd);
						break;
				case '-':       GenOrd=-abs(GenOrd);
						NfiOrd=-abs(NfiOrd);
						ZdrOrd=-abs(ZdrOrd);
						break;
				default:	return fprintf(stderr,"Invalid Gene Strand '%s\n'",Gene_Row[1]);
			}
			NfiStart=GenOrd<NfiOrd?(GenePos+1):(GenePos-1000);
			NfiStop=GenOrd<NfiOrd?(GenePos+1000):(GenePos-1);
			NfiBst=GenePos+100000;
			NfiScores1[i]=-100;
			while(NFI_Row=mysql_fetch_row(NFI_Result),NFIPos=NFI_Row?atoi(NFI_Row[0]):NfiStop+1,NFIPos<=NfiStop)
				if(NFIPos>=NfiStart&&NfiScores1[i]<=atoi(NFI_Row[1]))
				{
					if(NfiScores1[i]<atoi(NFI_Row[1])||abs(atoi(NFI_Row[0])-GenePos)<abs(NfiBst-GenePos))
					{
						NfiBst=atoi(NFI_Row[0]);
						NfiScores1[i]=atoi(NFI_Row[1]);
					}
				}
			ZdrStart=NfiOrd<ZdrOrd?(NfiBst+MinDist):(NfiBst-MaxDist);
			ZdrStop=NfiOrd<ZdrOrd?(NfiBst+MaxDist):(NfiBst-MinDist);
			ZdrStart=(GenOrd<ZdrOrd&&GenePos>ZdrStart)?GenePos:ZdrStart;
			ZdrStart=(GenOrd>ZdrOrd&&GenePos<ZdrStart)?GenePos:ZdrStart;
			ZdrStop=(GenOrd<ZdrOrd&&GenePos>ZdrStop)?GenePos:ZdrStop;
			ZdrStop=(GenOrd>ZdrOrd&&GenePos<ZdrStop)?GenePos:ZdrStop;
			ZdrBst=GenePos+100000;
			ZdrScores1[i]=100;
			while(ZDR_Row=mysql_fetch_row(ZDR_Result),ZDRPos=ZDR_Row?atoi(ZDR_Row[0]):ZdrStop+1,ZDRPos<=ZdrStop)
				if(ZDRPos>=ZdrStart&&ZdrScores1[i]>=atoi(ZDR_Row[1]))
				{
					if(ZdrScores1[i]>atoi(ZDR_Row[1])||abs(atoi(ZDR_Row[0])-NfiBst)<abs(ZdrBst-NfiBst))
					{
						ZdrBst=atoi(ZDR_Row[0]);
						ZdrScores1[i]=atof(ZDR_Row[1]);
					}
				}
			printf("%3s %d %-16s %4d %4.0f %4d %4.2f %4d\n",Gene_Row[2],GenePos,Gene_Row[3],NfiBst-GenePos,NfiScores1[i],ZdrBst-GenePos,ZdrScores1[i],NfiBst-ZdrBst);
		}

		mysql_free_result(Gene_Result);
		mysql_free_result(NFI_Result);
		mysql_free_result(ZDR_Result);


		fprintf(stderr,"Populating internal table 2\n");

		sprintf(query,"select start_site,strand from %s order by start_site",Gene_Table2);
		printf(mysql_query(&mysql,query)?strcat(strcat(query,"\n"),strcat(mysql_error(&mysql),"\n\n")):"");
		Gene_Result=mysql_store_result(&mysql);
		GeneCount2=mysql_num_rows(Gene_Result);

		sprintf(query,"select position,nfiscore from %s where nfiscore>=%f order by position",NFI_Table2,NfiMin);
		printf(mysql_query(&mysql,query)?strcat(strcat(query,"\n"),strcat(mysql_error(&mysql),"\n\n")):"");
		NFI_Result=mysql_store_result(&mysql);

		sprintf(query,"select position,deltalinking from %s where deltalinking<=%f order by position",ZDR_Table2,ZdrMax);
		printf(mysql_query(&mysql,query)?strcat(strcat(query,"\n"),strcat(mysql_error(&mysql),"\n\n")):"");
		ZDR_Result=mysql_store_result(&mysql);

		NfiScores2=(double*)malloc(GeneCount2*sizeof(double));
		ZdrScores2=(double*)malloc(GeneCount2*sizeof(double));

		NFI_Rollback=mysql_row_tell(NFI_Result);
		ZDR_Rollback=mysql_row_tell(ZDR_Result);

		for(i=0;i<GeneCount2;i++)
		{
			Gene_Row=mysql_fetch_row(Gene_Result);
			if(atoi(Gene_Row[0])-GenePos<=2000)
			{
				mysql_row_seek(NFI_Result,NFI_Rollback);
				mysql_row_seek(ZDR_Result,ZDR_Rollback);
			}
			GenePos=atoi(Gene_Row[0]);
			sprintf(query,Gene_Row[1]);
			switch(query[0])
			{
				case '+':       GenOrd=abs(GenOrd);
						NfiOrd=abs(NfiOrd);
						ZdrOrd=abs(ZdrOrd);
						break;
				case '-':       GenOrd=-abs(GenOrd);
						NfiOrd=-abs(NfiOrd);
						ZdrOrd=-abs(ZdrOrd);
						break;
				default:	return fprintf(stderr,"Invalid Gene Strand '%s\n'",Gene_Row[1]);
			}
			NfiStart=GenOrd<NfiOrd?(GenePos+1):(GenePos-1000);
			NfiStop=GenOrd<NfiOrd?(GenePos+1000):(GenePos-1);
			NfiBst=GenePos+100000;
			NfiScores2[i]=-100;
			while(NFI_Row=mysql_fetch_row(NFI_Result),NFIPos=NFI_Row?atoi(NFI_Row[0]):NfiStop+1,NFIPos<=NfiStop)
				if(NFIPos>=NfiStart&&NfiScores2[i]<=atoi(NFI_Row[1]))
				{
					if(NfiScores2[i]<atoi(NFI_Row[1])||abs(atoi(NFI_Row[0])-GenePos)<abs(NfiBst-GenePos))
					{
						NfiBst=atoi(NFI_Row[0]);
						NfiScores2[i]=atoi(NFI_Row[1]);
					}
				}
			ZdrStart=NfiOrd<ZdrOrd?(NfiBst+MinDist):(NfiBst-MaxDist);
			ZdrStop=NfiOrd<ZdrOrd?(NfiBst+MaxDist):(NfiBst-MinDist);
			ZdrStart=(GenOrd<ZdrOrd&&GenePos>ZdrStart)?GenePos:ZdrStart;
			ZdrStart=(GenOrd>ZdrOrd&&GenePos<ZdrStart)?GenePos:ZdrStart;
			ZdrStop=(GenOrd<ZdrOrd&&GenePos>ZdrStop)?GenePos:ZdrStop;
			ZdrStop=(GenOrd>ZdrOrd&&GenePos<ZdrStop)?GenePos:ZdrStop;
			ZdrBst=GenePos+100000;
			ZdrScores2[i]=100;
			while(ZDR_Row=mysql_fetch_row(ZDR_Result),ZDRPos=ZDR_Row?atoi(ZDR_Row[0]):ZdrStop+1,ZDRPos<=ZdrStop)
				if(ZDRPos>=ZdrStart&&ZdrScores2[i]>=atoi(ZDR_Row[1]))
				{
					if(ZdrScores2[i]>atoi(ZDR_Row[1])||abs(atoi(ZDR_Row[0])-NfiBst)<abs(ZdrBst-NfiBst))
					{
						ZdrBst=atoi(ZDR_Row[0]);
						ZdrScores2[i]=atof(ZDR_Row[1]);
					}
				}
		}


		mysql_free_result(Gene_Result);
		mysql_free_result(NFI_Result);
		mysql_free_result(ZDR_Result);

		mysql_close(&mysql);

		FILE *OutFile=fopen(argv[14],"w");
		if(!OutFile)
			return printf("Could not write to file '%s'\n",argv[14]);

		fprintf(stderr,"Generating results\n");

		MinDiff=100;
		MaxDiff=0;
		for(ZdrCut=ZdrMax;ZdrCut>=ZdrMin;ZdrCut-=ZdrStp)
		{
			for(NfiCut=NfiMin;NfiCut<=NfiMax;NfiCut+=NfiStp)
			{
				NfiZdrGenes1=0;
				for(i=0;i<GeneCount1;i++)
					if(NfiScores1[i]>=NfiCut&&ZdrScores1[i]<=ZdrCut)
						NfiZdrGenes1++;
				NfiZdrGenes2=0;
				for(i=0;i<GeneCount2;i++)
					if(NfiScores2[i]>=NfiCut&&ZdrScores2[i]<=ZdrCut)
						NfiZdrGenes2++;
				GenePerc1=(100.0*NfiZdrGenes1)/GeneCount1;
				GenePerc2=(100.0*NfiZdrGenes2)/GeneCount2;
				fprintf(OutFile,"%f %f %f %f %f\n",NfiCut,ZdrCut,GenePerc1-GenePerc2,GenePerc1,GenePerc2);
				fflush(OutFile);
				MinDiff=MinDiff>GenePerc1-GenePerc2?GenePerc1-GenePerc2:MinDiff;
				MaxDiff=MaxDiff<GenePerc1-GenePerc2?GenePerc1-GenePerc2:MaxDiff;
			}
		}

		fclose(OutFile);
	
	}

	if(argc>15)
	{
		sprintf(NFI_Table1,NFI_Table1+8);
		NFI_Table1[strlen(NFI_Table1)-8]='\0';
		sprintf(NFI_Table2,NFI_Table2+8);
		NFI_Table2[strlen(NFI_Table2)-8]='\0';
		g=gnuplot_init();
		sprintf(query,"set title \"%% Difference Between %s and %s of TSS w/(NFI + Z-DNA-12bps)\\n",NFI_Table1,NFI_Table2);
		for(i=0;i<argc;i++)
		{
			strcat(query,argv[i]);
			strcat(query," ");
		}
		strcat(query,"\"");
		gnuplot_cmd(g,query);
		sprintf(query,"set dgrid3d %.0f,%.0f,8",(ZdrMax-ZdrMin)/ZdrStp,(NfiMax-NfiMin)/NfiStp);
		gnuplot_cmd(g,query);
		sprintf(query,"set xrange [%f:%f]",NfiMin,NfiMax);
		sprintf(query,"set yrange [%f:%f]",ZdrMin,ZdrMax);
		gnuplot_cmd(g,query);
		if(!strcmp(argv[15],"-r"))
		{
			sprintf(query,"set zrange [*:*]");
			gnuplot_cmd(g,query);
			sprintf(query,"set cntrparam levels incremental -10,1,10");
			gnuplot_cmd(g,query);
		}
		else
		{
			sprintf(query,"set zrange [%f:%f]",MinDiff,MaxDiff);
			gnuplot_cmd(g,query);
			sprintf(query,"set cntrparam levels incremental %.0f,%d,%.0f",MinDiff,1+(int)((MaxDiff-MinDiff)/10),MaxDiff);
			gnuplot_cmd(g,query);
		}
		sprintf(query,"call 'Format/%s.format'",argv[0]);
		gnuplot_cmd(g,query);
		sprintf(query,"sp '%s' u 1:2:3 notitle",argv[14]);
		//sprintf(query,"sp '%s' w l lw 2",argv[14]);
		gnuplot_cmd(g,query);
		printf("Hit Enter to continue\n");
		getchar();
	}

	return 0;
}
Пример #20
0
void ParticleListCPUSorted::allocate(PlasmaData* pdata,int nptcls_in)
{
	//printf("Allocating Particle List on the CPU\n");

	if(pdata->plot_flag)
	plot = gnuplot_init();

	//gnuplot_cmd(plot,"set pointsize 0.1");
	// Allocate memory for particles
	nptcls_allocated = nptcls_in;

	nptcls = nptcls_in;

	num_cores = pdata->num_cores;

	// Allocate realkind arrays
	for(int i=0;i<ParticleList_nfloats;i++)
	{
		*get_float(i) = (realkind*)malloc(nptcls_allocated*sizeof(realkind));
	}

	// Allocate int arrays
	for(int i=0;i<ParticleList_nints;i++)
	{
		*get_int(i) = (int*)malloc(nptcls_allocated*sizeof(realkind));
	}

	buffer = (realkind*)malloc(nptcls_allocated*sizeof(realkind));

	num_subcycles = (int*)malloc(nptcls_allocated*sizeof(realkind));
	memset(num_subcycles,0,nptcls_allocated*sizeof(int));

	num_piccard = (realkind*)malloc(nptcls_allocated*sizeof(double));
	memset(num_piccard,0,nptcls_allocated*sizeof(double));

	num_piccard2 = (realkind*)malloc(nptcls_allocated*sizeof(double));
	memset(num_piccard2,0,nptcls_allocated*sizeof(double));


	// allocate short ints for cluster id's
	cluster_id = (int*)malloc(nptcls_allocated*sizeof(int));
	ptcl_index = (int*)malloc(nptcls_allocated*sizeof(int));

	piccard_timer = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));
	accel_timer = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));
	tally_timer = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));
	crossing_timer = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));
	dtau_est_timer = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));
	tally_timer2 = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));
	load_store_timer = (CPUTimer*)malloc(pdata->num_cores*sizeof(CPUTimer));

	int tid;
	omp_set_num_threads(pdata->num_cores);
#pragma omp parallel private(tid) default(shared) num_threads(pdata->num_cores)
	{
		tid = omp_get_thread_num();
		piccard_timer[tid] = *(new CPUTimer());
		accel_timer[tid] = *(new CPUTimer());
		tally_timer[tid] = *(new CPUTimer());
		crossing_timer[tid] = *(new CPUTimer());
		dtau_est_timer[tid] = *(new CPUTimer());

		tally_timer2[tid] = *(new CPUTimer());
		load_store_timer[tid] = *(new CPUTimer());
	}

	push_timer = new CPUTimer();


}