int main(void) { unsigned sampRate = 16000; unsigned nsamps = sampRate * 5; int16_t* buffer = (int16_t*) calloc(nsamps, sizeof(int16_t)); /* Record into the buffer */ LA_record(buffer, nsamps, sampRate, LA_REC_ONCE); printf("Recording...\n");fflush(stdout); while(LA_is_recording() == 1) sleep(1); /* Terminate the audio recording session */ LA_terminate(); /* Convert 16-bit ints to doubles for plotting */ double* dbuf = calloc(nsamps, sizeof(double)); for (unsigned i=0;i<nsamps;i++) dbuf[i] = (double) buffer[i]; /* Plot with gnuplot */ gnuplot_ctrl* h = gnuplot_init(); gnuplot_setstyle(h,"lines"); gnuplot_plot_x(h,dbuf,nsamps,"Live Audio"); gnuplot_close(h); /* Clean up */ free(dbuf); free(buffer); return 0; }
/** * @brief Open a new session, plot a signal, close the session. * @param title Plot title * @param style Plot style * @param label_x Label for X * @param label_y Label for Y * @param x Array of X coordinates * @param y Array of Y coordinates (can be NULL) * @param n Number of values in x and y. * @return * * This function opens a new gnuplot session, plots the provided * signal as an X or XY signal depending on a provided y, waits for * a carriage return on stdin and closes the session. * * It is Ok to provide an empty title, empty style, or empty labels for * X and Y. Defaults are provided in this case. */ void gnuplot_plot_once(char* title, char* style, char* label_x, char* label_y, float* x, float* y, int n) { gnuplot_ctrl* handle; if (x==NULL || n<1) return; if ((handle = gnuplot_init()) == NULL) return; if (style!=NULL) gnuplot_setstyle(handle, style); else gnuplot_setstyle(handle, (char*)"lines"); if (label_x!=NULL) gnuplot_set_xlabel(handle, label_x); else gnuplot_set_xlabel(handle, (char*)"X"); if (label_y!=NULL) gnuplot_set_ylabel(handle, label_y); else gnuplot_set_ylabel(handle, (char*)"Y"); if (y==NULL) gnuplot_plot_x(handle, x, n, title); else gnuplot_plot_xy(handle, x, y, n, title); printf("press ENTER to continue\n"); while (getchar()!='\n') {} gnuplot_close(handle); return; }
int main(int arg, char *argv[]) { int Npoint, dec, line, Nline, sector; double x0, xf; //socket variable SOCKET sock; const char *IP="192.168.128.3"; init_TCP_client(&sock, IP, Port); int Nset=5; char settings[Nset]; receive_TCP_client(&sock, settings, Nset); x0=(double)int_converter(settings[0]); xf=(double)int_converter(settings[1]); dec=int_converter(settings[2]); line=int_converter(settings[3]); Nline=line/2; sector=int_converter(settings[4]); Npoint=(int)(2.0*(xf-x0)*125.0/1.48/((double)dec)); char *buff=(char *)malloc((Npoint+1)*sizeof(char)); //gnuplot variable gnuplot_ctrl * h; double *y= (double *)malloc(Npoint*sizeof(double)); int i,j; //gnuplot object h=gnuplot_init(); gnuplot_setstyle(h,"lines"); gnuplot_set_xlabel(h,"time (us)"); gnuplot_set_ylabel(h,"signal"); gnuplot_cmd(h,"set yrange [1:%d]",Ymax); gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1); while(1) { if (receive_TCP_client(&sock, buff, Npoint+1)==1) { break; } if ((int)(buff[0])==Nline) { for (i=1; i<Npoint+1 ; i++) { y[i-1]=(double)(buff[i]); } gnuplot_resetplot(h); gnuplot_plot_x(h, y, Npoint, "RP"); } } usleep(30); close(sock); free(y); return 0; }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void Plotter::plot(std::vector<double> fx, const std::string& title) { int size = fx.size(); double* fxArray = new double[size]; std::copy(fx.begin(), fx.end(), fxArray); if (_plotter) gnuplot_plot_x(_plotter, fxArray, size, const_cast<char*>(title.c_str())); delete [] fxArray; }
void gnuplot_plot_once( char * title, char * style, char * label_x, char * label_y, double * x, double * y, int n ) { gnuplot_ctrl * handle ; if (x==NULL || n<1) return ; handle = gnuplot_init(); if (style!=NULL) { gnuplot_setstyle(handle, style); } else { gnuplot_setstyle(handle, "lines"); } if (label_x!=NULL) { gnuplot_set_xlabel(handle, label_x); } else { gnuplot_set_xlabel(handle, "X"); } if (label_y!=NULL) { gnuplot_set_ylabel(handle, label_y); } else { gnuplot_set_ylabel(handle, "Y"); } if (y==NULL) { gnuplot_plot_x(handle, x, n, title); } else { gnuplot_plot_xy(handle, x, y, n, title); } printf("press ENTER to continue\n"); while (getchar()!='\n') {} gnuplot_close(handle); return ; }
static void plot(){ gnuplot_resetplot(handle); gnuplot_plot_x(handle, samples, NSAMPLES, ""); }
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; }
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); }
/** * Parses a command. * * @param ctok Command string in strtok. * @param csv_file CSV file location. * @param gp gnuplot object. * @return True if the program should continue running. */ bool parse_cmd_line(char *ctok, char **csv_file, gnuplot_ctrl *gp, char *prompt, bool quiet) { // Command. if (!strcmp(ctok, "quit") || !strcmp(ctok, "exit")) { return false; } else if (!strcmp(ctok, "legend")) { // Toogle legend. if (!strcmp(strtok(NULL, " "), "off")) { gnuplot_cmd(gp, "set key off"); if (!quiet) { printf("Legend turned off.\n"); } } else { gnuplot_cmd(gp, "set key on"); if (!quiet) { printf("Legend turned on.\n"); } } } else if (!strcmp(ctok, "xlabel") || !strcmp(ctok, "ylabel")) { // Set xy label. char arg[64] = ""; char xy = ctok[0]; parse_spaced_arg(arg, ctok); if (!quiet) { printf("%clabel set to \"%s\"\n", xy, arg); } switch (xy) { case 'x': gnuplot_set_xlabel(gp, arg); break; case 'y': gnuplot_set_ylabel(gp, arg); } } else if (!strcmp(ctok, "plot")) { // Plot data. char lg_title[64] = ""; uint8_t col = atoi(strtok(NULL, " ")); double *items = NULL; unsigned int n = 0; parse_spaced_arg(lg_title, ctok); n = read_csv_col(&items, *csv_file, col); gnuplot_setstyle(gp, "lines"); gnuplot_plot_x(gp, items, n, lg_title); } else if (!strcmp(ctok, "gp")) { // Execute raw gnuplot command. char gp_cmd[1024] = ""; parse_spaced_arg(gp_cmd, ctok); gnuplot_cmd(gp, gp_cmd); } else if (!strcmp(ctok, "load")) { // Load CSV. char filename[2048] = ""; parse_spaced_arg(filename, ctok); *csv_file = malloc(strlen(filename) + 1); strcpy(*csv_file, filename); generate_prompt(prompt, *csv_file); } else { printf("Invalid command: %s\n", ctok); } return true; }
/** * 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; }
int main(int argc, char *argv[]) { gnuplot_ctrl * h1, * h2, * h3, * h4 ; double x[NPOINTS] ; double y[NPOINTS] ; int i ; /* * Initialize the gnuplot handle */ printf("*** example of gnuplot control through C ***\n") ; h1 = gnuplot_init() ; /* * Slopes */ gnuplot_setstyle(h1, "lines") ; printf("*** plotting slopes\n") ; printf("y = x\n") ; gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope") ; sleep(SLEEP_LGTH) ; printf("y = 2*x\n") ; gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x") ; sleep(SLEEP_LGTH) ; printf("y = -x\n") ; gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x") ; sleep(SLEEP_LGTH) ; /* * Equations */ gnuplot_resetplot(h1) ; printf("\n\n") ; printf("*** various equations\n") ; printf("y = sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("y = log(x)\n") ; gnuplot_plot_equation(h1, "log(x)", "logarithm") ; sleep(SLEEP_LGTH) ; printf("y = sin(x)*cos(2*x)\n") ; gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product") ; sleep(SLEEP_LGTH) ; /* * Styles */ gnuplot_resetplot(h1) ; printf("\n\n") ; printf("*** showing styles\n") ; printf("sine in points\n") ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("sine in impulses\n") ; gnuplot_setstyle(h1, "impulses") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("sine in steps\n") ; gnuplot_setstyle(h1, "steps") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; /* * User defined 1d and 2d point sets */ gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "impulses") ; printf("\n\n") ; printf("*** user-defined lists of doubles\n") ; for (i=0 ; i<NPOINTS ; i++) { x[i] = (double)i*i ; } gnuplot_plot_x(h1, x, NPOINTS, "user-defined doubles") ; sleep(SLEEP_LGTH) ; printf("*** user-defined lists of points\n"); for (i=0 ; i<NPOINTS ; i++) { x[i] = (double)i ; y[i] = (double)i * (double)i ; } gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_xy(h1, x, y, NPOINTS, "user-defined points") ; sleep(SLEEP_LGTH) ; /* * Multiple output screens */ printf("\n\n") ; printf("*** multiple output windows\n") ; gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "lines") ; h2 = gnuplot_init() ; gnuplot_setstyle(h2, "lines") ; h3 = gnuplot_init() ; gnuplot_setstyle(h3, "lines") ; h4 = gnuplot_init() ; gnuplot_setstyle(h4, "lines") ; printf("window 1: sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sin(x)") ; sleep(SLEEP_LGTH) ; printf("window 2: x*sin(x)\n") ; gnuplot_plot_equation(h2, "x*sin(x)", "x*sin(x)") ; sleep(SLEEP_LGTH) ; printf("window 3: log(x)/x\n") ; gnuplot_plot_equation(h3, "log(x)/x", "log(x)/x"); sleep(SLEEP_LGTH) ; printf("window 4: sin(x)/x\n") ; gnuplot_plot_equation(h4, "sin(x)/x", "sin(x)/x") ; sleep(SLEEP_LGTH) ; /* * close gnuplot handles */ printf("\n\n") ; printf("*** end of gnuplot example\n") ; gnuplot_close(h1) ; gnuplot_close(h2) ; gnuplot_close(h3) ; gnuplot_close(h4) ; return 0 ; }
void TwoStream_Initializer::check_step(ParticleList* particles, HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo) { if(myinfo->myid_mpi == 0) { particles->plot_particles(pdata); double pEnergy = ((fields[0] -> evaluate_energy())); double kEnergy = moments[0] -> evaluate_energy(); Energy_array[nplot] = pEnergy; kEnergy_array[nplot] = kEnergy; TEnergy_array[nplot] = (E0+kE0 - (kEnergy + pEnergy))/(E0+kE0); //printf("Energy Error= %e\n",(E0+kE0 - (Energy_array[nplot]+kEnergy_array[nplot]))/(E0+kE0)); max_t_array[nplot] = (nplot-1)*pdata->dt*2; if(nplot == 1) { max_array[0] = log(Energy_array[0]); max_t_array[nmax_array] = pdata->dt; nmax_array++; } else if(nplot > 1) { if(Energy_array[nplot-1] > fmax(Energy_array[nplot-2],Energy_array[nplot])) { //max_array[nmax_array] = log(Energy_array[nplot-1]); //max_t_array[nmax_array] = (nplot-1); //realkind period = (max_t_array[nmax_array]-max_t_array[nmax_array-1])*pdata->dt; //realkind vphase = 2.0*pi_const/period* 1.0*pdata->Lx/(2.0*pi_const); //printf("Energy fluctuation period = %f\n",period); //printf("Phase velocity = %f\n",vphase); //printf("Energy decay rate = %f\n",(max_array[nmax_array]-max_array[nmax_array-1])/ // (pdata->dt*(max_t_array[nmax_array]-max_t_array[nmax_array-1]))); nmax_array++; } } realkind charge_cons = moments[0] -> check_charge(moments_old); printf("Charge conservation = %e\n",charge_cons); charge_cons_array[nplot] = charge_cons; if((nplot > 0)&&(nplot%10 == 9)) { if(pdata->plot_flag){ gnuplot_resetplot(plot); gnuplot_resetplot(kenergy_plot); gnuplot_resetplot(Tenergy_plot); gnuplot_resetplot(charge_cons_plot); } } nplot++; if((pdata->plot_flag)&&(nplot%10 == 9)) { gnuplot_plot_xy(plot,max_t_array+1,Energy_array+1,nplot-1,"Field Energy"); gnuplot_cmd(plot,"replot \"E_vec.csv\" title \"Matlab Code\" with points"); gnuplot_plot_x(kenergy_plot,kEnergy_array,nplot,"Particle Energy"); gnuplot_plot_x(Tenergy_plot,TEnergy_array,nplot,"Total Energy"); gnuplot_plot_x(charge_cons_plot,charge_cons_array,nplot,"Charge Conservation"); } } }
int main(int argc, char *argv[]) { FILE *inputfiles,*posting_file; int i=0; char *fileinput,*stemming_file,*posting_filename; if(argc < 2) { printf("\nIncorrect Usage. ./keywordengine <filelist.txt>\n"); return 0; } if((inputfiles=fopen(argv[1],"r+"))==NULL) { printf("\nCould not open %s. Exiting\n",argv[1]); exit(0); } if((posting_file=fopen("../output/posting_list_file_input.txt","w"))==NULL) { printf("\nFatal Error! Could not open/create posting_list_file_input.txt. Check output directory.\nErrorcode : %d\n",errno); exit(0); } int after_stemming=0; int before_stemming=0; double ratio=0.0; double array[20]; for(i=0; i<20; i++) { array[i]=0; } while(!feof(inputfiles)) { fileinput=(char *)malloc(sizeof(char)*FILENAME); fscanf(inputfiles,"%s\n",fileinput); stemming_file=(char *)malloc(sizeof(char)*(strlen(fileinput)+8)); strcpy(stemming_file,"output_"); strcat(stemming_file,fileinput); posting_filename=(char *)malloc(sizeof(char)*(strlen(stemming_file)+6)); strcpy(posting_filename,"stem_"); strcat(posting_filename,stemming_file); fprintf(posting_file,"%s\n",posting_filename); /* Tokenise and remove stopwords */ getwords(fileinput); /* Add to postings list */ initialize(); before_stemming=add_document_to_postingslist(stemming_file); /* Apply Porter's Stemmer */ stemmer(stemming_file); /* Add to postings list */ initialize(); after_stemming=add_document_to_postingslist(posting_filename); ratio=(double)after_stemming/before_stemming; //printf("\nbefore=%d and after=%d Ratio= %lf\n",before_stemming,after_stemming,ratio); if(0 <= ratio && 0.05 > ratio ) array[0]++; else if(0.75 <= ratio && 0.765 > ratio ) array[1]++; else if(0.765 <= ratio && 0.780 > ratio ) array[2]++; else if(0.780 <= ratio && 0.795 > ratio ) array[3]++; else if(0.795 <= ratio && 0.810 > ratio ) array[4]++; else if(0.810 <= ratio && 0.825 > ratio ) array[5]++; else if(0.825 <= ratio && 0.840 > ratio ) array[6]++; else if(0.840 <= ratio && 0.855 > ratio ) array[7]++; else if(0.855 <= ratio && 0.870 > ratio ) array[8]++; else if(0.870 <= ratio && 0.885 > ratio ) array[9]++; else if(0.885 <= ratio && 0.9 > ratio ) array[10]++; else if(0.9 <= ratio && 0.915 > ratio ) array[11]++; else if(0.915 <= ratio && 0.930 > ratio ) array[12]++; else if(0.930 <= ratio && 0.945 > ratio ) array[13]++; else if(0.945 <= ratio && 0.960 > ratio ) array[14]++; else if(0.960 <= ratio && 0.975 > ratio ) array[15]++; else if(0.975 <= ratio && 0.990 > ratio ) array[16]++; else if(0.990 <= ratio && 1.05 > ratio ) array[17]++; else if(1.05 <= ratio && 1.20 > ratio ) array[18]++; else if(1.20 <= ratio && 1.35 >= ratio ) array[19]++; i++; free(fileinput); fileinput=NULL; } fclose(posting_file); fclose(inputfiles); gnuplot_ctrl *h1; h1 = gnuplot_init() ; gnuplot_setstyle(h1, "lines"); gnuplot_set_xlabel(h1, "Compression"); gnuplot_set_ylabel(h1, "Frequency"); gnuplot_plot_x(h1, array ,20, "Ratio Graph") ; getchar(); /*Closing the files*/ gnuplot_close(h1); return 0; }
void EnergyCons_Initializer::check_step(ParticleList* particles, HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo) { // Print out the sum of the x-component of the current if(myinfo->myid_mpi == 0) { Energy_array[nplot] = ((fields[0] -> evaluate_energy())); kEnergy_array[nplot] = particles->evaluate_energy(pdata); TEnergy_array[nplot] = kEnergy_array[nplot] + Energy_array[nplot]; printf("Energy Error= %e\n",(E0+kE0 - (Energy_array[nplot]+kEnergy_array[nplot]))/(E0+kE0)); if(nplot == 1) { max_array[0] = log(Energy_array[0]); max_t_array[nmax_array] = pdata->dt; nmax_array++; } else if(nplot > 1) { if(Energy_array[nplot-1] > fmax(Energy_array[nplot-2],Energy_array[nplot])) { max_array[nmax_array] = log(Energy_array[nplot-1]); max_t_array[nmax_array] = (nplot-1); float period = (max_t_array[nmax_array]-max_t_array[nmax_array-1])*pdata->dt; float vphase = 2.0*pi_const/period* 1.0*pdata->Lx/(2.0*pi_const); printf("Energy fluctuation period = %f\n",period); printf("Phase velocity = %f\n",vphase); printf("Energy decay rate = %f\n",(max_array[nmax_array]-max_array[nmax_array-1])/ (pdata->dt*(max_t_array[nmax_array]-max_t_array[nmax_array-1]))); nmax_array++; } } if(nplot > 0) { gnuplot_resetplot(plot); gnuplot_resetplot(kenergy_plot); gnuplot_resetplot(Tenergy_plot); } nplot++; gnuplot_plot_x(plot,Energy_array,nplot,"Field Energy"); gnuplot_plot_x(kenergy_plot,kEnergy_array,nplot,"Particle Energy"); gnuplot_plot_x(Tenergy_plot,TEnergy_array,nplot,"Total Energy"); //gnuplot_setstyle(plot,"lines"); gnuplot_plot_xy(plot,max_t_array,max_array,nmax_array,NULL); //gnuplot_setstyle(plot,"points"); } }